summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Vanni <vannilla@firemail.cc>2020-10-10 17:19:53 +0200
committerChristian Grothoff <christian@grothoff.org>2020-10-11 10:30:46 +0200
commit77339944c9605919a035744df1a839a6e5793a37 (patch)
tree39314fcbb31f3aa6b3c2050a40bcfa151f717873
parent03199f7f246e1d636c9feb921d66be48c907130f (diff)
Allow applications to change ProjectData with only some fields
Some simple applications (e.g. thin clients) might want to change the ProjectData structure (e.g. for gettext), but might not meet all the requirements needed to fill it out completely. A thin client might not provide any library, making the `libname' field useless. More importantly, not every application requires a configuration: some of them, especially clients, might simply use command line options to drive their behaviour.
-rw-r--r--src/util/configuration_loader.c3
-rw-r--r--src/util/os_installation.c2
-rw-r--r--src/util/program.c25
3 files changed, 19 insertions, 11 deletions
diff --git a/src/util/configuration_loader.c b/src/util/configuration_loader.c
index b9e5cb67f..51af24a9f 100644
--- a/src/util/configuration_loader.c
+++ b/src/util/configuration_loader.c
@@ -47,7 +47,8 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
- if (NULL != (baseconfig = getenv (base_config_varname)))
+ if (NULL != base_config_varname
+ && NULL != (baseconfig = getenv (base_config_varname)))
{
baseconfig = GNUNET_strdup (baseconfig);
}
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 34b88d761..1f2dd2e5b 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -150,6 +150,8 @@ get_path_from_proc_maps ()
FILE *f;
char *lgu;
+ if (NULL == current_pd->libname)
+ return NULL;
GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ());
if (NULL == (f = fopen (fn, "r")))
return NULL;
diff --git a/src/util/program.c b/src/util/program.c
index 8bda34b4f..b5484855c 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -232,15 +232,20 @@ GNUNET_PROGRAM_run2 (int argc,
sizeof(struct GNUNET_GETOPT_CommandLineOption),
&cmd_sorter);
loglev = NULL;
- xdg = getenv ("XDG_CONFIG_HOME");
- if (NULL != xdg)
- GNUNET_asprintf (&cfg_fn,
- "%s%s%s",
- xdg,
- DIR_SEPARATOR_STR,
- pd->config_file);
+ if (NULL != pd->config_file && NULL != pd->user_config_file)
+ {
+ xdg = getenv ("XDG_CONFIG_HOME");
+ if (NULL != xdg)
+ GNUNET_asprintf (&cfg_fn,
+ "%s%s%s",
+ xdg,
+ DIR_SEPARATOR_STR,
+ pd->config_file);
+ else
+ cfg_fn = GNUNET_strdup (pd->user_config_file);
+ }
else
- cfg_fn = GNUNET_strdup (pd->user_config_file);
+ cfg_fn = NULL;
lpfx = GNUNET_strdup (binaryName);
if (NULL != (spc = strstr (lpfx, " ")))
*spc = '\0';
@@ -269,7 +274,7 @@ GNUNET_PROGRAM_run2 (int argc,
}
else
{
- if (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn))
+ if (NULL != cfg_fn && GNUNET_YES == GNUNET_DISK_file_test (cfg_fn))
{
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn))
{
@@ -284,7 +289,7 @@ GNUNET_PROGRAM_run2 (int argc,
goto cleanup;
}
}
- else
+ else if (NULL != cfg_fn)
{
GNUNET_free (cfg_fn);
cfg_fn = NULL;