diff options
author | Graham Inggs <ginggs@debian.org> | 2018-02-05 14:48:51 +0200 |
---|---|---|
committer | Graham Inggs <ginggs@debian.org> | 2018-02-05 14:48:51 +0200 |
commit | 2ee50d030178cede83eb9d0005fbc19f819d30fe (patch) | |
tree | 67d75c0a7c47e15bed9d0735ecf12abec4f8157b /Settings.c | |
parent | 31b71b67011fa52f091df6fe536a11d6d0bfb256 (diff) | |
download | debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.gz debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.bz2 debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.zip |
Imported Upstream version 2.1.0upstream/2.1.0
Diffstat (limited to 'Settings.c')
-rw-r--r-- | Settings.c | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -165,11 +165,10 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { static bool Settings_read(Settings* this, const char* fileName) { FILE* fd; - uid_t euid = geteuid(); - - (void) seteuid(getuid()); + + CRT_dropPrivileges(); fd = fopen(fileName, "r"); - (void) seteuid(euid); + CRT_restorePrivileges(); if (!fd) return false; @@ -255,34 +254,40 @@ static bool Settings_read(Settings* this, const char* fileName) { static void writeFields(FILE* fd, ProcessField* fields, const char* name) { fprintf(fd, "%s=", name); + const char* sep = ""; for (int i = 0; fields[i]; i++) { // This "-1" is for compatibility with the older enum format. - fprintf(fd, "%d ", (int) fields[i]-1); + fprintf(fd, "%s%d", sep, (int) fields[i]-1); + sep = " "; } fprintf(fd, "\n"); } static void writeMeters(Settings* this, FILE* fd, int column) { + const char* sep = ""; for (int i = 0; i < this->columns[column].len; i++) { - fprintf(fd, "%s ", this->columns[column].names[i]); + fprintf(fd, "%s%s", sep, this->columns[column].names[i]); + sep = " "; } fprintf(fd, "\n"); } static void writeMeterModes(Settings* this, FILE* fd, int column) { + const char* sep = ""; for (int i = 0; i < this->columns[column].len; i++) { - fprintf(fd, "%d ", this->columns[column].modes[i]); + fprintf(fd, "%s%d", sep, this->columns[column].modes[i]); + sep = " "; } fprintf(fd, "\n"); } bool Settings_write(Settings* this) { FILE* fd; - uid_t euid = geteuid(); - (void) seteuid(getuid()); + CRT_dropPrivileges(); fd = fopen(this->filename, "w"); - (void) seteuid(euid); + CRT_restorePrivileges(); + if (fd == NULL) { return false; } @@ -368,8 +373,8 @@ Settings* Settings_new(int cpuCount) { htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - uid_t euid = geteuid(); - (void) seteuid(getuid()); + + CRT_dropPrivileges(); (void) mkdir(configDir, 0700); (void) mkdir(htopDir, 0700); free(htopDir); @@ -382,7 +387,7 @@ Settings* Settings_new(int cpuCount) { free(legacyDotfile); legacyDotfile = NULL; } - (void) seteuid(euid); + CRT_restorePrivileges(); } this->colorScheme = 0; this->changed = false; |