diff --git a/src/custom_sig.c b/src/custom_sig.c index af67ba1..5f2dfab 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -19,20 +20,15 @@ pid_t _PIDS[2]; void setServerSignal(int sig); -void sigIntHandler2(int sig) { - raise(SIGTERM); -} - void sigHandlerServer(int sig) { if (sig == SIGINT) { - printf("\n" PSERVER "Press again Ctrl^C to exit (within %d sec)\n", TIME_TO_RESET); - signal(SIGINT, sigIntHandler2); - alarm(TIME_TO_RESET); - } - - if (sig == SIGALRM) { - printf(PSERVER "Time to exit (%d sec) expired\n", TIME_TO_RESET); - signal(SIGINT, sigHandlerServer); + static int last_sigint = 0; + if (time(0) - last_sigint >= TIME_TO_RESET) { + printf("\n" PSERVER "Press again Ctrl^C to exit (within %d sec)\n", TIME_TO_RESET); + last_sigint = time(0); + } else { + raise(SIGTERM); + } } // abbandono di un giocatore @@ -65,7 +61,7 @@ void sigHandlerServer(int sig) { // msgq if (_MSGQID) { printf(PSERVER "Deleting msg\n"); - if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) { //TODO: funzioni + if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) { errExit("msgctl", "sigHandlerServer"); } }