aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_v2.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c209
1 files changed, 0 insertions, 209 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
deleted file mode 100644
index 7567c2981..000000000
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ /dev/null
@@ -1,209 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_netjail_start_v2.c
23 * @brief Command to start the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define NETJAIL_START_SCRIPT "./../testing/netjail_start_v2.sh"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct NetJailState
37{
38 /**
39 * Context for our asynchronous completion.
40 */
41 struct GNUNET_TESTING_AsyncContext ac;
42
43 // Child Wait handle
44 struct GNUNET_ChildWaitHandle *cwh;
45
46 /**
47 * Configuration file for the test topology.
48 */
49 char *topology_config;
50
51 /**
52 * The process id of the start script.
53 */
54 struct GNUNET_OS_Process *start_proc;
55
56};
57
58
59/**
60 * The cleanup function of this cmd frees resources the cmd allocated.
61 *
62 */
63static void
64netjail_start_cleanup (void *cls)
65{
66 struct NetJailState *ns = cls;
67
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
69 "netjail_start_cleanup!\n");
70
71 if (NULL != ns->cwh)
72 {
73 GNUNET_wait_child_cancel (ns->cwh);
74 ns->cwh = NULL;
75 }
76 if (NULL != ns->start_proc)
77 {
78 GNUNET_assert (0 ==
79 GNUNET_OS_process_kill (ns->start_proc,
80 SIGKILL));
81 GNUNET_assert (GNUNET_OK ==
82 GNUNET_OS_process_wait (ns->start_proc));
83 GNUNET_OS_process_destroy (ns->start_proc);
84 ns->start_proc = NULL;
85 }
86 GNUNET_free (ns);
87}
88
89
90/**
91 * Callback which will be called if the setup script finished.
92 *
93 */
94static void
95child_completed_callback (void *cls,
96 enum GNUNET_OS_ProcessStatusType type,
97 long unsigned int exit_code)
98{
99 struct NetJailState *ns = cls;
100
101 GNUNET_OS_process_destroy (ns->start_proc);
102 ns->start_proc = NULL;
103 if (0 == exit_code)
104 {
105 GNUNET_TESTING_async_finish (&ns->ac);
106 }
107 else
108 {
109 // FIXME: log status code
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
111 "Child completed with an error!\n");
112 GNUNET_TESTING_async_fail (&ns->ac);
113 }
114}
115
116
117/**
118* The run method starts the script which setup the network namespaces.
119*
120* @param cls closure.
121* @param is interpreter state.
122*/
123static void
124netjail_start_run (void *cls,
125 struct GNUNET_TESTING_Interpreter *is)
126{
127 struct NetJailState *ns = cls;
128 char pid[15];
129 enum GNUNET_GenericReturnValue helper_check;
130
131 // FIXME: NETJAIL_START_SCRIPT like this is bad,
132 // use location from share/gnunet/ of installed
133 // binary in case libgnunettesting is used as a lib!
134 helper_check = GNUNET_OS_check_helper_binary (
135 NETJAIL_START_SCRIPT,
136 GNUNET_YES,
137 NULL);
138
139 if (GNUNET_NO == helper_check)
140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 "No SUID for %s!\n",
143 NETJAIL_START_SCRIPT);
144 GNUNET_TESTING_interpreter_fail (is);
145 return;
146 }
147 if (GNUNET_SYSERR == helper_check)
148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "%s not found!\n",
151 NETJAIL_START_SCRIPT);
152 GNUNET_TESTING_interpreter_fail (is);
153 return;
154 }
155
156 GNUNET_snprintf (pid,
157 sizeof (pid),
158 "%u",
159 getpid ());
160 {
161 char *const script_argv[] = {
162 NETJAIL_START_SCRIPT,
163 ns->topology_config,
164 pid,
165 NULL
166 };
167
168 ns->start_proc
169 = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
170 NULL,
171 NULL,
172 NULL,
173 NETJAIL_START_SCRIPT,
174 script_argv);
175 }
176 ns->cwh = GNUNET_wait_child (ns->start_proc,
177 &child_completed_callback,
178 ns);
179 GNUNET_break (NULL != ns->cwh);
180}
181
182
183/**
184 * Create command.
185 *
186 * @param label name for command.
187 * @param topology_config Configuration file for the test topology.
188 * @return command.
189 */
190struct GNUNET_TESTING_Command
191GNUNET_TESTING_cmd_netjail_start_v2 (const char *label,
192 char *topology_config)
193{
194 struct NetJailState *ns;
195
196 ns = GNUNET_new (struct NetJailState);
197 ns->topology_config = topology_config;
198 {
199 struct GNUNET_TESTING_Command cmd = {
200 .cls = ns,
201 .label = label,
202 .run = &netjail_start_run,
203 .ac = &ns->ac,
204 .cleanup = &netjail_start_cleanup
205 };
206
207 return cmd;
208 }
209}