aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_stop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_stop.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c116
1 files changed, 38 insertions, 78 deletions
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 99084d9af..5033272a3 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -19,7 +19,7 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file testing/testing_api_cmd_hello_world.c 22 * @file testing/testing_api_cmd_netjail_stop.c
23 * @brief Command to stop the netjail script. 23 * @brief Command to stop the netjail script.
24 * @author t3sserakt 24 * @author t3sserakt
25 */ 25 */
@@ -31,7 +31,7 @@
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" 31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
32 32
33// Child Wait handle 33// Child Wait handle
34struct GNUNET_ChildWaitHandle *cwh; 34static struct GNUNET_ChildWaitHandle *cwh;
35 35
36/** 36/**
37 * Struct to hold information for callbacks. 37 * Struct to hold information for callbacks.
@@ -39,19 +39,21 @@ struct GNUNET_ChildWaitHandle *cwh;
39 */ 39 */
40struct NetJailState 40struct NetJailState
41{ 41{
42 // Number of local nodes in each namespace. 42 /**
43 char *local_m; 43 * Context for our asynchronous completion.
44 */
45 struct GNUNET_TESTING_AsyncContext ac;
44 46
45 // The number of namespaces. 47 /**
46 char *global_n; 48 * Configuration file for the test topology.
49 */
50 char *topology_config;
47 51
48 /** 52 /**
49 * The process id of the start script. 53 * The process id of the start script.
50 */ 54 */
51 struct GNUNET_OS_Process *stop_proc; 55 struct GNUNET_OS_Process *stop_proc;
52 56
53 // Flag indication if the script finished.
54 unsigned int finished;
55}; 57};
56 58
57 59
@@ -60,8 +62,7 @@ struct NetJailState
60 * 62 *
61 */ 63 */
62static void 64static void
63netjail_stop_cleanup (void *cls, 65netjail_stop_cleanup (void *cls)
64 const struct GNUNET_TESTING_Command *cmd)
65{ 66{
66 struct NetJailState *ns = cls; 67 struct NetJailState *ns = cls;
67 68
@@ -84,20 +85,6 @@ netjail_stop_cleanup (void *cls,
84 85
85 86
86/** 87/**
87 * Trait function of this cmd does nothing.
88 *
89 */
90static int
91netjail_stop_traits (void *cls,
92 const void **ret,
93 const char *trait,
94 unsigned int index)
95{
96 return GNUNET_OK;
97}
98
99
100/**
101 * Callback which will be called if the setup script finished. 88 * Callback which will be called if the setup script finished.
102 * 89 *
103 */ 90 */
@@ -108,17 +95,17 @@ child_completed_callback (void *cls,
108{ 95{
109 struct NetJailState *ns = cls; 96 struct NetJailState *ns = cls;
110 97
111 cwh = NULL; 98 cwh = NULL; // WTF? globals!?!?!
99 GNUNET_OS_process_destroy (ns->stop_proc);
100 ns->stop_proc = NULL;
112 if (0 == exit_code) 101 if (0 == exit_code)
113 { 102 {
114 ns->finished = GNUNET_YES; 103 GNUNET_TESTING_async_finish (&ns->ac);
115 } 104 }
116 else 105 else
117 { 106 {
118 ns->finished = GNUNET_SYSERR; 107 GNUNET_TESTING_async_fail (&ns->ac);
119 } 108 }
120 GNUNET_OS_process_destroy (ns->stop_proc);
121 ns->stop_proc = NULL;
122} 109}
123 110
124 111
@@ -126,18 +113,21 @@ child_completed_callback (void *cls,
126* The run method starts the script which deletes the network namespaces. 113* The run method starts the script which deletes the network namespaces.
127* 114*
128* @param cls closure. 115* @param cls closure.
129* @param cmd CMD being run.
130* @param is interpreter state. 116* @param is interpreter state.
131*/ 117*/
132static void 118static void
133netjail_stop_run (void *cls, 119netjail_stop_run (void *cls,
134 const struct GNUNET_TESTING_Command *cmd,
135 struct GNUNET_TESTING_Interpreter *is) 120 struct GNUNET_TESTING_Interpreter *is)
136{ 121{
137 struct NetJailState *ns = cls; 122 struct NetJailState *ns = cls;
123 char *pid;
124
125 GNUNET_asprintf (&pid,
126 "%u",
127 getpid ());
138 char *const script_argv[] = {NETJAIL_STOP_SCRIPT, 128 char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
139 ns->local_m, 129 ns->topology_config,
140 ns->global_n, 130 pid,
141 NULL}; 131 NULL};
142 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 132 unsigned int helper_check = GNUNET_OS_check_helper_binary (
143 NETJAIL_STOP_SCRIPT, 133 NETJAIL_STOP_SCRIPT,
@@ -149,14 +139,14 @@ netjail_stop_run (void *cls,
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "No SUID for %s!\n", 140 "No SUID for %s!\n",
151 NETJAIL_STOP_SCRIPT); 141 NETJAIL_STOP_SCRIPT);
152 GNUNET_TESTING_interpreter_fail (); 142 GNUNET_TESTING_interpreter_fail (is);
153 } 143 }
154 else if (GNUNET_NO == helper_check) 144 else if (GNUNET_NO == helper_check)
155 { 145 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "%s not found!\n", 147 "%s not found!\n",
158 NETJAIL_STOP_SCRIPT); 148 NETJAIL_STOP_SCRIPT);
159 GNUNET_TESTING_interpreter_fail (); 149 GNUNET_TESTING_interpreter_fail (is);
160 } 150 }
161 151
162 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 152 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
@@ -170,56 +160,26 @@ netjail_stop_run (void *cls,
170 &child_completed_callback, 160 &child_completed_callback,
171 ns); 161 ns);
172 GNUNET_break (NULL != cwh); 162 GNUNET_break (NULL != cwh);
173
174} 163}
175 164
176 165
177/**
178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 *
180 */
181static int
182netjail_stop_finish (void *cls,
183 GNUNET_SCHEDULER_TaskCallback cont,
184 void *cont_cls)
185{
186 struct NetJailState *ns = cls;
187
188 if (ns->finished)
189 {
190 cont (cont_cls);
191 }
192 return ns->finished;
193}
194
195
196/**
197 * Create command.
198 *
199 * @param label name for command.
200 * @param local_m Number of local nodes in each namespace.
201 * @param global_n The number of namespaces.
202 * @return command.
203 */
204struct GNUNET_TESTING_Command 166struct GNUNET_TESTING_Command
205GNUNET_TESTING_cmd_netjail_stop (const char *label, 167GNUNET_TESTING_cmd_netjail_stop (const char *label,
206 char *local_m, 168 char *topology_config)
207 char *global_n)
208{ 169{
209 struct NetJailState *ns; 170 struct NetJailState *ns;
210 171
211 ns = GNUNET_new (struct NetJailState); 172 ns = GNUNET_new (struct NetJailState);
212 ns->local_m = local_m; 173 ns->topology_config = topology_config;
213 ns->global_n = global_n; 174 {
214 175 struct GNUNET_TESTING_Command cmd = {
215 struct GNUNET_TESTING_Command cmd = { 176 .cls = ns,
216 .cls = ns, 177 .label = label,
217 .label = label, 178 .run = &netjail_stop_run,
218 .run = &netjail_stop_run, 179 .ac = &ns->ac,
219 .finish = &netjail_stop_finish, 180 .cleanup = &netjail_stop_cleanup
220 .cleanup = &netjail_stop_cleanup, 181 };
221 .traits = &netjail_stop_traits 182
222 }; 183 return cmd;
223 184 }
224 return cmd;
225} 185}