Skip to content

Commit

Permalink
Merge branch 'feat/refuse-saving-symlinked-config' (branch name super…
Browse files Browse the repository at this point in the history
…seded) of Scrumplex/htop
  • Loading branch information
Daniel Lange authored and Daniel Lange committed Mar 12, 2024
2 parents 4feac8e + f7c9ede commit 0dac8e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 9 additions & 3 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
}
Expand All @@ -826,6 +827,11 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H
legacyDotfile = NULL;
}
}

this->filename = xMalloc(PATH_MAX);
if (!realpath(this->initialFilename, this->filename))
free_and_xStrdup(&this->filename, this->initialFilename);

this->colorScheme = 0;
#ifdef HAVE_GETMOUSE
this->enableMouse = true;
Expand Down
1 change: 1 addition & 0 deletions Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct ScreenSettings_ {

typedef struct Settings_ {
char* filename;
char* initialFilename;
int config_version;
HeaderLayout hLayout;
MeterColumnSetting* hColumns;
Expand Down

0 comments on commit 0dac8e7

Please sign in to comment.