summaryrefslogtreecommitdiff
path: root/src/bootchart/bootchart.c
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2015-04-02 13:43:18 +0200
committerDaniel Mack <daniel@zonque.org>2015-04-03 15:29:18 +0200
commit34a4071e998f327945993ea6e6cbcaa0292b4093 (patch)
treef5d850771de78559cfbfc396fa65aaaf5d34ca0d /src/bootchart/bootchart.c
parent039958632036808f9baa207e72b9827fa97b7a10 (diff)
bootchart: clean up control flow logic
Don't blindly exit() from random functions, but return a proper error and upchain error conditions. squash! bootchart: clean up control flow logic When pread() returns "0", it's a read failure, so don't make the caller think log_sample() was successful, return meaningful error code instead of 0.
Diffstat (limited to 'src/bootchart/bootchart.c')
-rw-r--r--src/bootchart/bootchart.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index e4ade7e2f5..1024f78fa6 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -328,8 +328,11 @@ int main(int argc, char *argv[]) {
parse_conf();
r = parse_argv(argc, argv);
- if (r <= 0)
- return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+ if (r < 0)
+ return EXIT_FAILURE;
+
+ if (r == 0)
+ return EXIT_SUCCESS;
/*
* If the kernel executed us through init=/usr/lib/systemd/systemd-bootchart, then
@@ -367,7 +370,7 @@ int main(int argc, char *argv[]) {
log_error("Failed to setup graph start time.\n\n"
"The system uptime probably includes time that the system was suspended. "
"Use --rel to bypass this issue.");
- exit (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
has_procfs = access("/proc/vmstat", F_OK) == 0;
@@ -401,11 +404,14 @@ int main(int argc, char *argv[]) {
parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &build, NULL);
}
- if (has_procfs)
- log_sample(samples, &sampledata);
- else
+ if (has_procfs) {
+ r = log_sample(samples, &sampledata);
+ if (r < 0)
+ return EXIT_FAILURE;
+ } else {
/* wait for /proc to become available, discarding samples */
has_procfs = access("/proc/vmstat", F_OK) == 0;
+ }
sample_stop = gettime_ns();
@@ -432,7 +438,7 @@ int main(int argc, char *argv[]) {
break;
}
log_error_errno(errno, "nanosleep() failed: %m");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
} else {
overrun++;