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 /* Gcc will issue a warning here. What to do with it? */
156 control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) pipe_fd);
158 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
160 if (NULL == control_pipe)
162 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
163 putenv (GNUNET_OS_CONTROL_PIPE "=");
166 LOG (GNUNET_ERROR_TYPE_DEBUG,
167 "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
168 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
169 &parent_control_handler, control_pipe);
170 putenv (GNUNET_OS_CONTROL_PIPE "=");
175 * Get process structure for current process
177 * The pointer it returns points to static memory location and must not be
180 * @return pointer to the process sturcutre for this process
182 struct GNUNET_OS_Process *
183 GNUNET_OS_process_current ()
186 current_process.pid = GetCurrentProcessId ();
187 current_process.handle = GetCurrentProcess ();
189 current_process.pid = 0;
191 return ¤t_process;
196 * Sends a signal to the process
198 * @param proc pointer to process structure
200 * @return 0 on success, -1 on error
203 GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
209 if (NULL != proc->control_pipe)
211 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via pipe\n", sig, proc->pid);
212 ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
213 if (sizeof (csig) == ret)
216 /* pipe failed or non-existent, try other methods */
219 #if !defined (WINDOWS)
225 #if defined(WINDOWS) && !defined(__CYGWIN__)
228 int must_kill = GNUNET_YES;
229 if (0 != GetExitCodeProcess (proc->handle, &exitcode))
230 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
231 if (GNUNET_YES == must_kill)
232 if (0 == SafeTerminateProcess (proc->handle, 0, 0))
234 DWORD error_code = GetLastError ();
235 if ((error_code != WAIT_TIMEOUT) && (error_code != ERROR_PROCESS_ABORTED))
237 LOG ((error_code == ERROR_ACCESS_DENIED) ?
238 GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
239 "SafeTermiateProcess failed with code %lu\n", error_code);
240 /* The problem here is that a process that is already dying
241 * might cause SafeTerminateProcess to fail with
242 * ERROR_ACCESS_DENIED, but the process WILL die eventually.
243 * If we really had a permissions problem, hanging up (which
244 * is what will happen in process_wait() in that case) is
247 if (ERROR_ACCESS_DENIED == error_code)
253 SetErrnoFromWinError (error_code);
261 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
262 return PLIBC_KILL (proc->pid, sig);
265 #if defined (WINDOWS)
269 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
270 return PLIBC_KILL (proc->pid, sig);
276 * Get the pid of the process in question
278 * @param proc the process to get the pid of
280 * @return the current process id
283 GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
290 * Cleans up process structure contents (OS-dependent) and deallocates it
292 * @param proc pointer to process structure
295 GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
297 if (NULL != proc->control_pipe)
298 GNUNET_DISK_file_close (proc->control_pipe);
299 #if defined (WINDOWS)
300 if (proc->handle != NULL)
301 CloseHandle (proc->handle);
307 #include "gnunet_signal_lib.h"
309 extern GNUNET_SIGNAL_Handler w32_sigchld_handler;
312 * Make seaspider happy.
314 #define DWORD_WINAPI DWORD WINAPI
317 * @brief Waits for a process to terminate and invokes the SIGCHLD handler
318 * @param proc pointer to process structure
321 child_wait_thread (void *arg)
323 struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *) arg;
325 WaitForSingleObject (proc->handle, INFINITE);
327 if (w32_sigchld_handler)
328 w32_sigchld_handler ();
336 * Set process priority
338 * @param proc pointer to process structure
339 * @param prio priority value
340 * @return GNUNET_OK on success, GNUNET_SYSERR on error
343 GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
344 enum GNUNET_SCHEDULER_Priority prio)
348 GNUNET_assert (prio < GNUNET_SCHEDULER_PRIORITY_COUNT);
349 if (GNUNET_SCHEDULER_PRIORITY_KEEP == prio)
352 /* convert to MINGW/Unix values */
355 case GNUNET_SCHEDULER_PRIORITY_UI:
356 case GNUNET_SCHEDULER_PRIORITY_URGENT:
358 rprio = HIGH_PRIORITY_CLASS;
364 case GNUNET_SCHEDULER_PRIORITY_HIGH:
366 rprio = ABOVE_NORMAL_PRIORITY_CLASS;
372 case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
374 rprio = NORMAL_PRIORITY_CLASS;
380 case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
382 rprio = BELOW_NORMAL_PRIORITY_CLASS;
388 case GNUNET_SCHEDULER_PRIORITY_IDLE:
390 rprio = IDLE_PRIORITY_CLASS;
397 return GNUNET_SYSERR;
400 /* Set process priority */
403 HANDLE h = proc->handle;
405 GNUNET_assert (h != NULL);
406 SetPriorityClass (h, rprio);
412 if ((0 == pid) || (pid == getpid ()))
415 int delta = rprio - have;
418 if ((delta != 0) && (rprio == nice (delta)) && (errno != 0))
420 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "nice");
421 return GNUNET_SYSERR;
426 if (0 != setpriority (PRIO_PROCESS, pid, rprio))
428 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
430 return GNUNET_SYSERR;
434 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
435 "Priority management not availabe for this platform\n");
443 CreateCustomEnvTable (char **vars)
445 char *win32_env_table;
450 size_t tablesize = 0;
451 size_t items_count = 0;
460 win32_env_table = GetEnvironmentStringsA ();
461 if (NULL == win32_env_table)
463 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
465 index = GNUNET_malloc (sizeof (char *) * n_var);
466 for (c = 0; c < n_var; c++)
468 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
470 size_t len = strlen (ptr);
473 for (var_ptr = vars; *var_ptr; var_ptr++)
477 var_len = strlen (var);
478 if (strncmp (var, ptr, var_len) == 0)
482 tablesize += var_len + strlen (val) + 1;
487 tablesize += len + 1;
490 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
495 n_found += strlen (var) + strlen (val) + 1;
497 result = GNUNET_malloc (tablesize + n_found + 1);
498 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
500 size_t len = strlen (ptr);
503 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
507 var_len = strlen (var);
508 if (strncmp (var, ptr, var_len) == 0)
516 strcpy (result_ptr, ptr);
517 result_ptr += len + 1;
521 strcpy (result_ptr, var);
522 result_ptr += var_len;
523 strcpy (result_ptr, val);
524 result_ptr += strlen (val) + 1;
528 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
532 var_len = strlen (var);
535 strcpy (result_ptr, var);
536 result_ptr += var_len;
537 strcpy (result_ptr, val);
538 result_ptr += strlen (val) + 1;
541 FreeEnvironmentStrings (win32_env_table);
550 * Open '/dev/null' and make the result the given
553 * @param target_fd desired FD to point to /dev/null
554 * @param flags open flags (O_RDONLY, O_WRONLY)
557 open_dev_null (int target_fd,
562 fd = open ("/dev/null", flags);
565 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
570 if (-1 == dup2 (fd, target_fd))
572 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
576 GNUNET_break (0 == close (fd));
584 * @param pipe_control should a pipe be used to send signals to the child?
585 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which
586 * std handles of the parent are inherited by the child.
587 * pipe_stdin and pipe_stdout take priority over std_inheritance
588 * (when they are non-NULL).
589 * @param pipe_stdin pipe to use to send input to child process (or NULL)
590 * @param pipe_stdout pipe to use to get output from child process (or NULL)
591 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
592 * must be NULL on platforms where dup is not supported
593 * @param filename name of the binary
594 * @param argv NULL-terminated list of arguments to the process
595 * @return process ID of the new process, -1 on error
597 static struct GNUNET_OS_Process *
598 start_process (int pipe_control,
599 enum GNUNET_OS_InheritStdioFlags std_inheritance,
600 struct GNUNET_DISK_PipeHandle *pipe_stdin,
601 struct GNUNET_DISK_PipeHandle *pipe_stdout,
602 const SOCKTYPE *lsocks,
603 const char *filename,
610 struct GNUNET_OS_Process *gnunet_proc;
611 struct GNUNET_DISK_FileHandle *childpipe_read;
612 struct GNUNET_DISK_FileHandle *childpipe_write;
613 int childpipe_read_fd;
626 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename))
627 return NULL; /* not executable */
628 if (GNUNET_YES == pipe_control)
630 struct GNUNET_DISK_PipeHandle *childpipe;
631 int dup_childpipe_read_fd = -1;
632 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
633 if (NULL == childpipe)
635 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
636 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
637 GNUNET_DISK_pipe_close (childpipe);
638 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
639 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
640 &childpipe_read_fd, sizeof (int))) ||
641 (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
644 GNUNET_DISK_file_close (childpipe_read);
646 GNUNET_DISK_file_close (childpipe_write);
647 if (0 <= dup_childpipe_read_fd)
648 close (dup_childpipe_read_fd);
651 childpipe_read_fd = dup_childpipe_read_fd;
652 GNUNET_DISK_file_close (childpipe_read);
656 childpipe_read = NULL;
657 childpipe_write = NULL;
658 childpipe_read_fd = -1;
660 if (NULL != pipe_stdout)
662 GNUNET_assert (GNUNET_OK ==
663 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
665 GNUNET_DISK_PIPE_END_WRITE),
666 &fd_stdout_write, sizeof (int)));
667 GNUNET_assert (GNUNET_OK ==
668 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
669 (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
670 &fd_stdout_read, sizeof (int)));
672 if (NULL != pipe_stdin)
674 GNUNET_assert (GNUNET_OK ==
675 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
676 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
677 &fd_stdin_read, sizeof (int)));
678 GNUNET_assert (GNUNET_OK ==
679 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
680 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
681 &fd_stdin_write, sizeof (int)));
688 while (-1 != (k = lsocks[i++]))
689 GNUNET_array_append (lscp, ls, k);
690 GNUNET_array_append (lscp, ls, -1);
693 /* see https://gnunet.org/vfork */
701 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
702 GNUNET_array_grow (lscp, ls, 0);
704 GNUNET_DISK_file_close (childpipe_read);
706 GNUNET_DISK_file_close (childpipe_write);
707 if (0 <= childpipe_read_fd)
708 close (childpipe_read_fd);
714 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
715 gnunet_proc->pid = ret;
716 gnunet_proc->control_pipe = childpipe_write;
717 if (GNUNET_YES == pipe_control)
719 close (childpipe_read_fd);
721 GNUNET_array_grow (lscp, ls, 0);
724 if (0 <= childpipe_read_fd)
728 /* due to vfork, we must NOT free memory on DARWIN! */
729 GNUNET_DISK_file_close (childpipe_write);
731 snprintf (fdbuf, 100, "%x", childpipe_read_fd);
732 setenv (GNUNET_OS_CONTROL_PIPE, fdbuf, 1);
735 unsetenv (GNUNET_OS_CONTROL_PIPE);
736 if (NULL != pipe_stdin)
738 GNUNET_break (0 == close (fd_stdin_write));
739 if (-1 == dup2 (fd_stdin_read, 0))
740 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
741 GNUNET_break (0 == close (fd_stdin_read));
743 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_IN))
745 GNUNET_break (0 == close (0));
746 open_dev_null (0, O_RDONLY);
748 if (NULL != pipe_stdout)
750 GNUNET_break (0 == close (fd_stdout_read));
751 if (-1 == dup2 (fd_stdout_write, 1))
752 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
753 GNUNET_break (0 == close (fd_stdout_write));
755 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_OUT))
757 GNUNET_break (0 == close (1));
758 open_dev_null (1, O_WRONLY);
760 if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_ERR))
762 GNUNET_break (0 == close (2));
763 open_dev_null (2, O_WRONLY);
767 /* read systemd documentation... */
768 GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
769 setenv ("LISTEN_PID", lpid, 1);
772 while (-1 != lscp[i])
775 while (-1 != lscp[j])
781 GNUNET_assert (-1 != k);
782 GNUNET_assert (0 == close (lscp[j]));
790 /* Bury any existing FD, no matter what; they should all be closed
791 * on exec anyway and the important onces have been dup'ed away */
793 GNUNET_assert (-1 != dup2 (lscp[i], tgt));
795 /* unset close-on-exec flag */
796 flags = fcntl (tgt, F_GETFD);
797 GNUNET_assert (flags >= 0);
798 flags &= ~FD_CLOEXEC;
800 (void) fcntl (tgt, F_SETFD, flags);
804 GNUNET_snprintf (fds, sizeof (fds), "%u", i);
805 setenv ("LISTEN_FDS", fds, 1);
808 /* due to vfork, we must NOT free memory on DARWIN! */
809 GNUNET_array_grow (lscp, ls, 0);
811 execvp (filename, argv);
812 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
815 struct GNUNET_DISK_FileHandle *childpipe_read;
816 struct GNUNET_DISK_FileHandle *childpipe_write;
817 HANDLE childpipe_read_handle;
819 char **non_const_argv;
824 PROCESS_INFORMATION proc;
826 struct GNUNET_OS_Process *gnunet_proc;
827 char path[MAX_PATH + 1];
828 char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
829 char *env_block = NULL;
837 char *non_const_filename;
838 char win_path[MAX_PATH + 1];
839 struct GNUNET_DISK_PipeHandle *lsocks_pipe;
840 const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
851 HANDLE stdout_handle;
852 HANDLE stdih, stdoh, stdeh;
853 DWORD stdif, stdof, stdef;
857 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename))
858 return NULL; /* not executable */
860 /* Search in prefix dir (hopefully - the directory from which
861 * the current module was loaded), bindir and libdir, then in PATH
863 self_prefix = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
864 bindir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
865 libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
867 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
870 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
873 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
876 ptr += sprintf (pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
877 GNUNET_free (self_prefix);
878 GNUNET_free (bindir);
879 GNUNET_free (libdir);
881 alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
882 if (alloc_len != pathbuf_len - 1)
884 GNUNET_free (pathbuf);
885 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
889 cmdlen = strlen (filename);
890 if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) )
891 GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
893 GNUNET_asprintf (&non_const_filename, "%s", filename);
895 /* It could be in POSIX form, convert it to a DOS path early on */
896 if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
898 SetErrnoFromWinError (lRet);
899 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
901 GNUNET_free (non_const_filename);
902 GNUNET_free (pathbuf);
905 GNUNET_free (non_const_filename);
906 non_const_filename = GNUNET_strdup (win_path);
907 /* Check that this is the full path. If it isn't, search. */
908 /* FIXME: convert it to wchar_t and use SearchPathW?
909 * Remember: arguments to _start_process() are technically in UTF-8...
911 if (non_const_filename[1] == ':')
913 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
914 LOG (GNUNET_ERROR_TYPE_DEBUG,
915 "Using path `%s' as-is. PATH is %s\n", path, ptr);
917 else if (!SearchPathA
918 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
921 SetErrnoFromWinError (GetLastError ());
922 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
924 GNUNET_free (non_const_filename);
925 GNUNET_free (pathbuf);
929 LOG (GNUNET_ERROR_TYPE_DEBUG,
930 "Found `%s' in PATH `%s'\n", path, pathbuf);
931 GNUNET_free (pathbuf);
932 GNUNET_free (non_const_filename);
934 /* Count the number of arguments */
935 arg = (char **) argv;
942 /* Allocate a copy argv */
943 non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1));
945 /* Copy all argv strings */
947 arg = (char **) argv;
951 non_const_argv[argcount] = GNUNET_strdup (path);
953 non_const_argv[argcount] = GNUNET_strdup (*arg);
957 non_const_argv[argcount] = NULL;
961 arg = non_const_argv;
964 cmdlen = cmdlen + strlen (*arg) + 4;
968 /* Allocate and create cmd */
969 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
970 arg = non_const_argv;
973 char arg_last_char = (*arg)[strlen (*arg) - 1];
974 idx += sprintf (idx, "\"%s%s\"%s", *arg,
975 arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : "");
980 GNUNET_free (non_const_argv[--argcount]);
981 GNUNET_free (non_const_argv);
983 memset (&start, 0, sizeof (start));
984 start.cb = sizeof (start);
985 if ((pipe_stdin != NULL) || (pipe_stdout != NULL) || (std_inheritance != 0))
986 start.dwFlags |= STARTF_USESTDHANDLES;
988 stdih = GetStdHandle (STD_INPUT_HANDLE);
989 GetHandleInformation (stdih, &stdif);
990 if (pipe_stdin != NULL)
992 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
993 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
994 &stdin_handle, sizeof (HANDLE));
995 start.hStdInput = stdin_handle;
999 if (std_inheritance & GNUNET_OS_INHERIT_STD_IN)
1001 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 1);
1002 if (pipe_stdin == NULL)
1003 start.hStdInput = stdih;
1006 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 0);
1010 stdoh = GetStdHandle (STD_OUTPUT_HANDLE);
1011 GetHandleInformation (stdoh, &stdof);
1012 if (NULL != pipe_stdout)
1014 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1016 GNUNET_DISK_PIPE_END_WRITE),
1017 &stdout_handle, sizeof (HANDLE));
1018 start.hStdOutput = stdout_handle;
1022 if (std_inheritance & GNUNET_OS_INHERIT_STD_OUT)
1024 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 1);
1025 if (pipe_stdout == NULL)
1026 start.hStdOutput = stdoh;
1029 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 0);
1032 stdeh = GetStdHandle (STD_ERROR_HANDLE);
1033 GetHandleInformation (stdeh, &stdef);
1036 if (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)
1038 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 1);
1039 start.hStdError = stdeh;
1042 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 0);
1045 if (GNUNET_YES == pipe_control)
1047 struct GNUNET_DISK_PipeHandle *childpipe;
1048 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
1049 if (NULL == childpipe)
1051 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
1052 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
1053 GNUNET_DISK_pipe_close (childpipe);
1054 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
1055 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
1056 &childpipe_read_handle, sizeof (HANDLE))))
1059 GNUNET_DISK_file_close (childpipe_read);
1060 if (childpipe_write)
1061 GNUNET_DISK_file_close (childpipe_write);
1066 /* Unlike *nix variant, we don't dup the handle, so can't close
1067 * filehandle right now.
1069 SetHandleInformation (childpipe_read_handle, HANDLE_FLAG_INHERIT, 1);
1073 childpipe_read = NULL;
1074 childpipe_write = NULL;
1077 if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
1079 lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1081 if (lsocks_pipe == NULL)
1085 GNUNET_DISK_pipe_close (lsocks_pipe);
1086 if (GNUNET_YES == pipe_control)
1088 GNUNET_DISK_file_close (childpipe_write);
1089 GNUNET_DISK_file_close (childpipe_read);
1093 lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe,
1094 GNUNET_DISK_PIPE_END_WRITE);
1095 GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
1096 &lsocks_write, sizeof (HANDLE));
1097 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1098 (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
1099 &lsocks_read, sizeof (HANDLE));
1105 if (GNUNET_YES == pipe_control)
1107 GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
1108 GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
1110 if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
1112 /*This will tell the child that we're going to send lsocks over the pipe*/
1113 GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
1114 GNUNET_asprintf (&our_env[env_off++], "%lu", lsocks_read);
1116 our_env[env_off++] = NULL;
1117 env_block = CreateCustomEnvTable (our_env);
1119 GNUNET_free_non_null (our_env[--env_off]);
1122 if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
1124 LOG (GNUNET_ERROR_TYPE_DEBUG,
1125 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
1126 GNUNET_free (env_block);
1129 GNUNET_DISK_pipe_close (lsocks_pipe);
1130 if (GNUNET_YES == pipe_control)
1132 GNUNET_DISK_file_close (childpipe_write);
1133 GNUNET_DISK_file_close (childpipe_read);
1139 if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
1141 LOG (GNUNET_ERROR_TYPE_DEBUG,
1142 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno);
1143 GNUNET_free (env_block);
1147 GNUNET_DISK_pipe_close (lsocks_pipe);
1148 if (GNUNET_YES == pipe_control)
1150 GNUNET_DISK_file_close (childpipe_write);
1151 GNUNET_DISK_file_close (childpipe_read);
1156 bresult = CreateProcessW (wpath, wcmd, NULL, NULL, TRUE,
1157 DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
1158 error_code = GetLastError ();
1160 if ((NULL == pipe_stdin) && (stdih))
1161 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, stdif);
1164 if ((NULL == pipe_stdout) && (stdoh))
1165 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, stdof);
1168 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
1171 LOG (GNUNET_ERROR_TYPE_ERROR, "CreateProcess(%s, %s) failed: %lu\n", path, cmd, error_code);
1173 GNUNET_free (env_block);
1178 if (GNUNET_YES == pipe_control)
1180 GNUNET_DISK_file_close (childpipe_read);
1185 if (GNUNET_YES == pipe_control)
1187 GNUNET_DISK_file_close (childpipe_write);
1190 GNUNET_DISK_pipe_close (lsocks_pipe);
1191 SetErrnoFromWinError (error_code);
1195 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
1196 gnunet_proc->pid = proc.dwProcessId;
1197 gnunet_proc->handle = proc.hProcess;
1198 gnunet_proc->control_pipe = childpipe_write;
1200 CreateThread (NULL, 64000, &child_wait_thread, (void *) gnunet_proc, 0, NULL);
1202 ResumeThread (proc.hThread);
1203 CloseHandle (proc.hThread);
1205 if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) )
1208 GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
1210 /* This is a replacement for "goto error" that doesn't use goto */
1219 /* Tell the number of sockets */
1220 for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++);
1222 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1223 if (sizeof (count) != wrote)
1225 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1226 "Failed to write %u count bytes to the child: %u\n",
1227 sizeof (count), GetLastError ());
1230 for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
1232 WSAPROTOCOL_INFOA pi;
1233 /* Get a socket duplication info */
1234 if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
1236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1237 "Failed to duplicate an socket[%llu]: %u\n", i,
1241 /* Synchronous I/O is not nice, but we can't schedule this:
1242 * lsocks will be closed/freed by the caller soon, and until
1243 * the child creates a duplicate, closing a socket here will
1244 * close it for good.
1246 /* Send the size of the structure
1247 * (the child might be built with different headers...)
1250 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &size, sizeof (size));
1251 if (sizeof (size) != wrote)
1253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1254 "Failed to write %u size[%llu] bytes to the child: %u\n",
1255 sizeof (size), i, GetLastError ());
1258 /* Finally! Send the data */
1259 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &pi, sizeof (pi));
1260 if (sizeof (pi) != wrote)
1262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1263 "Failed to write %u socket[%llu] bytes to the child: %u\n",
1264 sizeof (pi), i, GetLastError ());
1268 /* This will block us until the child makes a final read or closes
1269 * the pipe (hence no 'wrote' check), since we have to wait for it
1270 * to duplicate the last socket, before we return and start closing
1273 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1278 GNUNET_DISK_file_sync (lsocks_write_fd);
1279 GNUNET_DISK_pipe_close (lsocks_pipe);
1283 /* If we can't pass on the socket(s), the child will block forever,
1284 * better put it out of its misery.
1286 SafeTerminateProcess (gnunet_proc->handle, 0, 0);
1287 CloseHandle (gnunet_proc->handle);
1288 if (NULL != gnunet_proc->control_pipe)
1289 GNUNET_DISK_file_close (gnunet_proc->control_pipe);
1290 GNUNET_free (gnunet_proc);
1303 * @param pipe_control should a pipe be used to send signals to the child?
1304 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1305 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1306 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1307 * @param filename name of the binary
1308 * @param argv NULL-terminated array of arguments to the process
1309 * @return pointer to process structure of the new process, NULL on error
1311 struct GNUNET_OS_Process *
1312 GNUNET_OS_start_process_vap (int pipe_control,
1313 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1314 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1315 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1316 const char *filename,
1319 return start_process (pipe_control,
1332 * @param pipe_control should a pipe be used to send signals to the child?
1333 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1334 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1335 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1336 * @param filename name of the binary
1337 * @param va NULL-terminated list of arguments to the process
1338 * @return pointer to process structure of the new process, NULL on error
1340 struct GNUNET_OS_Process *
1341 GNUNET_OS_start_process_va (int pipe_control,
1342 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1343 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1344 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1345 const char *filename, va_list va)
1347 struct GNUNET_OS_Process *ret;
1354 while (NULL != va_arg (ap, char *))
1357 argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
1360 while (NULL != (argv[argc] = va_arg (ap, char *)))
1363 ret = GNUNET_OS_start_process_vap (pipe_control,
1377 * @param pipe_control should a pipe be used to send signals to the child?
1378 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1379 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1380 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1381 * @param filename name of the binary
1382 * @param ... NULL-terminated list of arguments to the process
1383 * @return pointer to process structure of the new process, NULL on error
1385 struct GNUNET_OS_Process *
1386 GNUNET_OS_start_process (int pipe_control,
1387 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1388 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1389 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1390 const char *filename, ...)
1392 struct GNUNET_OS_Process *ret;
1395 va_start (ap, filename);
1396 ret = GNUNET_OS_start_process_va (pipe_control, std_inheritance, pipe_stdin,
1397 pipe_stdout, filename, ap);
1406 * @param pipe_control should a pipe be used to send signals to the child?
1407 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which
1408 * std handles of the parent are inherited by the child.
1409 * pipe_stdin and pipe_stdout take priority over std_inheritance
1410 * (when they are non-NULL).
1411 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
1412 * must be NULL on platforms where dup is not supported
1413 * @param filename name of the binary
1414 * @param argv NULL-terminated list of arguments to the process
1415 * @return process ID of the new process, -1 on error
1417 struct GNUNET_OS_Process *
1418 GNUNET_OS_start_process_v (int pipe_control,
1419 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1420 const SOCKTYPE *lsocks,
1421 const char *filename,
1424 return start_process (pipe_control,
1435 * Retrieve the status of a process, waiting on him if dead.
1436 * Nonblocking version.
1438 * @param proc process ID
1439 * @param type status type
1440 * @param code return code/signal number
1441 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
1444 GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1445 enum GNUNET_OS_ProcessStatusType *type,
1446 unsigned long *code)
1452 GNUNET_assert (0 != proc);
1453 ret = waitpid (proc->pid, &status, WNOHANG);
1456 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1457 return GNUNET_SYSERR;
1461 *type = GNUNET_OS_PROCESS_RUNNING;
1465 if (proc->pid != ret)
1467 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1468 return GNUNET_SYSERR;
1470 if (WIFEXITED (status))
1472 *type = GNUNET_OS_PROCESS_EXITED;
1473 *code = WEXITSTATUS (status);
1475 else if (WIFSIGNALED (status))
1477 *type = GNUNET_OS_PROCESS_SIGNALED;
1478 *code = WTERMSIG (status);
1480 else if (WIFSTOPPED (status))
1482 *type = GNUNET_OS_PROCESS_SIGNALED;
1483 *code = WSTOPSIG (status);
1486 else if (WIFCONTINUED (status))
1488 *type = GNUNET_OS_PROCESS_RUNNING;
1494 *type = GNUNET_OS_PROCESS_UNKNOWN;
1499 DWORD c, error_code, ret;
1503 if (h == NULL || ret == 0)
1505 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1507 return GNUNET_SYSERR;
1510 h = GetCurrentProcess ();
1513 ret = GetExitCodeProcess (h, &c);
1514 error_code = GetLastError ();
1515 if (ret == 0 || error_code != NO_ERROR)
1517 SetErrnoFromWinError (error_code);
1518 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
1519 return GNUNET_SYSERR;
1521 if (STILL_ACTIVE == c)
1523 *type = GNUNET_OS_PROCESS_RUNNING;
1527 *type = GNUNET_OS_PROCESS_EXITED;
1536 * Wait for a process
1538 * @param proc pointer to process structure
1539 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
1542 GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1545 pid_t pid = proc->pid;
1548 while ( (pid != (ret = waitpid (pid, NULL, 0))) &&
1549 (EINTR == errno) ) ;
1552 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1553 return GNUNET_SYSERR;
1562 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1564 return GNUNET_SYSERR;
1567 h = GetCurrentProcess ();
1569 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
1571 SetErrnoFromWinError (GetLastError ());
1572 return GNUNET_SYSERR;
1580 * Handle to a command.
1582 struct GNUNET_OS_CommandHandle
1588 struct GNUNET_OS_Process *eip;
1591 * Handle to the output pipe.
1593 struct GNUNET_DISK_PipeHandle *opipe;
1596 * Read-end of output pipe.
1598 const struct GNUNET_DISK_FileHandle *r;
1601 * Function to call on each line of output.
1603 GNUNET_OS_LineProcessor proc;
1606 * Closure for 'proc'.
1611 * Buffer for the output.
1616 * Task reading from pipe.
1618 GNUNET_SCHEDULER_TaskIdentifier rtask;
1623 struct GNUNET_TIME_Absolute timeout;
1626 * Current read offset in buf.
1633 * Stop/kill a command. Must ONLY be called either from
1634 * the callback after 'NULL' was passed for 'line' *OR*
1635 * from an independent task (not within the line processor).
1637 * @param cmd handle to the process
1640 GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
1642 if (NULL != cmd->proc)
1644 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
1645 GNUNET_SCHEDULER_cancel (cmd->rtask);
1647 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1648 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
1649 GNUNET_OS_process_destroy (cmd->eip);
1650 GNUNET_DISK_pipe_close (cmd->opipe);
1656 * Read from the process and call the line processor.
1658 * @param cls the 'struct GNUNET_OS_CommandHandle'
1659 * @param tc scheduler context
1662 cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1664 struct GNUNET_OS_CommandHandle *cmd = cls;
1665 GNUNET_OS_LineProcessor proc;
1669 cmd->rtask = GNUNET_SCHEDULER_NO_TASK;
1670 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1672 /* timeout, shutdown, etc. */
1675 proc (cmd->proc_cls, NULL);
1679 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
1680 sizeof (cmd->buf) - cmd->off);
1683 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
1685 cmd->buf[cmd->off] = '\0';
1686 cmd->proc (cmd->proc_cls, cmd->buf);
1690 proc (cmd->proc_cls, NULL);
1693 end = memchr (&cmd->buf[cmd->off], '\n', ret);
1698 cmd->proc (cmd->proc_cls, cmd->buf);
1699 memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
1700 cmd->off -= (end + 1 - cmd->buf);
1701 end = memchr (cmd->buf, '\n', cmd->off);
1704 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
1705 (cmd->timeout), cmd->r, &cmd_read, cmd);
1710 * Run the given command line and call the given function
1711 * for each line of the output.
1713 * @param proc function to call for each line of the output
1714 * @param proc_cls closure for proc
1715 * @param timeout when to time out
1716 * @param binary command to run
1717 * @param ... arguments to command
1718 * @return NULL on error
1720 struct GNUNET_OS_CommandHandle *
1721 GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1722 struct GNUNET_TIME_Relative timeout, const char *binary,
1725 struct GNUNET_OS_CommandHandle *cmd;
1726 struct GNUNET_OS_Process *eip;
1727 struct GNUNET_DISK_PipeHandle *opipe;
1730 opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1733 va_start (ap, binary);
1734 /* redirect stdout, don't inherit stderr/stdin */
1735 eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, binary, ap);
1739 GNUNET_DISK_pipe_close (opipe);
1742 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
1743 cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
1744 cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1748 cmd->proc_cls = proc_cls;
1749 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
1750 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1755 /* end of os_priority.c */