summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2024-03-12 09:49:28 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2024-03-12 19:03:58 +0100
commitf7c9ede286afa0a60b841a7d9fadf63d20c7059a (patch)
tree335b544fae2fe653a9a99799d992dca208b89ff5
parentf588b2731518e2a5b163d02cdeb3043c7d6fa92d (diff)
Print message if config file was resolved
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
-rw-r--r--CommandLine.c4
-rw-r--r--Settings.c14
-rw-r--r--Settings.h1
3 files changed, 12 insertions, 7 deletions
diff --git a/CommandLine.c b/CommandLine.c
index 09e67b85..69b80c1e 100644
--- a/CommandLine.c
+++ b/CommandLine.c
@@ -411,6 +411,10 @@ int CommandLine_run(int argc, char** argv) {
CRT_done();
if (settings->changed) {
+#ifndef NDEBUG
+ if (!String_eq(settings->initialFilename, settings->filename))
+ fprintf(stderr, "Configuration %s was resolved to %s\n", settings->initialFilename, settings->filename);
+#endif /* NDEBUG */
int r = Settings_write(settings, false);
if (r < 0)
fprintf(stderr, "Can not save configuration to %s: %s\n", settings->filename, strerror(-r));
diff --git a/Settings.c b/Settings.c
index c2d3e92f..6cbe46b9 100644
--- a/Settings.c
+++ b/Settings.c
@@ -74,6 +74,7 @@ static void writeQuotedList(FILE* fd, char** list) {
void Settings_delete(Settings* this) {
free(this->filename);
+ free(this->initialFilename);
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
String_freeArray(this->hColumns[i].names);
free(this->hColumns[i].modes);
@@ -795,7 +796,7 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H
char* legacyDotfile = NULL;
const char* rcfile = getenv("HTOPRC");
if (rcfile) {
- this->filename = xStrdup(rcfile);
+ this->initialFilename = xStrdup(rcfile);
} else {
const char* home = getenv("HOME");
if (!home) {
@@ -806,11 +807,11 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H
char* configDir = NULL;
char* htopDir = NULL;
if (xdgConfigHome) {
- this->filename = String_cat(xdgConfigHome, "/htop/htoprc");
+ this->initialFilename = String_cat(xdgConfigHome, "/htop/htoprc");
configDir = xStrdup(xdgConfigHome);
htopDir = String_cat(xdgConfigHome, "/htop");
} else {
- this->filename = String_cat(home, "/.config/htop/htoprc");
+ this->initialFilename = String_cat(home, "/.config/htop/htoprc");
configDir = String_cat(home, "/.config");
htopDir = String_cat(home, "/.config/htop");
}
@@ -827,10 +828,9 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H
}
}
- char* resolvedFilename = xMalloc(PATH_MAX);
- if (realpath(this->filename, resolvedFilename))
- free_and_xStrdup(&this->filename, resolvedFilename);
- free(resolvedFilename);
+ this->filename = xMalloc(PATH_MAX);
+ if (!realpath(this->initialFilename, this->filename))
+ free_and_xStrdup(&this->filename, this->initialFilename);
this->colorScheme = 0;
#ifdef HAVE_GETMOUSE
diff --git a/Settings.h b/Settings.h
index a7740ff3..de4e0096 100644
--- a/Settings.h
+++ b/Settings.h
@@ -54,6 +54,7 @@ typedef struct ScreenSettings_ {
typedef struct Settings_ {
char* filename;
+ char* initialFilename;
int config_version;
HeaderLayout hLayout;
MeterColumnSetting* hColumns;

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