]>
Commit | Line | Data |
---|---|---|
2c5db955 CP |
1 | #include "../lib/sstring.h" |
2 | #include "events.h" | |
3 | #include "schedule.h" | |
4 | #include "hooks.h" | |
5 | #include "modules.h" | |
6 | #include "config.h" | |
7 | #include "error.h" | |
010f1c74 | 8 | #include "nsmalloc.h" |
2c5db955 CP |
9 | |
10 | #include <stdlib.h> | |
11 | #include <stdio.h> | |
12 | #include <time.h> | |
13 | #include <sys/time.h> | |
88c8f330 | 14 | #include <signal.h> |
2c5db955 | 15 | |
83951d54 | 16 | int newserv_shutdown_pending; |
b8e79109 | 17 | int newserv_sigusr1_pending; |
83951d54 | 18 | |
2c5db955 | 19 | void initseed(); |
280505a5 | 20 | void init_logfile(); |
88c8f330 | 21 | void siginthandler(int sig); |
b8e79109 | 22 | void sigusr1handler(int sig); |
cdc37146 CP |
23 | void sigsegvhandler(int sig); |
24 | void handlecore(void); | |
2c5db955 | 25 | |
506a636c CP |
26 | static void (*oldsegv)(int); |
27 | ||
2c5db955 CP |
28 | int main(int argc, char **argv) { |
29 | initseed(); | |
30 | inithooks(); | |
31 | inithandlers(); | |
32 | initschedule(); | |
280505a5 | 33 | |
34 | init_logfile(); | |
2c5db955 CP |
35 | |
36 | initsstring(); | |
37 | ||
38 | if (argc>1) { | |
39 | initconfig(argv[1]); | |
40 | } else { | |
41 | initconfig("newserv.conf"); | |
42 | } | |
43 | ||
44 | /* Loading the modules will bring in the bulk of the code */ | |
45 | initmodules(); | |
88c8f330 | 46 | signal(SIGINT, siginthandler); |
b8e79109 | 47 | signal(SIGUSR1, sigusr1handler); |
506a636c | 48 | oldsegv = signal(SIGSEGV, sigsegvhandler); |
2c5db955 CP |
49 | |
50 | /* Main loop */ | |
51 | for(;;) { | |
52 | handleevents(10); | |
53 | doscheduledevents(time(NULL)); | |
83951d54 | 54 | if (newserv_shutdown_pending) { |
55 | newserv_shutdown(); | |
56 | break; | |
57 | } | |
b8e79109 | 58 | |
59 | if (newserv_sigusr1_pending) { | |
4eb459df | 60 | signal(SIGUSR1, sigusr1handler); |
b8e79109 | 61 | triggerhook(HOOK_CORE_SIGUSR1, NULL); |
62 | newserv_sigusr1_pending=0; | |
63 | } | |
2c5db955 | 64 | } |
707c5824 | 65 | |
707c5824 CP |
66 | freeconfig(); |
67 | finisstring(); | |
bd293217 P |
68 | |
69 | nsexit(); | |
2c5db955 CP |
70 | } |
71 | ||
72 | /* | |
73 | * seed the pseudo-random number generator, rand() | |
74 | */ | |
75 | void initseed() { | |
76 | struct timeval t; | |
77 | ||
78 | gettimeofday(&t, NULL); | |
79 | srand(t.tv_usec); | |
80 | } | |
88c8f330 CP |
81 | |
82 | void siginthandler(int sig) { | |
83 | newserv_shutdown_pending = 1; | |
84 | } | |
b8e79109 | 85 | |
86 | void sigusr1handler(int sig) { | |
87 | newserv_sigusr1_pending = 1; | |
88 | } | |
cdc37146 CP |
89 | |
90 | void sigsegvhandler(int sig) { | |
91 | handlecore(); | |
506a636c CP |
92 | |
93 | oldsegv(sig); | |
cdc37146 CP |
94 | } |
95 |