diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-11-29 10:25:47 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-11-29 10:25:47 +0000 |
commit | d5f83fb8b9a2ae2797b7b0e46bf6cd346743f4b3 (patch) | |
tree | a9afdf6ba9fcc2051a5043b061ea9dc86779fb9f /src/arm | |
parent | b0c50f22c52535650a7288c32a3ae3ed6336c32f (diff) | |
download | gnunet-d5f83fb8b9a2ae2797b7b0e46bf6cd346743f4b3.tar.gz gnunet-d5f83fb8b9a2ae2797b7b0e46bf6cd346743f4b3.zip |
- move do_start_process to util/
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm_api.c | 30 | ||||
-rw-r--r-- | src/arm/do_start_process.c | 155 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 31 |
3 files changed, 31 insertions, 185 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index d27b6b780..7e6ce1870 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -737,9 +737,6 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
737 | } | 737 | } |
738 | 738 | ||
739 | 739 | ||
740 | #include "do_start_process.c" | ||
741 | |||
742 | |||
743 | /** | 740 | /** |
744 | * A client specifically requested starting of ARM itself. | 741 | * A client specifically requested starting of ARM itself. |
745 | * This function is called with information about whether | 742 | * This function is called with information about whether |
@@ -832,26 +829,27 @@ arm_service_report (void *cls, | |||
832 | /* Means we are ONLY running locally */ | 829 | /* Means we are ONLY running locally */ |
833 | /* we're clearly running a test, don't daemonize */ | 830 | /* we're clearly running a test, don't daemonize */ |
834 | if (NULL == config) | 831 | if (NULL == config) |
835 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 832 | proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, |
836 | NULL, loprefix, quotedbinary, | 833 | NULL, loprefix, quotedbinary, |
837 | /* no daemonization! */ | 834 | /* no daemonization! */ |
838 | lopostfix, NULL); | 835 | lopostfix, NULL); |
839 | else | 836 | else |
840 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 837 | proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, |
841 | NULL, loprefix, quotedbinary, "-c", config, | 838 | NULL, loprefix, quotedbinary, "-c", config, |
842 | /* no daemonization! */ | 839 | /* no daemonization! */ |
843 | lopostfix, NULL); | 840 | lopostfix, NULL); |
844 | } | 841 | } |
845 | else | 842 | else |
846 | { | 843 | { |
847 | if (NULL == config) | 844 | if (NULL == config) |
848 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 845 | proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, |
849 | NULL, loprefix, quotedbinary, | 846 | NULL, loprefix, quotedbinary, |
850 | "-d", lopostfix, NULL); | 847 | "-d", lopostfix, NULL); |
851 | else | 848 | else |
852 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 849 | proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, |
853 | NULL, loprefix, quotedbinary, "-c", config, | 850 | NULL, loprefix, quotedbinary, "-c", |
854 | "-d", lopostfix, NULL); | 851 | config, |
852 | "-d", lopostfix, NULL); | ||
855 | } | 853 | } |
856 | GNUNET_free (binary); | 854 | GNUNET_free (binary); |
857 | GNUNET_free (quotedbinary); | 855 | GNUNET_free (quotedbinary); |
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c deleted file mode 100644 index 3ff6eba52..000000000 --- a/src/arm/do_start_process.c +++ /dev/null | |||
@@ -1,155 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | #include "gnunet_os_lib.h" | ||
22 | |||
23 | /** | ||
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. | ||
31 | * | ||
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 | ||
38 | */ | ||
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, ...) | ||
42 | { | ||
43 | va_list ap; | ||
44 | char **argv; | ||
45 | unsigned int argv_size; | ||
46 | const char *arg; | ||
47 | const char *rpos; | ||
48 | char *pos; | ||
49 | char *cp; | ||
50 | const char *last; | ||
51 | struct GNUNET_OS_Process *proc; | ||
52 | char *binary_path; | ||
53 | int quote_on; | ||
54 | unsigned int i; | ||
55 | size_t len; | ||
56 | |||
57 | argv_size = 1; | ||
58 | va_start (ap, first_arg); | ||
59 | arg = first_arg; | ||
60 | last = NULL; | ||
61 | do | ||
62 | { | ||
63 | rpos = arg; | ||
64 | quote_on = 0; | ||
65 | while ('\0' != *rpos) | ||
66 | { | ||
67 | if ('"' == *rpos) | ||
68 | { | ||
69 | if (1 == quote_on) | ||
70 | quote_on = 0; | ||
71 | else | ||
72 | quote_on = 1; | ||
73 | } | ||
74 | if ( (' ' == *rpos) && (0 == quote_on) ) | ||
75 | { | ||
76 | if (NULL != last) | ||
77 | argv_size++; | ||
78 | last = NULL; | ||
79 | rpos++; | ||
80 | while (' ' == *rpos) | ||
81 | rpos++; | ||
82 | } | ||
83 | if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=? | ||
84 | last = rpos; | ||
85 | if ('\0' != *rpos) | ||
86 | rpos++; | ||
87 | } | ||
88 | if (NULL != last) | ||
89 | argv_size++; | ||
90 | } | ||
91 | while (NULL != (arg = (va_arg (ap, const char*)))); | ||
92 | va_end (ap); | ||
93 | |||
94 | argv = GNUNET_malloc (argv_size * sizeof (char *)); | ||
95 | argv_size = 0; | ||
96 | va_start (ap, first_arg); | ||
97 | arg = first_arg; | ||
98 | last = NULL; | ||
99 | do | ||
100 | { | ||
101 | cp = GNUNET_strdup (arg); | ||
102 | quote_on = 0; | ||
103 | pos = cp; | ||
104 | while ('\0' != *pos) | ||
105 | { | ||
106 | if ('"' == *pos) | ||
107 | { | ||
108 | if (1 == quote_on) | ||
109 | quote_on = 0; | ||
110 | else | ||
111 | quote_on = 1; | ||
112 | } | ||
113 | if ( (' ' == *pos) && (0 == quote_on) ) | ||
114 | { | ||
115 | *pos = '\0'; | ||
116 | if (NULL != last) | ||
117 | argv[argv_size++] = GNUNET_strdup (last); | ||
118 | last = NULL; | ||
119 | pos++; | ||
120 | while (' ' == *pos) | ||
121 | pos++; | ||
122 | } | ||
123 | if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=? | ||
124 | last = pos; | ||
125 | if ('\0' != *pos) | ||
126 | pos++; | ||
127 | } | ||
128 | if (NULL != last) | ||
129 | argv[argv_size++] = GNUNET_strdup (last); | ||
130 | last = NULL; | ||
131 | GNUNET_free (cp); | ||
132 | } | ||
133 | while (NULL != (arg = (va_arg (ap, const char*)))); | ||
134 | va_end (ap); | ||
135 | argv[argv_size] = NULL; | ||
136 | |||
137 | for(i = 0; i < argv_size; i++) | ||
138 | { | ||
139 | len = strlen (argv[i]); | ||
140 | if ( (argv[i][0] == '"') && (argv[i][len-1] == '"')) | ||
141 | { | ||
142 | memmove (&argv[i][0], &argv[i][1], len - 2); | ||
143 | argv[i][len-2] = '\0'; | ||
144 | } | ||
145 | } | ||
146 | binary_path = argv[0]; | ||
147 | proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, | ||
148 | binary_path, argv); | ||
149 | while (argv_size > 0) | ||
150 | GNUNET_free (argv[--argv_size]); | ||
151 | GNUNET_free (argv); | ||
152 | return proc; | ||
153 | } | ||
154 | |||
155 | /* end of do_start_process.c */ | ||
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index dcc9cf352..b30e8542e 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -246,8 +246,6 @@ static struct GNUNET_SERVER_Handle *server; | |||
246 | static struct GNUNET_SERVER_NotificationContext *notifier; | 246 | static struct GNUNET_SERVER_NotificationContext *notifier; |
247 | 247 | ||
248 | 248 | ||
249 | #include "do_start_process.c" | ||
250 | |||
251 | /** | 249 | /** |
252 | * Transmit a status result message. | 250 | * Transmit a status result message. |
253 | * | 251 | * |
@@ -496,27 +494,32 @@ start_process (struct ServiceList *sl, | |||
496 | { | 494 | { |
497 | if (NULL == sl->config) | 495 | if (NULL == sl->config) |
498 | sl->proc = | 496 | sl->proc = |
499 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 497 | GNUNET_OS_start_process_s (sl->pipe_control, |
500 | lsocks, loprefix, quotedbinary, "-L", | 498 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
501 | "DEBUG", options, NULL); | 499 | lsocks, loprefix, quotedbinary, "-L", |
500 | "DEBUG", options, NULL); | ||
502 | else | 501 | else |
503 | sl->proc = | 502 | sl->proc = |
504 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 503 | GNUNET_OS_start_process_s (sl->pipe_control, |
505 | lsocks, loprefix, quotedbinary, "-c", sl->config, "-L", | 504 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
506 | "DEBUG", options, NULL); | 505 | lsocks, loprefix, quotedbinary, "-c", |
506 | sl->config, "-L", | ||
507 | "DEBUG", options, NULL); | ||
507 | } | 508 | } |
508 | else | 509 | else |
509 | { | 510 | { |
510 | if (NULL == sl->config) | 511 | if (NULL == sl->config) |
511 | sl->proc = | 512 | sl->proc = |
512 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 513 | GNUNET_OS_start_process_s (sl->pipe_control, |
513 | lsocks, loprefix, quotedbinary, | 514 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
514 | options, NULL); | 515 | lsocks, loprefix, quotedbinary, |
516 | options, NULL); | ||
515 | else | 517 | else |
516 | sl->proc = | 518 | sl->proc = |
517 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 519 | GNUNET_OS_start_process_s (sl->pipe_control, |
518 | lsocks, loprefix, quotedbinary, "-c", sl->config, | 520 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
519 | options, NULL); | 521 | lsocks, loprefix, quotedbinary, "-c", |
522 | sl->config, options, NULL); | ||
520 | } | 523 | } |
521 | GNUNET_free (binary); | 524 | GNUNET_free (binary); |
522 | GNUNET_free (quotedbinary); | 525 | GNUNET_free (quotedbinary); |