diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2022-08-14 19:58:03 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2022-08-22 21:32:49 +0200 |
commit | 62d59403d92abaf256604bfc17e76c85ce64ea35 (patch) | |
tree | d863afd15fb7c091d826907f9b310803a6035e7f /pcp/PCPDynamicMeter.c | |
parent | 5aa207f9af6622583fd60edebaef1c3ed19ab91d (diff) |
Add fallback for HOME environment variable
If the environment variable HOME is not set, try to get the home
directory from the systems password database.
Diffstat (limited to 'pcp/PCPDynamicMeter.c')
-rw-r--r-- | pcp/PCPDynamicMeter.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pcp/PCPDynamicMeter.c b/pcp/PCPDynamicMeter.c index 7c55e4bf..e8999881 100644 --- a/pcp/PCPDynamicMeter.c +++ b/pcp/PCPDynamicMeter.c @@ -12,12 +12,14 @@ in the source distribution for its full text. #include <ctype.h> #include <dirent.h> #include <errno.h> -#include <pcp/pmapi.h> +#include <pwd.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <pcp/pmapi.h> + #include "Macros.h" #include "Platform.h" #include "RichString.h" @@ -251,6 +253,12 @@ void PCPDynamicMeters_init(PCPDynamicMeters* meters) { const char* home = getenv("HOME"); char* path; + if (!xdgConfigHome && !home) { + const struct passwd* pw = getpwuid(getuid()); + if (pw) + home = pw->pw_dir; + } + meters->table = Hashtable_new(0, true); /* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */ |