chiark / gitweb /
bootchart: switch to log_* helpers
[elogind.git] / src / bootchart / svg.c
index e111fa9cce57faa612e9957f5b61d675320be160..8c8fab941d9027f62665cc0f5b4990a60ac211ff 100644 (file)
  ***/
 
 #include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <limits.h>
 #include <unistd.h>
 #include <sys/utsname.h>
-#include <sys/stat.h>
 #include <fcntl.h>
 
 #include "util.h"
@@ -173,6 +170,9 @@ static void svg_title(const char *build) {
                 if (!fgets(cmdline, 255, f))
                         sprintf(cmdline, "Unknown");
                 fclose(f);
+        } else {
+                if (fd >= 0)
+                        close(fd);
         }
 
         /* extract root fs so we can find disk model name in sysfs */
@@ -186,14 +186,17 @@ 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)
+                                close(fd);
                 }
         }
 
         /* various utsname parameters */
         if (uname(&uts))
-                fprintf(stderr, "Error getting uname info\n");
+                log_error("Error getting uname info\n");
 
         /* date */
         t = time(NULL);
@@ -211,6 +214,9 @@ static void svg_title(const char *build) {
                         }
                 }
                 fclose(f);
+        } else {
+                if (fd >= 0)
+                        close(fd);
         }
 
         svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
@@ -1170,7 +1176,7 @@ static void svg_ps_bars(void) {
 
                 ps->sample = ps->sample->next;
                 sample_hz = ps->sample;
-                for (ii=0;((ii<(int)arg_hz/2)&&(ps->sample->next));ii++)
+                for (ii=0;((ii<(int)arg_hz/2)&&(sample_hz->next));ii++)
                         sample_hz = sample_hz->next;
 
                 /* subtract bootchart cpu utilization from total */