diff options
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r-- | src/util/os_priority.c | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 5799d893b..8d045c72b 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -326,7 +326,6 @@ open_dev_null (int target_fd, int flags) | |||
326 | /** | 326 | /** |
327 | * Start a process. | 327 | * Start a process. |
328 | * | 328 | * |
329 | * @param pipe_control should a pipe be used to send signals to the child? | ||
330 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which | 329 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which |
331 | * std handles of the parent are inherited by the child. | 330 | * std handles of the parent are inherited by the child. |
332 | * pipe_stdin and pipe_stdout take priority over std_inheritance | 331 | * pipe_stdin and pipe_stdout take priority over std_inheritance |
@@ -341,8 +340,7 @@ open_dev_null (int target_fd, int flags) | |||
341 | * @return process ID of the new process, -1 on error | 340 | * @return process ID of the new process, -1 on error |
342 | */ | 341 | */ |
343 | static struct GNUNET_OS_Process * | 342 | static struct GNUNET_OS_Process * |
344 | start_process (int pipe_control, | 343 | start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
345 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | ||
346 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 344 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
347 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 345 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
348 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | 346 | struct GNUNET_DISK_PipeHandle *pipe_stderr, |
@@ -373,12 +371,12 @@ start_process (int pipe_control, | |||
373 | if (GNUNET_SYSERR == | 371 | if (GNUNET_SYSERR == |
374 | GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL)) | 372 | GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL)) |
375 | return NULL; /* not executable */ | 373 | return NULL; /* not executable */ |
376 | if (GNUNET_YES == pipe_control) | 374 | if (0 != (std_inheritance & GNUNET_OS_USE_PIPE_CONTROL)) |
377 | { | 375 | { |
378 | struct GNUNET_DISK_PipeHandle *childpipe; | 376 | struct GNUNET_DISK_PipeHandle *childpipe; |
379 | int dup_childpipe_read_fd = -1; | 377 | int dup_childpipe_read_fd = -1; |
380 | 378 | ||
381 | childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); | 379 | childpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); |
382 | if (NULL == childpipe) | 380 | if (NULL == childpipe) |
383 | return NULL; | 381 | return NULL; |
384 | childpipe_read = | 382 | childpipe_read = |
@@ -486,7 +484,7 @@ start_process (int pipe_control, | |||
486 | gnunet_proc = GNUNET_new (struct GNUNET_OS_Process); | 484 | gnunet_proc = GNUNET_new (struct GNUNET_OS_Process); |
487 | gnunet_proc->pid = ret; | 485 | gnunet_proc->pid = ret; |
488 | gnunet_proc->control_pipe = childpipe_write; | 486 | gnunet_proc->control_pipe = childpipe_write; |
489 | if (GNUNET_YES == pipe_control) | 487 | if (0 != (std_inheritance & GNUNET_OS_USE_PIPE_CONTROL)) |
490 | { | 488 | { |
491 | close (childpipe_read_fd); | 489 | close (childpipe_read_fd); |
492 | } | 490 | } |
@@ -594,7 +592,6 @@ start_process (int pipe_control, | |||
594 | /** | 592 | /** |
595 | * Start a process. | 593 | * Start a process. |
596 | * | 594 | * |
597 | * @param pipe_control should a pipe be used to send signals to the child? | ||
598 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags | 595 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags |
599 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 596 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
600 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 597 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
@@ -604,16 +601,14 @@ start_process (int pipe_control, | |||
604 | * @return pointer to process structure of the new process, NULL on error | 601 | * @return pointer to process structure of the new process, NULL on error |
605 | */ | 602 | */ |
606 | struct GNUNET_OS_Process * | 603 | struct GNUNET_OS_Process * |
607 | GNUNET_OS_start_process_vap (int pipe_control, | 604 | GNUNET_OS_start_process_vap (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
608 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | ||
609 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 605 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
610 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 606 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
611 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | 607 | struct GNUNET_DISK_PipeHandle *pipe_stderr, |
612 | const char *filename, | 608 | const char *filename, |
613 | char *const argv[]) | 609 | char *const argv[]) |
614 | { | 610 | { |
615 | return start_process (pipe_control, | 611 | return start_process (std_inheritance, |
616 | std_inheritance, | ||
617 | pipe_stdin, | 612 | pipe_stdin, |
618 | pipe_stdout, | 613 | pipe_stdout, |
619 | pipe_stderr, | 614 | pipe_stderr, |
@@ -626,7 +621,6 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
626 | /** | 621 | /** |
627 | * Start a process. | 622 | * Start a process. |
628 | * | 623 | * |
629 | * @param pipe_control should a pipe be used to send signals to the child? | ||
630 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags | 624 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags |
631 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 625 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
632 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 626 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
@@ -636,8 +630,7 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
636 | * @return pointer to process structure of the new process, NULL on error | 630 | * @return pointer to process structure of the new process, NULL on error |
637 | */ | 631 | */ |
638 | struct GNUNET_OS_Process * | 632 | struct GNUNET_OS_Process * |
639 | GNUNET_OS_start_process_va (int pipe_control, | 633 | GNUNET_OS_start_process_va (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
640 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | ||
641 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 634 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
642 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 635 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
643 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | 636 | struct GNUNET_DISK_PipeHandle *pipe_stderr, |
@@ -660,8 +653,7 @@ GNUNET_OS_start_process_va (int pipe_control, | |||
660 | while (NULL != (argv[argc] = va_arg (ap, char *))) | 653 | while (NULL != (argv[argc] = va_arg (ap, char *))) |
661 | argc++; | 654 | argc++; |
662 | va_end (ap); | 655 | va_end (ap); |
663 | ret = GNUNET_OS_start_process_vap (pipe_control, | 656 | ret = GNUNET_OS_start_process_vap (std_inheritance, |
664 | std_inheritance, | ||
665 | pipe_stdin, | 657 | pipe_stdin, |
666 | pipe_stdout, | 658 | pipe_stdout, |
667 | pipe_stderr, | 659 | pipe_stderr, |
@@ -675,7 +667,6 @@ GNUNET_OS_start_process_va (int pipe_control, | |||
675 | /** | 667 | /** |
676 | * Start a process. | 668 | * Start a process. |
677 | * | 669 | * |
678 | * @param pipe_control should a pipe be used to send signals to the child? | ||
679 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags | 670 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags |
680 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 671 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
681 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 672 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
@@ -684,8 +675,7 @@ GNUNET_OS_start_process_va (int pipe_control, | |||
684 | * @return pointer to process structure of the new process, NULL on error | 675 | * @return pointer to process structure of the new process, NULL on error |
685 | */ | 676 | */ |
686 | struct GNUNET_OS_Process * | 677 | struct GNUNET_OS_Process * |
687 | GNUNET_OS_start_process (int pipe_control, | 678 | GNUNET_OS_start_process (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
688 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | ||
689 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 679 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
690 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 680 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
691 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | 681 | struct GNUNET_DISK_PipeHandle *pipe_stderr, |
@@ -696,8 +686,7 @@ GNUNET_OS_start_process (int pipe_control, | |||
696 | va_list ap; | 686 | va_list ap; |
697 | 687 | ||
698 | va_start (ap, filename); | 688 | va_start (ap, filename); |
699 | ret = GNUNET_OS_start_process_va (pipe_control, | 689 | ret = GNUNET_OS_start_process_va (std_inheritance, |
700 | std_inheritance, | ||
701 | pipe_stdin, | 690 | pipe_stdin, |
702 | pipe_stdout, | 691 | pipe_stdout, |
703 | pipe_stderr, | 692 | pipe_stderr, |
@@ -711,7 +700,6 @@ GNUNET_OS_start_process (int pipe_control, | |||
711 | /** | 700 | /** |
712 | * Start a process. | 701 | * Start a process. |
713 | * | 702 | * |
714 | * @param pipe_control should a pipe be used to send signals to the child? | ||
715 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which | 703 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which |
716 | * std handles of the parent are inherited by the child. | 704 | * std handles of the parent are inherited by the child. |
717 | * pipe_stdin and pipe_stdout take priority over std_inheritance | 705 | * pipe_stdin and pipe_stdout take priority over std_inheritance |
@@ -723,14 +711,12 @@ GNUNET_OS_start_process (int pipe_control, | |||
723 | * @return process ID of the new process, -1 on error | 711 | * @return process ID of the new process, -1 on error |
724 | */ | 712 | */ |
725 | struct GNUNET_OS_Process * | 713 | struct GNUNET_OS_Process * |
726 | GNUNET_OS_start_process_v (int pipe_control, | 714 | GNUNET_OS_start_process_v (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
727 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | ||
728 | const int *lsocks, | 715 | const int *lsocks, |
729 | const char *filename, | 716 | const char *filename, |
730 | char *const argv[]) | 717 | char *const argv[]) |
731 | { | 718 | { |
732 | return start_process (pipe_control, | 719 | return start_process (std_inheritance, |
733 | std_inheritance, | ||
734 | NULL, | 720 | NULL, |
735 | NULL, | 721 | NULL, |
736 | NULL, | 722 | NULL, |
@@ -747,7 +733,6 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
747 | * in the order they appear. Arguments containing spaces can be used by | 733 | * in the order they appear. Arguments containing spaces can be used by |
748 | * quoting them with @em ". | 734 | * quoting them with @em ". |
749 | * | 735 | * |
750 | * @param pipe_control should a pipe be used to send signals to the child? | ||
751 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags | 736 | * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags |
752 | * @param lsocks array of listen sockets to dup systemd-style (or NULL); | 737 | * @param lsocks array of listen sockets to dup systemd-style (or NULL); |
753 | * must be NULL on platforms where dup is not supported | 738 | * must be NULL on platforms where dup is not supported |
@@ -759,8 +744,7 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
759 | * @return pointer to process structure of the new process, NULL on error | 744 | * @return pointer to process structure of the new process, NULL on error |
760 | */ | 745 | */ |
761 | struct GNUNET_OS_Process * | 746 | struct GNUNET_OS_Process * |
762 | GNUNET_OS_start_process_s (int pipe_control, | 747 | GNUNET_OS_start_process_s (enum GNUNET_OS_InheritStdioFlags std_inheritance, |
763 | unsigned int std_inheritance, | ||
764 | const int *lsocks, | 748 | const int *lsocks, |
765 | const char *filename, | 749 | const char *filename, |
766 | ...) | 750 | ...) |
@@ -869,8 +853,7 @@ GNUNET_OS_start_process_s (int pipe_control, | |||
869 | } | 853 | } |
870 | } | 854 | } |
871 | binary_path = argv[0]; | 855 | binary_path = argv[0]; |
872 | proc = GNUNET_OS_start_process_v (pipe_control, | 856 | proc = GNUNET_OS_start_process_v (std_inheritance, |
873 | std_inheritance, | ||
874 | lsocks, | 857 | lsocks, |
875 | binary_path, | 858 | binary_path, |
876 | argv); | 859 | argv); |
@@ -1169,13 +1152,18 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, | |||
1169 | struct GNUNET_DISK_PipeHandle *opipe; | 1152 | struct GNUNET_DISK_PipeHandle *opipe; |
1170 | va_list ap; | 1153 | va_list ap; |
1171 | 1154 | ||
1172 | opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 1155 | opipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_RW); |
1173 | if (NULL == opipe) | 1156 | if (NULL == opipe) |
1174 | return NULL; | 1157 | return NULL; |
1175 | va_start (ap, binary); | 1158 | va_start (ap, binary); |
1176 | /* redirect stdout, don't inherit stderr/stdin */ | 1159 | /* redirect stdout, don't inherit stderr/stdin */ |
1177 | eip = | 1160 | eip = |
1178 | GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap); | 1161 | GNUNET_OS_start_process_va (GNUNET_OS_INHERIT_STD_NONE, |
1162 | NULL, | ||
1163 | opipe, | ||
1164 | NULL, | ||
1165 | binary, | ||
1166 | ap); | ||
1179 | va_end (ap); | 1167 | va_end (ap); |
1180 | if (NULL == eip) | 1168 | if (NULL == eip) |
1181 | { | 1169 | { |