summaryrefslogtreecommitdiffstats
path: root/pcp
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2022-08-14 19:58:03 +0200
committerBenBE <BenBE@geshi.org>2022-08-22 21:32:49 +0200
commit62d59403d92abaf256604bfc17e76c85ce64ea35 (patch)
treed863afd15fb7c091d826907f9b310803a6035e7f /pcp
parent5aa207f9af6622583fd60edebaef1c3ed19ab91d (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')
-rw-r--r--pcp/PCPDynamicColumn.c7
-rw-r--r--pcp/PCPDynamicMeter.c10
2 files changed, 16 insertions, 1 deletions
diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c
index aab25253..33c6d72a 100644
--- a/pcp/PCPDynamicColumn.c
+++ b/pcp/PCPDynamicColumn.c
@@ -14,6 +14,7 @@ in the source distribution for its full text.
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
+#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -194,6 +195,12 @@ void PCPDynamicColumns_init(PCPDynamicColumns* columns) {
const char* home = getenv("HOME");
char* path;
+ if (!xdgConfigHome && !home) {
+ const struct passwd* pw = getpwuid(getuid());
+ if (pw)
+ home = pw->pw_dir;
+ }
+
columns->table = Hashtable_new(0, true);
/* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */
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 */

© 2014-2024 Faster IT GmbH | imprint | privacy policy