diff options
author | Volodymyr Vasiutyk <volodymyr.vasiutyk@gmail.com> | 2021-10-06 10:45:07 +0300 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2021-10-31 15:07:00 +0100 |
commit | 2ef70ad7f692686710091132978129b614f6dd1a (patch) | |
tree | 448c24ac798a6ab5bc18ac37cd9517bddc9f3a73 /linux | |
parent | 2977414d540c9cb78baa3d7fc612fcb4d6ecc72f (diff) |
Early program termination only from main()
Diffstat (limited to 'linux')
-rw-r--r-- | linux/Platform.c | 16 | ||||
-rw-r--r-- | linux/Platform.h | 6 |
2 files changed, 12 insertions, 10 deletions
diff --git a/linux/Platform.c b/linux/Platform.c index e7f3d8f0..93953e86 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -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) { diff --git a/linux/Platform.h b/linux/Platform.h index 9c4e65d4..2e2fb3e6 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -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); |