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

@ -86,9 +86,9 @@ typedef struct CommandLineSettings_ {
bool readonly; bool readonly;
} CommandLineSettings; } CommandLineSettings;
static CommandLineSettings parseArguments(const char* program, int argc, char** argv) { static CommandLineStatus parseArguments(const char* program, int argc, char** argv, CommandLineSettings* flags) {
CommandLineSettings flags = { *flags = (CommandLineSettings) {
.pidMatchList = NULL, .pidMatchList = NULL,
.commFilter = NULL, .commFilter = NULL,
.userId = (uid_t)-1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2)) .userId = (uid_t)-1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2))
@ -131,10 +131,10 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
switch (opt) { switch (opt) {
case 'h': case 'h':
printHelpFlag(program); printHelpFlag(program);
exit(0); return STATUS_OK_EXIT;
case 'V': case 'V':
printVersionFlag(program); printVersionFlag(program);
exit(0); return STATUS_OK_EXIT;
case 's': case 's':
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
if (String_eq(optarg, "help")) { if (String_eq(optarg, "help")) {
@ -143,29 +143,29 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
const char* description = Process_fields[j].description; const char* description = Process_fields[j].description;
if (name) printf("%19s %s\n", name, description); if (name) printf("%19s %s\n", name, description);
} }
exit(0); return STATUS_OK_EXIT;
} }
flags.sortKey = 0; flags->sortKey = 0;
for (int j = 1; j < LAST_PROCESSFIELD; j++) { for (int j = 1; j < LAST_PROCESSFIELD; j++) {
if (Process_fields[j].name == NULL) if (Process_fields[j].name == NULL)
continue; continue;
if (String_eq(optarg, Process_fields[j].name)) { if (String_eq(optarg, Process_fields[j].name)) {
flags.sortKey = j; flags->sortKey = j;
break; break;
} }
} }
if (flags.sortKey == 0) { if (flags->sortKey == 0) {
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg); fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
exit(1); return STATUS_ERROR_EXIT;
} }
break; break;
case 'd': case 'd':
if (sscanf(optarg, "%16d", &(flags.delay)) == 1) { if (sscanf(optarg, "%16d", &(flags->delay)) == 1) {
if (flags.delay < 1) flags.delay = 1; if (flags->delay < 1) flags->delay = 1;
if (flags.delay > 100) flags.delay = 100; if (flags->delay > 100) flags->delay = 100;
} else { } else {
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg); fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
exit(1); return STATUS_ERROR_EXIT;
} }
break; break;
case 'u': case 'u':
@ -177,30 +177,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
} }
if (!username) { if (!username) {
flags.userId = geteuid(); flags->userId = geteuid();
} else if (!Action_setUserOnly(username, &(flags.userId))) { } else if (!Action_setUserOnly(username, &(flags->userId))) {
for (const char *itr = username; *itr; ++itr) for (const char *itr = username; *itr; ++itr)
if (!isdigit((unsigned char)*itr)) { if (!isdigit((unsigned char)*itr)) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username); fprintf(stderr, "Error: invalid user \"%s\".\n", username);
exit(1); return STATUS_ERROR_EXIT;
} }
flags.userId = atol(username); flags->userId = atol(username);
} }
break; break;
} }
case 'C': case 'C':
flags.useColors = false; flags->useColors = false;
break; break;
case 'M': case 'M':
#ifdef HAVE_GETMOUSE #ifdef HAVE_GETMOUSE
flags.enableMouse = false; flags->enableMouse = false;
#endif #endif
break; break;
case 'U': case 'U':
flags.allowUnicode = false; flags->allowUnicode = false;
break; break;
case 't': case 't':
flags.treeView = true; flags->treeView = true;
break; break;
case 'p': { case 'p': {
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */ assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
@ -208,14 +208,14 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
char* saveptr; char* saveptr;
const char* pid = strtok_r(argCopy, ",", &saveptr); const char* pid = strtok_r(argCopy, ",", &saveptr);
if (!flags.pidMatchList) { if (!flags->pidMatchList) {
flags.pidMatchList = Hashtable_new(8, false); flags->pidMatchList = Hashtable_new(8, false);
} }
while(pid) { while(pid) {
unsigned int num_pid = atoi(pid); unsigned int num_pid = atoi(pid);
// deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here // deepcode ignore CastIntegerToAddress: we just want a non-NULL pointer here
Hashtable_put(flags.pidMatchList, num_pid, (void *) 1); Hashtable_put(flags->pidMatchList, num_pid, (void *) 1);
pid = strtok_r(NULL, ",", &saveptr); pid = strtok_r(NULL, ",", &saveptr);
} }
free(argCopy); free(argCopy);
@ -224,7 +224,7 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
} }
case 'F': { case 'F': {
assert(optarg); assert(optarg);
free_and_xStrdup(&flags.commFilter, optarg); free_and_xStrdup(&flags->commFilter, optarg);
break; break;
} }
case 'H': { case 'H': {
@ -234,28 +234,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
delay = argv[optind++]; delay = argv[optind++];
} }
if (delay) { if (delay) {
if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) { if (sscanf(delay, "%16d", &(flags->highlightDelaySecs)) == 1) {
if (flags.highlightDelaySecs < 1) if (flags->highlightDelaySecs < 1)
flags.highlightDelaySecs = 1; flags->highlightDelaySecs = 1;
} else { } else {
fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay); fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay);
exit(1); return STATUS_ERROR_EXIT;
} }
} }
flags.highlightChanges = true; flags->highlightChanges = true;
break; break;
} }
case 128: case 128:
flags.readonly = true; flags->readonly = true;
break; break;
default: default: {
if (Platform_getLongOption(opt, argc, argv) == false) CommandLineStatus status;
exit(1); if ((status = Platform_getLongOption(opt, argc, argv)) != STATUS_OK)
break; return status;
break;
}
} }
} }
return flags; return STATUS_OK;
} }
static void CommandLine_delay(ProcessList* pl, unsigned long millisec) { static void CommandLine_delay(ProcessList* pl, unsigned long millisec) {
@ -288,12 +290,17 @@ int CommandLine_run(const char* name, int argc, char** argv) {
else else
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
CommandLineSettings flags = parseArguments(name, argc, argv); CommandLineStatus status = STATUS_OK;
CommandLineSettings flags = { 0 };
if ((status = parseArguments(name, argc, argv, &flags)) != STATUS_OK)
return status != STATUS_OK_EXIT ? 1 : 0;
if (flags.readonly) if (flags.readonly)
Settings_enableReadonly(); Settings_enableReadonly();
Platform_init(); if (!Platform_init())
return 1;
Process_setupColumnWidths(); Process_setupColumnWidths();

View File

@ -8,6 +8,11 @@ Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
typedef enum {
STATUS_OK,
STATUS_ERROR_EXIT,
STATUS_OK_EXIT
} CommandLineStatus;
int CommandLine_run(const char* name, int argc, char** argv); int CommandLine_run(const char* name, int argc, char** argv);

View File

@ -126,7 +126,7 @@ static double Platform_nanosecondsPerMachTick = 1.0;
static double Platform_nanosecondsPerSchedulerTick = -1; static double Platform_nanosecondsPerSchedulerTick = -1;
void Platform_init(void) { bool Platform_init(void) {
Platform_nanosecondsPerMachTick = Platform_calculateNanosecondsPerMachTick(); Platform_nanosecondsPerMachTick = Platform_calculateNanosecondsPerMachTick();
// Determine the number of scheduler clock ticks per second // Determine the number of scheduler clock ticks per second
@ -139,6 +139,8 @@ void Platform_init(void) {
const double nanos_per_sec = 1e9; const double nanos_per_sec = 1e9;
Platform_nanosecondsPerSchedulerTick = nanos_per_sec / scheduler_ticks_per_sec; Platform_nanosecondsPerSchedulerTick = nanos_per_sec / scheduler_ticks_per_sec;
return true;
} }
// Converts ticks in the Mach "timebase" to nanoseconds. // Converts ticks in the Mach "timebase" to nanoseconds.

View File

@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "NetworkIOMeter.h" #include "NetworkIOMeter.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "darwin/DarwinProcess.h" #include "darwin/DarwinProcess.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
@ -33,7 +34,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
// Converts ticks in the Mach "timebase" to nanoseconds. // Converts ticks in the Mach "timebase" to nanoseconds.
// See `mach_timebase_info`, as used to define the `Platform_nanosecondsPerMachTick` constant. // See `mach_timebase_info`, as used to define the `Platform_nanosecondsPerMachTick` constant.
@ -87,8 +88,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -105,8 +105,9 @@ const MeterClass* const Platform_meterTypes[] = {
NULL NULL
}; };
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -23,6 +23,7 @@ in the source distribution for its full text.
#include "Process.h" #include "Process.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
#include "generic/uname.h" #include "generic/uname.h"
@ -36,7 +37,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -78,8 +79,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -127,8 +127,9 @@ const MeterClass* const Platform_meterTypes[] = {
NULL NULL
}; };
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "Process.h" #include "Process.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
#include "generic/uname.h" #include "generic/uname.h"
@ -32,7 +33,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -78,8 +79,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

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

View File

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

View File

@ -174,8 +174,9 @@ const MeterClass* const Platform_meterTypes[] = {
NULL NULL
}; };
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -24,6 +24,7 @@ in the source distribution for its full text.
#include "Process.h" #include "Process.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
#include "generic/uname.h" #include "generic/uname.h"
@ -42,7 +43,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -82,8 +83,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -121,8 +121,9 @@ const MeterClass* const Platform_meterTypes[] = {
NULL NULL
}; };
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -20,6 +20,7 @@ in the source distribution for its full text.
#include "Process.h" #include "Process.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
#include "generic/uname.h" #include "generic/uname.h"
@ -34,7 +35,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -76,8 +77,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -257,7 +257,7 @@ size_t Platform_addMetric(PCPMetric id, const char* name) {
/* global state from the environment and command line arguments */ /* global state from the environment and command line arguments */
pmOptions opts; pmOptions opts;
void Platform_init(void) { bool Platform_init(void) {
const char* source; const char* source;
if (opts.context == PM_CONTEXT_ARCHIVE) { if (opts.context == PM_CONTEXT_ARCHIVE) {
source = opts.archives[0]; source = opts.archives[0];
@ -277,12 +277,12 @@ void Platform_init(void) {
} }
if (sts < 0) { if (sts < 0) {
fprintf(stderr, "Cannot setup PCP metric source: %s\n", pmErrStr(sts)); fprintf(stderr, "Cannot setup PCP metric source: %s\n", pmErrStr(sts));
exit(1); return false;
} }
/* setup timezones and other general startup preparation completion */ /* setup timezones and other general startup preparation completion */
if (pmGetContextOptions(sts, &opts) < 0 || opts.errors) { if (pmGetContextOptions(sts, &opts) < 0 || opts.errors) {
pmflush(); pmflush();
exit(1); return false;
} }
pcp = xCalloc(1, sizeof(Platform)); pcp = xCalloc(1, sizeof(Platform));
@ -309,7 +309,8 @@ void Platform_init(void) {
sts = pmLookupName(pcp->totalMetrics, pcp->names, pcp->pmids); sts = pmLookupName(pcp->totalMetrics, pcp->names, pcp->pmids);
if (sts < 0) { if (sts < 0) {
fprintf(stderr, "Error: cannot lookup metric names: %s\n", pmErrStr(sts)); fprintf(stderr, "Error: cannot lookup metric names: %s\n", pmErrStr(sts));
exit(1); Platform_done();
return false;
} }
for (size_t i = 0; i < pcp->totalMetrics; i++) { for (size_t i = 0; i < pcp->totalMetrics; i++) {
@ -361,6 +362,8 @@ void Platform_init(void) {
Platform_getRelease(0); Platform_getRelease(0);
Platform_getMaxCPU(); Platform_getMaxCPU();
Platform_getMaxPid(); Platform_getMaxPid();
return true;
} }
void Platform_dynamicColumnsDone(Hashtable* columns) { void Platform_dynamicColumnsDone(Hashtable* columns) {
@ -697,16 +700,16 @@ void Platform_longOptionsUsage(ATTR_UNUSED const char* name) {
" --timezone=TZ set reporting timezone\n"); " --timezone=TZ set reporting timezone\n");
} }
bool Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) { CommandLineStatus Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
/* libpcp export without a header definition */ /* libpcp export without a header definition */
extern void __pmAddOptHost(pmOptions*, char*); extern void __pmAddOptHost(pmOptions*, char*);
switch (opt) { switch (opt) {
case PLATFORM_LONGOPT_HOST: /* --host=HOSTSPEC */ case PLATFORM_LONGOPT_HOST: /* --host=HOSTSPEC */
if (argv[optind][0] == '\0') if (argv[optind][0] == '\0')
return false; return STATUS_ERROR_EXIT;
__pmAddOptHost(&opts, optarg); __pmAddOptHost(&opts, optarg);
return true; return STATUS_OK;
case PLATFORM_LONGOPT_HOSTZONE: /* --hostzone */ case PLATFORM_LONGOPT_HOSTZONE: /* --hostzone */
if (opts.timezone) { if (opts.timezone) {
@ -715,23 +718,23 @@ bool Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
} else { } else {
opts.tzflag = 1; opts.tzflag = 1;
} }
return true; return STATUS_OK;
case PLATFORM_LONGOPT_TIMEZONE: /* --timezone=TZ */ case PLATFORM_LONGOPT_TIMEZONE: /* --timezone=TZ */
if (argv[optind][0] == '\0') if (argv[optind][0] == '\0')
return false; return STATUS_ERROR_EXIT;
if (opts.tzflag) { if (opts.tzflag) {
pmprintf("%s: at most one of -Z and -z allowed\n", pmGetProgname()); pmprintf("%s: at most one of -Z and -z allowed\n", pmGetProgname());
opts.errors++; opts.errors++;
} else { } else {
opts.timezone = optarg; opts.timezone = optarg;
} }
return true; return STATUS_OK;
default: default:
break; break;
} }
return false; return STATUS_ERROR_EXIT;
} }
void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -34,6 +34,7 @@ in the source distribution for its full text.
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "RichString.h" #include "RichString.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "pcp/PCPDynamicColumn.h" #include "pcp/PCPDynamicColumn.h"
#include "pcp/PCPDynamicMeter.h" #include "pcp/PCPDynamicMeter.h"
@ -67,7 +68,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -126,7 +127,7 @@ enum {
void Platform_longOptionsUsage(const char* name); void Platform_longOptionsUsage(const char* name);
bool Platform_getLongOption(int opt, int argc, char** argv); CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv);
extern pmOptions opts; extern pmOptions opts;

View File

@ -122,8 +122,9 @@ const MeterClass* const Platform_meterTypes[] = {
NULL NULL
}; };
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -35,6 +35,7 @@ in the source distribution for its full text.
#include "NetworkIOMeter.h" #include "NetworkIOMeter.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "generic/hostname.h" #include "generic/hostname.h"
#include "generic/uname.h" #include "generic/uname.h"
@ -59,7 +60,7 @@ extern const ProcessField Platform_defaultFields[];
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -105,8 +106,8 @@ static inline void Platform_getRelease(char** string) {
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {

View File

@ -68,8 +68,9 @@ const MeterClass* const Platform_meterTypes[] = {
static const char Platform_unsupported[] = "unsupported"; static const char Platform_unsupported[] = "unsupported";
void Platform_init(void) { bool Platform_init(void) {
/* no platform-specific setup needed */ /* no platform-specific setup needed */
return true;
} }
void Platform_done(void) { void Platform_done(void) {

View File

@ -15,6 +15,7 @@ in the source distribution for its full text.
#include "NetworkIOMeter.h" #include "NetworkIOMeter.h"
#include "ProcessLocksScreen.h" #include "ProcessLocksScreen.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "CommandLine.h"
#include "generic/gettime.h" #include "generic/gettime.h"
#include "unsupported/UnsupportedProcess.h" #include "unsupported/UnsupportedProcess.h"
@ -27,7 +28,7 @@ extern const ProcessField Platform_defaultFields[];
extern const MeterClass* const Platform_meterTypes[]; extern const MeterClass* const Platform_meterTypes[];
void Platform_init(void); bool Platform_init(void);
void Platform_done(void); void Platform_done(void);
@ -65,8 +66,8 @@ void Platform_getRelease(char** string);
static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
static inline bool Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
return false; return STATUS_ERROR_EXIT;
} }
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {