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_crt_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;
659 if (NULL != pipe_stdout)
661 GNUNET_assert (GNUNET_OK ==
662 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
664 GNUNET_DISK_PIPE_END_WRITE),
665 &fd_stdout_write, sizeof (int)));
666 GNUNET_assert (GNUNET_OK ==
667 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
668 (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
669 &fd_stdout_read, sizeof (int)));
671 if (NULL != pipe_stdin)
673 GNUNET_assert (GNUNET_OK ==
674 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
675 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
676 &fd_stdin_read, sizeof (int)));
677 GNUNET_assert (GNUNET_OK ==
678 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
679 (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
680 &fd_stdin_write, sizeof (int)));
687 while (-1 != (k = lsocks[i++]))
688 GNUNET_array_append (lscp, ls, k);
689 GNUNET_array_append (lscp, ls, -1);
692 /* see https://gnunet.org/vfork */
700 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
701 GNUNET_array_grow (lscp, ls, 0);
703 GNUNET_DISK_file_close (childpipe_read);
705 GNUNET_DISK_file_close (childpipe_write);
706 if (0 <= childpipe_read_fd)
707 close (childpipe_read_fd);
713 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
714 gnunet_proc->pid = ret;
715 gnunet_proc->control_pipe = childpipe_write;
716 if (GNUNET_YES == pipe_control)
718 close (childpipe_read_fd);
720 GNUNET_array_grow (lscp, ls, 0);
723 if (0 <= childpipe_read_fd)
727 /* due to vfork, we must NOT free memory on DARWIN! */
728 GNUNET_DISK_file_close (childpipe_write);
730 snprintf (fdbuf, 100, "%x", childpipe_read_fd);
731 setenv (GNUNET_OS_CONTROL_PIPE, fdbuf, 1);
733 if (NULL != pipe_stdin)
735 GNUNET_break (0 == close (fd_stdin_write));
736 if (-1 == dup2 (fd_stdin_read, 0))
737 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
738 GNUNET_break (0 == close (fd_stdin_read));
740 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_IN))
742 GNUNET_break (0 == close (0));
743 open_dev_null (0, O_RDONLY);
745 if (NULL != pipe_stdout)
747 GNUNET_break (0 == close (fd_stdout_read));
748 if (-1 == dup2 (fd_stdout_write, 1))
749 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
750 GNUNET_break (0 == close (fd_stdout_write));
752 else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_OUT))
754 GNUNET_break (0 == close (1));
755 open_dev_null (1, O_WRONLY);
757 if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_ERR))
759 GNUNET_break (0 == close (2));
760 open_dev_null (2, O_WRONLY);
764 /* read systemd documentation... */
765 GNUNET_snprintf (lpid, sizeof (lpid), "%u", getpid ());
766 setenv ("LISTEN_PID", lpid, 1);
769 while (-1 != lscp[i])
772 while (-1 != lscp[j])
778 GNUNET_assert (-1 != k);
779 GNUNET_assert (0 == close (lscp[j]));
787 /* Bury any existing FD, no matter what; they should all be closed
788 * on exec anyway and the important onces have been dup'ed away */
790 GNUNET_assert (-1 != dup2 (lscp[i], tgt));
792 /* unset close-on-exec flag */
793 flags = fcntl (tgt, F_GETFD);
794 GNUNET_assert (flags >= 0);
795 flags &= ~FD_CLOEXEC;
797 (void) fcntl (tgt, F_SETFD, flags);
801 GNUNET_snprintf (fds, sizeof (fds), "%u", i);
802 setenv ("LISTEN_FDS", fds, 1);
805 /* due to vfork, we must NOT free memory on DARWIN! */
806 GNUNET_array_grow (lscp, ls, 0);
808 execvp (filename, argv);
809 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
812 struct GNUNET_DISK_FileHandle *childpipe_read;
813 struct GNUNET_DISK_FileHandle *childpipe_write;
814 HANDLE childpipe_read_handle;
816 char **non_const_argv;
821 PROCESS_INFORMATION proc;
823 struct GNUNET_OS_Process *gnunet_proc;
824 char path[MAX_PATH + 1];
825 char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
826 char *env_block = NULL;
834 char *non_const_filename;
835 char win_path[MAX_PATH + 1];
836 struct GNUNET_DISK_PipeHandle *lsocks_pipe;
837 const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
848 HANDLE stdout_handle;
849 HANDLE stdih, stdoh, stdeh;
850 DWORD stdif, stdof, stdef;
854 if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename))
855 return NULL; /* not executable */
857 /* Search in prefix dir (hopefully - the directory from which
858 * the current module was loaded), bindir and libdir, then in PATH
860 self_prefix = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
861 bindir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
862 libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
864 pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
867 pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
870 pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
873 ptr += sprintf (pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
874 GNUNET_free (self_prefix);
875 GNUNET_free (bindir);
876 GNUNET_free (libdir);
878 alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
879 if (alloc_len != pathbuf_len - 1)
881 GNUNET_free (pathbuf);
882 errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
886 cmdlen = strlen (filename);
887 if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) )
888 GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
890 GNUNET_asprintf (&non_const_filename, "%s", filename);
892 /* It could be in POSIX form, convert it to a DOS path early on */
893 if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
895 SetErrnoFromWinError (lRet);
896 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
898 GNUNET_free (non_const_filename);
899 GNUNET_free (pathbuf);
902 GNUNET_free (non_const_filename);
903 non_const_filename = GNUNET_strdup (win_path);
904 /* Check that this is the full path. If it isn't, search. */
905 /* FIXME: convert it to wchar_t and use SearchPathW?
906 * Remember: arguments to _start_process() are technically in UTF-8...
908 if (non_const_filename[1] == ':')
910 snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
911 LOG (GNUNET_ERROR_TYPE_DEBUG,
912 "Using path `%s' as-is. PATH is %s\n", path, ptr);
914 else if (!SearchPathA
915 (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
918 SetErrnoFromWinError (GetLastError ());
919 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
921 GNUNET_free (non_const_filename);
922 GNUNET_free (pathbuf);
926 LOG (GNUNET_ERROR_TYPE_DEBUG,
927 "Found `%s' in PATH `%s'\n", path, pathbuf);
928 GNUNET_free (pathbuf);
929 GNUNET_free (non_const_filename);
931 /* Count the number of arguments */
932 arg = (char **) argv;
939 /* Allocate a copy argv */
940 non_const_argv = GNUNET_malloc (sizeof (char *) * (argcount + 1));
942 /* Copy all argv strings */
944 arg = (char **) argv;
948 non_const_argv[argcount] = GNUNET_strdup (path);
950 non_const_argv[argcount] = GNUNET_strdup (*arg);
954 non_const_argv[argcount] = NULL;
958 arg = non_const_argv;
961 cmdlen = cmdlen + strlen (*arg) + 4;
965 /* Allocate and create cmd */
966 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
967 arg = non_const_argv;
970 char arg_last_char = (*arg)[strlen (*arg) - 1];
971 idx += sprintf (idx, "\"%s%s\"%s", *arg,
972 arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : "");
977 GNUNET_free (non_const_argv[--argcount]);
978 GNUNET_free (non_const_argv);
980 memset (&start, 0, sizeof (start));
981 start.cb = sizeof (start);
982 if ((pipe_stdin != NULL) || (pipe_stdout != NULL) || (std_inheritance != 0))
983 start.dwFlags |= STARTF_USESTDHANDLES;
985 stdih = GetStdHandle (STD_INPUT_HANDLE);
986 GetHandleInformation (stdih, &stdif);
987 if (pipe_stdin != NULL)
989 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
990 (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
991 &stdin_handle, sizeof (HANDLE));
992 start.hStdInput = stdin_handle;
996 if (std_inheritance & GNUNET_OS_INHERIT_STD_IN)
998 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 1);
999 if (pipe_stdin == NULL)
1000 start.hStdInput = stdih;
1003 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 0);
1007 stdoh = GetStdHandle (STD_OUTPUT_HANDLE);
1008 GetHandleInformation (stdoh, &stdof);
1009 if (NULL != pipe_stdout)
1011 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1013 GNUNET_DISK_PIPE_END_WRITE),
1014 &stdout_handle, sizeof (HANDLE));
1015 start.hStdOutput = stdout_handle;
1019 if (std_inheritance & GNUNET_OS_INHERIT_STD_OUT)
1021 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 1);
1022 if (pipe_stdout == NULL)
1023 start.hStdOutput = stdoh;
1026 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 0);
1029 stdeh = GetStdHandle (STD_ERROR_HANDLE);
1030 GetHandleInformation (stdeh, &stdef);
1033 if (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)
1035 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 1);
1036 start.hStdError = stdeh;
1039 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 0);
1042 if (GNUNET_YES == pipe_control)
1044 struct GNUNET_DISK_PipeHandle *childpipe;
1045 childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
1046 if (NULL == childpipe)
1048 childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
1049 childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
1050 GNUNET_DISK_pipe_close (childpipe);
1051 if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
1052 (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
1053 &childpipe_read_handle, sizeof (HANDLE))))
1056 GNUNET_DISK_file_close (childpipe_read);
1057 if (childpipe_write)
1058 GNUNET_DISK_file_close (childpipe_write);
1063 /* Unlike *nix variant, we don't dup the handle, so can't close
1064 * filehandle right now.
1066 SetHandleInformation (childpipe_read_handle, HANDLE_FLAG_INHERIT, 1);
1070 childpipe_read = NULL;
1071 childpipe_write = NULL;
1074 if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
1076 lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1078 if (lsocks_pipe == NULL)
1082 GNUNET_DISK_pipe_close (lsocks_pipe);
1083 if (GNUNET_YES == pipe_control)
1085 GNUNET_DISK_file_close (childpipe_write);
1086 GNUNET_DISK_file_close (childpipe_read);
1090 lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe,
1091 GNUNET_DISK_PIPE_END_WRITE);
1092 GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
1093 &lsocks_write, sizeof (HANDLE));
1094 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
1095 (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
1096 &lsocks_read, sizeof (HANDLE));
1102 if (GNUNET_YES == pipe_control)
1104 GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
1105 GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
1107 if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
1109 /*This will tell the child that we're going to send lsocks over the pipe*/
1110 GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
1111 GNUNET_asprintf (&our_env[env_off++], "%lu", lsocks_read);
1113 our_env[env_off++] = NULL;
1114 env_block = CreateCustomEnvTable (our_env);
1116 GNUNET_free_non_null (our_env[--env_off]);
1119 if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
1121 LOG (GNUNET_ERROR_TYPE_DEBUG,
1122 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
1123 GNUNET_free (env_block);
1126 GNUNET_DISK_pipe_close (lsocks_pipe);
1127 if (GNUNET_YES == pipe_control)
1129 GNUNET_DISK_file_close (childpipe_write);
1130 GNUNET_DISK_file_close (childpipe_read);
1136 if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
1138 LOG (GNUNET_ERROR_TYPE_DEBUG,
1139 "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", cmd, errno);
1140 GNUNET_free (env_block);
1144 GNUNET_DISK_pipe_close (lsocks_pipe);
1145 if (GNUNET_YES == pipe_control)
1147 GNUNET_DISK_file_close (childpipe_write);
1148 GNUNET_DISK_file_close (childpipe_read);
1153 bresult = CreateProcessW (wpath, wcmd, NULL, NULL, TRUE,
1154 DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
1155 error_code = GetLastError ();
1157 if ((NULL == pipe_stdin) && (stdih))
1158 SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, stdif);
1161 if ((NULL == pipe_stdout) && (stdoh))
1162 SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, stdof);
1165 SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
1168 LOG (GNUNET_ERROR_TYPE_ERROR, "CreateProcess(%s, %s) failed: %lu\n", path, cmd, error_code);
1170 GNUNET_free (env_block);
1175 if (GNUNET_YES == pipe_control)
1177 GNUNET_DISK_file_close (childpipe_read);
1182 if (GNUNET_YES == pipe_control)
1184 GNUNET_DISK_file_close (childpipe_write);
1187 GNUNET_DISK_pipe_close (lsocks_pipe);
1188 SetErrnoFromWinError (error_code);
1192 gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
1193 gnunet_proc->pid = proc.dwProcessId;
1194 gnunet_proc->handle = proc.hProcess;
1195 gnunet_proc->control_pipe = childpipe_write;
1197 CreateThread (NULL, 64000, &child_wait_thread, (void *) gnunet_proc, 0, NULL);
1199 ResumeThread (proc.hThread);
1200 CloseHandle (proc.hThread);
1202 if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) )
1205 GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
1207 /* This is a replacement for "goto error" that doesn't use goto */
1216 /* Tell the number of sockets */
1217 for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++);
1219 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1220 if (sizeof (count) != wrote)
1222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1223 "Failed to write %u count bytes to the child: %u\n",
1224 sizeof (count), GetLastError ());
1227 for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
1229 WSAPROTOCOL_INFOA pi;
1230 /* Get a socket duplication info */
1231 if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
1233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1234 "Failed to duplicate an socket[%llu]: %u\n", i,
1238 /* Synchronous I/O is not nice, but we can't schedule this:
1239 * lsocks will be closed/freed by the caller soon, and until
1240 * the child creates a duplicate, closing a socket here will
1241 * close it for good.
1243 /* Send the size of the structure
1244 * (the child might be built with different headers...)
1247 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &size, sizeof (size));
1248 if (sizeof (size) != wrote)
1250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1251 "Failed to write %u size[%llu] bytes to the child: %u\n",
1252 sizeof (size), i, GetLastError ());
1255 /* Finally! Send the data */
1256 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &pi, sizeof (pi));
1257 if (sizeof (pi) != wrote)
1259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1260 "Failed to write %u socket[%llu] bytes to the child: %u\n",
1261 sizeof (pi), i, GetLastError ());
1265 /* This will block us until the child makes a final read or closes
1266 * the pipe (hence no 'wrote' check), since we have to wait for it
1267 * to duplicate the last socket, before we return and start closing
1270 wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
1275 GNUNET_DISK_file_sync (lsocks_write_fd);
1276 GNUNET_DISK_pipe_close (lsocks_pipe);
1280 /* If we can't pass on the socket(s), the child will block forever,
1281 * better put it out of its misery.
1283 SafeTerminateProcess (gnunet_proc->handle, 0, 0);
1284 CloseHandle (gnunet_proc->handle);
1285 if (NULL != gnunet_proc->control_pipe)
1286 GNUNET_DISK_file_close (gnunet_proc->control_pipe);
1287 GNUNET_free (gnunet_proc);
1300 * @param pipe_control should a pipe be used to send signals to the child?
1301 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1302 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1303 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1304 * @param filename name of the binary
1305 * @param argv NULL-terminated array of arguments to the process
1306 * @return pointer to process structure of the new process, NULL on error
1308 struct GNUNET_OS_Process *
1309 GNUNET_OS_start_process_vap (int pipe_control,
1310 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1311 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1312 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1313 const char *filename,
1316 return start_process (pipe_control,
1329 * @param pipe_control should a pipe be used to send signals to the child?
1330 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1331 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1332 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1333 * @param filename name of the binary
1334 * @param va NULL-terminated list of arguments to the process
1335 * @return pointer to process structure of the new process, NULL on error
1337 struct GNUNET_OS_Process *
1338 GNUNET_OS_start_process_va (int pipe_control,
1339 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1340 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1341 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1342 const char *filename, va_list va)
1344 struct GNUNET_OS_Process *ret;
1351 while (NULL != va_arg (ap, char *))
1354 argv = GNUNET_malloc (sizeof (char *) * (argc + 1));
1357 while (NULL != (argv[argc] = va_arg (ap, char *)))
1360 ret = GNUNET_OS_start_process_vap (pipe_control,
1374 * @param pipe_control should a pipe be used to send signals to the child?
1375 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
1376 * @param pipe_stdin pipe to use to send input to child process (or NULL)
1377 * @param pipe_stdout pipe to use to get output from child process (or NULL)
1378 * @param filename name of the binary
1379 * @param ... NULL-terminated list of arguments to the process
1380 * @return pointer to process structure of the new process, NULL on error
1382 struct GNUNET_OS_Process *
1383 GNUNET_OS_start_process (int pipe_control,
1384 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1385 struct GNUNET_DISK_PipeHandle *pipe_stdin,
1386 struct GNUNET_DISK_PipeHandle *pipe_stdout,
1387 const char *filename, ...)
1389 struct GNUNET_OS_Process *ret;
1392 va_start (ap, filename);
1393 ret = GNUNET_OS_start_process_va (pipe_control, std_inheritance, pipe_stdin,
1394 pipe_stdout, filename, ap);
1403 * @param pipe_control should a pipe be used to send signals to the child?
1404 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which
1405 * std handles of the parent are inherited by the child.
1406 * pipe_stdin and pipe_stdout take priority over std_inheritance
1407 * (when they are non-NULL).
1408 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
1409 * must be NULL on platforms where dup is not supported
1410 * @param filename name of the binary
1411 * @param argv NULL-terminated list of arguments to the process
1412 * @return process ID of the new process, -1 on error
1414 struct GNUNET_OS_Process *
1415 GNUNET_OS_start_process_v (int pipe_control,
1416 enum GNUNET_OS_InheritStdioFlags std_inheritance,
1417 const SOCKTYPE *lsocks,
1418 const char *filename,
1421 return start_process (pipe_control,
1432 * Retrieve the status of a process, waiting on him if dead.
1433 * Nonblocking version.
1435 * @param proc process ID
1436 * @param type status type
1437 * @param code return code/signal number
1438 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
1441 GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
1442 enum GNUNET_OS_ProcessStatusType *type,
1443 unsigned long *code)
1449 GNUNET_assert (0 != proc);
1450 ret = waitpid (proc->pid, &status, WNOHANG);
1453 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1454 return GNUNET_SYSERR;
1458 *type = GNUNET_OS_PROCESS_RUNNING;
1462 if (proc->pid != ret)
1464 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1465 return GNUNET_SYSERR;
1467 if (WIFEXITED (status))
1469 *type = GNUNET_OS_PROCESS_EXITED;
1470 *code = WEXITSTATUS (status);
1472 else if (WIFSIGNALED (status))
1474 *type = GNUNET_OS_PROCESS_SIGNALED;
1475 *code = WTERMSIG (status);
1477 else if (WIFSTOPPED (status))
1479 *type = GNUNET_OS_PROCESS_SIGNALED;
1480 *code = WSTOPSIG (status);
1483 else if (WIFCONTINUED (status))
1485 *type = GNUNET_OS_PROCESS_RUNNING;
1491 *type = GNUNET_OS_PROCESS_UNKNOWN;
1496 DWORD c, error_code, ret;
1500 if (h == NULL || ret == 0)
1502 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1504 return GNUNET_SYSERR;
1507 h = GetCurrentProcess ();
1510 ret = GetExitCodeProcess (h, &c);
1511 error_code = GetLastError ();
1512 if (ret == 0 || error_code != NO_ERROR)
1514 SetErrnoFromWinError (error_code);
1515 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
1516 return GNUNET_SYSERR;
1518 if (STILL_ACTIVE == c)
1520 *type = GNUNET_OS_PROCESS_RUNNING;
1524 *type = GNUNET_OS_PROCESS_EXITED;
1533 * Wait for a process
1535 * @param proc pointer to process structure
1536 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
1539 GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
1542 pid_t pid = proc->pid;
1545 while ( (pid != (ret = waitpid (pid, NULL, 0))) &&
1546 (EINTR == errno) ) ;
1549 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
1550 return GNUNET_SYSERR;
1559 LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n",
1561 return GNUNET_SYSERR;
1564 h = GetCurrentProcess ();
1566 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
1568 SetErrnoFromWinError (GetLastError ());
1569 return GNUNET_SYSERR;
1577 * Handle to a command.
1579 struct GNUNET_OS_CommandHandle
1585 struct GNUNET_OS_Process *eip;
1588 * Handle to the output pipe.
1590 struct GNUNET_DISK_PipeHandle *opipe;
1593 * Read-end of output pipe.
1595 const struct GNUNET_DISK_FileHandle *r;
1598 * Function to call on each line of output.
1600 GNUNET_OS_LineProcessor proc;
1603 * Closure for 'proc'.
1608 * Buffer for the output.
1613 * Task reading from pipe.
1615 GNUNET_SCHEDULER_TaskIdentifier rtask;
1620 struct GNUNET_TIME_Absolute timeout;
1623 * Current read offset in buf.
1630 * Stop/kill a command. Must ONLY be called either from
1631 * the callback after 'NULL' was passed for 'line' *OR*
1632 * from an independent task (not within the line processor).
1634 * @param cmd handle to the process
1637 GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
1639 if (NULL != cmd->proc)
1641 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask);
1642 GNUNET_SCHEDULER_cancel (cmd->rtask);
1644 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1645 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (cmd->eip));
1646 GNUNET_OS_process_destroy (cmd->eip);
1647 GNUNET_DISK_pipe_close (cmd->opipe);
1653 * Read from the process and call the line processor.
1655 * @param cls the 'struct GNUNET_OS_CommandHandle'
1656 * @param tc scheduler context
1659 cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1661 struct GNUNET_OS_CommandHandle *cmd = cls;
1662 GNUNET_OS_LineProcessor proc;
1666 cmd->rtask = GNUNET_SCHEDULER_NO_TASK;
1667 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1669 /* timeout, shutdown, etc. */
1672 proc (cmd->proc_cls, NULL);
1676 GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
1677 sizeof (cmd->buf) - cmd->off);
1680 if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
1682 cmd->buf[cmd->off] = '\0';
1683 cmd->proc (cmd->proc_cls, cmd->buf);
1687 proc (cmd->proc_cls, NULL);
1690 end = memchr (&cmd->buf[cmd->off], '\n', ret);
1695 cmd->proc (cmd->proc_cls, cmd->buf);
1696 memmove (cmd->buf, end + 1, cmd->off - (end + 1 - cmd->buf));
1697 cmd->off -= (end + 1 - cmd->buf);
1698 end = memchr (cmd->buf, '\n', cmd->off);
1701 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
1702 (cmd->timeout), cmd->r, &cmd_read, cmd);
1707 * Run the given command line and call the given function
1708 * for each line of the output.
1710 * @param proc function to call for each line of the output
1711 * @param proc_cls closure for proc
1712 * @param timeout when to time out
1713 * @param binary command to run
1714 * @param ... arguments to command
1715 * @return NULL on error
1717 struct GNUNET_OS_CommandHandle *
1718 GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
1719 struct GNUNET_TIME_Relative timeout, const char *binary,
1722 struct GNUNET_OS_CommandHandle *cmd;
1723 struct GNUNET_OS_Process *eip;
1724 struct GNUNET_DISK_PipeHandle *opipe;
1727 opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1730 va_start (ap, binary);
1731 /* redirect stdout, don't inherit stderr/stdin */
1732 eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, binary, ap);
1736 GNUNET_DISK_pipe_close (opipe);
1739 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
1740 cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
1741 cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1745 cmd->proc_cls = proc_cls;
1746 cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
1747 cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1752 /* end of os_priority.c */