summaryrefslogtreecommitdiff
path: root/src/bootchart/log.c
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2013-03-07 08:52:54 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-07 16:09:22 +0100
commite90f9fa4d1cab6f73fc502fe9ef705c1bb2912a0 (patch)
treeb51656f91da0c129aae7eecc3bd3463463ff984c /src/bootchart/log.c
parent650001c6f7532601a9e5f685c348dae9541352cf (diff)
bootchart: add parameter "-C" to expand process names to the full cmdline
Diffstat (limited to 'src/bootchart/log.c')
-rw-r--r--src/bootchart/log.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/bootchart/log.c b/src/bootchart/log.c
index cf6c3a73f6..1e3f4a9e8c 100644
--- a/src/bootchart/log.c
+++ b/src/bootchart/log.c
@@ -95,6 +95,26 @@ static char *bufgetline(char *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;
+
+ sprintf(filename, "%d/cmdline", pid);
+ fd = openat(procfd, filename, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+
+ n = read(fd, buffer, buf_len-1);
+ if (n > 0) {
+ int i;
+ for (i = 0; i < n; i++)
+ if (buffer[i] == '\0')
+ buffer[i] = ' ';
+ buffer[n] = '\0';
+ }
+ return 0;
+}
void log_sample(int sample)
{
@@ -273,7 +293,12 @@ schedstat_next:
if (!sscanf(buf, "%s %*s %*s", key))
continue;
- strncpy(ps->name, key, 16);
+ strncpy(ps->name, key, 256);
+
+ /* cmdline */
+ if (show_cmdline)
+ pid_cmdline_strncpy(ps->name, pid, 256);
+
/* discard line 2 */
m = bufgetline(buf);
if (!m)
@@ -433,7 +458,11 @@ catch_rename:
if (!sscanf(buf, "%s %*s %*s", key))
continue;
- strncpy(ps->name, key, 16);
+ strncpy(ps->name, key, 256);
+
+ /* cmdline */
+ if (show_cmdline)
+ pid_cmdline_strncpy(ps->name, pid, 256);
}
}
}