Early program termination only from main()

This commit is contained in:
Volodymyr Vasiutyk
2021-10-06 10:45:07 +03:00
committed by BenBE
parent 2977414d54
commit 2ef70ad7f6
20 changed files with 123 additions and 90 deletions

View File

@ -835,7 +835,7 @@ void Platform_longOptionsUsage(const char* name)
#endif
}
bool Platform_getLongOption(int opt, int argc, char** argv) {
CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv) {
#ifndef HAVE_LIBCAP
(void) argc;
(void) argv;
@ -858,16 +858,16 @@ bool Platform_getLongOption(int opt, int argc, char** argv) {
Platform_capabilitiesMode = CAP_MODE_STRICT;
} else {
fprintf(stderr, "Error: invalid capabilities mode \"%s\".\n", mode);
exit(1);
return STATUS_ERROR_EXIT;
}
return true;
return STATUS_OK;
}
#endif
default:
break;
}
return false;
return STATUS_ERROR_EXIT;
}
#ifdef HAVE_LIBCAP
@ -956,20 +956,22 @@ static int dropCapabilities(enum CapMode mode) {
}
#endif
void Platform_init(void) {
bool Platform_init(void) {
#ifdef HAVE_LIBCAP
if (dropCapabilities(Platform_capabilitiesMode) < 0)
exit(1);
return false;
#endif
if (access(PROCDIR, R_OK) != 0) {
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
exit(1);
return false;
}
#ifdef HAVE_SENSORS_SENSORS_H
LibSensors_init();
#endif
return true;
}
void Platform_done(void) {

View File

@ -27,6 +27,7 @@ in the source distribution for its full text.
#include "ProcessLocksScreen.h"
#include "RichString.h"
#include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h"
#include "generic/hostname.h"
#include "generic/uname.h"
@ -45,8 +46,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void);
bool Platform_init(void);
void Platform_done(void);
void Platform_setBindings(Htop_Action* keys);
@ -100,7 +100,7 @@ static inline void Platform_getRelease(char** string) {
void Platform_longOptionsUsage(const char* name);
bool Platform_getLongOption(int opt, int argc, char** argv);
CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv);
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
Generic_gettime_realtime(tv, msec);