mirror of https://github.com/xzeldon/htop.git
Fail gracefully when /proc is not mounted
(thanks to Philipp Hagemeister)
This commit is contained in:
parent
47e881f460
commit
1b21827f1f
9
CRT.c
9
CRT.c
|
@ -11,8 +11,10 @@ in the source distribution for its full text.
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#ifdef HAVE_EXECINFO_H
|
#ifdef HAVE_EXECINFO_H
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -198,6 +200,13 @@ void CRT_done() {
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRT_fatalError(const char* note) {
|
||||||
|
char* sysMsg = strerror(errno);
|
||||||
|
CRT_done();
|
||||||
|
fprintf(stderr, "%s: %s\n", note, sysMsg);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
int CRT_readKey() {
|
int CRT_readKey() {
|
||||||
nocbreak();
|
nocbreak();
|
||||||
cbreak();
|
cbreak();
|
||||||
|
|
2
CRT.h
2
CRT.h
|
@ -119,6 +119,8 @@ void CRT_init(int delay, int colorScheme);
|
||||||
|
|
||||||
void CRT_done();
|
void CRT_done();
|
||||||
|
|
||||||
|
void CRT_fatalError(const char* note);
|
||||||
|
|
||||||
int CRT_readKey();
|
int CRT_readKey();
|
||||||
|
|
||||||
void CRT_disableDelay();
|
void CRT_disableDelay();
|
||||||
|
|
|
@ -3,6 +3,8 @@ What's new in version 1.0.2
|
||||||
|
|
||||||
* Add IO priority support ('i' key)
|
* Add IO priority support ('i' key)
|
||||||
* Avoid deleting .htoprc if it is a symlink
|
* Avoid deleting .htoprc if it is a symlink
|
||||||
|
* Fail gracefully when /proc is not mounted
|
||||||
|
(thanks to Philipp Hagemeister)
|
||||||
* BUGFIX: Fix crashes when process list is empty
|
* BUGFIX: Fix crashes when process list is empty
|
||||||
|
|
||||||
What's new in version 1.0.1
|
What's new in version 1.0.1
|
||||||
|
|
|
@ -193,7 +193,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
|
||||||
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
||||||
|
|
||||||
FILE* file = fopen(PROCSTATFILE, "r");
|
FILE* file = fopen(PROCSTATFILE, "r");
|
||||||
assert(file != NULL);
|
if (file == NULL) {
|
||||||
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
||||||
|
}
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int cpus = -1;
|
int cpus = -1;
|
||||||
do {
|
do {
|
||||||
|
@ -758,7 +760,9 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
unsigned long long int swapFree = 0;
|
unsigned long long int swapFree = 0;
|
||||||
|
|
||||||
FILE* file = fopen(PROCMEMINFOFILE, "r");
|
FILE* file = fopen(PROCMEMINFOFILE, "r");
|
||||||
assert(file != NULL);
|
if (file == NULL) {
|
||||||
|
CRT_fatalError("Cannot open " PROCMEMINFOFILE);
|
||||||
|
}
|
||||||
int cpus = this->cpuCount;
|
int cpus = this->cpuCount;
|
||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
@ -796,7 +800,9 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
file = fopen(PROCSTATFILE, "r");
|
file = fopen(PROCSTATFILE, "r");
|
||||||
assert(file != NULL);
|
if (file == NULL) {
|
||||||
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
||||||
|
}
|
||||||
for (int i = 0; i <= cpus; i++) {
|
for (int i = 0; i <= cpus; i++) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int cpuid;
|
int cpuid;
|
||||||
|
|
Loading…
Reference in New Issue