diff options
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_stop.c')
-rw-r--r-- | src/testing/testing_api_cmd_netjail_stop.c | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 5033272a3..e3bf7da62 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c | |||
@@ -26,12 +26,10 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | 30 | ||
30 | 31 | ||
31 | #define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" | 32 | #define NETJAIL_STOP_SCRIPT "netjail_stop.sh" |
32 | |||
33 | // Child Wait handle | ||
34 | static struct GNUNET_ChildWaitHandle *cwh; | ||
35 | 33 | ||
36 | /** | 34 | /** |
37 | * Struct to hold information for callbacks. | 35 | * Struct to hold information for callbacks. |
@@ -44,6 +42,9 @@ struct NetJailState | |||
44 | */ | 42 | */ |
45 | struct GNUNET_TESTING_AsyncContext ac; | 43 | struct GNUNET_TESTING_AsyncContext ac; |
46 | 44 | ||
45 | // Child Wait handle | ||
46 | struct GNUNET_ChildWaitHandle *cwh; | ||
47 | |||
47 | /** | 48 | /** |
48 | * Configuration file for the test topology. | 49 | * Configuration file for the test topology. |
49 | */ | 50 | */ |
@@ -54,6 +55,11 @@ struct NetJailState | |||
54 | */ | 55 | */ |
55 | struct GNUNET_OS_Process *stop_proc; | 56 | struct GNUNET_OS_Process *stop_proc; |
56 | 57 | ||
58 | /** | ||
59 | * Shall we read the topology from file, or from a string. | ||
60 | */ | ||
61 | unsigned int *read_file; | ||
62 | |||
57 | }; | 63 | }; |
58 | 64 | ||
59 | 65 | ||
@@ -66,10 +72,10 @@ netjail_stop_cleanup (void *cls) | |||
66 | { | 72 | { |
67 | struct NetJailState *ns = cls; | 73 | struct NetJailState *ns = cls; |
68 | 74 | ||
69 | if (NULL != cwh) | 75 | if (NULL != ns->cwh) |
70 | { | 76 | { |
71 | GNUNET_wait_child_cancel (cwh); | 77 | GNUNET_wait_child_cancel (ns->cwh); |
72 | cwh = NULL; | 78 | ns->cwh = NULL; |
73 | } | 79 | } |
74 | if (NULL != ns->stop_proc) | 80 | if (NULL != ns->stop_proc) |
75 | { | 81 | { |
@@ -95,7 +101,7 @@ child_completed_callback (void *cls, | |||
95 | { | 101 | { |
96 | struct NetJailState *ns = cls; | 102 | struct NetJailState *ns = cls; |
97 | 103 | ||
98 | cwh = NULL; // WTF? globals!?!?! | 104 | ns->cwh = NULL; |
99 | GNUNET_OS_process_destroy (ns->stop_proc); | 105 | GNUNET_OS_process_destroy (ns->stop_proc); |
100 | ns->stop_proc = NULL; | 106 | ns->stop_proc = NULL; |
101 | if (0 == exit_code) | 107 | if (0 == exit_code) |
@@ -121,16 +127,16 @@ netjail_stop_run (void *cls, | |||
121 | { | 127 | { |
122 | struct NetJailState *ns = cls; | 128 | struct NetJailState *ns = cls; |
123 | char *pid; | 129 | char *pid; |
130 | char *data_dir; | ||
131 | char *script_name; | ||
132 | char *read_file; | ||
124 | 133 | ||
125 | GNUNET_asprintf (&pid, | 134 | |
126 | "%u", | 135 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
127 | getpid ()); | 136 | GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT); |
128 | char *const script_argv[] = {NETJAIL_STOP_SCRIPT, | 137 | GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); |
129 | ns->topology_config, | ||
130 | pid, | ||
131 | NULL}; | ||
132 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( | 138 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( |
133 | NETJAIL_STOP_SCRIPT, | 139 | script_name, |
134 | GNUNET_YES, | 140 | GNUNET_YES, |
135 | NULL); | 141 | NULL); |
136 | 142 | ||
@@ -138,39 +144,50 @@ netjail_stop_run (void *cls, | |||
138 | { | 144 | { |
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
140 | "No SUID for %s!\n", | 146 | "No SUID for %s!\n", |
141 | NETJAIL_STOP_SCRIPT); | 147 | script_name); |
142 | GNUNET_TESTING_interpreter_fail (is); | 148 | GNUNET_TESTING_interpreter_fail (is); |
143 | } | 149 | } |
144 | else if (GNUNET_NO == helper_check) | 150 | else if (GNUNET_NO == helper_check) |
145 | { | 151 | { |
146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
147 | "%s not found!\n", | 153 | "%s not found!\n", |
148 | NETJAIL_STOP_SCRIPT); | 154 | script_name); |
149 | GNUNET_TESTING_interpreter_fail (is); | 155 | GNUNET_TESTING_interpreter_fail (is); |
150 | } | 156 | } |
151 | 157 | ||
152 | ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, | 158 | GNUNET_asprintf (&pid, |
153 | NULL, | 159 | "%u", |
154 | NULL, | 160 | getpid ()); |
155 | NULL, | 161 | { |
156 | NETJAIL_STOP_SCRIPT, | 162 | char *const script_argv[] = {script_name, |
157 | script_argv); | 163 | ns->topology_config, |
158 | 164 | pid, | |
159 | cwh = GNUNET_wait_child (ns->stop_proc, | 165 | read_file, |
160 | &child_completed_callback, | 166 | NULL}; |
161 | ns); | 167 | ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, |
162 | GNUNET_break (NULL != cwh); | 168 | NULL, |
169 | NULL, | ||
170 | NULL, | ||
171 | script_name, | ||
172 | script_argv); | ||
173 | } | ||
174 | ns->cwh = GNUNET_wait_child (ns->stop_proc, | ||
175 | &child_completed_callback, | ||
176 | ns); | ||
177 | GNUNET_break (NULL != ns->cwh); | ||
163 | } | 178 | } |
164 | 179 | ||
165 | 180 | ||
166 | struct GNUNET_TESTING_Command | 181 | struct GNUNET_TESTING_Command |
167 | GNUNET_TESTING_cmd_netjail_stop (const char *label, | 182 | GNUNET_TESTING_cmd_netjail_stop (const char *label, |
168 | char *topology_config) | 183 | char *topology_config, |
184 | unsigned int *read_file) | ||
169 | { | 185 | { |
170 | struct NetJailState *ns; | 186 | struct NetJailState *ns; |
171 | 187 | ||
172 | ns = GNUNET_new (struct NetJailState); | 188 | ns = GNUNET_new (struct NetJailState); |
173 | ns->topology_config = topology_config; | 189 | ns->topology_config = topology_config; |
190 | ns->read_file = read_file; | ||
174 | { | 191 | { |
175 | struct GNUNET_TESTING_Command cmd = { | 192 | struct GNUNET_TESTING_Command cmd = { |
176 | .cls = ns, | 193 | .cls = ns, |