+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
/***
- log.c - This file is part of systemd-bootchart
+ This file is part of systemd.
Copyright (C) 2009-2013 Intel Coproration
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#define _GNU_SOURCE 1
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <fcntl.h>
#include <time.h>
-
-#include "bootchart.h"
#include "util.h"
+#include "strxcpyx.h"
+#include "store.h"
+#include "bootchart.h"
/*
* Alloc a static 4k buffer for stdio - primarily used to increase
*/
static char smaps_buf[4096];
DIR *proc;
-int procfd=-1;
+int procfd = -1;
-double gettime_ns(void)
-{
+double gettime_ns(void) {
struct timespec n;
clock_gettime(CLOCK_MONOTONIC, &n);
return (n.tv_sec + (n.tv_nsec / 1000000000.0));
}
-
-void log_uptime(void)
-{
- FILE _cleanup_fclose_ *f = NULL;
+void log_uptime(void) {
+ _cleanup_fclose_ FILE *f = NULL;
char str[32];
double uptime;
log_start = gettime_ns();
/* start graph at kernel boot time */
- if (relative)
+ if (arg_relative)
graph_start = log_start;
else
graph_start = log_start - uptime;
}
-
-static char *bufgetline(char *buf)
-{
+static char *bufgetline(char *buf) {
char *c;
if (!buf)
return c;
}
-static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) {
- char filename[PATH_MAX];
- int _cleanup_close_ fd=-1;
- ssize_t n;
+static int pid_cmdline_strscpy(char *buffer, size_t buf_len, int pid) {
+ char filename[PATH_MAX];
+ _cleanup_close_ int fd=-1;
+ ssize_t n;
- sprintf(filename, "%d/cmdline", pid);
- fd = openat(procfd, filename, O_RDONLY);
- if (fd < 0)
- return -errno;
+ sprintf(filename, "%d/cmdline", pid);
+ fd = openat(procfd, filename, O_RDONLY);
+ if (fd < 0)
+ return -errno;
- n = read(fd, buffer, buf_len-1);
+ n = read(fd, buffer, buf_len-1);
if (n > 0) {
int i;
for (i = 0; i < n; i++)
buffer[i] = ' ';
buffer[n] = '\0';
}
- return 0;
+ return 0;
}
-void log_sample(int sample)
-{
+void log_sample(int sample) {
static int vmstat;
static int schedstat;
- char buf[4095];
+ char buf[4096];
char key[256];
char val[256];
char rt[256];
break;
}
- if (entropy) {
+ if (arg_entropy) {
if (!e_fd) {
e_fd = openat(procfd, "sys/kernel/random/entropy_avail", O_RDONLY);
}
/* end of our LL? then append a new record */
if (ps->pid != pid) {
- FILE _cleanup_fclose_ *st = NULL;
+ _cleanup_fclose_ FILE *st = NULL;
char t[32];
struct ps_struct *parent;
ps = ps->next_ps;
ps->pid = pid;
- ps->sample = calloc(samples_len + 1, sizeof(struct ps_sched_struct));
+ ps->sample = calloc(arg_samples_len + 1, sizeof(struct ps_sched_struct));
if (!ps->sample) {
perror("calloc(ps_struct)");
exit (EXIT_FAILURE);
if (!sscanf(buf, "%s %*s %*s", key))
continue;
- strncpy(ps->name, key, 256);
+ strscpy(ps->name, sizeof(ps->name), key);
/* cmdline */
- if (show_cmdline)
- pid_cmdline_strncpy(ps->name, pid, 256);
+ if (arg_show_cmdline)
+ pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid);
/* discard line 2 */
m = bufgetline(buf);
- ps->sample[ps->first].runtime)
/ 1000000000.0;
- if (!pss)
+ if (!arg_pss)
goto catch_rename;
/* Pss */
if (!ps->smaps) {
catch_rename:
/* catch process rename, try to randomize time */
- mod = (hz < 4.0) ? 4.0 : (hz / 4.0);
+ mod = (arg_hz < 4.0) ? 4.0 : (arg_hz / 4.0);
if (((samples - ps->first) + pid) % (int)(mod) == 0) {
/* re-fetch name */
if (!sscanf(buf, "%s %*s %*s", key))
continue;
- strncpy(ps->name, key, 256);
+ strscpy(ps->name, sizeof(ps->name), key);
/* cmdline */
- if (show_cmdline)
- pid_cmdline_strncpy(ps->name, pid, 256);
+ if (arg_show_cmdline)
+ pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid);
}
}
}