From 15ab8f44d0be82c14cdc7074448ed2949e151f04 Mon Sep 17 00:00:00 2001 From: elvis Date: Thu, 5 May 2022 21:12:44 +0200 Subject: [PATCH] perror for client.c --- src/client.c | 56 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/client.c b/src/client.c index 0a5dfe1..9080931 100644 --- a/src/client.c +++ b/src/client.c @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) { memset(&siga, 0, sizeof(siga)); siga.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &siga, NULL) == -1) { - perror("sigaction.\n"); + perror("main: sigaction"); return 1; } @@ -194,12 +194,12 @@ int main(int argc, char* argv[]) { } if(reorderCommandList(&cmds) < 0) { - perror("reorder"); + perror("main: reorderCommandList"); goto _cleanup; } if(execute(cmds, print) < 0) { - perror("execute"); + perror("main: execute"); goto _cleanup; } @@ -243,7 +243,7 @@ int addCommand(cmd_t **l, char cmd, char *arg) { cmd_t *new = calloc(1, sizeof(cmd_t)); if(!new) { - perror("calloc"); + perror("addCommand: calloc"); return -1; } new->name = cmd; @@ -251,7 +251,7 @@ int addCommand(cmd_t **l, char cmd, char *arg) { if (arg) { new->arg = malloc(MAXARGLENGTH); if (new->arg == NULL) { - perror("malloc arg"); + perror("addCommand: malloc"); free(new); return -1; } @@ -314,7 +314,7 @@ int reorderCommandList(cmd_t **l) { if(tmp->next->name == 'r' || tmp->next->name == 'R') { cmd_t *new = calloc(1, sizeof(*new)); if(!new){ - perror("calloc new"); + perror("reorderCommandList: case d, calloc"); return -1; } @@ -323,7 +323,7 @@ int reorderCommandList(cmd_t **l) { new->arg = malloc(MAXARGLENGTH); if (new->arg == NULL) { - perror("malloc arg"); + perror("reorderCommandList: case d, malloc"); free(new); return -1; } @@ -357,7 +357,7 @@ int reorderCommandList(cmd_t **l) { if(tmp->next->name == 'w' || tmp->next->name == 'W') { cmd_t *new = calloc(1, sizeof(*new)); if(!new){ - perror("calloc new"); + perror("reorderCommandList: case D, calloc"); return -1; } @@ -366,7 +366,7 @@ int reorderCommandList(cmd_t **l) { new->arg = malloc(MAXARGLENGTH); if (new->arg == NULL) { - perror("malloc arg"); + perror("reorderCommandList: case D, malloc"); free(new); return -1; } @@ -404,7 +404,7 @@ int execute(cmd_t *l, int print) { long num; num = strtol(tmp->arg, NULL, 10); if(num==0 && errno==EINVAL) { - perror("Invalid time specified after -t"); + fprintf(stderr, "t - Tempo non riconosciuto dopo l'opzione -t\n"); return -1; } // milliseconds to nanoseconds @@ -436,15 +436,15 @@ int execute(cmd_t *l, int print) { strncpy(globalSocket, tmp->arg, strnlen(tmp->arg, MAXARGLENGTH)+1); if(cmd_f(tmp->arg) != 0) { if (print) - perror("-f"); + perror("execute: -f"); ok = 0; } if (print) { - fprintf(stdout, "f - Connessione al socket: %s\tEsito: ", globalSocket); + fprintf(stdout, "f - Connessione al socket: %s [Esito: ", globalSocket); if(ok) - printf("ok\n"); + printf("ok]\n"); if(!ok) - printf("errore\n"); + printf("errore]\n"); } if(!ok) { closeConnection(tmp->arg); @@ -531,7 +531,7 @@ int execute(cmd_t *l, int print) { if (setDirectory(Dir, 1) == -1) { if(print) - perror("-D"); + perror("execute: -D"); } if (print) printf("D - Cartella per le scritture: %s [Esito: ok]\n", Dir); @@ -550,7 +550,7 @@ int execute(cmd_t *l, int print) { if(setDirectory(dir, 0) == -1) { if(print) - perror("-d"); + perror("execute: -d"); } if(print) printf("d - Cartella per le letture: %s [Esito: ok]\n", dir); @@ -588,7 +588,7 @@ int execute(cmd_t *l, int print) { // ----------------------------------------------------------------------------- -// funzioni relative ai comandi +// commands // -f int cmd_f(char *socket) { @@ -618,7 +618,7 @@ int cmd_w(char *dirname, char *Dir, int print) { // copy dirname because we modify it after char *tofree = calloc(strnlen(dirname, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("malloc"); + perror("cmd_w: calloc"); return -1; } strncpy(tofree, dirname, strnlen(dirname, MAXARGLENGTH)); @@ -713,7 +713,7 @@ int cmd_W(char *filelist, char *Dir, int print) { // we copy filelist because we modify it later char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1); if(!tofree) { - perror("malloc"); + perror("cmd_W: malloc"); return -1; } memset(tofree, 0, strnlen(filelist, MAXARGLENGTH)+1); @@ -782,11 +782,11 @@ int cmd_r(char *filelist, char *dir, int print) { // we copy filelist because we modify it later char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1); - memset(tofree, 0, strnlen(filelist, MAXARGLENGTH)+1); if(!tofree) { - perror("malloc"); + perror("cmd_r: malloc"); return -1; } + memset(tofree, 0, strnlen(filelist, MAXARGLENGTH)+1); strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)); char *token = NULL; @@ -914,7 +914,7 @@ int cmd_l(char *filelist, int print) { // we copy filelist because we modify it later char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("malloc"); + perror("cmd_l: malloc"); return -1; } strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)); @@ -937,7 +937,7 @@ int cmd_l(char *filelist, int print) { if (print != 0) { printf("errore]\n"); fflush(stdout); - perror("-l"); + perror("cmd_l: lockFile"); } } else if(print != 0) { printf("ok]\n"); @@ -958,7 +958,7 @@ int cmd_u(char *filelist, int print) { // we copy filelist because we modify it later char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("calloc"); + perror("cmd_u: calloc"); return -1; } strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)); @@ -981,7 +981,7 @@ int cmd_u(char *filelist, int print) { if (print != 0) { printf("errore]\n"); fflush(stdout); - perror("-u"); + perror("cmd_u: unlockFile"); } } else if(print != 0) { printf("ok]\n"); @@ -1002,7 +1002,7 @@ int cmd_c(char *filelist, int print) { // we copy filelist because we modify it later char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("calloc"); + perror("cmd_c: calloc"); return -1; } strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)); @@ -1025,14 +1025,14 @@ int cmd_c(char *filelist, int print) { if (print) { printf("errore]\n"); fflush(stdout); - perror("-c"); + perror("cmd_c: lockFile"); } } else { if (removeFile(token) == -1) { if (print) { printf("errore]\n"); fflush(stdout); - perror("-c"); + perror("cmd_c: removeFile"); } } else if (print) { printf("ok]\n");