diff options
Diffstat (limited to 'src/util/helper.c')
-rw-r--r-- | src/util/helper.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/util/helper.c b/src/util/helper.c index a70d86f18..21f196ebc 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -49,12 +49,12 @@ struct GNUNET_HELPER_SendHandle | |||
49 | * Message to transmit (allocated at the end of this struct) | 49 | * Message to transmit (allocated at the end of this struct) |
50 | */ | 50 | */ |
51 | const struct GNUNET_MessageHeader *msg; | 51 | const struct GNUNET_MessageHeader *msg; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * The handle to a helper process. | 54 | * The handle to a helper process. |
55 | */ | 55 | */ |
56 | struct GNUNET_HELPER_Handle *h; | 56 | struct GNUNET_HELPER_Handle *h; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Function to call upon completion. | 59 | * Function to call upon completion. |
60 | */ | 60 | */ |
@@ -83,22 +83,22 @@ struct GNUNET_HELPER_Handle | |||
83 | * PipeHandle to receive data from the helper | 83 | * PipeHandle to receive data from the helper |
84 | */ | 84 | */ |
85 | struct GNUNET_DISK_PipeHandle *helper_in; | 85 | struct GNUNET_DISK_PipeHandle *helper_in; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * PipeHandle to send data to the helper | 88 | * PipeHandle to send data to the helper |
89 | */ | 89 | */ |
90 | struct GNUNET_DISK_PipeHandle *helper_out; | 90 | struct GNUNET_DISK_PipeHandle *helper_out; |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * FileHandle to receive data from the helper | 93 | * FileHandle to receive data from the helper |
94 | */ | 94 | */ |
95 | const struct GNUNET_DISK_FileHandle *fh_from_helper; | 95 | const struct GNUNET_DISK_FileHandle *fh_from_helper; |
96 | 96 | ||
97 | /** | 97 | /** |
98 | * FileHandle to send data to the helper | 98 | * FileHandle to send data to the helper |
99 | */ | 99 | */ |
100 | const struct GNUNET_DISK_FileHandle *fh_to_helper; | 100 | const struct GNUNET_DISK_FileHandle *fh_to_helper; |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * The process id of the helper | 103 | * The process id of the helper |
104 | */ | 104 | */ |
@@ -138,7 +138,7 @@ struct GNUNET_HELPER_Handle | |||
138 | * NULL-terminated list of command-line arguments. | 138 | * NULL-terminated list of command-line arguments. |
139 | */ | 139 | */ |
140 | char **binary_argv; | 140 | char **binary_argv; |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Task to read from the helper. | 143 | * Task to read from the helper. |
144 | */ | 144 | */ |
@@ -172,7 +172,7 @@ struct GNUNET_HELPER_Handle | |||
172 | * @return #GNUNET_OK on success; #GNUNET_SYSERR on error | 172 | * @return #GNUNET_OK on success; #GNUNET_SYSERR on error |
173 | */ | 173 | */ |
174 | int | 174 | int |
175 | GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, | 175 | GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, |
176 | int soft_kill) | 176 | int soft_kill) |
177 | { | 177 | { |
178 | struct GNUNET_HELPER_SendHandle *sh; | 178 | struct GNUNET_HELPER_SendHandle *sh; |
@@ -200,7 +200,7 @@ GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, | |||
200 | if (NULL == h->helper_proc) | 200 | if (NULL == h->helper_proc) |
201 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
202 | if (GNUNET_YES == soft_kill) | 202 | if (GNUNET_YES == soft_kill) |
203 | { | 203 | { |
204 | /* soft-kill only possible with pipes */ | 204 | /* soft-kill only possible with pipes */ |
205 | GNUNET_assert (NULL != h->helper_in); | 205 | GNUNET_assert (NULL != h->helper_in); |
206 | ret = GNUNET_DISK_pipe_close (h->helper_in); | 206 | ret = GNUNET_DISK_pipe_close (h->helper_in); |
@@ -281,7 +281,7 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h) | |||
281 | * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper | 281 | * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper |
282 | */ | 282 | */ |
283 | static void | 283 | static void |
284 | stop_helper (struct GNUNET_HELPER_Handle *h, | 284 | stop_helper (struct GNUNET_HELPER_Handle *h, |
285 | int soft_kill) | 285 | int soft_kill) |
286 | { | 286 | { |
287 | if (GNUNET_SCHEDULER_NO_TASK != h->restart_task) | 287 | if (GNUNET_SCHEDULER_NO_TASK != h->restart_task) |
@@ -352,9 +352,9 @@ helper_read (void *cls, | |||
352 | } | 352 | } |
353 | if (0 == t) | 353 | if (0 == t) |
354 | { | 354 | { |
355 | /* this happens if the helper is shut down via a | 355 | /* this happens if the helper is shut down via a |
356 | signal, so it is not a "hard" error */ | 356 | signal, so it is not a "hard" error */ |
357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
358 | "Got 0 bytes from helper `%s' (EOF)\n", | 358 | "Got 0 bytes from helper `%s' (EOF)\n", |
359 | h->binary_name); | 359 | h->binary_name); |
360 | if (NULL != h->exp_cb) | 360 | if (NULL != h->exp_cb) |
@@ -370,7 +370,7 @@ helper_read (void *cls, | |||
370 | &restart_task, h); | 370 | &restart_task, h); |
371 | return; | 371 | return; |
372 | } | 372 | } |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
374 | "Got %u bytes from helper `%s'\n", | 374 | "Got %u bytes from helper `%s'\n", |
375 | (unsigned int) t, | 375 | (unsigned int) t, |
376 | h->binary_name); | 376 | h->binary_name); |
@@ -379,7 +379,7 @@ helper_read (void *cls, | |||
379 | if (GNUNET_SYSERR == | 379 | if (GNUNET_SYSERR == |
380 | GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO)) | 380 | GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO)) |
381 | { | 381 | { |
382 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 382 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
383 | _("Failed to parse inbound message from helper `%s'\n"), | 383 | _("Failed to parse inbound message from helper `%s'\n"), |
384 | h->binary_name); | 384 | h->binary_name); |
385 | if (NULL != h->exp_cb) | 385 | if (NULL != h->exp_cb) |
@@ -387,7 +387,7 @@ helper_read (void *cls, | |||
387 | h->exp_cb (h->cb_cls); | 387 | h->exp_cb (h->cb_cls); |
388 | GNUNET_HELPER_stop (h, GNUNET_NO); | 388 | GNUNET_HELPER_stop (h, GNUNET_NO); |
389 | return; | 389 | return; |
390 | } | 390 | } |
391 | stop_helper (h, GNUNET_NO); | 391 | stop_helper (h, GNUNET_NO); |
392 | /* Restart the helper */ | 392 | /* Restart the helper */ |
393 | h->restart_task = | 393 | h->restart_task = |
@@ -414,7 +414,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
414 | stop_helper (h, GNUNET_NO); | 414 | stop_helper (h, GNUNET_NO); |
415 | h->restart_task = | 415 | h->restart_task = |
416 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 416 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
417 | &restart_task, h); | 417 | &restart_task, h); |
418 | return; | 418 | return; |
419 | } | 419 | } |
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -425,7 +425,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
425 | h->fh_to_helper = | 425 | h->fh_to_helper = |
426 | GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); | 426 | GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); |
427 | h->helper_proc = | 427 | h->helper_proc = |
428 | GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR, | 428 | GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR, |
429 | h->helper_in, h->helper_out, | 429 | h->helper_in, h->helper_out, |
430 | h->binary_name, | 430 | h->binary_name, |
431 | h->binary_argv); | 431 | h->binary_argv); |
@@ -435,15 +435,15 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
435 | stop_helper (h, GNUNET_NO); | 435 | stop_helper (h, GNUNET_NO); |
436 | h->restart_task = | 436 | h->restart_task = |
437 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 437 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
438 | &restart_task, h); | 438 | &restart_task, h); |
439 | return; | 439 | return; |
440 | } | 440 | } |
441 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); | 441 | GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE); |
442 | GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); | 442 | GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ); |
443 | if (NULL != h->mst) | 443 | if (NULL != h->mst) |
444 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 444 | h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
445 | h->fh_from_helper, | 445 | h->fh_from_helper, |
446 | &helper_read, | 446 | &helper_read, |
447 | h); | 447 | h); |
448 | } | 448 | } |
449 | 449 | ||
@@ -558,7 +558,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h) | |||
558 | * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper | 558 | * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper |
559 | */ | 559 | */ |
560 | void | 560 | void |
561 | GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, | 561 | GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, |
562 | int soft_kill) | 562 | int soft_kill) |
563 | { | 563 | { |
564 | h->exp_cb = NULL; | 564 | h->exp_cb = NULL; |
@@ -591,7 +591,7 @@ helper_write (void *cls, | |||
591 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 591 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
592 | h->fh_to_helper, &helper_write, h); | 592 | h->fh_to_helper, &helper_write, h); |
593 | return; | 593 | return; |
594 | } | 594 | } |
595 | if (NULL == (sh = h->sh_head)) | 595 | if (NULL == (sh = h->sh_head)) |
596 | { | 596 | { |
597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -600,7 +600,7 @@ helper_write (void *cls, | |||
600 | } | 600 | } |
601 | buf = (const char*) sh->msg; | 601 | buf = (const char*) sh->msg; |
602 | t = GNUNET_DISK_file_write (h->fh_to_helper, | 602 | t = GNUNET_DISK_file_write (h->fh_to_helper, |
603 | &buf[sh->wpos], | 603 | &buf[sh->wpos], |
604 | ntohs (sh->msg->size) - sh->wpos); | 604 | ntohs (sh->msg->size) - sh->wpos); |
605 | if (-1 == t) | 605 | if (-1 == t) |
606 | { | 606 | { |
@@ -640,8 +640,8 @@ helper_write (void *cls, | |||
640 | } | 640 | } |
641 | if (NULL != h->sh_head) | 641 | if (NULL != h->sh_head) |
642 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 642 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
643 | h->fh_to_helper, | 643 | h->fh_to_helper, |
644 | &helper_write, | 644 | &helper_write, |
645 | h); | 645 | h); |
646 | } | 646 | } |
647 | 647 | ||
@@ -655,12 +655,12 @@ helper_write (void *cls, | |||
655 | * @param cont continuation to run once the message is out (#GNUNET_OK on succees, #GNUNET_NO | 655 | * @param cont continuation to run once the message is out (#GNUNET_OK on succees, #GNUNET_NO |
656 | * if the helper process died, #GNUNET_SYSERR during #GNUNET_HELPER_destroy). | 656 | * if the helper process died, #GNUNET_SYSERR during #GNUNET_HELPER_destroy). |
657 | * @param cont_cls closure for @a cont | 657 | * @param cont_cls closure for @a cont |
658 | * @return NULL if the message was dropped, | 658 | * @return NULL if the message was dropped, |
659 | * otherwise handle to cancel *cont* (actual transmission may | 659 | * otherwise handle to cancel *cont* (actual transmission may |
660 | * not be abortable) | 660 | * not be abortable) |
661 | */ | 661 | */ |
662 | struct GNUNET_HELPER_SendHandle * | 662 | struct GNUNET_HELPER_SendHandle * |
663 | GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, | 663 | GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, |
664 | const struct GNUNET_MessageHeader *msg, | 664 | const struct GNUNET_MessageHeader *msg, |
665 | int can_drop, | 665 | int can_drop, |
666 | GNUNET_HELPER_Continuation cont, | 666 | GNUNET_HELPER_Continuation cont, |
@@ -686,10 +686,10 @@ GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, | |||
686 | sh); | 686 | sh); |
687 | if (GNUNET_SCHEDULER_NO_TASK == h->write_task) | 687 | if (GNUNET_SCHEDULER_NO_TASK == h->write_task) |
688 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 688 | h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, |
689 | h->fh_to_helper, | 689 | h->fh_to_helper, |
690 | &helper_write, | 690 | &helper_write, |
691 | h); | 691 | h); |
692 | 692 | ||
693 | return sh; | 693 | return sh; |
694 | } | 694 | } |
695 | 695 | ||