aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-12-11 17:47:58 +0100
committerChristian Grothoff <christian@grothoff.org>2018-12-11 17:47:58 +0100
commitcefc7647dc8db23452da80cfb4384cca641bb99d (patch)
tree80a7cecd85bacc33eb2baeb7da2c0a88e6b8d105 /src/util
parente68c4624f12fe7172ea6de5b4a5d89d9e49eae91 (diff)
downloadgnunet-cefc7647dc8db23452da80cfb4384cca641bb99d.tar.gz
gnunet-cefc7647dc8db23452da80cfb4384cca641bb99d.zip
make sure peer launches if default config not found and -c not given
Diffstat (limited to 'src/util')
-rw-r--r--src/util/gnunet-config.c16
-rw-r--r--src/util/program.c93
-rw-r--r--src/util/service.c51
3 files changed, 110 insertions, 50 deletions
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index 46c523da4..3c7eaa6dc 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -142,6 +142,7 @@ run (void *cls,
142{ 142{
143 struct GNUNET_CONFIGURATION_Handle *out = NULL; 143 struct GNUNET_CONFIGURATION_Handle *out = NULL;
144 struct GNUNET_CONFIGURATION_Handle *diff = NULL; 144 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
145 char *cfg_fn;
145 146
146 (void) cls; 147 (void) cls;
147 (void) args; 148 (void) args;
@@ -236,6 +237,20 @@ run (void *cls,
236 option, 237 option,
237 value); 238 value);
238 } 239 }
240 cfg_fn = NULL;
241 if (NULL == cfgfile)
242 {
243 const char *xdg = getenv ("XDG_CONFIG_HOME");
244 if (NULL != xdg)
245 GNUNET_asprintf (&cfg_fn,
246 "%s%s%s",
247 xdg,
248 DIR_SEPARATOR_STR,
249 GNUNET_OS_project_data_get ()->config_file);
250 else
251 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
252 cfgfile = cfg_fn;
253 }
239 if ( (NULL != diff) || (NULL != out) ) 254 if ( (NULL != diff) || (NULL != out) )
240 { 255 {
241 if (GNUNET_OK != 256 if (GNUNET_OK !=
@@ -243,6 +258,7 @@ run (void *cls,
243 cfgfile)) 258 cfgfile))
244 ret = 2; 259 ret = 2;
245 } 260 }
261 GNUNET_free_non_null (cfg_fn);
246 if (NULL != out) 262 if (NULL != out)
247 GNUNET_CONFIGURATION_destroy (out); 263 GNUNET_CONFIGURATION_destroy (out);
248 cleanup: 264 cleanup:
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 */
103static int 107static int
104cmd_sorter (const void *a1, const void *a2) 108cmd_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;
diff --git a/src/util/service.c b/src/util/service.c
index 2dc7dd576..098030ddf 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1587,6 +1587,7 @@ return_agpl (void *cls,
1587 struct GNUNET_MessageHeader *res; 1587 struct GNUNET_MessageHeader *res;
1588 size_t slen; 1588 size_t slen;
1589 1589
1590 (void) msg;
1590 slen = strlen (GNUNET_AGPL_URL) + 1; 1591 slen = strlen (GNUNET_AGPL_URL) + 1;
1591 env = GNUNET_MQ_msg_extra (res, 1592 env = GNUNET_MQ_msg_extra (res,
1592 GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, 1593 GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
@@ -1811,37 +1812,45 @@ GNUNET_SERVICE_run_ (int argc,
1811 GNUNET_break (0); 1812 GNUNET_break (0);
1812 goto shutdown; 1813 goto shutdown;
1813 } 1814 }
1814 if (NULL == opt_cfg_filename) 1815 if (NULL != opt_cfg_filename)
1815 opt_cfg_filename = GNUNET_strdup (cfg_filename);
1816 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename))
1817 { 1816 {
1818 if (GNUNET_SYSERR == 1817 if ( (GNUNET_YES !=
1819 GNUNET_CONFIGURATION_load (cfg, 1818 GNUNET_DISK_file_test (opt_cfg_filename)) ||
1820 opt_cfg_filename)) 1819 (GNUNET_SYSERR ==
1820 GNUNET_CONFIGURATION_load (cfg,
1821 opt_cfg_filename)) )
1821 { 1822 {
1822 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1823 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1823 _("Malformed configuration file `%s', exit ...\n"), 1824 _("Malformed configuration file `%s', exit ...\n"),
1824 opt_cfg_filename); 1825 opt_cfg_filename);
1825 goto shutdown; 1826 goto shutdown;
1826 } 1827 }
1827 } 1828 }
1828 else 1829 else
1829 { 1830 {
1830 if (GNUNET_SYSERR == 1831 if (GNUNET_YES ==
1831 GNUNET_CONFIGURATION_load (cfg, 1832 GNUNET_DISK_file_test (cfg_filename))
1832 NULL))
1833 { 1833 {
1834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1834 if (GNUNET_SYSERR ==
1835 _("Malformed configuration, exit ...\n")); 1835 GNUNET_CONFIGURATION_load (cfg,
1836 goto shutdown; 1836 cfg_filename))
1837 {
1838 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1839 _("Malformed configuration file `%s', exit ...\n"),
1840 cfg_filename);
1841 goto shutdown;
1842 }
1837 } 1843 }
1838 if (0 != strcmp (opt_cfg_filename, 1844 else
1839 cfg_filename))
1840 { 1845 {
1841 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1846 if (GNUNET_SYSERR ==
1842 _("Could not access configuration file `%s'\n"), 1847 GNUNET_CONFIGURATION_load (cfg,
1843 opt_cfg_filename); 1848 NULL))
1844 goto shutdown; 1849 {
1850 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1851 _("Malformed configuration, exit ...\n"));
1852 goto shutdown;
1853 }
1845 } 1854 }
1846 } 1855 }
1847 if (GNUNET_OK != setup_service (&sh)) 1856 if (GNUNET_OK != setup_service (&sh))
@@ -1857,7 +1866,7 @@ GNUNET_SERVICE_run_ (int argc,
1857 LOG (GNUNET_ERROR_TYPE_DEBUG, 1866 LOG (GNUNET_ERROR_TYPE_DEBUG,
1858 "Service `%s' runs with configuration from `%s'\n", 1867 "Service `%s' runs with configuration from `%s'\n",
1859 service_name, 1868 service_name,
1860 opt_cfg_filename); 1869 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
1861 if ((GNUNET_OK == 1870 if ((GNUNET_OK ==
1862 GNUNET_CONFIGURATION_get_value_number (sh.cfg, 1871 GNUNET_CONFIGURATION_get_value_number (sh.cfg,
1863 "TESTING", 1872 "TESTING",