diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-07-17 14:55:15 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-07-17 14:55:15 +0200 |
commit | c5ff2059f619ac91c14d55412314d1c67de6a593 (patch) | |
tree | 18c324c5d2bbbe9a913ae693ff75b109d050a1e5 /flowtop.c | |
parent | 5d6d5f85d8ed49698eb3d790308e05a50b784c54 (diff) |
flowtop, netsniff-ng: Move process name extraction to own function
flowtop and the netsniff-ng's netlink message dissector both need to get
the process name for a pid from /proc/<pid>/exe, thus move that
functionality to an own function.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'flowtop.c')
-rw-r--r-- | flowtop.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -38,6 +38,7 @@ #include "locking.h" #include "pkt_buff.h" #include "screen.h" +#include "proc.h" struct flow_entry { uint32_t flow_id, use, status; @@ -474,14 +475,9 @@ static int walk_process(unsigned int pid, struct flow_entry *n) continue; if (S_ISSOCK(statbuf.st_mode) && (ino_t) n->inode == statbuf.st_ino) { - memset(n->cmdline, 0, sizeof(n->cmdline)); - - snprintf(path, sizeof(path), "/proc/%u/exe", pid); - - ret = readlink(path, n->cmdline, - sizeof(n->cmdline) - 1); + ret = proc_get_cmdline(pid, n->cmdline, sizeof(n->cmdline)); if (ret < 0) - panic("readlink error: %s\n", strerror(errno)); + panic("Failed to get process cmdline: %s\n", strerror(errno)); n->procnum = pid; closedir(dir); @@ -501,7 +497,7 @@ static void walk_processes(struct flow_entry *n) /* n->inode must be set */ if (n->inode <= 0) { - memset(n->cmdline, 0, sizeof(n->cmdline)); + n->cmdline[0] = '\0'; return; } |