Elaborato_SO/src/custom_signal.c

32 lines
850 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <custom_signal.h>
#include <structures.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);
}