From 61c4152cffa5ae3ed09e13a15bc86ccb07b59ea4 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 1 Apr 2018 17:54:12 -0500 Subject: [PATCH] fix kernel_log() and add error-checking execl requires a full path to the executable, and the arguments begin with argv[0], not argv[1]. --- src/utils.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/utils.c b/src/utils.c index eb7f873..9214db7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,22 +20,29 @@ void kernel_log(int mode) pid_t pid; int status; pid = fork(); + if(pid < 0) { + perror("fork"); + exit(1); + } if(pid == 0) { if(mode) { - execl("dmesg", "-E", NULL); + execl("/bin/dmesg", "/bin/dmesg", "-E", NULL); } else { - execl("dmesg", "-D", NULL); + execl("/bin/dmesg", "/bin/dmesg", "-D", NULL); } - - exit(0); + /* execl should not return */ + perror("execl"); + exit(1); } waitpid(pid, &status, 0); + if(!WIFEXITED(status) || WEXITSTATUS(status)) + exit(1); } char* trim(char* s)