sistemato sigint e liberato il sigalarm
This commit is contained in:
parent
f89c162652
commit
b75279c7fa
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <time.h>
|
||||||
#include <sys/msg.h>
|
#include <sys/msg.h>
|
||||||
#include <sys/sem.h>
|
#include <sys/sem.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
|
@ -19,20 +20,15 @@ pid_t _PIDS[2];
|
||||||
|
|
||||||
void setServerSignal(int sig);
|
void setServerSignal(int sig);
|
||||||
|
|
||||||
void sigIntHandler2(int sig) {
|
|
||||||
raise(SIGTERM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sigHandlerServer(int sig) {
|
void sigHandlerServer(int sig) {
|
||||||
if (sig == SIGINT) {
|
if (sig == SIGINT) {
|
||||||
printf("\n" PSERVER "Press again Ctrl^C to exit (within %d sec)\n", TIME_TO_RESET);
|
static int last_sigint = 0;
|
||||||
signal(SIGINT, sigIntHandler2);
|
if (time(0) - last_sigint >= TIME_TO_RESET) {
|
||||||
alarm(TIME_TO_RESET);
|
printf("\n" PSERVER "Press again Ctrl^C to exit (within %d sec)\n", TIME_TO_RESET);
|
||||||
}
|
last_sigint = time(0);
|
||||||
|
} else {
|
||||||
if (sig == SIGALRM) {
|
raise(SIGTERM);
|
||||||
printf(PSERVER "Time to exit (%d sec) expired\n", TIME_TO_RESET);
|
}
|
||||||
signal(SIGINT, sigHandlerServer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// abbandono di un giocatore
|
// abbandono di un giocatore
|
||||||
|
@ -65,7 +61,7 @@ void sigHandlerServer(int sig) {
|
||||||
// msgq
|
// msgq
|
||||||
if (_MSGQID) {
|
if (_MSGQID) {
|
||||||
printf(PSERVER "Deleting msg\n");
|
printf(PSERVER "Deleting msg\n");
|
||||||
if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) { //TODO: funzioni
|
if (msgctl(_MSGQID, IPC_RMID, NULL) == -1) {
|
||||||
errExit("msgctl", "sigHandlerServer");
|
errExit("msgctl", "sigHandlerServer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue