]>
jfr.im git - irc/quakenet/newserv.git/blob - core/main.c
1 #include "../lib/sstring.h"
2 #include "../lib/valgrind.h"
17 #include <sys/types.h>
25 void siginthandler(int sig
);
26 void sigusr1handler(int sig
);
27 void sigsegvhandler(int sig
);
28 void sighuphandler(int sig
);
29 void handlecore(void);
30 void handlesignals(void);
32 int newserv_shutdown_pending
;
33 static int newserv_sigint_pending
, newserv_sigusr1_pending
, newserv_sighup_pending
;
34 static void (*oldsegv
)(int);
36 int main(int argc
, char **argv
) {
37 char *config
= "newserv.conf";
49 if (strcmp(argv
[1], "--help")==0) {
50 printf("Syntax: %s [config]\n", argv
[0]);
52 printf("Default configuration file unless specified: %s\n", config
);
62 /* modules can rely on this directory always being there */
63 if (mkdir("data", 0700) < 0 && errno
!= EEXIST
) {
68 /* Loading the modules will bring in the bulk of the code */
70 signal(SIGPIPE
, SIG_IGN
);
71 signal(SIGINT
, siginthandler
);
72 signal(SIGUSR1
, sigusr1handler
);
73 signal(SIGHUP
, sighuphandler
);
74 oldsegv
= signal(SIGSEGV
, sigsegvhandler
);
79 doscheduledevents(time(NULL
));
81 if (newserv_shutdown_pending
) {
97 if (RUNNING_ON_VALGRIND
) {
98 /* We've already manually called _fini for each of the modules. Make sure
99 * it's not getting called again when the libraries are unloaded. */
106 void handlesignals(void) {
107 if (newserv_sigusr1_pending
) {
108 signal(SIGUSR1
, sigusr1handler
);
109 Error("core", ERR_INFO
, "SIGUSR1 received.");
110 triggerhook(HOOK_CORE_SIGUSR1
, NULL
);
111 newserv_sigusr1_pending
=0;
114 if (newserv_sighup_pending
) {
115 signal(SIGHUP
, sighuphandler
);
116 Error("core", ERR_INFO
, "SIGHUP received, rehashing...");
117 triggerhook(HOOK_CORE_REHASH
, (void *)1);
118 newserv_sighup_pending
=0;
121 if (newserv_sigint_pending
) {
122 Error("core", ERR_INFO
, "SIGINT received, terminating.");
123 triggerhook(HOOK_CORE_SIGINT
, NULL
);
124 newserv_sigint_pending
=0;
125 newserv_shutdown_pending
=1;
130 * seed the pseudo-random number generator, rand()
135 gettimeofday(&t
, NULL
);
139 void siginthandler(int sig
) {
140 newserv_sigint_pending
= 1;
143 void sigusr1handler(int sig
) {
144 newserv_sigusr1_pending
= 1;
147 void sighuphandler(int sig
) {
148 newserv_sighup_pending
= 1;
151 void sigsegvhandler(int sig
) {