summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordatenwolf <@datenwolf.net>2022-01-18 01:04:49 +0100
committerdatenwolf <@datenwolf.net>2022-01-18 01:04:49 +0100
commit33143b31800f3bfaaaea2ae857af9f01cd03fcf9 (patch)
treed6948ad013fa93615446b8df0baf1879cdd6001a
parent4060a0e9dad36565ae4f082d748d6a46234e8423 (diff)
downloadpmon-main.tar.gz
pmon-main.tar.bz2
deal with empty cmdline properlymain
-rw-r--r--pmon.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/pmon.c b/pmon.c
index b7a5efa..f693550 100644
--- a/pmon.c
+++ b/pmon.c
@@ -19,10 +19,12 @@ static char* pid_cmdline(pid_t const pid)
snprintf(path, sizeof(path)-1, "/proc/%lu/cmdline", (long unsigned)pid);
FILE *fil = fopen(path, "r");
if( !fil ){ return NULL; }
- size_t cmdlen = 0;
+ size_t cmdbuflen = 0;
char *cmdline = NULL;
- getline(&cmdline, &cmdlen, fil);
+ ssize_t const cmdlen = getline(&cmdline, &cmdbuflen, fil);
+ fprintf(stderr, "cmdlen=%lu\n", (long unsigned)cmdlen);
fclose(fil);
+ if( !cmdbuflen || 0 >= cmdlen ){ free(cmdline); cmdline = NULL; }
return cmdline;
}
@@ -121,11 +123,13 @@ static int handle_proc_ev(int nl_sock)
printf("set mcast listen ok\n");
break;
case PROC_EVENT_FORK:
- printf("fork: parent tid=%d pid=%d -> child tid=%d pid=%d\n",
- nlcn_msg.proc_ev.event_data.fork.parent_pid,
- nlcn_msg.proc_ev.event_data.fork.parent_tgid,
- nlcn_msg.proc_ev.event_data.fork.child_pid,
- nlcn_msg.proc_ev.event_data.fork.child_tgid);
+ cmdline = pid_cmdline(nlcn_msg.proc_ev.event_data.fork.parent_pid);
+ printf("fork: parent tid=%d pid=%d cmd='%s' -> child tid=%d pid=%d\n",
+ (int)nlcn_msg.proc_ev.event_data.fork.parent_pid,
+ (int)nlcn_msg.proc_ev.event_data.fork.parent_tgid,
+ cmdline,
+ (int)nlcn_msg.proc_ev.event_data.fork.child_pid,
+ (int)nlcn_msg.proc_ev.event_data.fork.child_tgid);
break;
case PROC_EVENT_EXEC:
cmdline = pid_cmdline(nlcn_msg.proc_ev.event_data.exec.process_pid);