chiark / gitweb /
everywhere: make use of new0() and macro() macros, and stop using perror()
[elogind.git] / src / bootchart / bootchart.c
index edbd3815cd508f8c9da1c71196c4d95d72b79700..630f9c5d15649d3281d7e59f950b74daa931999d 100644 (file)
@@ -234,8 +234,7 @@ static int parse_args(int argc, char *argv[]) {
         return 0;
 }
 
-static void do_journal_append(char *file)
-{
+static void do_journal_append(char *file) {
         struct iovec iovec[5];
         int r, f, j = 0;
         ssize_t n;
@@ -262,12 +261,12 @@ static void do_journal_append(char *file)
 
         f = open(file, O_RDONLY);
         if (f < 0) {
-                log_error("Failed to read bootchart data: %m\n");
+                log_error("Failed to read bootchart data: %m");
                 return;
         }
         n = loop_read(f, p + 10, BOOTCHART_MAX, false);
         if (n < 0) {
-                log_error("Failed to read bootchart data: %s\n", strerror(-n));
+                log_error("Failed to read bootchart data: %s", strerror(-n));
                 close(f);
                 return;
         }
@@ -319,10 +318,10 @@ int main(int argc, char *argv[]) {
         (void) setrlimit(RLIMIT_NOFILE, &rlim);
 
         /* start with empty ps LL */
-        ps_first = calloc(1, sizeof(struct ps_struct));
+        ps_first = new0(struct ps_struct, 1);
         if (!ps_first) {
-                perror("calloc(ps_struct)");
-                exit(EXIT_FAILURE);
+                log_oom();
+                return EXIT_FAILURE;
         }
 
         /* handle TERM/INT nicely */
@@ -332,7 +331,7 @@ int main(int argc, char *argv[]) {
 
         log_uptime();
 
-        LIST_HEAD_INIT(struct list_sample_data, head);
+        LIST_HEAD_INIT(head);
 
         /* main program loop */
         for (samples = 0; !exiting && samples < arg_samples_len; samples++) {
@@ -398,15 +397,15 @@ int main(int argc, char *argv[]) {
                                         /* caught signal, probably HUP! */
                                         break;
                                 }
-                                perror("nanosleep()");
-                                exit (EXIT_FAILURE);
+                                log_error("nanosleep() failed: %m");
+                                exit(EXIT_FAILURE);
                         }
                 } else {
                         overrun++;
                         /* calculate how many samples we lost and scrap them */
                         arg_samples_len -= (int)(newint_ns / interval);
                 }
-                LIST_PREPEND(struct list_sample_data, link, head, sampledata);
+                LIST_PREPEND(link, head, sampledata);
         }
 
         /* do some cleanup, close fd's */