mirror of https://github.com/xzeldon/htop.git
Only consider a read successful when the file seems valid
Require at least the `fields` entry to be present, so we can have a decent guess that it was indeed a settings file.
This commit is contained in:
parent
8c653212c0
commit
03b2581745
16
Settings.c
16
Settings.c
|
@ -172,7 +172,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
if (!fd)
|
if (!fd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool readMeters = false;
|
bool didReadMeters = false;
|
||||||
|
bool didReadFields = false;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* line = String_readLine(fd);
|
char* line = String_readLine(fd);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
|
@ -187,6 +188,7 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
}
|
}
|
||||||
if (String_eq(option[0], "fields")) {
|
if (String_eq(option[0], "fields")) {
|
||||||
readFields(this->fields, &(this->flags), option[1]);
|
readFields(this->fields, &(this->flags), option[1]);
|
||||||
|
didReadFields = true;
|
||||||
} else if (String_eq(option[0], "sort_key")) {
|
} else if (String_eq(option[0], "sort_key")) {
|
||||||
// This "+1" is for compatibility with the older enum format.
|
// This "+1" is for compatibility with the older enum format.
|
||||||
this->sortKey = atoi(option[1]) + 1;
|
this->sortKey = atoi(option[1]) + 1;
|
||||||
|
@ -232,24 +234,24 @@ static bool Settings_read(Settings* this, const char* fileName) {
|
||||||
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
|
||||||
} else if (String_eq(option[0], "left_meters")) {
|
} else if (String_eq(option[0], "left_meters")) {
|
||||||
Settings_readMeters(this, option[1], 0);
|
Settings_readMeters(this, option[1], 0);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meters")) {
|
} else if (String_eq(option[0], "right_meters")) {
|
||||||
Settings_readMeters(this, option[1], 1);
|
Settings_readMeters(this, option[1], 1);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "left_meter_modes")) {
|
} else if (String_eq(option[0], "left_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 0);
|
Settings_readMeterModes(this, option[1], 0);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
} else if (String_eq(option[0], "right_meter_modes")) {
|
} else if (String_eq(option[0], "right_meter_modes")) {
|
||||||
Settings_readMeterModes(this, option[1], 1);
|
Settings_readMeterModes(this, option[1], 1);
|
||||||
readMeters = true;
|
didReadMeters = true;
|
||||||
}
|
}
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (!readMeters) {
|
if (!didReadMeters) {
|
||||||
Settings_defaultMeters(this);
|
Settings_defaultMeters(this);
|
||||||
}
|
}
|
||||||
return true;
|
return didReadFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
|
||||||
|
|
Loading…
Reference in New Issue