diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-02 08:24:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-02 08:24:28 +0000 |
commit | f1f198df545fbb423a61dc2fa945fe97bdcfe098 (patch) | |
tree | 296cbaf17dfbd1c26ac636d23141c5361905c80d /src | |
parent | 8025ab3ecdbaf1d0e5128bb21a443545848139ae (diff) | |
download | gnunet-f1f198df545fbb423a61dc2fa945fe97bdcfe098.tar.gz gnunet-f1f198df545fbb423a61dc2fa945fe97bdcfe098.zip |
adding GNUNET_OS_start_process_vap function
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_os_lib.h | 17 | ||||
-rw-r--r-- | src/util/os_priority.c | 80 |
2 files changed, 67 insertions, 30 deletions
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 944713606..c56947431 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h | |||
@@ -241,6 +241,23 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, | |||
241 | enum GNUNET_SCHEDULER_Priority prio); | 241 | enum GNUNET_SCHEDULER_Priority prio); |
242 | 242 | ||
243 | 243 | ||
244 | |||
245 | /** | ||
246 | * Start a process. | ||
247 | * | ||
248 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | ||
249 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | ||
250 | * @param filename name of the binary | ||
251 | * @param argv NULL-terminated array of arguments to the process | ||
252 | * @return pointer to process structure of the new process, NULL on error | ||
253 | */ | ||
254 | struct GNUNET_OS_Process * | ||
255 | GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, | ||
256 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | ||
257 | const char *filename, | ||
258 | char *const argv[]); | ||
259 | |||
260 | |||
244 | /** | 261 | /** |
245 | * Start a process. | 262 | * Start a process. |
246 | * | 263 | * |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index e1f64ba0c..13f002f5d 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -534,16 +534,15 @@ CreateCustomEnvTable (char **vars) | |||
534 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 534 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
535 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 535 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
536 | * @param filename name of the binary | 536 | * @param filename name of the binary |
537 | * @param va NULL-terminated list of arguments to the process | 537 | * @param argv NULL-terminated array of arguments to the process |
538 | * @return pointer to process structure of the new process, NULL on error | 538 | * @return pointer to process structure of the new process, NULL on error |
539 | */ | 539 | */ |
540 | struct GNUNET_OS_Process * | 540 | struct GNUNET_OS_Process * |
541 | GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 541 | GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, |
542 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 542 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
543 | const char *filename, va_list va) | 543 | const char *filename, |
544 | char *const argv[]) | ||
544 | { | 545 | { |
545 | va_list ap; | ||
546 | |||
547 | #if ENABLE_WINDOWS_WORKAROUNDS | 546 | #if ENABLE_WINDOWS_WORKAROUNDS |
548 | char *childpipename = NULL; | 547 | char *childpipename = NULL; |
549 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; | 548 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; |
@@ -552,8 +551,6 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
552 | 551 | ||
553 | #ifndef MINGW | 552 | #ifndef MINGW |
554 | pid_t ret; | 553 | pid_t ret; |
555 | char **argv; | ||
556 | int argc; | ||
557 | int fd_stdout_write; | 554 | int fd_stdout_write; |
558 | int fd_stdout_read; | 555 | int fd_stdout_read; |
559 | int fd_stdin_read; | 556 | int fd_stdin_read; |
@@ -567,20 +564,6 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
567 | if (control_pipe == NULL) | 564 | if (control_pipe == NULL) |
568 | return NULL; | 565 | return NULL; |
569 | #endif | 566 | #endif |
570 | |||
571 | argc = 0; | ||
572 | va_copy (ap, va); | ||
573 | while (NULL != va_arg (ap, char *)) | ||
574 | argc++; | ||
575 | |||
576 | va_end (ap); | ||
577 | argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); | ||
578 | argc = 0; | ||
579 | va_copy (ap, va); | ||
580 | while (NULL != (argv[argc] = va_arg (ap, char *))) | ||
581 | argc++; | ||
582 | |||
583 | va_end (ap); | ||
584 | if (pipe_stdout != NULL) | 567 | if (pipe_stdout != NULL) |
585 | { | 568 | { |
586 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle | 569 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle |
@@ -619,7 +602,6 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
619 | gnunet_proc->control_pipe = control_pipe; | 602 | gnunet_proc->control_pipe = control_pipe; |
620 | #endif | 603 | #endif |
621 | } | 604 | } |
622 | GNUNET_free (argv); | ||
623 | #if ENABLE_WINDOWS_WORKAROUNDS | 605 | #if ENABLE_WINDOWS_WORKAROUNDS |
624 | GNUNET_free (childpipename); | 606 | GNUNET_free (childpipename); |
625 | #endif | 607 | #endif |
@@ -656,7 +638,7 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
656 | char *cmd, *idx; | 638 | char *cmd, *idx; |
657 | STARTUPINFOW start; | 639 | STARTUPINFOW start; |
658 | PROCESS_INFORMATION proc; | 640 | PROCESS_INFORMATION proc; |
659 | 641 | int argc; | |
660 | HANDLE stdin_handle; | 642 | HANDLE stdin_handle; |
661 | HANDLE stdout_handle; | 643 | HANDLE stdout_handle; |
662 | 644 | ||
@@ -721,26 +703,24 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
721 | GNUNET_free (non_const_filename); | 703 | GNUNET_free (non_const_filename); |
722 | 704 | ||
723 | cmdlen = 0; | 705 | cmdlen = 0; |
724 | va_copy (ap, va); | 706 | argc = 0; |
725 | while (NULL != (arg = va_arg (ap, char *))) | 707 | while (NULL != (arg = argv[argc++])) |
726 | { | 708 | { |
727 | if (cmdlen == 0) | 709 | if (cmdlen == 0) |
728 | cmdlen = cmdlen + strlen (path) + 3; | 710 | cmdlen = cmdlen + strlen (path) + 3; |
729 | else | 711 | else |
730 | cmdlen = cmdlen + strlen (arg) + 3; | 712 | cmdlen = cmdlen + strlen (arg) + 3; |
731 | } | 713 | } |
732 | va_end (ap); | ||
733 | 714 | ||
734 | cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); | 715 | cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1)); |
735 | va_copy (ap, va); | 716 | argc = 0; |
736 | while (NULL != (arg = va_arg (ap, char *))) | 717 | while (NULL != (arg = argv[argc++])) |
737 | { | 718 | { |
738 | if (idx == cmd) | 719 | if (idx == cmd) |
739 | idx += sprintf (idx, "\"%s\" ", path); | 720 | idx += sprintf (idx, "\"%s\" ", path); |
740 | else | 721 | else |
741 | idx += sprintf (idx, "\"%s\" ", arg); | 722 | idx += sprintf (idx, "\"%s\" ", arg); |
742 | } | 723 | } |
743 | va_end (ap); | ||
744 | 724 | ||
745 | memset (&start, 0, sizeof (start)); | 725 | memset (&start, 0, sizeof (start)); |
746 | start.cb = sizeof (start); | 726 | start.cb = sizeof (start); |
@@ -826,6 +806,46 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
826 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 806 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
827 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 807 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
828 | * @param filename name of the binary | 808 | * @param filename name of the binary |
809 | * @param va NULL-terminated list of arguments to the process | ||
810 | * @return pointer to process structure of the new process, NULL on error | ||
811 | */ | ||
812 | struct GNUNET_OS_Process * | ||
813 | GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | ||
814 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | ||
815 | const char *filename, va_list va) | ||
816 | { | ||
817 | struct GNUNET_OS_Process *ret; | ||
818 | va_list ap; | ||
819 | char **argv; | ||
820 | int argc; | ||
821 | |||
822 | argc = 0; | ||
823 | va_copy (ap, va); | ||
824 | while (NULL != va_arg (ap, char *)) | ||
825 | argc++; | ||
826 | va_end (ap); | ||
827 | argv = GNUNET_malloc (sizeof (char *) * (argc + 1)); | ||
828 | argc = 0; | ||
829 | va_copy (ap, va); | ||
830 | while (NULL != (argv[argc] = va_arg (ap, char *))) | ||
831 | argc++; | ||
832 | va_end (ap); | ||
833 | ret = GNUNET_OS_start_process_vap (pipe_stdin, | ||
834 | pipe_stdout, | ||
835 | filename, | ||
836 | argv); | ||
837 | GNUNET_free (argv); | ||
838 | return ret; | ||
839 | } | ||
840 | |||
841 | |||
842 | |||
843 | /** | ||
844 | * Start a process. | ||
845 | * | ||
846 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | ||
847 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | ||
848 | * @param filename name of the binary | ||
829 | * @param ... NULL-terminated list of arguments to the process | 849 | * @param ... NULL-terminated list of arguments to the process |
830 | * | 850 | * |
831 | * @return pointer to process structure of the new process, NULL on error | 851 | * @return pointer to process structure of the new process, NULL on error |