X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbootchart%2Fbootchart.c;h=7affacfdbfebb01e685d1584ec18a464a75bc627;hb=e93450c6c053d7499971a2b1310e893978f67f74;hp=6b9252dbb982043de65983ce76c85e369b9519a5;hpb=8d6167101696a28b7ac61b48fd2c1920564c4e90;p=elogind.git diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 6b9252dbb..7affacfdb 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -32,10 +33,12 @@ #include #include #include +#include #include "bootchart.h" #include "util.h" +#include "fileio.h" double graph_start; double log_start; @@ -47,9 +50,10 @@ struct cpu_stat_struct cpustat[MAXCPUS]; int pscount; int cpus; double interval; -FILE *of; +FILE *of = NULL; int overrun = 0; static int exiting = 0; +int sysfd=-1; /* graph defaults */ int entropy = 0; @@ -64,7 +68,7 @@ double scale_x = 100.0; /* 100px = 1sec */ double scale_y = 20.0; /* 16px = 1 process bar */ char init_path[PATH_MAX] = "/sbin/init"; -char output_path[PATH_MAX] = "/var/log"; +char output_path[PATH_MAX] = "/run/log"; static struct rlimit rlim; @@ -78,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]; @@ -235,6 +240,7 @@ int main(int argc, char *argv[]) execl(init_path, init_path, NULL); } } + argv[0][0] = '@'; /* start with empty ps LL */ ps_first = calloc(1, sizeof(struct ps_struct)); @@ -264,6 +270,23 @@ int main(int argc, char *argv[]) sampletime[samples] = gettime_ns(); + if (!of && (access(output_path, R_OK|W_OK|X_OK) == 0)) { + t = time(NULL); + strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); + snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + of = fopen(output_file, "w"); + } + + if (sysfd < 0) { + 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(); @@ -321,23 +344,27 @@ int main(int argc, char *argv[]) if (ps->smaps) fclose(ps->smaps); } - closedir(proc); - t = time(NULL); - strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); - snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + if (!of) { + t = time(NULL); + strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); + snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + of = fopen(output_file, "w"); + } - of = fopen(output_file, "w"); if (!of) { perror("open output_file"); exit (EXIT_FAILURE); } - svg_do(); + svg_do(build); fprintf(stderr, "bootchartd: Wrote %s\n", output_file); fclose(of); + closedir(proc); + close(sysfd); + /* nitpic cleanups */ ps = ps_first; while (ps->next_ps) {