#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>
#include <getopt.h>
#include <limits.h>
#include <errno.h>
+#include <fcntl.h>
#include "bootchart.h"
FILE *of = NULL;
int overrun = 0;
static int exiting = 0;
+int sysfd=-1;
/* graph defaults */
int entropy = 0;
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))
if (ps->smaps)
fclose(ps->smaps);
}
- closedir(proc);
if (!of) {
t = time(NULL);
fprintf(stderr, "bootchartd: Wrote %s\n", output_file);
fclose(of);
+ closedir(proc);
+ close(sysfd);
+
/* nitpic cleanups */
ps = ps_first;
while (ps->next_ps) {
#include <limits.h>
#include <unistd.h>
#include <sys/utsname.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "bootchart.h"
#include "util.h"
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");
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);
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")) {