[systemd-commits] 2 commits - src/bootchart
Auke-Jan Kok
auke at kemper.freedesktop.org
Thu Feb 14 12:00:41 PST 2013
src/bootchart/bootchart.c | 19 +++++++++++++++++--
src/bootchart/bootchart.h | 4 +++-
src/bootchart/svg.c | 29 +++++++++++++----------------
3 files changed, 33 insertions(+), 19 deletions(-)
New commits:
commit e93450c6c053d7499971a2b1310e893978f67f74
Author: Harald Hoyer <harald at redhat.com>
Date: Thu Feb 14 11:26:07 2013 +0100
bootchart: parse /etc/os-release rather than system-release
Also parse it early, so that we can get it in the initramfs.
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index e34c08a..7affacf 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -82,6 +82,7 @@ static void signal_handler(int sig)
int main(int argc, char *argv[])
{
+ _cleanup_free_ char *build = NULL;
struct sigaction sig;
struct ps_struct *ps;
char output_file[PATH_MAX];
@@ -280,6 +281,12 @@ int main(int argc, char *argv[])
sysfd = open("/sys", O_RDONLY);
}
+ if (!build) {
+ parse_env_file("/etc/os-release", NEWLINE,
+ "PRETTY_NAME", &build,
+ NULL);
+ }
+
/* wait for /proc to become available, discarding samples */
if (!(graph_start > 0.0))
log_uptime();
@@ -350,7 +357,7 @@ int main(int argc, char *argv[])
exit (EXIT_FAILURE);
}
- svg_do();
+ svg_do(build);
fprintf(stderr, "bootchartd: Wrote %s\n", output_file);
fclose(of);
diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h
index 6b11fd8..84e9420 100644
--- a/src/bootchart/bootchart.h
+++ b/src/bootchart/bootchart.h
@@ -124,4 +124,4 @@ extern double gettime_ns(void);
extern void log_uptime(void);
extern void log_sample(int sample);
-extern void svg_do(void);
+extern void svg_do(const char *build);
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index dc55cb3..414d7af 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -140,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];
@@ -149,7 +149,6 @@ 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;
@@ -201,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",
@@ -1053,7 +1044,7 @@ static void svg_top_ten_pss(void)
}
-void svg_do(void)
+void svg_do(const char *build)
{
struct ps_struct *ps;
@@ -1106,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");
commit b823b5e272d07d31c12625a268e8d563289a4db5
Author: Harald Hoyer <harald at redhat.com>
Date: Thu Feb 14 11:26:05 2013 +0100
bootchart: more fixes for bootchart in the initramfs
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index adfaba5..e34c08a 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -23,6 +23,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
@@ -32,6 +33,7 @@
#include <getopt.h>
#include <limits.h>
#include <errno.h>
+#include <fcntl.h>
#include "bootchart.h"
@@ -51,6 +53,7 @@ double interval;
FILE *of = NULL;
int overrun = 0;
static int exiting = 0;
+int sysfd=-1;
/* graph defaults */
int entropy = 0;
@@ -273,6 +276,9 @@ int main(int argc, char *argv[])
of = fopen(output_file, "w");
}
+ if (sysfd < 0) {
+ sysfd = open("/sys", O_RDONLY);
+ }
/* wait for /proc to become available, discarding samples */
if (!(graph_start > 0.0))
@@ -331,7 +337,6 @@ int main(int argc, char *argv[])
if (ps->smaps)
fclose(ps->smaps);
}
- closedir(proc);
if (!of) {
t = time(NULL);
@@ -350,6 +355,9 @@ int main(int argc, char *argv[])
fprintf(stderr, "bootchartd: Wrote %s\n", output_file);
fclose(of);
+ closedir(proc);
+ close(sysfd);
+
/* nitpic cleanups */
ps = ps_first;
while (ps->next_ps) {
diff --git a/src/bootchart/bootchart.h b/src/bootchart/bootchart.h
index 7793cfc..6b11fd8 100644
--- a/src/bootchart/bootchart.h
+++ b/src/bootchart/bootchart.h
@@ -117,6 +117,8 @@ extern char init_path[PATH_MAX];
extern FILE *of;
extern DIR *proc;
+extern int procfd;
+extern int sysfd;
extern double gettime_ns(void);
extern void log_uptime(void);
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index 6ad7348..dc55cb3 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -28,6 +28,8 @@
#include <limits.h>
#include <unistd.h>
#include <sys/utsname.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "bootchart.h"
#include "util.h"
@@ -151,10 +153,12 @@ static void svg_title(void)
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");
@@ -167,8 +171,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);
@@ -184,7 +189,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")) {
More information about the systemd-commits
mailing list