aboutsummaryrefslogtreecommitdiff
path: root/src/util/program.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/program.c')
-rw-r--r--src/util/program.c87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/util/program.c b/src/util/program.c
index b5484855c..e34b37370 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -122,22 +122,7 @@ cmd_sorter (const void *a1, const void *a2)
122} 122}
123 123
124 124
125/** 125enum GNUNET_GenericReturnValue
126 * Run a standard GNUnet command startup sequence (initialize loggers
127 * and configuration, parse options).
128 *
129 * @param argc number of command line arguments in @a argv
130 * @param argv command line arguments
131 * @param binaryName our expected name
132 * @param binaryHelp help text for the program
133 * @param options command line options
134 * @param task main function to run
135 * @param task_cls closure for @a task
136 * @param run_without_scheduler #GNUNET_NO start the scheduler, #GNUNET_YES do not
137 * start the scheduler just run the main task
138 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
139 */
140int
141GNUNET_PROGRAM_run2 (int argc, 126GNUNET_PROGRAM_run2 (int argc,
142 char *const *argv, 127 char *const *argv,
143 const char *binaryName, 128 const char *binaryName,
@@ -156,7 +141,8 @@ GNUNET_PROGRAM_run2 (int argc,
156 char *logfile; 141 char *logfile;
157 char *cfg_fn; 142 char *cfg_fn;
158 const char *xdg; 143 const char *xdg;
159 int ret; 144 enum GNUNET_GenericReturnValue ret;
145 int iret;
160 unsigned int cnt; 146 unsigned int cnt;
161 unsigned long long skew_offset; 147 unsigned long long skew_offset;
162 unsigned long long skew_variance; 148 unsigned long long skew_variance;
@@ -232,7 +218,7 @@ GNUNET_PROGRAM_run2 (int argc,
232 sizeof(struct GNUNET_GETOPT_CommandLineOption), 218 sizeof(struct GNUNET_GETOPT_CommandLineOption),
233 &cmd_sorter); 219 &cmd_sorter);
234 loglev = NULL; 220 loglev = NULL;
235 if (NULL != pd->config_file && NULL != pd->user_config_file) 221 if ((NULL != pd->config_file) && (NULL != pd->user_config_file))
236 { 222 {
237 xdg = getenv ("XDG_CONFIG_HOME"); 223 xdg = getenv ("XDG_CONFIG_HOME");
238 if (NULL != xdg) 224 if (NULL != xdg)
@@ -249,12 +235,18 @@ GNUNET_PROGRAM_run2 (int argc,
249 lpfx = GNUNET_strdup (binaryName); 235 lpfx = GNUNET_strdup (binaryName);
250 if (NULL != (spc = strstr (lpfx, " "))) 236 if (NULL != (spc = strstr (lpfx, " ")))
251 *spc = '\0'; 237 *spc = '\0';
252 ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv); 238 iret = GNUNET_GETOPT_run (binaryName,
253 if ((GNUNET_OK > ret) || 239 allopts,
254 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) 240 (unsigned int) argc,
241 argv);
242 if ((GNUNET_OK > iret) ||
243 (GNUNET_OK != GNUNET_log_setup (lpfx,
244 loglev,
245 logfile)))
255 { 246 {
256 GNUNET_free (allopts); 247 GNUNET_free (allopts);
257 GNUNET_free (lpfx); 248 GNUNET_free (lpfx);
249 ret = (enum GNUNET_GenericReturnValue) iret;
258 goto cleanup; 250 goto cleanup;
259 } 251 }
260 if (NULL != cc.cfgfile) 252 if (NULL != cc.cfgfile)
@@ -274,7 +266,7 @@ GNUNET_PROGRAM_run2 (int argc,
274 } 266 }
275 else 267 else
276 { 268 {
277 if (NULL != cfg_fn && GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)) 269 if ((NULL != cfg_fn) && (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)))
278 { 270 {
279 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) 271 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn))
280 { 272 {
@@ -306,14 +298,16 @@ GNUNET_PROGRAM_run2 (int argc,
306 } 298 }
307 GNUNET_free (allopts); 299 GNUNET_free (allopts);
308 GNUNET_free (lpfx); 300 GNUNET_free (lpfx);
309 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, 301 if ((GNUNET_OK ==
310 "testing", 302 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
311 "skew_offset", 303 "testing",
312 &skew_offset)) && 304 "skew_offset",
313 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, 305 &skew_offset)) &&
314 "testing", 306 (GNUNET_OK ==
315 "skew_variance", 307 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
316 &skew_variance))) 308 "testing",
309 "skew_variance",
310 &skew_variance)))
317 { 311 {
318 clock_offset = skew_offset - skew_variance; 312 clock_offset = skew_offset - skew_variance;
319 GNUNET_TIME_set_offset (clock_offset); 313 GNUNET_TIME_set_offset (clock_offset);
@@ -323,16 +317,26 @@ GNUNET_PROGRAM_run2 (int argc,
323 specified in the configuration, remember the command-line option 317 specified in the configuration, remember the command-line option
324 in "cfg". This is typically really only having an effect if we 318 in "cfg". This is typically really only having an effect if we
325 are running code in src/arm/, as obviously the rest of the code 319 are running code in src/arm/, as obviously the rest of the code
326 has little business with ARM-specific options. */if (GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, "arm", "CONFIG")) 320 has little business with ARM-specific options. */
321 if (GNUNET_YES !=
322 GNUNET_CONFIGURATION_have_value (cfg,
323 "arm",
324 "CONFIG"))
327 { 325 {
328 if (NULL != cc.cfgfile) 326 if (NULL != cc.cfgfile)
329 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cc.cfgfile); 327 GNUNET_CONFIGURATION_set_value_string (cfg,
328 "arm",
329 "CONFIG",
330 cc.cfgfile);
330 else if (NULL != cfg_fn) 331 else if (NULL != cfg_fn)
331 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cfg_fn); 332 GNUNET_CONFIGURATION_set_value_string (cfg,
333 "arm",
334 "CONFIG",
335 cfg_fn);
332 } 336 }
333 337
334 /* run */ 338 /* run */
335 cc.args = &argv[ret]; 339 cc.args = &argv[iret];
336 if ((NULL == cc.cfgfile) && (NULL != cfg_fn)) 340 if ((NULL == cc.cfgfile) && (NULL != cfg_fn))
337 cc.cfgfile = GNUNET_strdup (cfg_fn); 341 cc.cfgfile = GNUNET_strdup (cfg_fn);
338 if (GNUNET_NO == run_without_scheduler) 342 if (GNUNET_NO == run_without_scheduler)
@@ -355,20 +359,7 @@ cleanup:
355} 359}
356 360
357 361
358/** 362enum GNUNET_GenericReturnValue
359 * Run a standard GNUnet command startup sequence (initialize loggers
360 * and configuration, parse options).
361 *
362 * @param argc number of command line arguments
363 * @param argv command line arguments
364 * @param binaryName our expected name
365 * @param binaryHelp help text for the program
366 * @param options command line options
367 * @param task main function to run
368 * @param task_cls closure for @a task
369 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
370 */
371int
372GNUNET_PROGRAM_run (int argc, 363GNUNET_PROGRAM_run (int argc,
373 char *const *argv, 364 char *const *argv,
374 const char *binaryName, 365 const char *binaryName,