sistemato sigint e liberato il sigalarm

This commit is contained in:
Edi De Candido 2023-06-14 17:54:14 +02:00
parent f89c162652
commit b75279c7fa
1 changed files with 9 additions and 13 deletions

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
@ -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");
}
}