diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-12-11 17:47:58 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-12-11 17:47:58 +0100 |
commit | cefc7647dc8db23452da80cfb4384cca641bb99d (patch) | |
tree | 80a7cecd85bacc33eb2baeb7da2c0a88e6b8d105 /src/util/program.c | |
parent | e68c4624f12fe7172ea6de5b4a5d89d9e49eae91 (diff) | |
download | gnunet-cefc7647dc8db23452da80cfb4384cca641bb99d.tar.gz gnunet-cefc7647dc8db23452da80cfb4384cca641bb99d.zip |
make sure peer launches if default config not found and -c not given
Diffstat (limited to 'src/util/program.c')
-rw-r--r-- | src/util/program.c | 93 |
1 files changed, 64 insertions, 29 deletions
diff --git a/src/util/program.c b/src/util/program.c index da58348d0..2fa8676a2 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -87,9 +87,13 @@ program_main (void *cls) | |||
87 | struct CommandContext *cc = cls; | 87 | struct CommandContext *cc = cls; |
88 | 88 | ||
89 | GNUNET_SPEEDUP_start_(cc->cfg); | 89 | GNUNET_SPEEDUP_start_(cc->cfg); |
90 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 90 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
91 | NULL); | ||
91 | GNUNET_RESOLVER_connect (cc->cfg); | 92 | GNUNET_RESOLVER_connect (cc->cfg); |
92 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); | 93 | cc->task (cc->task_cls, |
94 | cc->args, | ||
95 | cc->cfgfile, | ||
96 | cc->cfg); | ||
93 | } | 97 | } |
94 | 98 | ||
95 | 99 | ||
@@ -101,7 +105,8 @@ program_main (void *cls) | |||
101 | * @param a2 second command line option | 105 | * @param a2 second command line option |
102 | */ | 106 | */ |
103 | static int | 107 | static int |
104 | cmd_sorter (const void *a1, const void *a2) | 108 | cmd_sorter (const void *a1, |
109 | const void *a2) | ||
105 | { | 110 | { |
106 | const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; | 111 | const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; |
107 | const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; | 112 | const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; |
@@ -264,18 +269,17 @@ GNUNET_PROGRAM_run2 (int argc, | |||
264 | GNUNET_free (lpfx); | 269 | GNUNET_free (lpfx); |
265 | goto cleanup; | 270 | goto cleanup; |
266 | } | 271 | } |
267 | if (NULL == cc.cfgfile) | 272 | if (NULL != cc.cfgfile) |
268 | cc.cfgfile = GNUNET_strdup (cfg_fn); | ||
269 | if (GNUNET_YES == | ||
270 | GNUNET_DISK_file_test (cc.cfgfile)) | ||
271 | { | 273 | { |
272 | if (GNUNET_SYSERR == | 274 | if ( (GNUNET_YES != |
273 | GNUNET_CONFIGURATION_load (cfg, | 275 | GNUNET_DISK_file_test (cc.cfgfile)) || |
274 | cc.cfgfile)) | 276 | (GNUNET_SYSERR == |
277 | GNUNET_CONFIGURATION_load (cfg, | ||
278 | cc.cfgfile)) ) | ||
275 | { | 279 | { |
276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
277 | _("Malformed configuration file `%s', exit ...\n"), | 281 | _("Unreadable or malformed configuration file `%s', exit ...\n"), |
278 | cc.cfgfile); | 282 | cc.cfgfile); |
279 | ret = GNUNET_SYSERR; | 283 | ret = GNUNET_SYSERR; |
280 | GNUNET_free (allopts); | 284 | GNUNET_free (allopts); |
281 | GNUNET_free (lpfx); | 285 | GNUNET_free (lpfx); |
@@ -284,16 +288,37 @@ GNUNET_PROGRAM_run2 (int argc, | |||
284 | } | 288 | } |
285 | else | 289 | else |
286 | { | 290 | { |
287 | if (0 != strcmp (cc.cfgfile, | 291 | if (GNUNET_YES == |
288 | cfg_fn)) | 292 | GNUNET_DISK_file_test (cfg_fn)) |
289 | { | 293 | { |
290 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 294 | if (GNUNET_SYSERR == |
291 | _("Could not access configuration file `%s'\n"), | 295 | GNUNET_CONFIGURATION_load (cfg, |
292 | cc.cfgfile); | 296 | cfg_fn)) |
293 | ret = GNUNET_SYSERR; | 297 | { |
294 | GNUNET_free (allopts); | 298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
295 | GNUNET_free (lpfx); | 299 | _("Unreadable or malformed default configuration file `%s', exit ...\n"), |
296 | goto cleanup; | 300 | cfg_fn); |
301 | ret = GNUNET_SYSERR; | ||
302 | GNUNET_free (allopts); | ||
303 | GNUNET_free (lpfx); | ||
304 | goto cleanup; | ||
305 | } | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | GNUNET_free (cfg_fn); | ||
310 | cfg_fn = NULL; | ||
311 | if (GNUNET_OK != | ||
312 | GNUNET_CONFIGURATION_load (cfg, | ||
313 | NULL)) | ||
314 | { | ||
315 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
316 | _("Unreadable or malformed configuration, exit ...\n")); | ||
317 | ret = GNUNET_SYSERR; | ||
318 | GNUNET_free (allopts); | ||
319 | GNUNET_free (lpfx); | ||
320 | goto cleanup; | ||
321 | } | ||
297 | } | 322 | } |
298 | } | 323 | } |
299 | GNUNET_free (allopts); | 324 | GNUNET_free (allopts); |
@@ -320,20 +345,30 @@ GNUNET_PROGRAM_run2 (int argc, | |||
320 | has little business with ARM-specific options. */ | 345 | has little business with ARM-specific options. */ |
321 | if (GNUNET_YES != | 346 | if (GNUNET_YES != |
322 | GNUNET_CONFIGURATION_have_value (cfg, | 347 | GNUNET_CONFIGURATION_have_value (cfg, |
323 | "arm", | 348 | "arm", |
324 | "CONFIG")) | 349 | "CONFIG")) |
325 | { | 350 | { |
326 | GNUNET_CONFIGURATION_set_value_string (cfg, | 351 | if (NULL != cc.cfgfile) |
327 | "arm", | 352 | GNUNET_CONFIGURATION_set_value_string (cfg, |
328 | "CONFIG", | 353 | "arm", |
329 | cc.cfgfile); | 354 | "CONFIG", |
355 | cc.cfgfile); | ||
356 | else if (NULL != cfg_fn) | ||
357 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
358 | "arm", | ||
359 | "CONFIG", | ||
360 | cfg_fn); | ||
330 | } | 361 | } |
331 | 362 | ||
332 | /* run */ | 363 | /* run */ |
333 | cc.args = &argv[ret]; | 364 | cc.args = &argv[ret]; |
365 | if ( (NULL == cc.cfgfile) && | ||
366 | (NULL != cfg_fn) ) | ||
367 | cc.cfgfile = GNUNET_strdup (cfg_fn); | ||
334 | if (GNUNET_NO == run_without_scheduler) | 368 | if (GNUNET_NO == run_without_scheduler) |
335 | { | 369 | { |
336 | GNUNET_SCHEDULER_run (&program_main, &cc); | 370 | GNUNET_SCHEDULER_run (&program_main, |
371 | &cc); | ||
337 | } | 372 | } |
338 | else | 373 | else |
339 | { | 374 | { |
@@ -347,7 +382,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
347 | cleanup: | 382 | cleanup: |
348 | GNUNET_CONFIGURATION_destroy (cfg); | 383 | GNUNET_CONFIGURATION_destroy (cfg); |
349 | GNUNET_free_non_null (cc.cfgfile); | 384 | GNUNET_free_non_null (cc.cfgfile); |
350 | GNUNET_free (cfg_fn); | 385 | GNUNET_free_non_null (cfg_fn); |
351 | GNUNET_free_non_null (loglev); | 386 | GNUNET_free_non_null (loglev); |
352 | GNUNET_free_non_null (logfile); | 387 | GNUNET_free_non_null (logfile); |
353 | return ret; | 388 | return ret; |