From 2f5dcd9be4c9f23bf8029371216b4e7e7902fb62 Mon Sep 17 00:00:00 2001 From: Gineus <41481916+Gineus@users.noreply.github.com> Date: Mon, 3 Mar 2025 20:53:14 +0000 Subject: [PATCH] Implemented all TODO --- examples/systemcalls/systemcalls.c | 140 ++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 34 deletions(-) diff --git a/examples/systemcalls/systemcalls.c b/examples/systemcalls/systemcalls.c index 6793970..f7bbc3e 100644 --- a/examples/systemcalls/systemcalls.c +++ b/examples/systemcalls/systemcalls.c @@ -1,4 +1,12 @@ #include "systemcalls.h" +#include // for errno +#include // for system() +#include // for fprintf() +#include // for syslog() +#include // for fork(), execv() +#include // for wait() +#include // for strerror +#include // for O_WRONLY, O_TRUNC, O_CREAT /** * @param cmd the command to execute with system() @@ -9,13 +17,13 @@ */ bool do_system(const char *cmd) { + const int result = system(cmd); -/* - * TODO add your code here - * Call the system() function with the command set in the cmd - * and return a boolean true if the system() call completed with success - * or false() if it returned a failure -*/ + if (result != 0) + { + syslog(LOG_ERR, "Command '%s' failed with return code %d", cmd, result); + return false; + } return true; } @@ -38,30 +46,51 @@ bool do_exec(int count, ...) { va_list args; va_start(args, count); - char * command[count+1]; + char *command[count + 1]; int i; - for(i=0; i