forked from DIKUNIX/dikumud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signals.c
85 lines (60 loc) · 1.61 KB
/
signals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************
* file: signals.c , trapping of signals from Unix. Part of DIKUMUD *
* Usage : Signal Trapping. *
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
************************************************************************* */
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>
#include "utils.h"
int checkpointing(void);
int shutdown_request(void);
int logsig(void);
int hupsig(void);
void signal_setup(void)
{
struct itimerval itime;
struct timeval interval;
signal(SIGUSR2, shutdown_request);
/* just to be on the safe side: */
signal(SIGHUP, hupsig);
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, hupsig);
signal(SIGALRM, logsig);
signal(SIGTERM, hupsig);
/* set up the deadlock-protection */
interval.tv_sec = 900; /* 15 minutes */
interval.tv_usec = 0;
itime.it_interval = interval;
itime.it_value = interval;
setitimer(ITIMER_VIRTUAL, &itime, 0);
signal(SIGVTALRM, checkpointing);
}
int checkpointing(void)
{
extern int tics;
if (!tics)
{
log_message("CHECKPOINT shutdown: tics not updated");
abort();
}
else
tics = 0;
}
int shutdown_request(void)
{
extern int clean_shutdown;
log_message("Received USR2 - shutdown request");
clean_shutdown = 1;
}
/* kick out players etc */
int hupsig(void)
{
extern int clean_shutdown;
log_message("Received SIGHUP, SIGINT, or SIGTERM. Shutting down");
exit(0); /* something more elegant should perhaps be substituted */
}
int logsig(void)
{
log_message("Signal received. Ignoring.");
}