chiark / gitweb /
bootchart: switch to log_* helpers
authorDaniel Mack <daniel@zonque.org>
Thu, 2 Apr 2015 11:24:30 +0000 (13:24 +0200)
committerDaniel Mack <daniel@zonque.org>
Fri, 3 Apr 2015 13:29:18 +0000 (15:29 +0200)
Let the helper functions take care of the string message output.

src/bootchart/bootchart.c
src/bootchart/store.c
src/bootchart/svg.c

index f50479d0f8f642055a64507a1901db7cb2ae9926..e4ade7e2f5006bb5be953d609bea70de0f772dae 100644 (file)
@@ -135,31 +135,30 @@ static void parse_conf(void) {
 }
 
 static void help(void) {
-        fprintf(stdout,
-                "Usage: %s [OPTIONS]\n\n"
-                "Options:\n"
-                "  -r, --rel             Record time relative to recording\n"
-                "  -f, --freq=FREQ       Sample frequency [%g]\n"
-                "  -n, --samples=N       Stop sampling at [%d] samples\n"
-                "  -x, --scale-x=N       Scale the graph horizontally [%g] \n"
-                "  -y, --scale-y=N       Scale the graph vertically [%g] \n"
-                "  -p, --pss             Enable PSS graph (CPU intensive)\n"
-                "  -e, --entropy         Enable the entropy_avail graph\n"
-                "  -o, --output=PATH     Path to output files [%s]\n"
-                "  -i, --init=PATH       Path to init executable [%s]\n"
-                "  -F, --no-filter       Disable filtering of unimportant or ephemeral processes\n"
-                "  -C, --cmdline         Display full command lines with arguments\n"
-                "  -c, --control-group   Display process control group\n"
-                "      --per-cpu         Draw each CPU utilization and wait bar also\n"
-                "  -h, --help            Display this message\n\n"
-                "See bootchart.conf for more information.\n",
-                program_invocation_short_name,
-                DEFAULT_HZ,
-                DEFAULT_SAMPLES_LEN,
-                DEFAULT_SCALE_X,
-                DEFAULT_SCALE_Y,
-                DEFAULT_OUTPUT,
-                DEFAULT_INIT);
+        printf("Usage: %s [OPTIONS]\n\n"
+               "Options:\n"
+               "  -r --rel             Record time relative to recording\n"
+               "  -f --freq=FREQ       Sample frequency [%g]\n"
+               "  -n --samples=N       Stop sampling at [%d] samples\n"
+               "  -x --scale-x=N       Scale the graph horizontally [%g] \n"
+               "  -y --scale-y=N       Scale the graph vertically [%g] \n"
+               "  -p --pss             Enable PSS graph (CPU intensive)\n"
+               "  -e --entropy         Enable the entropy_avail graph\n"
+               "  -o --output=PATH     Path to output files [%s]\n"
+               "  -i --init=PATH       Path to init executable [%s]\n"
+               "  -F --no-filter       Disable filtering of unimportant or ephemeral processes\n"
+               "  -C --cmdline         Display full command lines with arguments\n"
+               "  -c --control-group   Display process control group\n"
+               "     --per-cpu         Draw each CPU utilization and wait bar also\n"
+               "  -h --help            Display this message\n\n"
+               "See bootchart.conf for more information.\n",
+               program_invocation_short_name,
+               DEFAULT_HZ,
+               DEFAULT_SAMPLES_LEN,
+               DEFAULT_SCALE_X,
+               DEFAULT_SCALE_Y,
+               DEFAULT_OUTPUT,
+               DEFAULT_INIT);
 }
 
 static int parse_argv(int argc, char *argv[]) {
@@ -365,10 +364,9 @@ int main(int argc, char *argv[]) {
         log_uptime();
 
         if (graph_start < 0.0) {
-                fprintf(stderr,
-                        "Failed to setup graph start time.\n\nThe system uptime "
-                        "probably includes time that the system was suspended. "
-                        "Use --rel to bypass this issue.\n");
+                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);
         }
 
@@ -514,7 +512,7 @@ int main(int argc, char *argv[]) {
         free(sampledata);
         /* don't complain when overrun once, happens most commonly on 1st sample */
         if (overrun > 1)
-                fprintf(stderr, "systemd-boochart: Warning: sample time overrun %i times\n", overrun);
+                log_warning("systemd-boochart: sample time overrun %i times\n", overrun);
 
         return 0;
 }
index fb3dc9ad6e6cb138a2b614f4f41055cc63c46cce..0663e100e8dcc96488e245dc1254f1793fec15da 100644 (file)
@@ -143,10 +143,8 @@ void log_sample(int sample, struct list_sample_data **ptr) {
         if (vmstat < 0) {
                 /* block stuff */
                 vmstat = openat(procfd, "vmstat", O_RDONLY);
-                if (vmstat == -1) {
-                        log_error_errno(errno, "Failed to open /proc/vmstat: %m");
-                        exit(EXIT_FAILURE);
-                }
+                if (vmstat == -1)
+                        return log_error_errno(errno, "Failed to open /proc/vmstat: %m");
         }
 
         n = pread(vmstat, buf, sizeof(buf) - 1, 0);
index 54129159accdf7117b6d88e1acfb7dc45b3b0d53..8c8fab941d9027f62665cc0f5b4990a60ac211ff 100644 (file)
@@ -186,7 +186,7 @@ static void svg_title(const char *build) {
                 f = fdopen(fd, "r");
                 if (f) {
                         if (!fgets(model, 255, f))
-                                fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
+                                log_error("Error reading disk model for %s: %m\n", rootbdev);
                         fclose(f);
                 } else {
                         if (fd >= 0)
@@ -196,7 +196,7 @@ static void svg_title(const char *build) {
 
         /* various utsname parameters */
         if (uname(&uts))
-                fprintf(stderr, "Error getting uname info\n");
+                log_error("Error getting uname info\n");
 
         /* date */
         t = time(NULL);