diff options
Diffstat (limited to 'pmon.c')
-rw-r--r-- | pmon.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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); |