]>
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); |
2c5db955 CP |
23 | |
24 | int main(int argc, char **argv) { | |
25 | initseed(); | |
26 | inithooks(); | |
27 | inithandlers(); | |
28 | initschedule(); | |
280505a5 | 29 | |
30 | init_logfile(); | |
2c5db955 CP |
31 | |
32 | initsstring(); | |
33 | ||
34 | if (argc>1) { | |
35 | initconfig(argv[1]); | |
36 | } else { | |
37 | initconfig("newserv.conf"); | |
38 | } | |
39 | ||
40 | /* Loading the modules will bring in the bulk of the code */ | |
41 | initmodules(); | |
88c8f330 | 42 | signal(SIGINT, siginthandler); |
b8e79109 | 43 | signal(SIGUSR1, sigusr1handler); |
2c5db955 CP |
44 | |
45 | /* Main loop */ | |
46 | for(;;) { | |
47 | handleevents(10); | |
48 | doscheduledevents(time(NULL)); | |
83951d54 | 49 | if (newserv_shutdown_pending) { |
50 | newserv_shutdown(); | |
51 | break; | |
52 | } | |
b8e79109 | 53 | |
54 | if (newserv_sigusr1_pending) { | |
55 | triggerhook(HOOK_CORE_SIGUSR1, NULL); | |
56 | newserv_sigusr1_pending=0; | |
57 | } | |
2c5db955 | 58 | } |
707c5824 | 59 | |
103521a1 | 60 | nsexit(); |
707c5824 CP |
61 | |
62 | freeconfig(); | |
63 | finisstring(); | |
2c5db955 CP |
64 | } |
65 | ||
66 | /* | |
67 | * seed the pseudo-random number generator, rand() | |
68 | */ | |
69 | void initseed() { | |
70 | struct timeval t; | |
71 | ||
72 | gettimeofday(&t, NULL); | |
73 | srand(t.tv_usec); | |
74 | } | |
88c8f330 CP |
75 | |
76 | void siginthandler(int sig) { | |
77 | newserv_shutdown_pending = 1; | |
78 | } | |
b8e79109 | 79 | |
80 | void sigusr1handler(int sig) { | |
81 | newserv_sigusr1_pending = 1; | |
82 | } |