2 This file is part of GNUnet.
3 (C) 2011, 2012 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 3, 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.
21 #include "gnunet_os_lib.h"
24 * Actually start a process. All of the arguments given to this
25 * function are strings that are used for the "argv" array. However,
26 * if those strings contain spaces, the given argument is split into
27 * multiple argv entries without spaces. Similarly, if an argument is
28 * the empty string, it is skipped. This function has the inherent
29 * limitation that it does NOT allow passing command line arguments
30 * with spaces to the new process.
32 * @param pipe_control should a pipe be used to send signals to the child?
33 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
34 * @param lsocks array of listen sockets to dup starting at fd3 (systemd-style), or NULL
35 * @param first_arg first argument for argv (may be an empty string)
36 * @param ... more arguments, NULL terminated
37 * @return handle of the started process, NULL on error
39 static struct GNUNET_OS_Process *
40 do_start_process (int pipe_control, unsigned int std_inheritance,
41 const SOCKTYPE * lsocks, const char *first_arg, ...)
45 unsigned int argv_size;
51 struct GNUNET_OS_Process *proc;
55 va_start (ap, first_arg);
73 if ((last == NULL) && (*rpos != '\0'))
82 while (NULL != (arg = (va_arg (ap, const char*))));
86 argv = GNUNET_malloc (argv_size * sizeof (char *));
88 va_start (ap, first_arg);
95 cp = GNUNET_strdup (arg);
103 argv[argv_size++] = GNUNET_strdup (last);
109 if ((last == NULL) && (*pos != '\0'))
115 argv[argv_size++] = GNUNET_strdup (last);
120 while (NULL != (arg = (va_arg (ap, const char*))));
123 argv[argv_size] = NULL;
124 binary_path = argv[0];
125 proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks,
127 while (argv_size > 0)
128 GNUNET_free (argv[--argv_size]);
133 /* end of do_start_process.c */