summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-10-23 14:39:48 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-10-23 14:44:06 +0200
commit98ea1cffdab73c69d69bf0f9a464bd0ef6e16dd3 (patch)
tree57842cf21ca46cda3307edd947db58f2814aa915
parentfea42c5091f45a8e6189614be50db88b029df7fc (diff)
flowtop: Store basename of cmdline in struct flow_entry
The cmdline entry of struct flow_entry is only used to display the process name using basename() in presenter_screen_do_line(). Instead of calling basename() everytime just call it once when we read the cmdline proc entry and store the basename in struct flow_entry. Also rename the struct member accordingly. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--flowtop.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/flowtop.c b/flowtop.c
index e2fd233..24de53f 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -59,7 +59,7 @@ struct flow_entry {
char country_src[128], country_dst[128];
char city_src[128], city_dst[128];
char rev_dns_src[256], rev_dns_dst[256];
- char cmdline[256];
+ char procname[256];
struct flow_entry *next;
int inode;
unsigned int procnum;
@@ -452,10 +452,14 @@ 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) {
- ret = proc_get_cmdline(pid, n->cmdline, sizeof(n->cmdline));
+ char cmdline[256];
+
+ ret = proc_get_cmdline(pid, cmdline, sizeof(cmdline));
if (ret < 0)
panic("Failed to get process cmdline: %s\n", strerror(errno));
+ if (snprintf(n->procname, sizeof(n->procname), "%s", basename(cmdline)) < 0)
+ n->procname[0] = '\0';
n->procnum = pid;
closedir(dir);
return 1;
@@ -474,7 +478,7 @@ static void walk_processes(struct flow_entry *n)
/* n->inode must be set */
if (n->inode <= 0) {
- n->cmdline[0] = '\0';
+ n->procname[0] = '\0';
return;
}
@@ -858,8 +862,7 @@ static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n,
/* PID, application name */
if (n->procnum > 0) {
- slprintf(tmp, sizeof(tmp), "%s(%d)", basename(n->cmdline),
- n->procnum);
+ slprintf(tmp, sizeof(tmp), "%s(%d)", n->procname, n->procnum);
printw("[");
attron(COLOR_PAIR(3));