diff options
Diffstat (limited to 'src/testbed/gnunet-helper-testbed.c')
-rw-r--r-- | src/testbed/gnunet-helper-testbed.c | 558 |
1 files changed, 280 insertions, 278 deletions
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index 0650e7dbd..f7d089d93 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c | |||
@@ -49,12 +49,12 @@ | |||
49 | /** | 49 | /** |
50 | * Generic logging shortcut | 50 | * Generic logging shortcut |
51 | */ | 51 | */ |
52 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) | 52 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Debug logging shorthand | 55 | * Debug logging shorthand |
56 | */ | 56 | */ |
57 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 57 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
@@ -66,7 +66,8 @@ | |||
66 | /** | 66 | /** |
67 | * Context for a single write on a chunk of memory | 67 | * Context for a single write on a chunk of memory |
68 | */ | 68 | */ |
69 | struct WriteContext { | 69 | struct WriteContext |
70 | { | ||
70 | /** | 71 | /** |
71 | * The data to write | 72 | * The data to write |
72 | */ | 73 | */ |
@@ -146,50 +147,50 @@ static int status; | |||
146 | * @param cls NULL | 147 | * @param cls NULL |
147 | */ | 148 | */ |
148 | static void | 149 | static void |
149 | shutdown_task(void *cls) | 150 | shutdown_task (void *cls) |
150 | { | 151 | { |
151 | LOG_DEBUG("Shutting down\n"); | 152 | LOG_DEBUG ("Shutting down\n"); |
152 | if (NULL != testbed) | 153 | if (NULL != testbed) |
153 | { | 154 | { |
154 | LOG_DEBUG("Killing testbed\n"); | 155 | LOG_DEBUG ("Killing testbed\n"); |
155 | GNUNET_break(0 == GNUNET_OS_process_kill(testbed, GNUNET_TERM_SIG)); | 156 | GNUNET_break (0 == GNUNET_OS_process_kill (testbed, GNUNET_TERM_SIG)); |
156 | } | 157 | } |
157 | if (NULL != read_task_id) | 158 | if (NULL != read_task_id) |
158 | { | 159 | { |
159 | GNUNET_SCHEDULER_cancel(read_task_id); | 160 | GNUNET_SCHEDULER_cancel (read_task_id); |
160 | read_task_id = NULL; | 161 | read_task_id = NULL; |
161 | } | 162 | } |
162 | if (NULL != write_task_id) | 163 | if (NULL != write_task_id) |
163 | { | 164 | { |
164 | struct WriteContext *wc; | 165 | struct WriteContext *wc; |
165 | 166 | ||
166 | wc = GNUNET_SCHEDULER_cancel(write_task_id); | 167 | wc = GNUNET_SCHEDULER_cancel (write_task_id); |
167 | write_task_id = NULL; | 168 | write_task_id = NULL; |
168 | GNUNET_free(wc->data); | 169 | GNUNET_free (wc->data); |
169 | GNUNET_free(wc); | 170 | GNUNET_free (wc); |
170 | } | 171 | } |
171 | if (NULL != child_death_task_id) | 172 | if (NULL != child_death_task_id) |
172 | { | 173 | { |
173 | GNUNET_SCHEDULER_cancel(child_death_task_id); | 174 | GNUNET_SCHEDULER_cancel (child_death_task_id); |
174 | child_death_task_id = NULL; | 175 | child_death_task_id = NULL; |
175 | } | 176 | } |
176 | if (NULL != stdin_fd) | 177 | if (NULL != stdin_fd) |
177 | (void)GNUNET_DISK_file_close(stdin_fd); | 178 | (void) GNUNET_DISK_file_close (stdin_fd); |
178 | if (NULL != stdout_fd) | 179 | if (NULL != stdout_fd) |
179 | (void)GNUNET_DISK_file_close(stdout_fd); | 180 | (void) GNUNET_DISK_file_close (stdout_fd); |
180 | GNUNET_MST_destroy(tokenizer); | 181 | GNUNET_MST_destroy (tokenizer); |
181 | tokenizer = NULL; | 182 | tokenizer = NULL; |
182 | if (NULL != testbed) | 183 | if (NULL != testbed) |
183 | { | 184 | { |
184 | GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(testbed)); | 185 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (testbed)); |
185 | GNUNET_OS_process_destroy(testbed); | 186 | GNUNET_OS_process_destroy (testbed); |
186 | testbed = NULL; | 187 | testbed = NULL; |
187 | } | 188 | } |
188 | if (NULL != test_system) | 189 | if (NULL != test_system) |
189 | { | 190 | { |
190 | GNUNET_TESTING_system_destroy(test_system, GNUNET_YES); | 191 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); |
191 | test_system = NULL; | 192 | test_system = NULL; |
192 | } | 193 | } |
193 | } | 194 | } |
194 | 195 | ||
195 | 196 | ||
@@ -199,34 +200,34 @@ shutdown_task(void *cls) | |||
199 | * @param cls the WriteContext | 200 | * @param cls the WriteContext |
200 | */ | 201 | */ |
201 | static void | 202 | static void |
202 | write_task(void *cls) | 203 | write_task (void *cls) |
203 | { | 204 | { |
204 | struct WriteContext *wc = cls; | 205 | struct WriteContext *wc = cls; |
205 | ssize_t bytes_wrote; | 206 | ssize_t bytes_wrote; |
206 | 207 | ||
207 | GNUNET_assert(NULL != wc); | 208 | GNUNET_assert (NULL != wc); |
208 | write_task_id = NULL; | 209 | write_task_id = NULL; |
209 | bytes_wrote = GNUNET_DISK_file_write(stdout_fd, | 210 | bytes_wrote = GNUNET_DISK_file_write (stdout_fd, |
210 | wc->data + wc->pos, | 211 | wc->data + wc->pos, |
211 | wc->length - wc->pos); | 212 | wc->length - wc->pos); |
212 | if (GNUNET_SYSERR == bytes_wrote) | 213 | if (GNUNET_SYSERR == bytes_wrote) |
213 | { | 214 | { |
214 | LOG(GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); | 215 | LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); |
215 | GNUNET_free(wc->data); | 216 | GNUNET_free (wc->data); |
216 | GNUNET_free(wc); | 217 | GNUNET_free (wc); |
217 | return; | 218 | return; |
218 | } | 219 | } |
219 | wc->pos += bytes_wrote; | 220 | wc->pos += bytes_wrote; |
220 | if (wc->pos == wc->length) | 221 | if (wc->pos == wc->length) |
221 | { | 222 | { |
222 | GNUNET_free(wc->data); | 223 | GNUNET_free (wc->data); |
223 | GNUNET_free(wc); | 224 | GNUNET_free (wc); |
224 | return; | 225 | return; |
225 | } | 226 | } |
226 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, | 227 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
227 | stdout_fd, | 228 | stdout_fd, |
228 | &write_task, | 229 | &write_task, |
229 | wc); | 230 | wc); |
230 | } | 231 | } |
231 | 232 | ||
232 | 233 | ||
@@ -237,7 +238,7 @@ write_task(void *cls) | |||
237 | * @param cls closure, NULL if we need to self-restart | 238 | * @param cls closure, NULL if we need to self-restart |
238 | */ | 239 | */ |
239 | static void | 240 | static void |
240 | child_death_task(void *cls) | 241 | child_death_task (void *cls) |
241 | { | 242 | { |
242 | const struct GNUNET_DISK_FileHandle *pr; | 243 | const struct GNUNET_DISK_FileHandle *pr; |
243 | char c[16]; | 244 | char c[16]; |
@@ -245,36 +246,36 @@ child_death_task(void *cls) | |||
245 | unsigned long code; | 246 | unsigned long code; |
246 | int ret; | 247 | int ret; |
247 | 248 | ||
248 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); | 249 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); |
249 | child_death_task_id = NULL; | 250 | child_death_task_id = NULL; |
250 | /* consume the signal */ | 251 | /* consume the signal */ |
251 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); | 252 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c))); |
252 | LOG_DEBUG("Got SIGCHLD\n"); | 253 | LOG_DEBUG ("Got SIGCHLD\n"); |
253 | if (NULL == testbed) | 254 | if (NULL == testbed) |
254 | { | 255 | { |
255 | GNUNET_break(0); | 256 | GNUNET_break (0); |
256 | return; | 257 | return; |
257 | } | 258 | } |
258 | GNUNET_break(GNUNET_SYSERR != | 259 | GNUNET_break (GNUNET_SYSERR != |
259 | (ret = GNUNET_OS_process_status(testbed, &type, &code))); | 260 | (ret = GNUNET_OS_process_status (testbed, &type, &code))); |
260 | if (GNUNET_NO != ret) | 261 | if (GNUNET_NO != ret) |
262 | { | ||
263 | GNUNET_OS_process_destroy (testbed); | ||
264 | testbed = NULL; | ||
265 | /* Send SIGTERM to our process group */ | ||
266 | if (0 != kill (0, GNUNET_TERM_SIG)) | ||
261 | { | 267 | { |
262 | GNUNET_OS_process_destroy(testbed); | 268 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); |
263 | testbed = NULL; | 269 | GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */ |
264 | /* Send SIGTERM to our process group */ | ||
265 | if (0 != kill(0, GNUNET_TERM_SIG)) | ||
266 | { | ||
267 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "signal"); | ||
268 | GNUNET_SCHEDULER_shutdown(); /* Couldn't send the signal, we shutdown frowning */ | ||
269 | } | ||
270 | return; | ||
271 | } | 270 | } |
272 | LOG_DEBUG("Child hasn't died. Resuming to monitor its status\n"); | 271 | return; |
272 | } | ||
273 | LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); | ||
273 | child_death_task_id = | 274 | child_death_task_id = |
274 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 275 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
275 | pr, | 276 | pr, |
276 | &child_death_task, | 277 | &child_death_task, |
277 | NULL); | 278 | NULL); |
278 | } | 279 | } |
279 | 280 | ||
280 | 281 | ||
@@ -291,7 +292,7 @@ child_death_task(void *cls) | |||
291 | * #GNUNET_SYSERR to stop further processing with error | 292 | * #GNUNET_SYSERR to stop further processing with error |
292 | */ | 293 | */ |
293 | static int | 294 | static int |
294 | tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) | 295 | tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) |
295 | { | 296 | { |
296 | const struct GNUNET_TESTBED_HelperInit *msg; | 297 | const struct GNUNET_TESTBED_HelperInit *msg; |
297 | struct GNUNET_TESTBED_HelperReply *reply; | 298 | struct GNUNET_TESTBED_HelperReply *reply; |
@@ -303,7 +304,7 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) | |||
303 | char *config; | 304 | char *config; |
304 | char *xconfig; | 305 | char *xconfig; |
305 | char *evstr; | 306 | char *evstr; |
306 | //char *str; | 307 | // char *str; |
307 | size_t config_size; | 308 | size_t config_size; |
308 | uLongf ul_config_size; | 309 | uLongf ul_config_size; |
309 | size_t xconfig_size; | 310 | size_t xconfig_size; |
@@ -311,177 +312,177 @@ tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) | |||
311 | uint16_t hostname_size; | 312 | uint16_t hostname_size; |
312 | uint16_t msize; | 313 | uint16_t msize; |
313 | 314 | ||
314 | msize = ntohs(message->size); | 315 | msize = ntohs (message->size); |
315 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || | 316 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || |
316 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs(message->type))) | 317 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) |
317 | { | 318 | { |
318 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 319 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
319 | goto error; | 320 | goto error; |
320 | } | 321 | } |
321 | msg = (const struct GNUNET_TESTBED_HelperInit *)message; | 322 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; |
322 | trusted_ip_size = ntohs(msg->trusted_ip_size); | 323 | trusted_ip_size = ntohs (msg->trusted_ip_size); |
323 | trusted_ip = (char *)&msg[1]; | 324 | trusted_ip = (char *) &msg[1]; |
324 | if ('\0' != trusted_ip[trusted_ip_size]) | 325 | if ('\0' != trusted_ip[trusted_ip_size]) |
325 | { | 326 | { |
326 | LOG(GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); | 327 | LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); |
327 | goto error; | 328 | goto error; |
328 | } | 329 | } |
329 | hostname_size = ntohs(msg->hostname_size); | 330 | hostname_size = ntohs (msg->hostname_size); |
330 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + | 331 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 |
331 | hostname_size) >= msize) | 332 | + hostname_size) >= msize) |
332 | { | 333 | { |
333 | GNUNET_break(0); | 334 | GNUNET_break (0); |
334 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 335 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
335 | goto error; | 336 | goto error; |
336 | } | 337 | } |
337 | ul_config_size = (uLongf)ntohs(msg->config_size); | 338 | ul_config_size = (uLongf) ntohs (msg->config_size); |
338 | config = GNUNET_malloc(ul_config_size); | 339 | config = GNUNET_malloc (ul_config_size); |
339 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + | 340 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size |
340 | sizeof(struct GNUNET_TESTBED_HelperInit)); | 341 | + sizeof(struct GNUNET_TESTBED_HelperInit)); |
341 | int ret = uncompress((Bytef *)config, | 342 | int ret = uncompress ((Bytef *) config, |
342 | &ul_config_size, | 343 | &ul_config_size, |
343 | (const Bytef *)(trusted_ip + trusted_ip_size + 1 + | 344 | (const Bytef *) (trusted_ip + trusted_ip_size + 1 |
344 | hostname_size), | 345 | + hostname_size), |
345 | (uLongf)xconfig_size); | 346 | (uLongf) xconfig_size); |
346 | if (Z_OK != ret) | 347 | if (Z_OK != ret) |
348 | { | ||
349 | switch (ret) | ||
347 | { | 350 | { |
348 | switch (ret) | 351 | case Z_MEM_ERROR: |
349 | { | 352 | LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); |
350 | case Z_MEM_ERROR: | 353 | break; |
351 | LOG(GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); | 354 | |
352 | break; | 355 | case Z_BUF_ERROR: |
353 | 356 | LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); | |
354 | case Z_BUF_ERROR: | 357 | break; |
355 | LOG(GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); | 358 | |
356 | break; | 359 | case Z_DATA_ERROR: |
357 | 360 | LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | |
358 | case Z_DATA_ERROR: | 361 | break; |
359 | LOG(GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | 362 | |
360 | break; | 363 | default: |
361 | 364 | GNUNET_break (0); | |
362 | default: | ||
363 | GNUNET_break(0); | ||
364 | } | ||
365 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
366 | "Error while uncompressing config -- exiting\n"); | ||
367 | GNUNET_free(config); | ||
368 | goto error; | ||
369 | } | 365 | } |
370 | cfg = GNUNET_CONFIGURATION_create(); | 366 | LOG (GNUNET_ERROR_TYPE_ERROR, |
367 | "Error while uncompressing config -- exiting\n"); | ||
368 | GNUNET_free (config); | ||
369 | goto error; | ||
370 | } | ||
371 | cfg = GNUNET_CONFIGURATION_create (); | ||
371 | if (GNUNET_OK != | 372 | if (GNUNET_OK != |
372 | GNUNET_CONFIGURATION_deserialize(cfg, config, ul_config_size, NULL)) | 373 | GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL)) |
373 | { | 374 | { |
374 | LOG(GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); | 375 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); |
375 | GNUNET_free(config); | 376 | GNUNET_free (config); |
376 | goto error; | 377 | goto error; |
377 | } | 378 | } |
378 | GNUNET_free(config); | 379 | GNUNET_free (config); |
379 | hostname = NULL; | 380 | hostname = NULL; |
380 | if (0 != hostname_size) | 381 | if (0 != hostname_size) |
381 | { | 382 | { |
382 | hostname = GNUNET_malloc(hostname_size + 1); | 383 | hostname = GNUNET_malloc (hostname_size + 1); |
383 | GNUNET_strlcpy(hostname, | 384 | GNUNET_strlcpy (hostname, |
384 | ((char *)&msg[1]) + trusted_ip_size + 1, | 385 | ((char *) &msg[1]) + trusted_ip_size + 1, |
385 | hostname_size + 1); | 386 | hostname_size + 1); |
386 | } | 387 | } |
387 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ | 388 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ |
388 | evstr = getenv(GNUNET_TESTING_PREFIX); | 389 | evstr = getenv (GNUNET_TESTING_PREFIX); |
389 | if (NULL != evstr) | 390 | if (NULL != evstr) |
390 | { | 391 | { |
391 | /* unsetting the variable will invalidate the pointer! */ | 392 | /* unsetting the variable will invalidate the pointer! */ |
392 | evstr = GNUNET_strdup(evstr); | 393 | evstr = GNUNET_strdup (evstr); |
393 | GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); | 394 | GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX)); |
394 | } | 395 | } |
395 | test_system = | 396 | test_system = |
396 | GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); | 397 | GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL); |
397 | if (NULL != evstr) | 398 | if (NULL != evstr) |
398 | { | 399 | { |
399 | char *evar; | 400 | char *evar; |
400 | 401 | ||
401 | GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); | 402 | GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr); |
402 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', | 403 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', |
403 | see putenv(): becomes part of envrionment! */ | 404 | see putenv(): becomes part of envrionment! */ |
404 | GNUNET_free(evstr); | 405 | GNUNET_free (evstr); |
405 | evstr = NULL; | 406 | evstr = NULL; |
406 | } | 407 | } |
407 | GNUNET_free_non_null(hostname); | 408 | GNUNET_free_non_null (hostname); |
408 | hostname = NULL; | 409 | hostname = NULL; |
409 | GNUNET_assert(NULL != test_system); | 410 | GNUNET_assert (NULL != test_system); |
410 | GNUNET_assert(GNUNET_OK == | 411 | GNUNET_assert (GNUNET_OK == |
411 | GNUNET_TESTING_configuration_create(test_system, cfg)); | 412 | GNUNET_TESTING_configuration_create (test_system, cfg)); |
412 | GNUNET_assert(GNUNET_OK == | 413 | GNUNET_assert (GNUNET_OK == |
413 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 414 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
414 | "PATHS", | 415 | "PATHS", |
415 | "DEFAULTCONFIG", | 416 | "DEFAULTCONFIG", |
416 | &config)); | 417 | &config)); |
417 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config)) | 418 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) |
418 | { | 419 | { |
419 | LOG(GNUNET_ERROR_TYPE_WARNING, | 420 | LOG (GNUNET_ERROR_TYPE_WARNING, |
420 | "Unable to write config file: %s -- exiting\n", | 421 | "Unable to write config file: %s -- exiting\n", |
421 | config); | 422 | config); |
422 | GNUNET_CONFIGURATION_destroy(cfg); | 423 | GNUNET_CONFIGURATION_destroy (cfg); |
423 | GNUNET_free(config); | 424 | GNUNET_free (config); |
424 | goto error; | 425 | goto error; |
425 | } | 426 | } |
426 | LOG_DEBUG("Staring testbed with config: %s\n", config); | 427 | LOG_DEBUG ("Staring testbed with config: %s\n", config); |
427 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-testbed"); | 428 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed"); |
428 | { | 429 | { |
429 | char *evar; | 430 | char *evar; |
430 | 431 | ||
431 | /* expose testbed configuration through env variable */ | 432 | /* expose testbed configuration through env variable */ |
432 | GNUNET_asprintf(&evar, "%s=%s", ENV_TESTBED_CONFIG, config); | 433 | GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config); |
433 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', | 434 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', |
434 | see putenv(): becomes part of envrionment! */ | 435 | see putenv(): becomes part of envrionment! */ |
435 | evstr = NULL; | 436 | evstr = NULL; |
436 | } | 437 | } |
437 | testbed = GNUNET_OS_start_process(PIPE_CONTROL, | 438 | testbed = GNUNET_OS_start_process (PIPE_CONTROL, |
438 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, | 439 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, |
439 | NULL, | 440 | NULL, |
440 | NULL, | 441 | NULL, |
441 | NULL, | 442 | NULL, |
442 | binary, | 443 | binary, |
443 | "gnunet-service-testbed", | 444 | "gnunet-service-testbed", |
444 | "-c", | 445 | "-c", |
445 | config, | 446 | config, |
446 | NULL); | 447 | NULL); |
447 | GNUNET_free(binary); | 448 | GNUNET_free (binary); |
448 | GNUNET_free(config); | 449 | GNUNET_free (config); |
449 | if (NULL == testbed) | 450 | if (NULL == testbed) |
450 | { | 451 | { |
451 | LOG(GNUNET_ERROR_TYPE_WARNING, | 452 | LOG (GNUNET_ERROR_TYPE_WARNING, |
452 | "Error starting gnunet-service-testbed -- exiting\n"); | 453 | "Error starting gnunet-service-testbed -- exiting\n"); |
453 | GNUNET_CONFIGURATION_destroy(cfg); | 454 | GNUNET_CONFIGURATION_destroy (cfg); |
454 | goto error; | 455 | goto error; |
455 | } | 456 | } |
456 | done_reading = GNUNET_YES; | 457 | done_reading = GNUNET_YES; |
457 | config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); | 458 | config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); |
458 | GNUNET_CONFIGURATION_destroy(cfg); | 459 | GNUNET_CONFIGURATION_destroy (cfg); |
459 | cfg = NULL; | 460 | cfg = NULL; |
460 | xconfig_size = | 461 | xconfig_size = |
461 | GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); | 462 | GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); |
462 | GNUNET_free(config); | 463 | GNUNET_free (config); |
463 | wc = GNUNET_new(struct WriteContext); | 464 | wc = GNUNET_new (struct WriteContext); |
464 | wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); | 465 | wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); |
465 | reply = GNUNET_realloc(xconfig, wc->length); | 466 | reply = GNUNET_realloc (xconfig, wc->length); |
466 | memmove(&reply[1], reply, xconfig_size); | 467 | memmove (&reply[1], reply, xconfig_size); |
467 | reply->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); | 468 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); |
468 | reply->header.size = htons((uint16_t)wc->length); | 469 | reply->header.size = htons ((uint16_t) wc->length); |
469 | reply->config_size = htons((uint16_t)config_size); | 470 | reply->config_size = htons ((uint16_t) config_size); |
470 | wc->data = reply; | 471 | wc->data = reply; |
471 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, | 472 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
472 | stdout_fd, | 473 | stdout_fd, |
473 | &write_task, | 474 | &write_task, |
474 | wc); | 475 | wc); |
475 | child_death_task_id = GNUNET_SCHEDULER_add_read_file( | 476 | child_death_task_id = GNUNET_SCHEDULER_add_read_file ( |
476 | GNUNET_TIME_UNIT_FOREVER_REL, | 477 | GNUNET_TIME_UNIT_FOREVER_REL, |
477 | GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), | 478 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), |
478 | &child_death_task, | 479 | &child_death_task, |
479 | NULL); | 480 | NULL); |
480 | return GNUNET_OK; | 481 | return GNUNET_OK; |
481 | 482 | ||
482 | error: | 483 | error: |
483 | status = GNUNET_SYSERR; | 484 | status = GNUNET_SYSERR; |
484 | GNUNET_SCHEDULER_shutdown(); | 485 | GNUNET_SCHEDULER_shutdown (); |
485 | return GNUNET_SYSERR; | 486 | return GNUNET_SYSERR; |
486 | } | 487 | } |
487 | 488 | ||
@@ -492,41 +493,41 @@ error: | |||
492 | * @param cls NULL | 493 | * @param cls NULL |
493 | */ | 494 | */ |
494 | static void | 495 | static void |
495 | read_task(void *cls) | 496 | read_task (void *cls) |
496 | { | 497 | { |
497 | char buf[GNUNET_MAX_MESSAGE_SIZE]; | 498 | char buf[GNUNET_MAX_MESSAGE_SIZE]; |
498 | ssize_t sread; | 499 | ssize_t sread; |
499 | 500 | ||
500 | read_task_id = NULL; | 501 | read_task_id = NULL; |
501 | sread = GNUNET_DISK_file_read(stdin_fd, buf, sizeof(buf)); | 502 | sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof(buf)); |
502 | if ((GNUNET_SYSERR == sread) || (0 == sread)) | 503 | if ((GNUNET_SYSERR == sread) || (0 == sread)) |
503 | { | 504 | { |
504 | LOG_DEBUG("STDIN closed\n"); | 505 | LOG_DEBUG ("STDIN closed\n"); |
505 | GNUNET_SCHEDULER_shutdown(); | 506 | GNUNET_SCHEDULER_shutdown (); |
506 | return; | 507 | return; |
507 | } | 508 | } |
508 | if (GNUNET_YES == done_reading) | 509 | if (GNUNET_YES == done_reading) |
509 | { | 510 | { |
510 | /* didn't expect any more data! */ | 511 | /* didn't expect any more data! */ |
511 | GNUNET_break_op(0); | 512 | GNUNET_break_op (0); |
512 | GNUNET_SCHEDULER_shutdown(); | 513 | GNUNET_SCHEDULER_shutdown (); |
513 | return; | 514 | return; |
514 | } | 515 | } |
515 | LOG_DEBUG("Read %u bytes\n", (unsigned int)sread); | 516 | LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); |
516 | /* FIXME: could introduce a GNUNET_MST_read2 to read | 517 | /* FIXME: could introduce a GNUNET_MST_read2 to read |
517 | directly from 'stdin_fd' and save a memcpy() here */ | 518 | directly from 'stdin_fd' and save a memcpy() here */ |
518 | if (GNUNET_OK != | 519 | if (GNUNET_OK != |
519 | GNUNET_MST_from_buffer(tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) | 520 | GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) |
520 | { | 521 | { |
521 | GNUNET_break(0); | 522 | GNUNET_break (0); |
522 | GNUNET_SCHEDULER_shutdown(); | 523 | GNUNET_SCHEDULER_shutdown (); |
523 | return; | 524 | return; |
524 | } | 525 | } |
525 | read_task_id /* No timeout while reading */ | 526 | read_task_id /* No timeout while reading */ |
526 | = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 527 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
527 | stdin_fd, | 528 | stdin_fd, |
528 | &read_task, | 529 | &read_task, |
529 | NULL); | 530 | NULL); |
530 | } | 531 | } |
531 | 532 | ||
532 | 533 | ||
@@ -539,20 +540,20 @@ read_task(void *cls) | |||
539 | * @param cfg configuration | 540 | * @param cfg configuration |
540 | */ | 541 | */ |
541 | static void | 542 | static void |
542 | run(void *cls, | 543 | run (void *cls, |
543 | char *const *args, | 544 | char *const *args, |
544 | const char *cfgfile, | 545 | const char *cfgfile, |
545 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 546 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
546 | { | 547 | { |
547 | LOG_DEBUG("Starting testbed helper...\n"); | 548 | LOG_DEBUG ("Starting testbed helper...\n"); |
548 | tokenizer = GNUNET_MST_create(&tokenizer_cb, NULL); | 549 | tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); |
549 | stdin_fd = GNUNET_DISK_get_handle_from_native(stdin); | 550 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); |
550 | stdout_fd = GNUNET_DISK_get_handle_from_native(stdout); | 551 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); |
551 | read_task_id = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, | 552 | read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
552 | stdin_fd, | 553 | stdin_fd, |
553 | &read_task, | 554 | &read_task, |
554 | NULL); | 555 | NULL); |
555 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 556 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
556 | } | 557 | } |
557 | 558 | ||
558 | 559 | ||
@@ -560,18 +561,18 @@ run(void *cls, | |||
560 | * Signal handler called for SIGCHLD. | 561 | * Signal handler called for SIGCHLD. |
561 | */ | 562 | */ |
562 | static void | 563 | static void |
563 | sighandler_child_death() | 564 | sighandler_child_death () |
564 | { | 565 | { |
565 | static char c; | 566 | static char c; |
566 | int old_errno; /* back-up errno */ | 567 | int old_errno; /* back-up errno */ |
567 | 568 | ||
568 | old_errno = errno; | 569 | old_errno = errno; |
569 | GNUNET_break( | 570 | GNUNET_break ( |
570 | 1 == | 571 | 1 == |
571 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, | 572 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, |
572 | GNUNET_DISK_PIPE_END_WRITE), | 573 | GNUNET_DISK_PIPE_END_WRITE), |
573 | &c, | 574 | &c, |
574 | sizeof(c))); | 575 | sizeof(c))); |
575 | errno = old_errno; | 576 | errno = old_errno; |
576 | } | 577 | } |
577 | 578 | ||
@@ -584,31 +585,32 @@ sighandler_child_death() | |||
584 | * @return return code | 585 | * @return return code |
585 | */ | 586 | */ |
586 | int | 587 | int |
587 | main(int argc, char **argv) | 588 | main (int argc, char **argv) |
588 | { | 589 | { |
589 | struct GNUNET_SIGNAL_Context *shc_chld; | 590 | struct GNUNET_SIGNAL_Context *shc_chld; |
590 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; | 591 | struct GNUNET_GETOPT_CommandLineOption options[] = |
592 | { GNUNET_GETOPT_OPTION_END }; | ||
591 | int ret; | 593 | int ret; |
592 | 594 | ||
593 | status = GNUNET_OK; | 595 | status = GNUNET_OK; |
594 | if (NULL == | 596 | if (NULL == |
595 | (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) | 597 | (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) |
596 | { | 598 | { |
597 | GNUNET_break(0); | 599 | GNUNET_break (0); |
598 | return 1; | 600 | return 1; |
599 | } | 601 | } |
600 | shc_chld = | 602 | shc_chld = |
601 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); | 603 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
602 | ret = GNUNET_PROGRAM_run(argc, | 604 | ret = GNUNET_PROGRAM_run (argc, |
603 | argv, | 605 | argv, |
604 | "gnunet-helper-testbed", | 606 | "gnunet-helper-testbed", |
605 | "Helper for starting gnunet-service-testbed", | 607 | "Helper for starting gnunet-service-testbed", |
606 | options, | 608 | options, |
607 | &run, | 609 | &run, |
608 | NULL); | 610 | NULL); |
609 | GNUNET_SIGNAL_handler_uninstall(shc_chld); | 611 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
610 | shc_chld = NULL; | 612 | shc_chld = NULL; |
611 | GNUNET_DISK_pipe_close(sigpipe); | 613 | GNUNET_DISK_pipe_close (sigpipe); |
612 | if (GNUNET_OK != ret) | 614 | if (GNUNET_OK != ret) |
613 | return 1; | 615 | return 1; |
614 | return (GNUNET_OK == status) ? 0 : 1; | 616 | return (GNUNET_OK == status) ? 0 : 1; |