2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/os_priority.c
23 * @brief Methods to set process priority
28 #include "gnunet_common.h"
29 #include "gnunet_os_lib.h"
30 #include "gnunet_scheduler_lib.h"
31 #include "gnunet_strings_lib.h"
32 #include "gnunet_crypto_lib.h"
36 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
38 #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
40 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
42 #define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE"
45 struct GNUNET_OS_Process
60 * Pipe we use to signal the process.
61 * NULL if unused, or if process was deemed uncontrollable.
63 struct GNUNET_DISK_FileHandle *control_pipe;
68 * Handle for 'this' process.
70 static struct GNUNET_OS_Process current_process;
74 * This handler is called when there are control data to be read on the pipe
76 * @param cls the 'struct GNUNET_DISK_FileHandle' of the control pipe
77 * @param tc scheduler context
80 parent_control_handler (void *cls,
81 const struct GNUNET_SCHEDULER_TaskContext *tc)
83 struct GNUNET_DISK_FileHandle *control_pipe = cls;
88 LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__,
90 if (0 != (tc->reason &
91 (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT)))
93 GNUNET_DISK_file_close (control_pipe);
97 ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
98 if (sizeof (sig) != ret)
101 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
102 LOG (GNUNET_ERROR_TYPE_WARNING, "Closing control pipe\n");
103 GNUNET_DISK_file_close (control_pipe);
107 pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
108 GNUNET_assert ( (NULL == pipe_fd) || (strlen (pipe_fd) <= 0) );
109 LOG (GNUNET_ERROR_TYPE_DEBUG,
110 "Got control code %d from parent via pipe %s\n", sig, pipe_fd);
111 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
112 control_pipe, &parent_control_handler,
119 * Task that connects this process to its parent via pipe;
120 * essentially, the parent control handler will read signal numbers
121 * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment
122 * variable) and raise those signals.
124 * @param cls closure (unused)
125 * @param tc scheduler context (unused)
128 GNUNET_OS_install_parent_control_handler (void *cls,
130 GNUNET_SCHEDULER_TaskContext *tc)
134 struct GNUNET_DISK_FileHandle *control_pipe;
137 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
138 if ( (NULL == env_buf) || (strlen (env_buf) <= 0) )
140 LOG (GNUNET_ERROR_TYPE_DEBUG,
141 "Not installing a handler because $%s is empty\n",
142 GNUNET_OS_CONTROL_PIPE);
143 putenv (GNUNET_OS_CONTROL_PIPE "=");
147 pipe_fd = strtoull (env_buf, &env_buf_end, 16);
148 if ((0 != errno) || (env_buf == env_buf_end))
150 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
151 putenv (GNUNET_OS_CONTROL_PIPE "=");
154 if (pipe_fd >= FD_SETSIZE)
156 LOG (GNUNET_ERROR_TYPE_ERROR,
157 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", env_buf);
158 putenv (GNUNET_OS_CONTROL_PIPE "=");
161 /* Gcc will issue a warning here. What to do with it? */
163 control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) pipe_fd);
165 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
167 if (NULL == control_pipe)
169 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
170 putenv (GNUNET_OS_CONTROL_PIPE "=");
173 LOG (GNUNET_ERROR_TYPE_DEBUG,
174 "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
175 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
176 &parent_control_handler, control_pipe);
177 putenv (GNUNET_OS_CONTROL_PIPE "=");
182 * Get process structure for current process
184 * The pointer it returns points to static memory location and must not be
187 * @return pointer to the process sturcutre for this process
189 struct GNUNET_OS_Process *
190 GNUNET_OS_process_current ()
193 current_process.pid = GetCurrentProcessId ();
194 current_process.handle = GetCurrentProcess ();
196 current_process.pid = 0;
198 return ¤t_process;
203 * Sends a signal to the process
205 * @param proc pointer to process structure
207 * @return 0 on success, -1 on error
210 GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
216 if (NULL != proc->control_pipe)
218 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via pipe\n", sig, proc->pid);
219 ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
220 if (sizeof (csig) == ret)
223 /* pipe failed or non-existent, try other methods */
226 #if !defined (WINDOWS)
232 #if defined(WINDOWS) && !defined(__CYGWIN__)
235 int must_kill = GNUNET_YES;
236 if (0 != GetExitCodeProcess (proc->handle, &exitcode))
237 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
238 if (GNUNET_YES == must_kill)
239 if (0 == SafeTerminateProcess (proc->handle, 0, 0))
241 DWORD error_code = GetLastError ();
242 if ((error_code != WAIT_TIMEOUT) && (error_code != ERROR_PROCESS_ABORTED))
244 LOG ((error_code == ERROR_ACCESS_DENIED) ?
245 GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
246 "SafeTermiateProcess failed with code %lu\n", error_code);
247 /* The problem here is that a process that is already dying
248 * might cause SafeTerminateProcess to fail with
249 * ERROR_ACCESS_DENIED, but the process WILL die eventually.
250 * If we really had a permissions problem, hanging up (which
251 * is what will happen in process_wait() in that case) is
254 if (ERROR_ACCESS_DENIED == error_code)
260 SetErrnoFromWinError (error_code);
268 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
269 return PLIBC_KILL (proc->pid, sig);
272 #if defined (WINDOWS)
276 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
277 return PLIBC_KILL (proc->pid, sig);
283 * Get the pid of the process in question
285 * @param proc the process to get the pid of
287 * @return the current process id
290 GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
297 * Cleans up process structure contents (OS-dependent) and deallocates it
299 * @param proc pointer to process structure
302 GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
304 if (NULL != proc->control_pipe)
305 GNUNET_DISK_file_close (proc->control_pipe);
306 #if defined (WINDOWS)
307 if (proc->handle != NULL)
308 CloseHandle (proc->handle);
314 #include "gnunet_signal_lib.h"
316 extern GNUNET_SIGNAL_Handler w32_sigchld_handler;
319 * Make seaspider happy.
321 #define DWORD_WINAPI DWORD WINAPI
324 * @brief Waits for a process to terminate and invokes the SIGCHLD handler
325 * @param proc pointer to process structure
328 child_wait_thread (void *arg)
330 struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *) arg;
332 WaitForSingleObject (proc->handle, INFINITE);
334 if (w32_sigchld_handler)
335 w32_sigchld_handler ();
343 * Set process priority
345 * @param proc pointer to process structure
346 * @param prio priority value
347 * @return GNUNET_OK on success, GNUNET_SYSERR on error
350 GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
351 enum GNUNET_SCHEDULER_Priority prio)
355 GNUNET_assert (prio < GNUNET_SCHEDULER_PRIORITY_COUNT);
356 if (GNUNET_SCHEDULER_PRIORITY_KEEP == prio)
359 /* convert to MINGW/Unix values */
362 case GNUNET_SCHEDULER_PRIORITY_UI:
363 case GNUNET_SCHEDULER_PRIORITY_URGENT:
365 rprio = HIGH_PRIORITY_CLASS;
371 case GNUNET_SCHEDULER_PRIORITY_HIGH:
373 rprio = ABOVE_NORMAL_PRIORITY_CLASS;
379 case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
381 rprio = NORMAL_PRIORITY_CLASS;
387 case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
389 rprio = BELOW_NORMAL_PRIORITY_CLASS;
395 case GNUNET_SCHEDULER_PRIORITY_IDLE:
397 rprio = IDLE_PRIORITY_CLASS;
404 return GNUNET_SYSERR;
407 /* Set process priority */
410 HANDLE h = proc->handle;
412 GNUNET_assert (h != NULL);
413 SetPriorityClass (h, rprio);
419 if ((0 == pid) || (pid == getpid ()))
422 int delta = rprio - have;
425 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
427 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice");
428 return GNUNET_SYSERR;
433 if (0 != setpriority (PRIO_PROCESS, pid, rprio))
435 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
437 return GNUNET_SYSERR;
441 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
442 "Priority management not availabe for this platform\n");
450 CreateCustomEnvTable (char **vars)
452 char *win32_env_table;
457 size_t tablesize = 0;
458 size_t items_count = 0;
467 win32_env_table = GetEnvironmentStringsA ();
468 if (NULL == win32_env_table)
470 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
472 index = GNUNET_malloc (sizeof (char *) * n_var);
473 for (c = 0; c < n_var; c++)
475 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
477 size_t len = strlen (ptr);
480 for (var_ptr = vars; *var_ptr; var_ptr++)
484 var_len = strlen (var);
485 if (strncmp (var, ptr, var_len) == 0)
489 tablesize += var_len + strlen (val) + 1;
494 tablesize += len + 1;
497 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
502 n_found += strlen (var) + strlen (val) + 1;
504 result = GNUNET_malloc (tablesize + n_found + 1);
505 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
507 size_t len = strlen (ptr);
510 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
514 var_len = strlen (var);
515 if (strncmp (var, ptr, var_len) == 0)
523 strcpy (result_ptr, ptr);
524 result_ptr += len + 1;
528 strcpy (result_ptr, var);
529 result_ptr += var_len;
530 strcpy (result_ptr, val);
531 result_ptr += strlen (val) + 1;
535 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
539 var_len = strlen (var);
542 strcpy (result_ptr, var);
543 result_ptr += var_len;
544 strcpy (result_ptr, val);
545 result_ptr += strlen (val) + 1;
548 FreeEnvironmentStrings (win32_env_table);
557 * Open '/dev/null' and make the result the given
560 * @param target_fd desired FD to point to /dev/null
561 * @param flags open flags (O_RDONLY, O_WRONLY)
564 open_dev_null (int target_fd,
569 fd = open ("/dev/null", flags);
572 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
577 if (-1 == dup2 (fd, target_fd))
579 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
583 GNUNET_break (0 == close (fd));
591 * @param pipe_control should a pipe be used to send signals to the child?
592 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which
593 * std handles of the parent are inherited by the child.
594 * pipe_stdin and pipe_stdout take priority over std_inheritance
595 * (when they are non-NULL).
596 * @param pipe_stdin pipe to use to send input to child process (or NULL)
597 * @param pipe_stdout pipe to use to get output from child process (or NULL)
598 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
599 * must be NULL on platforms where dup is not supported
600 * @param filename name of the binary
601 * @param argv NULL-terminated list of arguments to the process
602 * @return process ID of the new process, -1 on error
604 static struct GNUNET_OS_Process *
605 start_process (int pipe_control,
606 enum GNUNET_OS_InheritStdioFlags std_inheritance,
607 struct GNUNET_DISK_PipeHandle *pipe_stdin,
608 struct GNUNET_DISK_PipeHandle *pipe_stdout,
609 const SOCKTYPE *lsocks,
610 const char *filename,
617 struct GNUNET_OS_Process *gnunet_proc;
618 struct GNUNET_DISK_FileHandle *childpipe_read;
619 struct GNUNET_DISK_FileHandle *childpipe_write;
620 int childpipe_read_fd;
633 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename))
634 return NULL; /* not executable */
635 if (GNUNET_YES == pipe_control)
637 struct GNUNET_DISK_PipeHandle *childpipe;
638 int dup_childpipe_read_fd = -1;
639 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
640 if (NULL == childpipe)
642 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
643 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
644 GNUNET_DISK_pipe_close (childpipe);
645 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
646 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
647 &childpipe_read_fd, sizeof (int))) ||
648 (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
651 GNUNET_DISK_file_close (childpipe_read);
653 GNUNET_DISK_file_close (childpipe_write);
654 if (0 <= dup_childpipe_read_fd)
655 close (dup_childpipe_read_fd);
658 childpipe_read_fd = dup_childpipe_read_fd;
659 GNUNET_DISK_file_close (childpipe_read);
663 childpipe_read = NULL;
664 childpipe_write = NULL;
665 childpipe_read_fd = -1;
667 if (NULL != pipe_stdout)
669 GNUNET_assert (GNUNET_OK ==
670 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
672 GNUNET_DISK_PIPE_END_WRITE),
673 &fd_stdout_write, sizeof (int)));
674 GNUNET_assert (GNUNET_OK ==
675 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
676 (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
677 &fd_stdout_read, sizeof (int)));
679 if (NULL != pipe_stdin)
681 GNUNET_assert (GNUNET_OK ==
682 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
683 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
684 &fd_stdin_read, sizeof (int)));
685 GNUNET_assert (GNUNET_OK ==
686 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
687 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
688 &fd_stdin_write, sizeof (int)));
695 while (-1 != (k = lsocks[i++]))
696 GNUNET_array_append (lscp, ls, k);
697 GNUNET_array_append (lscp, ls, -1);
700 /* see https://gnunet.org/vfork */
708 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
709 GNUNET_array_grow (lscp, ls, 0);
711 GNUNET_DISK_file_close (childpipe_read);
713 GNUNET_DISK_file_close (childpipe_write);
714 if (0 <= childpipe_read_fd)
715 close (childpipe_read_fd);
721 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
722 gnunet_proc->pid = ret;
723 gnunet_proc->control_pipe = childpipe_write;
724 if (GNUNET_YES == pipe_control)
726 close (childpipe_read_fd);
728 GNUNET_array_grow (lscp, ls, 0);
731 if (0 <= childpipe_read_fd)
735 /* due to vfork, we must NOT free memory on DARWIN! */
736 GNUNET_DISK_file_close (childpipe_write);
738 snprintf (fdbuf, 100, "%x", childpipe_read_fd);
739 setenv (GNUNET_OS_CONTROL_PIPE, fdbuf, 1);
742 unsetenv (GNUNET_OS_CONTROL_PIPE);
743 if (NULL != pipe_stdin)
745 GNUNET_break (0 == close (fd_stdin_write));
746 if (-1 == dup2 (fd_stdin_read, 0))
747 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
748 GNUNET_break (0 == close (fd_stdin_read));
750 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_IN))
752 GNUNET_break (0 == close (0));
753 open_dev_null (0, O_RDONLY);
755 if (NULL != pipe_stdout)
757 GNUNET_break (0 == close (fd_stdout_read));
758 if (-1 == dup2 (fd_stdout_write, 1))
759 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
760 GNUNET_break (0 == close (fd_stdout_write));
762 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_OUT))
764 GNUNET_break (0 == close (1));
765 open_dev_null (1, O_WRONLY);
767 if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_ERR))
769 GNUNET_break (0 == close (2));
770 open_dev_null (2, O_WRONLY);
774 /* read systemd documentation... */
775 GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
776 setenv ("LISTEN_PID", lpid, 1);
779 while (-1 != lscp[i])
782 while (-1 != lscp[j])
788 GNUNET_assert (-1 != k);
789 GNUNET_assert (0 == close (lscp[j]));
797 /* Bury any existing FD, no matter what; they should all be closed
798 * on exec anyway and the important onces have been dup'ed away */
800 GNUNET_assert (-1 != dup2 (lscp[i], tgt));
802 /* unset close-on-exec flag */
803 flags = fcntl (tgt, F_GETFD);
804 GNUNET_assert (flags >= 0);
805 flags &= ~FD_CLOEXEC;
807 (void) fcntl (tgt, F_SETFD, flags);
811 GNUNET_snprintf (fds, sizeof (fds), "%u", i);
812 setenv ("LISTEN_FDS", fds, 1);
815 /* due to vfork, we must NOT free memory on DARWIN! */
816 GNUNET_array_grow (lscp, ls, 0);
818 execvp (filename, argv);
819 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
822 struct GNUNET_DISK_FileHandle *childpipe_read;
823 struct GNUNET_DISK_FileHandle *childpipe_write;
824 HANDLE childpipe_read_handle;
826 char **non_const_argv;
831 PROCESS_INFORMATION proc;
833 struct GNUNET_OS_Process *gnunet_proc;
834 char path[MAX_PATH + 1];
835 char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
836 char *env_block = NULL;
844 char *non_const_filename;
845 char win_path[MAX_PATH + 1];
846 struct GNUNET_DISK_PipeHandle *lsocks_pipe;
847 const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
858 HANDLE stdout_handle;
859 HANDLE stdih, stdoh, stdeh;
860 DWORD stdif, stdof, stdef;
864 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename))
865 return NULL; /* not executable */
867 /* Search in prefix dir (hopefully - the directory from which
868 * the current module was loaded), bindir and libdir, then in PATH
870 self_prefix = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
871 bindir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
872 libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
874 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
877 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
880 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
883 ptr += sprintf (pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
884 GNUNET_free (self_prefix);
885 GNUNET_free (bindir);
886 GNUNET_free (libdir);
888 alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
889 if (alloc_len != pathbuf_len - 1)
891 GNUNET_free (pathbuf);
892 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
896 cmdlen = strlen (filename);
897 if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) )
898 GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
900 GNUNET_asprintf (&non_const_filename, "%s", filename);
902 /* It could be in POSIX form, convert it to a DOS path early on */
903 if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
905 SetErrnoFromWinError (lRet);
906 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
908 GNUNET_free (non_const_filename);
909 GNUNET_free (pathbuf);
912 GNUNET_free (non_const_filename);
913 non_const_filename = GNUNET_strdup (win_path);
914 /* Check that this is the full path. If it isn't, search. */
915 /* FIXME: convert it to wchar_t and use SearchPathW?
916 * Remember: arguments to _start_process() are technically in UTF-8...
918 if (non_const_filename[1] == ':')
920 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
921 LOG (GNUNET_ERROR_TYPE_DEBUG,
922 "Using path `%s' as-is. PATH is %s\n", path, ptr);
924 else if (!SearchPathA
925 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
928 SetErrnoFromWinError (GetLastError ());
929 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
931 GNUNET_free (non_const_filename);
932 GNUNET_free (pathbuf);
936 LOG (GNUNET_ERROR_TYPE_DEBUG,
937 "Found `%s' in PATH `%s'\n", path, pathbuf);
938 GNUNET_free (pathbuf);
939 GNUNET_free (non_const_filename);
941 /* Count the number of arguments */
942 arg = (char **) argv;
949 /* Allocate a copy argv */
950 non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1));
952 /* Copy all argv strings */
954 arg = (char **) argv;
958 non_const_argv[argcount] = GNUNET_strdup (path);
960 non_const_argv[argcount] = GNUNET_strdup (*arg);
964 non_const_argv[argcount] = NULL;
968 arg = non_const_argv;
971 cmdlen = cmdlen + strlen (*arg) + 4;
975 /* Allocate and create cmd */
976 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
977 arg = non_const_argv;
980 char arg_last_char = (*arg)[strlen (*arg) - 1];
981 idx += sprintf (idx, "\"%s%s\"%s", *arg,
982 arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : "");
987 GNUNET_free (non_const_argv[--argcount]);
988 GNUNET_free (non_const_argv);
990 memset (&start, 0, sizeof (start));
991 start.cb = sizeof (start);
992 if ((pipe_stdin != NULL) || (pipe_stdout != NULL) || (std_inheritance != 0))
993 start.dwFlags |= STARTF_USESTDHANDLES;
995 stdih = GetStdHandle (STD_INPUT_HANDLE);
996 GetHandleInformation (stdih, &stdif);
997 if (pipe_stdin != NULL)
999 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1000 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
1001 &stdin_handle, sizeof (HANDLE));
1002 start.hStdInput = stdin_handle;
1006 if (std_inheritance & GNUNET_OS_INHERIT_STD_IN)
1008 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 1);
1009 if (pipe_stdin == NULL)
1010 start.hStdInput = stdih;
1013 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 0);
1017 stdoh = GetStdHandle (STD_OUTPUT_HANDLE);
1018 GetHandleInformation (stdoh, &stdof);
1019 if (NULL != pipe_stdout)
1021 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1023 GNUNET_DISK_PIPE_END_WRITE),
1024 &stdout_handle, sizeof (HANDLE));
1025 start.hStdOutput = stdout_handle;
1029 if (std_inheritance & GNUNET_OS_INHERIT_STD_OUT)
1031 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 1);
1032 if (pipe_stdout == NULL)
1033 start.hStdOutput = stdoh;
1036 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 0);
1039 stdeh = GetStdHandle (STD_ERROR_HANDLE);
1040 GetHandleInformation (stdeh, &stdef);
1043 if (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)
1045 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 1);
1046 start.hStdError = stdeh;
1049 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 0);
1052 if (GNUNET_YES == pipe_control)
1054 struct GNUNET_DISK_PipeHandle *childpipe;
1055 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
1056 if (NULL == childpipe)
1058 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
1059 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
1060 GNUNET_DISK_pipe_close (childpipe);
1061 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
1062 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
1063 &childpipe_read_handle, sizeof (HANDLE))))
1066 GNUNET_DISK_file_close (childpipe_read);
1067 if (childpipe_write)
1068 GNUNET_DISK_file_close (childpipe_write);
1073 /* Unlike *nix variant, we don't dup the handle, so can't close
1074 * filehandle right now.
1076 SetHandleInformation (childpipe_read_handle, HANDLE_FLAG_INHERIT, 1);
1080 childpipe_read = NULL;
1081 childpipe_write = NULL;
1084 if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
1086 lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1088 if (lsocks_pipe == NULL)
1092 GNUNET_DISK_pipe_close (lsocks_pipe);
1093 if (GNUNET_YES == pipe_control)
1095 GNUNET_DISK_file_close (childpipe_write);
1096 GNUNET_DISK_file_close (childpipe_read);
1100 lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe,
1101 GNUNET_DISK_PIPE_END_WRITE);
1102 GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
1103 &lsocks_write, sizeof (HANDLE));
1104 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1105 (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
1106 &lsocks_read, sizeof (HANDLE));
1112 if (GNUNET_YES == pipe_control)
1114 GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
1115 GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
1117 if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
1119 /*This will tell the child that we're going to send lsocks over the pipe*/
1120 GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
1121 GNUNET_asprintf (&our_env[env_off++], "%lu", lsocks_read);
1123 our_env[env_off++] = NULL;
1124 env_block = CreateCustomEnvTable (our_env);
1126 GNUNET_free_non_null (our_env[--env_off]);
1129 if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
1131 LOG (GNUNET_ERROR_TYPE_DEBUG,
1132 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
1133 GNUNET_free (env_block);
1136 GNUNET_DISK_pipe_close (lsocks_pipe);
1137 if (GNUNET_YES == pipe_control)
1139 GNUNET_DISK_file_close (childpipe_write);
1140 GNUNET_DISK_file_close (childpipe_read);
1146 if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
1148 LOG (GNUNET_ERROR_TYPE_DEBUG,
1149 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno);
1150 GNUNET_free (env_block);
1154 GNUNET_DISK_pipe_close (lsocks_pipe);
1155 if (GNUNET_YES == pipe_control)
1157 GNUNET_DISK_file_close (childpipe_write);
1158 GNUNET_DISK_file_close (childpipe_read);
1163 bresult = CreateProcessW (wpath, wcmd, NULL, NULL, TRUE,
1164 DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
1165 error_code = GetLastError ();
1167 if ((NULL == pipe_stdin) && (stdih))
1168 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, stdif);
1171 if ((NULL == pipe_stdout) && (stdoh))
1172 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, stdof);
1175 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
1178 LOG (GNUNET_ERROR_TYPE_ERROR, "CreateProcess(%s, %s) failed: %lu\n", path, cmd, error_code);
1180 GNUNET_free (env_block);
1185 if (GNUNET_YES == pipe_control)
1187 GNUNET_DISK_file_close (childpipe_read);
1192 if (GNUNET_YES == pipe_control)
1194 GNUNET_DISK_file_close (childpipe_write);
1197 GNUNET_DISK_pipe_close (lsocks_pipe);
1198 SetErrnoFromWinError (error_code);
1202 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
1203 gnunet_proc->pid = proc.dwProcessId;
1204 gnunet_proc->handle = proc.hProcess;
1205 gnunet_proc->control_pipe = childpipe_write;
1207 CreateThread (NULL, 64000, &child_wait_thread, (void *) gnunet_proc, 0, NULL);
1209 ResumeThread (proc.hThread);
1210 CloseHandle (proc.hThread);
1212 if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) )
1215 GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
1217 /* This is a replacement for "goto error" that doesn't use goto */
1226 /* Tell the number of sockets */
1227 for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++);
1229 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1230 if (sizeof (count) != wrote)
1232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1233 "Failed to write %u count bytes to the child: %u\n",
1234 sizeof (count), GetLastError ());
1237 for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
1239 WSAPROTOCOL_INFOA pi;
1240 /* Get a socket duplication info */
1241 if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
1243 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1244 "Failed to duplicate an socket[%llu]: %u\n", i,
1248 /* Synchronous I/O is not nice, but we can't schedule this:
1249 * lsocks will be closed/freed by the caller soon, and until
1250 * the child creates a duplicate, closing a socket here will
1251 * close it for good.
1253 /* Send the size of the structure
1254 * (the child might be built with different headers...)
1257 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &size, sizeof (size));
1258 if (sizeof (size) != wrote)
1260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1261 "Failed to write %u size[%llu] bytes to the child: %u\n",
1262 sizeof (size), i, GetLastError ());
1265 /* Finally! Send the data */
1266 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &pi, sizeof (pi));
1267 if (sizeof (pi) != wrote)
1269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1270 "Failed to write %u socket[%llu] bytes to the child: %u\n",
1271 sizeof (pi), i, GetLastError ());
1275 /* This will block us until the child makes a final read or closes
1276 * the pipe (hence no 'wrote' check), since we have to wait for it
1277 * to duplicate the last socket, before we return and start closing
1280 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1285 GNUNET_DISK_file_sync (lsocks_write_fd);
1286 GNUNET_DISK_pipe_close (lsocks_pipe);
1290 /* If we can't pass on the socket(s), the child will block forever,
1291 * better put it out of its misery.
1293 SafeTerminateProcess (gnunet_proc->handle, 0, 0);
1294 CloseHandle (gnunet_proc->handle);
1295 if (NULL != gnunet_proc->control_pipe)
1296 GNUNET_DISK_file_close (gnunet_proc->control_pipe);
1297 GNUNET_free (gnunet_proc);
1310 * @param pipe_control should a pipe be used to send signals to the child?
1311 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1312 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1313 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1314 * @param filename name of the binary
1315 * @param argv NULL-terminated array of arguments to the process
1316 * @return pointer to process structure of the new process, NULL on error
1318 struct GNUNET_OS_Process *
1319 GNUNET_OS_start_process_vap (int pipe_control,
1320 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1321 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1322 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1323 const char *filename,
1326 return start_process (pipe_control,
1339 * @param pipe_control should a pipe be used to send signals to the child?
1340 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1341 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1342 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1343 * @param filename name of the binary
1344 * @param va NULL-terminated list of arguments to the process
1345 * @return pointer to process structure of the new process, NULL on error
1347 struct GNUNET_OS_Process *
1348 GNUNET_OS_start_process_va (int pipe_control,
1349 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1350 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1351 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1352 const char *filename, va_list va)
1354 struct GNUNET_OS_Process *ret;
1361 while (NULL != va_arg (ap, char *))
1364 argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
1367 while (NULL != (argv[argc] = va_arg (ap, char *)))
1370 ret = GNUNET_OS_start_process_vap (pipe_control,
1384 * @param pipe_control should a pipe be used to send signals to the child?
1385 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1386 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1387 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1388 * @param filename name of the binary
1389 * @param ... NULL-terminated list of arguments to the process
1390 * @return pointer to process structure of the new process, NULL on error
1392 struct GNUNET_OS_Process *
1393 GNUNET_OS_start_process (int pipe_control,
1394 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1395 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1396 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1397 const char *filename, ...)
1399 struct GNUNET_OS_Process *ret;
1402 va_start (ap, filename);
1403 ret = GNUNET_OS_start_process_va (pipe_control, std_inheritance, pipe_stdin,
1404 pipe_stdout, filename, ap);
1413 * @param pipe_control should a pipe be used to send signals to the child?
1414 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which
1415 * std handles of the parent are inherited by the child.
1416 * pipe_stdin and pipe_stdout take priority over std_inheritance
1417 * (when they are non-NULL).
1418 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
1419 * must be NULL on platforms where dup is not supported
1420 * @param filename name of the binary
1421 * @param argv NULL-terminated list of arguments to the process
1422 * @return process ID of the new process, -1 on error
1424 struct GNUNET_OS_Process *
1425 GNUNET_OS_start_process_v (int pipe_control,
1426 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1427 const SOCKTYPE *lsocks,
1428 const char *filename,
1431 return start_process (pipe_control,
1442 * Retrieve the status of a process, waiting on him if dead.
1443 * Nonblocking version.
1445 * @param proc process ID
1446 * @param type status type
1447 * @param code return code/signal number
1448 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
1451 GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1452 enum GNUNET_OS_ProcessStatusType *type,
1453 unsigned long *code)
1459 GNUNET_assert (0 != proc);
1460 ret = waitpid (proc->pid, &status, WNOHANG);
1463 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1464 return GNUNET_SYSERR;
1468 *type = GNUNET_OS_PROCESS_RUNNING;
1472 if (proc->pid != ret)
1474 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1475 return GNUNET_SYSERR;
1477 if (WIFEXITED (status))
1479 *type = GNUNET_OS_PROCESS_EXITED;
1480 *code = WEXITSTATUS (status);
1482 else if (WIFSIGNALED (status))
1484 *type = GNUNET_OS_PROCESS_SIGNALED;
1485 *code = WTERMSIG (status);
1487 else if (WIFSTOPPED (status))
1489 *type = GNUNET_OS_PROCESS_SIGNALED;
1490 *code = WSTOPSIG (status);
1493 else if (WIFCONTINUED (status))
1495 *type = GNUNET_OS_PROCESS_RUNNING;
1501 *type = GNUNET_OS_PROCESS_UNKNOWN;
1506 DWORD c, error_code, ret;
1510 if (h == NULL || ret == 0)
1512 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1514 return GNUNET_SYSERR;
1517 h = GetCurrentProcess ();
1520 ret = GetExitCodeProcess (h, &c);
1521 error_code = GetLastError ();
1522 if (ret == 0 || error_code != NO_ERROR)
1524 SetErrnoFromWinError (error_code);
1525 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
1526 return GNUNET_SYSERR;
1528 if (STILL_ACTIVE == c)
1530 *type = GNUNET_OS_PROCESS_RUNNING;
1534 *type = GNUNET_OS_PROCESS_EXITED;
1543 * Wait for a process
1545 * @param proc pointer to process structure
1546 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
1549 GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1552 pid_t pid = proc->pid;
1555 while ( (pid != (ret = waitpid (pid, NULL, 0))) &&
1556 (EINTR == errno) ) ;
1559 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1560 return GNUNET_SYSERR;
1569 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1571 return GNUNET_SYSERR;
1574 h = GetCurrentProcess ();
1576 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
1578 SetErrnoFromWinError (GetLastError ());
1579 return GNUNET_SYSERR;
1587 * Handle to a command.
1589 struct GNUNET_OS_CommandHandle
1595 struct GNUNET_OS_Process *eip;
1598 * Handle to the output pipe.
1600 struct GNUNET_DISK_PipeHandle *opipe;
1603 * Read-end of output pipe.
1605 const struct GNUNET_DISK_FileHandle *r;
1608 * Function to call on each line of output.
1610 GNUNET_OS_LineProcessor proc;
1613 * Closure for 'proc'.
1618 * Buffer for the output.
1623 * Task reading from pipe.
1625 GNUNET_SCHEDULER_TaskIdentifier rtask;
1630 struct GNUNET_TIME_Absolute timeout;
1633 * Current read offset in buf.
1640 * Stop/kill a command. Must ONLY be called either from
1641 * the callback after 'NULL' was passed for 'line' *OR*
1642 * from an independent task (not within the line processor).
1644 * @param cmd handle to the process
1647 GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
1649 if (NULL != cmd->proc)
1651 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
1652 GNUNET_SCHEDULER_cancel (cmd->rtask);
1654 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1655 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
1656 GNUNET_OS_process_destroy (cmd->eip);
1657 GNUNET_DISK_pipe_close (cmd->opipe);
1663 * Read from the process and call the line processor.
1665 * @param cls the 'struct GNUNET_OS_CommandHandle'
1666 * @param tc scheduler context
1669 cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1671 struct GNUNET_OS_CommandHandle *cmd = cls;
1672 GNUNET_OS_LineProcessor proc;
1676 cmd->rtask = GNUNET_SCHEDULER_NO_TASK;
1677 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1679 /* timeout, shutdown, etc. */
1682 proc (cmd->proc_cls, NULL);
1686 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
1687 sizeof (cmd->buf) - cmd->off);
1690 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
1692 cmd->buf[cmd->off] = '\0';
1693 cmd->proc (cmd->proc_cls, cmd->buf);
1697 proc (cmd->proc_cls, NULL);
1700 end = memchr (&cmd->buf[cmd->off], '\n', ret);
1705 cmd->proc (cmd->proc_cls, cmd->buf);
1706 memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
1707 cmd->off -= (end + 1 - cmd->buf);
1708 end = memchr (cmd->buf, '\n', cmd->off);
1711 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
1712 (cmd->timeout), cmd->r, &cmd_read, cmd);
1717 * Run the given command line and call the given function
1718 * for each line of the output.
1720 * @param proc function to call for each line of the output
1721 * @param proc_cls closure for proc
1722 * @param timeout when to time out
1723 * @param binary command to run
1724 * @param ... arguments to command
1725 * @return NULL on error
1727 struct GNUNET_OS_CommandHandle *
1728 GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1729 struct GNUNET_TIME_Relative timeout, const char *binary,
1732 struct GNUNET_OS_CommandHandle *cmd;
1733 struct GNUNET_OS_Process *eip;
1734 struct GNUNET_DISK_PipeHandle *opipe;
1737 opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1740 va_start (ap, binary);
1741 /* redirect stdout, don't inherit stderr/stdin */
1742 eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, binary, ap);
1746 GNUNET_DISK_pipe_close (opipe);
1749 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
1750 cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
1751 cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1755 cmd->proc_cls = proc_cls;
1756 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
1757 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1762 /* end of os_priority.c */