aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 35fb90f3c..2ff70c33e 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -26,8 +26,11 @@
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#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" 31#define NETJAIL_START_SCRIPT "netjail_start.sh"
32
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
31 34
32/** 35/**
33 * Struct to hold information for callbacks. 36 * Struct to hold information for callbacks.
@@ -53,6 +56,10 @@ struct NetJailState
53 */ 56 */
54 char *topology_config; 57 char *topology_config;
55 58
59 /**
60 * Shall we read the topology from file, or from a string.
61 */
62 unsigned int *read_file;
56}; 63};
57 64
58 65
@@ -70,11 +77,15 @@ netjail_start_cleanup (void *cls)
70 77
71 if (NULL != ns->cwh) 78 if (NULL != ns->cwh)
72 { 79 {
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Cancel child\n");
73 GNUNET_wait_child_cancel (ns->cwh); 82 GNUNET_wait_child_cancel (ns->cwh);
74 ns->cwh = NULL; 83 ns->cwh = NULL;
75 } 84 }
76 if (NULL != ns->start_proc) 85 if (NULL != ns->start_proc)
77 { 86 {
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
88 "Kill process\n");
78 GNUNET_assert (0 == 89 GNUNET_assert (0 ==
79 GNUNET_OS_process_kill (ns->start_proc, 90 GNUNET_OS_process_kill (ns->start_proc,
80 SIGKILL)); 91 SIGKILL));
@@ -100,6 +111,7 @@ child_completed_callback (void *cls,
100 111
101 GNUNET_OS_process_destroy (ns->start_proc); 112 GNUNET_OS_process_destroy (ns->start_proc);
102 ns->start_proc = NULL; 113 ns->start_proc = NULL;
114 ns->cwh = NULL;
103 if (0 == exit_code) 115 if (0 == exit_code)
104 { 116 {
105 GNUNET_TESTING_async_finish (&ns->ac); 117 GNUNET_TESTING_async_finish (&ns->ac);
@@ -127,20 +139,28 @@ netjail_start_run (void *cls,
127 struct NetJailState *ns = cls; 139 struct NetJailState *ns = cls;
128 char pid[15]; 140 char pid[15];
129 enum GNUNET_GenericReturnValue helper_check; 141 enum GNUNET_GenericReturnValue helper_check;
142 char *data_dir;
143 char *script_name;
144 char *read_file;
145
146 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
147 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT);
148 GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
130 149
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 ( 150 helper_check = GNUNET_OS_check_helper_binary (
135 NETJAIL_START_SCRIPT, 151 script_name,
136 GNUNET_YES, 152 GNUNET_YES,
137 NULL); 153 NULL);
138 154
155 LOG (GNUNET_ERROR_TYPE_DEBUG,
156 "script_name %s\n",
157 script_name);
158
139 if (GNUNET_NO == helper_check) 159 if (GNUNET_NO == helper_check)
140 { 160 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 "No SUID for %s!\n", 162 "No SUID for %s!\n",
143 NETJAIL_START_SCRIPT); 163 script_name);
144 GNUNET_TESTING_interpreter_fail (is); 164 GNUNET_TESTING_interpreter_fail (is);
145 return; 165 return;
146 } 166 }
@@ -148,7 +168,7 @@ netjail_start_run (void *cls,
148 { 168 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "%s not found!\n", 170 "%s not found!\n",
151 NETJAIL_START_SCRIPT); 171 script_name);
152 GNUNET_TESTING_interpreter_fail (is); 172 GNUNET_TESTING_interpreter_fail (is);
153 return; 173 return;
154 } 174 }
@@ -159,9 +179,10 @@ netjail_start_run (void *cls,
159 getpid ()); 179 getpid ());
160 { 180 {
161 char *const script_argv[] = { 181 char *const script_argv[] = {
162 NETJAIL_START_SCRIPT, 182 script_name,
163 ns->topology_config, 183 ns->topology_config,
164 pid, 184 pid,
185 read_file,
165 NULL 186 NULL
166 }; 187 };
167 188
@@ -170,7 +191,7 @@ netjail_start_run (void *cls,
170 NULL, 191 NULL,
171 NULL, 192 NULL,
172 NULL, 193 NULL,
173 NETJAIL_START_SCRIPT, 194 script_name,
174 script_argv); 195 script_argv);
175 } 196 }
176 ns->cwh = GNUNET_wait_child (ns->start_proc, 197 ns->cwh = GNUNET_wait_child (ns->start_proc,
@@ -189,12 +210,14 @@ netjail_start_run (void *cls,
189 */ 210 */
190struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
191GNUNET_TESTING_cmd_netjail_start (const char *label, 212GNUNET_TESTING_cmd_netjail_start (const char *label,
192 char *topology_config) 213 char *topology_config,
214 unsigned int *read_file)
193{ 215{
194 struct NetJailState *ns; 216 struct NetJailState *ns;
195 217
196 ns = GNUNET_new (struct NetJailState); 218 ns = GNUNET_new (struct NetJailState);
197 ns->topology_config = topology_config; 219 ns->topology_config = topology_config;
220 ns->read_file = read_file;
198 { 221 {
199 struct GNUNET_TESTING_Command cmd = { 222 struct GNUNET_TESTING_Command cmd = {
200 .cls = ns, 223 .cls = ns,