From 1c3ec2c102b62112383986195fcce3ddb3ea2bbc Mon Sep 17 00:00:00 2001 From: lomna-dev Date: Sun, 4 Jun 2023 22:04:53 +0530 Subject: [PATCH] Better Logging For Commands Better messages for the commands --- src/tasks.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/tasks.c b/src/tasks.c index dbba48c..e88d733 100644 --- a/src/tasks.c +++ b/src/tasks.c @@ -226,7 +226,15 @@ void TASKS_do_all_tasks(){ while(cll != NULL){ char *cmd = cll->data; printf("+ %s\n", cmd); - system(cmd); + int r_code = system(cmd); + + if(errno != 0 && r_code == -1) + perror(cmd); + + if(r_code != EXIT_SUCCESS) + printf("[✗] FAILED COMMAND : %s\n[✗] C system() function return value : %d\n", cmd, r_code); + else + printf("[✔] COMPLETED COMMAND : %s\n[✔] C system() function return value : %d\n", cmd, r_code); cll = cll->next; } printf("\n"); @@ -265,7 +273,7 @@ void TASKS_do_tasks_ifchange(char *filename){ icll = icll->next; } - if(map == NULL) skip_task = false; + if(map == NULL || tasks[i].ifchange == NULL) skip_task = false; if(skip_task) continue; printf("[*] EXECUTING TASK : %s\n", tasks[i].name); @@ -273,13 +281,24 @@ void TASKS_do_tasks_ifchange(char *filename){ while(cll != NULL){ char *cmd = cll->data; printf("+ %s\n", cmd); - system(cmd); + int r_code = system(cmd); + + // Don't know if this is cross platform, but according to Linux man-pages 6.03 + // If a child process could not be created, or its status could not be retrieved, the return value is -1 and errno is set to indicate the error. + if(errno != 0 && r_code == -1) + perror(cmd); + + if(r_code != EXIT_SUCCESS) + printf("[✗] FAILED COMMAND : %s\n[✗] C system() function return value : %d\n", cmd, r_code); + else + printf("[✔] COMPLETED COMMAND : %s\n[✔] C system() function return value : %d\n", cmd, r_code); cll = cll->next; } printf("\n"); } if(new_map != NULL){ + printf("\n<-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <-> <->\n"); printf("\nSaving file named %s with sha1 values\n", binary_filename); LookupList_print(new_map); LookupList_store(new_map, binary_filename); @@ -291,6 +310,7 @@ void TASKS_do_tasks_ifchange(char *filename){ } int main(int argc, char *argv[]){ + errno = 0; char *tasks_file = "main.tsk"; if(argc > 1){