mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-13 04:34:35 +03:00
Print current settings on crash
This commit is contained in:
24
Settings.c
24
Settings.c
@ -281,13 +281,20 @@ static void writeMeterModes(const Settings* this, FILE* fd, int column) {
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
|
||||
int Settings_write(const Settings* this) {
|
||||
FILE* fd = fopen(this->filename, "w");
|
||||
if (fd == NULL)
|
||||
return -errno;
|
||||
int Settings_write(const Settings* this, bool onCrash) {
|
||||
FILE* fd;
|
||||
if (onCrash) {
|
||||
fd = stderr;
|
||||
} else {
|
||||
fd = fopen(this->filename, "w");
|
||||
if (fd == NULL)
|
||||
return -errno;
|
||||
}
|
||||
|
||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
||||
if (!onCrash) {
|
||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
||||
}
|
||||
writeFields(fd, this->fields, "fields");
|
||||
// This "-1" is for compatibility with the older enum format.
|
||||
fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1);
|
||||
@ -333,6 +340,9 @@ int Settings_write(const Settings* this) {
|
||||
fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity);
|
||||
#endif
|
||||
|
||||
if (onCrash)
|
||||
return 0;
|
||||
|
||||
int r = 0;
|
||||
|
||||
if (ferror(fd) != 0)
|
||||
@ -431,7 +441,7 @@ Settings* Settings_new(unsigned int initialCpuCount) {
|
||||
ok = Settings_read(this, legacyDotfile, initialCpuCount);
|
||||
if (ok) {
|
||||
// Transition to new location and delete old configuration file
|
||||
if (Settings_write(this) == 0) {
|
||||
if (Settings_write(this, false) == 0) {
|
||||
unlink(legacyDotfile);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user