30 lines
776 B
C
30 lines
776 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <../inc/custom_signal.h>
|
|
|
|
void serverSigHandler(int sig) {
|
|
static int sigint_count = DEFAULT_SIGINT;
|
|
|
|
switch (sig) {
|
|
case SIGINT:
|
|
sigint_count--;
|
|
if (sigint_count > 0) {
|
|
printf("<Server> Press again Ctrl^C to exit (whitin %d sec)\n", TIME_TO_RESET);
|
|
alarm(TIME_TO_RESET);
|
|
} else {
|
|
// TODO bisogna fare un "at exit"
|
|
exit(0);
|
|
}
|
|
break;
|
|
default: //SIGALRM
|
|
printf("<Server> Time to exit (%d sec) expired\n", TIME_TO_RESET);
|
|
sigint_count = DEFAULT_SIGINT;
|
|
break;
|
|
}
|
|
}
|
|
|
|
void setServerSignalHandler() {
|
|
signal(SIGINT, serverSigHandler);
|
|
signal(SIGALRM, serverSigHandler);
|
|
} |