From c5ff2059f619ac91c14d55412314d1c67de6a593 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 17 Jul 2015 14:55:15 +0200 Subject: 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//exe, thus move that functionality to an own function. Signed-off-by: Tobias Klauser --- flowtop.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'flowtop.c') diff --git a/flowtop.c b/flowtop.c index 7fd9055..a522daf 100644 --- a/flowtop.c +++ b/flowtop.c @@ -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; } -- cgit v1.2.3-54-g00ecf