summaryrefslogtreecommitdiffstats
path: root/pcp
diff options
context:
space:
mode:
authorVolodymyr Vasiutyk <volodymyr.vasiutyk@gmail.com>2021-10-06 10:45:07 +0300
committerBenBE <BenBE@geshi.org>2021-10-31 15:07:00 +0100
commit2ef70ad7f692686710091132978129b614f6dd1a (patch)
tree448c24ac798a6ab5bc18ac37cd9517bddc9f3a73 /pcp
parent2977414d540c9cb78baa3d7fc612fcb4d6ecc72f (diff)
Early program termination only from main()
Diffstat (limited to 'pcp')
-rw-r--r--pcp/Platform.c25
-rw-r--r--pcp/Platform.h5
2 files changed, 17 insertions, 13 deletions
diff --git a/pcp/Platform.c b/pcp/Platform.c
index cd7b1f48..150660af 100644
--- a/pcp/Platform.c
+++ b/pcp/Platform.c
@@ -257,7 +257,7 @@ size_t Platform_addMetric(PCPMetric id, const char* name) {
/* global state from the environment and command line arguments */
pmOptions opts;
-void Platform_init(void) {
+bool Platform_init(void) {
const char* source;
if (opts.context == PM_CONTEXT_ARCHIVE) {
source = opts.archives[0];
@@ -277,12 +277,12 @@ void Platform_init(void) {
}
if (sts < 0) {
fprintf(stderr, "Cannot setup PCP metric source: %s\n", pmErrStr(sts));
- exit(1);
+ return false;
}
/* setup timezones and other general startup preparation completion */
if (pmGetContextOptions(sts, &opts) < 0 || opts.errors) {
pmflush();
- exit(1);
+ return false;
}
pcp = xCalloc(1, sizeof(Platform));
@@ -309,7 +309,8 @@ void Platform_init(void) {
sts = pmLookupName(pcp->totalMetrics, pcp->names, pcp->pmids);
if (sts < 0) {
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++) {
@@ -361,6 +362,8 @@ void Platform_init(void) {
Platform_getRelease(0);
Platform_getMaxCPU();
Platform_getMaxPid();
+
+ return true;
}
void Platform_dynamicColumnsDone(Hashtable* columns) {
@@ -697,16 +700,16 @@ void Platform_longOptionsUsage(ATTR_UNUSED const char* name) {
" --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 */
extern void __pmAddOptHost(pmOptions*, char*);
switch (opt) {
case PLATFORM_LONGOPT_HOST: /* --host=HOSTSPEC */
if (argv[optind][0] == '\0')
- return false;
+ return STATUS_ERROR_EXIT;
__pmAddOptHost(&opts, optarg);
- return true;
+ return STATUS_OK;
case PLATFORM_LONGOPT_HOSTZONE: /* --hostzone */
if (opts.timezone) {
@@ -715,23 +718,23 @@ bool Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
} else {
opts.tzflag = 1;
}
- return true;
+ return STATUS_OK;
case PLATFORM_LONGOPT_TIMEZONE: /* --timezone=TZ */
if (argv[optind][0] == '\0')
- return false;
+ return STATUS_ERROR_EXIT;
if (opts.tzflag) {
pmprintf("%s: at most one of -Z and -z allowed\n", pmGetProgname());
opts.errors++;
} else {
opts.timezone = optarg;
}
- return true;
+ return STATUS_OK;
default:
break;
}
- return false;
+ return STATUS_ERROR_EXIT;
}
void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
diff --git a/pcp/Platform.h b/pcp/Platform.h
index 37a87996..ad38cbbd 100644
--- a/pcp/Platform.h
+++ b/pcp/Platform.h
@@ -34,6 +34,7 @@ in the source distribution for its full text.
#include "ProcessLocksScreen.h"
#include "RichString.h"
#include "SignalsPanel.h"
+#include "CommandLine.h"
#include "pcp/PCPDynamicColumn.h"
#include "pcp/PCPDynamicMeter.h"
@@ -67,7 +68,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);
@@ -126,7 +127,7 @@ enum {
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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy