chiark / gitweb /
bootchart: parse /etc/os-release rather than system-release
[elogind.git] / src / bootchart / svg.c
index 156918a94bf7f79e865b0f2dda57ead92f7e795f..414d7af9b98451584362f367c397c53e4ebe505c 100644 (file)
@@ -1,16 +1,24 @@
-/*
- * svg.c
- *
- * Copyright (C) 2009-2012 Intel Coproration
- *
- * Authors:
- *   Auke Kok <auke-jan.h.kok@intel.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- */
+/***
+  bootchart.c - This file is part of systemd-bootchart
+
+  Copyright (C) 2009-2013 Intel Coproration
+
+  Authors:
+    Auke Kok <auke-jan.h.kok@intel.com>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+ ***/
 
 #include <stdio.h>
 #include <stdarg.h>
 #include <limits.h>
 #include <unistd.h>
 #include <sys/utsname.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "bootchart.h"
+#include "util.h"
+#include "macro.h"
 
 
 #define time_to_graph(t) ((t) * scale_x)
@@ -85,10 +97,10 @@ static void svg_header(void)
 
         /* write some basic info as a comment, including some help */
         svg("<!-- This file is a bootchart SVG file. It is best rendered in a browser -->\n");
-        svg("<!-- such as Chrome/Chromium, firefox. Other applications that render    -->\n");
-        svg("<!-- these files properly but much more slow are ImageMagick, gimp,      -->\n");
-        svg("<!-- inkscape, etc.. To display the files on your system, just point     -->\n");
-        svg("<!-- your browser to file:///var/log/ and click. This bootchart was      -->\n\n");
+        svg("<!-- such as Chrome, Chromium, or Firefox. Other applications that       -->\n");
+        svg("<!-- render these files properly but more slowly are ImageMagick, gimp,  -->\n");
+        svg("<!-- inkscape, etc. To display the files on your system, just point      -->\n");
+        svg("<!-- your browser to file:///run/log/ and click. This bootchart was      -->\n\n");
 
         svg("<!-- generated by bootchart version %s, running with options:  -->\n", VERSION);
         svg("<!-- hz=\"%f\" n=\"%d\" -->\n", hz, len);
@@ -128,7 +140,7 @@ static void svg_header(void)
 }
 
 
-static void svg_title(void)
+static void svg_title(const char *build)
 {
         char cmdline[256] = "";
         char filename[PATH_MAX];
@@ -137,14 +149,15 @@ static void svg_title(void)
         char model[256] = "Unknown";
         char date[256] = "Unknown";
         char cpu[256] = "Unknown";
-        char build[256] = "Unknown";
         char *c;
         FILE *f;
         time_t t;
+        int fd;
         struct utsname uts;
 
         /* grab /proc/cmdline */
-        f = fopen("/proc/cmdline", "r");
+        fd = openat(procfd, "cmdline", O_RDONLY);
+        f = fdopen(fd, "r");
         if (f) {
                 if (!fgets(cmdline, 255, f))
                         sprintf(cmdline, "Unknown");
@@ -157,8 +170,9 @@ static void svg_title(void)
                 strncpy(rootbdev, &c[10], 3);
                 rootbdev[3] = '\0';
         }
-        sprintf(filename, "/sys/block/%s/device/model", rootbdev);
-        f = fopen(filename, "r");
+        sprintf(filename, "block/%s/device/model", rootbdev);
+        fd = openat(sysfd, filename, O_RDONLY);
+        f = fdopen(fd, "r");
         if (f) {
                 if (!fgets(model, 255, f))
                         fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
@@ -174,7 +188,8 @@ static void svg_title(void)
         strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
 
         /* CPU type */
-        f = fopen("/proc/cpuinfo", "r");
+        fd = openat(procfd, "cpuinfo", O_RDONLY);
+        f = fdopen(fd, "r");
         if (f) {
                 while (fgets(buf, 255, f)) {
                         if (strstr(buf, "model name")) {
@@ -185,14 +200,6 @@ static void svg_title(void)
                 fclose(f);
         }
 
-        /* Build - 1st line from /etc/system-release */
-        f = fopen("/etc/system-release", "r");
-        if (f) {
-                if (fgets(buf, 255, f))
-                        strncpy(build, buf, 255);
-                fclose(f);
-        }
-
         svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
             uts.nodename, date);
         svg("<text class=\"t2\" x=\"20\" y=\"50\">System: %s %s %s %s</text>\n",
@@ -702,7 +709,7 @@ static int ps_filter(struct ps_struct *ps)
 
 static void svg_do_initcall(int count_only)
 {
-        FILE *f;
+        FILE _cleanup_pclose_ *f = NULL;
         double t;
         char func[256];
         int ret;
@@ -787,8 +794,6 @@ static void svg_do_initcall(int count_only)
 
                 kcount++;
         }
-
-        fclose(f);
 }
 
 
@@ -1039,7 +1044,7 @@ static void svg_top_ten_pss(void)
 }
 
 
-void svg_do(void)
+void svg_do(const char *build)
 {
         struct ps_struct *ps;
 
@@ -1092,7 +1097,7 @@ void svg_do(void)
         svg("</g>\n\n");
 
         svg("<g transform=\"translate(10,  0)\">\n");
-        svg_title();
+        svg_title(build);
         svg("</g>\n\n");
 
         svg("<g transform=\"translate(10,200)\">\n");