diff options
Diffstat (limited to 'src/util/program.c')
-rw-r--r-- | src/util/program.c | 112 |
1 files changed, 59 insertions, 53 deletions
diff --git a/src/util/program.c b/src/util/program.c index 6538f303f..5582f30c6 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -36,6 +36,10 @@ | |||
36 | #include "gnunet_scheduler_lib.h" | 36 | #include "gnunet_scheduler_lib.h" |
37 | #include <gcrypt.h> | 37 | #include <gcrypt.h> |
38 | 38 | ||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
40 | |||
41 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | ||
42 | |||
39 | /** | 43 | /** |
40 | * Context for the command. | 44 | * Context for the command. |
41 | */ | 45 | */ |
@@ -125,9 +129,9 @@ cmd_sorter (__const void *a1, __const void *a2) | |||
125 | */ | 129 | */ |
126 | int | 130 | int |
127 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | 131 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, |
128 | const char *binaryHelp, | 132 | const char *binaryHelp, |
129 | const struct GNUNET_GETOPT_CommandLineOption *options, | 133 | const struct GNUNET_GETOPT_CommandLineOption *options, |
130 | GNUNET_PROGRAM_Main task, void *task_cls) | 134 | GNUNET_PROGRAM_Main task, void *task_cls) |
131 | { | 135 | { |
132 | struct CommandContext cc; | 136 | struct CommandContext cc; |
133 | char *path; | 137 | char *path; |
@@ -155,29 +159,29 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | |||
155 | logfile = NULL; | 159 | logfile = NULL; |
156 | gargs = getenv ("GNUNET_ARGS"); | 160 | gargs = getenv ("GNUNET_ARGS"); |
157 | if (gargs != NULL) | 161 | if (gargs != NULL) |
158 | { | ||
159 | char **gargv; | ||
160 | unsigned int gargc; | ||
161 | int i; | ||
162 | char *tok; | ||
163 | char *cargs; | ||
164 | |||
165 | gargv = NULL; | ||
166 | gargc = 0; | ||
167 | for (i = 0; i < argc; i++) | ||
168 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
169 | cargs = GNUNET_strdup (gargs); | ||
170 | tok = strtok (cargs, " "); | ||
171 | while (NULL != tok) | ||
172 | { | 162 | { |
173 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); | 163 | char **gargv; |
174 | tok = strtok (NULL, " "); | 164 | unsigned int gargc; |
165 | int i; | ||
166 | char *tok; | ||
167 | char *cargs; | ||
168 | |||
169 | gargv = NULL; | ||
170 | gargc = 0; | ||
171 | for (i = 0; i < argc; i++) | ||
172 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); | ||
173 | cargs = GNUNET_strdup (gargs); | ||
174 | tok = strtok (cargs, " "); | ||
175 | while (NULL != tok) | ||
176 | { | ||
177 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); | ||
178 | tok = strtok (NULL, " "); | ||
179 | } | ||
180 | GNUNET_free (cargs); | ||
181 | GNUNET_array_append (gargv, gargc, NULL); | ||
182 | argv = (char *const *) gargv; | ||
183 | argc = gargc - 1; | ||
175 | } | 184 | } |
176 | GNUNET_free (cargs); | ||
177 | GNUNET_array_append (gargv, gargc, NULL); | ||
178 | argv = (char *const *) gargv; | ||
179 | argc = gargc - 1; | ||
180 | } | ||
181 | memset (&cc, 0, sizeof (cc)); | 185 | memset (&cc, 0, sizeof (cc)); |
182 | loglev = NULL; | 186 | loglev = NULL; |
183 | cc.task = task; | 187 | cc.task = task; |
@@ -189,27 +193,28 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | |||
189 | setlocale (LC_ALL, ""); | 193 | setlocale (LC_ALL, ""); |
190 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 194 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
191 | if (path != NULL) | 195 | if (path != NULL) |
192 | { | 196 | { |
193 | BINDTEXTDOMAIN ("GNUnet", path); | 197 | BINDTEXTDOMAIN ("GNUnet", path); |
194 | GNUNET_free (path); | 198 | GNUNET_free (path); |
195 | } | 199 | } |
196 | textdomain ("GNUnet"); | 200 | textdomain ("GNUnet"); |
197 | #endif | 201 | #endif |
198 | cnt = 0; | 202 | cnt = 0; |
199 | while (options[cnt].name != NULL) | 203 | while (options[cnt].name != NULL) |
200 | cnt++; | 204 | cnt++; |
201 | allopts = | 205 | allopts = |
202 | GNUNET_malloc ((cnt + | 206 | GNUNET_malloc ((cnt + |
203 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + | 207 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + |
204 | sizeof (defoptions)); | 208 | sizeof (defoptions)); |
205 | memcpy (allopts, defoptions, sizeof (defoptions)); | 209 | memcpy (allopts, defoptions, sizeof (defoptions)); |
206 | memcpy (&allopts | 210 | memcpy (&allopts |
207 | [sizeof (defoptions) / | 211 | [sizeof (defoptions) / |
208 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, | 212 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, |
209 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); | 213 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); |
210 | cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); | 214 | cnt += |
215 | sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); | ||
211 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), | 216 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), |
212 | &cmd_sorter); | 217 | &cmd_sorter); |
213 | loglev = NULL; | 218 | loglev = NULL; |
214 | cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | 219 | cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); |
215 | lpfx = GNUNET_strdup (binaryName); | 220 | lpfx = GNUNET_strdup (binaryName); |
@@ -217,30 +222,31 @@ GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | |||
217 | *spc = '\0'; | 222 | *spc = '\0'; |
218 | if ((-1 == | 223 | if ((-1 == |
219 | (ret = | 224 | (ret = |
220 | GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) || | 225 | GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) |
221 | (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)) ) | 226 | || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) |
222 | { | 227 | { |
223 | GNUNET_CONFIGURATION_destroy (cfg); | 228 | GNUNET_CONFIGURATION_destroy (cfg); |
224 | GNUNET_free_non_null (cc.cfgfile); | 229 | GNUNET_free_non_null (cc.cfgfile); |
225 | GNUNET_free_non_null (loglev); | 230 | GNUNET_free_non_null (loglev); |
226 | GNUNET_free_non_null (logfile); | 231 | GNUNET_free_non_null (logfile); |
227 | GNUNET_free (allopts); | 232 | GNUNET_free (allopts); |
228 | GNUNET_free (lpfx); | 233 | GNUNET_free (lpfx); |
229 | return GNUNET_SYSERR; | 234 | return GNUNET_SYSERR; |
230 | } | 235 | } |
231 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); | 236 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); |
232 | GNUNET_free (allopts); | 237 | GNUNET_free (allopts); |
233 | GNUNET_free (lpfx); | 238 | GNUNET_free (lpfx); |
234 | if (GNUNET_OK == | 239 | if (GNUNET_OK == |
235 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", | 240 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", |
236 | &skew_offset) && | 241 | &skew_offset) && |
237 | (GNUNET_OK == | 242 | (GNUNET_OK == |
238 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", | 243 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", |
239 | "skew_variance", &skew_variance))) | 244 | "skew_variance", |
240 | { | 245 | &skew_variance))) |
241 | clock_offset = skew_offset - skew_variance; | 246 | { |
242 | GNUNET_TIME_set_offset (clock_offset); | 247 | clock_offset = skew_offset - skew_variance; |
243 | } | 248 | GNUNET_TIME_set_offset (clock_offset); |
249 | } | ||
244 | /* run */ | 250 | /* run */ |
245 | cc.args = &argv[ret]; | 251 | cc.args = &argv[ret]; |
246 | GNUNET_SCHEDULER_run (&program_main, &cc); | 252 | GNUNET_SCHEDULER_run (&program_main, &cc); |