/[cvs]/eggdrop1.9/src/main.c
ViewVC logotype

Annotation of /eggdrop1.9/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.171 - (hide annotations) (download) (as text)
Sun Jun 20 13:33:48 2004 UTC (15 years ago) by wingman
Branch: MAIN
Changes since 1.170: +296 -176 lines
File MIME type: text/x-chdr
* Moved terminal mode out of telnetparty into core. No more need to
  load telnetparty in order to get a console.

* Started the beginning (heh) of '.restart'. Currently only the framework
  works, meaning if you do '.restart' the old stuff isn't cleared since
  currently everything leaks a <section>_shutdown() method :-/.

  At least we can test memory leaks (and i guess there are a lot) this way
  by doing a restart and check if there's a single byte of memory allocated
  (there _shouldn't_ be any).

1 wcc 1.156 /* main.c
2 guppy 1.56 *
3     * Copyright (C) 1997 Robey Pointer
4 wcc 1.153 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
5 guppy 1.56 *
6 fabian 1.14 * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10 guppy 1.56 *
11 segfault 1.1 * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15 guppy 1.56 *
16 segfault 1.1 * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 fabian 1.14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20 tothwolf 1.117
21     #ifndef lint
22 wingman 1.171 static const char rcsid[] = "$Id: main.c,v 1.170 2004/06/19 18:07:01 wingman Exp $";
23 wcc 1.156 #endif
24    
25     #if HAVE_CONFIG_H
26     # include <config.h>
27 tothwolf 1.117 #endif
28 segfault 1.1
29 wcc 1.158 #include <eggdrop/eggdrop.h>
30 stdarg 1.151 #include <ctype.h>
31 stdarg 1.145 #include <unistd.h>
32 wcc 1.156 #include <fcntl.h>
33 wcc 1.158 #include <string.h>
34     #include <stdlib.h>
35     #include <sys/stat.h>
36     #include <errno.h>
37     #include <signal.h>
38     #include <netdb.h>
39     #include <setjmp.h>
40     #include <locale.h>
41     #include <ctype.h>
42     #include <ltdl.h>
43 wcc 1.154
44 wcc 1.161 #include <eggdrop/stat.h>
45    
46 wcc 1.129 #ifdef TIME_WITH_SYS_TIME
47     # include <sys/time.h>
48     # include <time.h>
49 wcc 1.154 #else
50     # ifdef HAVE_SYS_TIME_H
51     # include <sys/time.h>
52     # else
53     # include <time.h>
54     # endif
55 wcc 1.129 #endif
56 wcc 1.154
57 wcc 1.158 #include "lib/compat/compat.h"
58     #include "debug.h"
59     #include "core_config.h"
60 wingman 1.167 #include "core_party.h"
61 wcc 1.158 #include "core_binds.h"
62     #include "logfile.h"
63 wingman 1.171 #include "terminal.h"
64 wingman 1.167 #include "bg.h"
65     #include "main.h"
66 ite 1.76
67 wcc 1.154 #ifdef STOP_UAC /* OSF/1 complains a lot */
68     # include <sys/sysinfo.h>
69     # define UAC_NOPRINT 0x00000001 /* Don't report unaligned fixups */
70 segfault 1.1 #endif
71 drummer 1.71
72 poptix 1.62 #ifdef CYGWIN_HACKS
73 wcc 1.154 # include <windows.h>
74 poptix 1.62 #endif
75    
76 segfault 1.1 #ifndef _POSIX_SOURCE
77 wcc 1.154 # define _POSIX_SOURCE 1 /* Solaris needs this */
78 segfault 1.1 #endif
79    
80 wingman 1.171 #define RUNMODE_NORMAL 1
81     #define RUNMODE_SHUTDOWN 2
82     #define RUNMODE_RESTART 3
83    
84     int runmode = 1; /* The most important variable ever! */
85 wcc 1.154 int backgrd = 1; /* Run in the background? */
86     int make_userfile = 0; /* Start bot in make-userfile mode? */
87 wingman 1.171 int terminal_mode = 0; /* Terminal mode */
88 wcc 1.154
89 stdarg 1.166 const char *configfile = NULL; /* Name of the config file */
90     char pid_file[512]; /* Name of Eggdrop's pid file */
91 wcc 1.154
92     time_t online_since; /* Time the bot was started */
93     time_t now; /* Current time */
94     egg_timeval_t egg_timeval_now; /* Current time in seconds and microseconds. */
95 segfault 1.1
96 wcc 1.154 int use_stderr = 1; /* Send stuff to stderr instead of logfiles? */
97 ite 1.109
98 wcc 1.155 char version[81];
99    
100 wcc 1.154 static int lastmin = 99;
101     static struct tm nowtm;
102    
103     void core_config_init();
104 fabian 1.27
105 fabian 1.44 void fatal(const char *s, int recoverable)
106 segfault 1.1 {
107 wcc 1.160 putlog(LOG_MISC, "*", "Fatal: %s", s);
108 wcc 1.154 flushlogs();
109     unlink(pid_file);
110     if (!recoverable) {
111     bg_send_quit(BG_ABORT);
112     exit(1);
113     }
114 segfault 1.1 }
115    
116     static void got_bus(int z)
117     {
118 wcc 1.160 fatal("BUS ERROR.", 1);
119 segfault 1.1 #ifdef SA_RESETHAND
120 wcc 1.154 kill(getpid(), SIGBUS);
121 segfault 1.1 #else
122 wcc 1.154 bg_send_quit(BG_ABORT);
123     exit(1);
124 segfault 1.1 #endif
125     }
126    
127     static void got_segv(int z)
128     {
129 wcc 1.160 fatal("SEGMENT VIOLATION.", 1);
130 segfault 1.1 #ifdef SA_RESETHAND
131 wcc 1.154 kill(getpid(), SIGSEGV);
132 segfault 1.1 #else
133 wcc 1.154 bg_send_quit(BG_ABORT);
134     exit(1);
135 segfault 1.1 #endif
136     }
137    
138     static void got_fpe(int z)
139     {
140 wcc 1.160 fatal("FLOATING POINT ERROR.", 0);
141 segfault 1.1 }
142    
143     static void got_term(int z)
144     {
145 wcc 1.154 eggdrop_event("sigterm");
146 wingman 1.171 if (core_config.die_on_sigterm)
147     core_shutdown (SHUTDOWN_SIGTERM, NULL, NULL);
148     else
149     putlog(LOG_MISC, "*", _("Received TERM signal (ignoring)."));
150 segfault 1.1 }
151    
152     static void got_quit(int z)
153     {
154 wcc 1.154 eggdrop_event("sigquit");
155 wcc 1.157 putlog(LOG_MISC, "*", _("Received QUIT signal (ignoring)."));
156 wcc 1.154 return;
157 segfault 1.1 }
158    
159     static void got_hup(int z)
160     {
161 wcc 1.154 eggdrop_event("sighup");
162 wcc 1.157 putlog(LOG_MISC, "*", _("Received HUP signal (ignoring)."));
163 wcc 1.154 return;
164 segfault 1.1 }
165    
166 wingman 1.168 #if 0
167 segfault 1.1 static void got_ill(int z)
168     {
169 wcc 1.154 eggdrop_event("sigill");
170 wcc 1.157 putlog(LOG_MISC, "*", _("Received ILL signal (ignoring)."));
171 fabian 1.10 }
172 wingman 1.168 #endif
173 fabian 1.10
174 ite 1.114
175 wcc 1.135 static void print_version(void)
176 segfault 1.1 {
177 wcc 1.154 printf("%s\n", version);
178 ite 1.114 }
179    
180 wcc 1.163 static void print_help(char *const *argv)
181 wcc 1.154 {
182     print_version();
183 wcc 1.157 printf(_("\nUsage: %s [OPTIONS]... [FILE]\n"), argv[0]);
184 wcc 1.154 printf(_("\n\
185 ite 1.114 -h, --help Print help and exit\n\
186     -v, --version Print version and exit\n\
187     -n, --foreground Don't go into the background (default=off)\n\
188     -c --channel-stats (with -n) Display channel stats every 10 seconds\n\
189     -t --terminal (with -n) Use terminal to simulate dcc-chat\n\
190     -m --make-userfile Userfile creation mode\n\
191 wcc 1.135 FILE optional config filename (default 'config.xml')\n"));
192 wcc 1.154 printf("\n");
193 ite 1.114 }
194 segfault 1.1
195 wcc 1.156 static void do_args(int argc, char *const *argv)
196 ite 1.114 {
197 wcc 1.154 int c;
198 ite 1.114
199 wcc 1.154 optarg = 0;
200     optind = 1;
201     opterr = 1;
202     optopt = '?';
203 ite 1.114
204 wcc 1.154 while (1) {
205     int option_index = 0;
206 ite 1.114
207 wcc 1.154 static struct option long_options[] = {
208     {"help", 0, NULL, 'h'},
209     {"version", 0, NULL, 'v'},
210     {"load-module", 1, NULL, 'p'},
211     {"foreground", 0, NULL, 'n'},
212     {"terminal", 0, NULL, 't'},
213     {"make-userfile", 0, NULL, 'm'},
214     {NULL, 0, NULL, 0}
215     };
216    
217     c = getopt_long(argc, argv, "hvp:nctm", long_options, &option_index);
218     if (c == -1) break;
219     switch (c) {
220     case 'n':
221     backgrd = 0;
222     break;
223     case 't':
224 wingman 1.171 terminal_mode = 1;
225 wcc 1.154 break;
226     case 'm':
227     make_userfile = 1;
228     break;
229     case 'v':
230     print_version();
231     bg_send_quit(BG_ABORT);
232     exit(0);
233     break; /* this should never be reached */
234     case 'h':
235     print_help(argv);
236     bg_send_quit(BG_ABORT);
237     exit(0);
238     break; /* this should never be reached */
239     case 0: /* Long option with no short option */
240     case '?': /* Invalid option. */
241     /* getopt_long() already printed an error message. */
242     bg_send_quit(BG_ABORT);
243     exit(1);
244     default: /* bug: option not considered. */
245 wcc 1.157 fprintf(stderr, _("%s: option unknown: %c\n"), argv[0], c);
246 wcc 1.154 bg_send_quit(BG_ABORT);
247     exit(1);
248     break; /* this should never be reached */
249     }
250     }
251 stdarg 1.166 if (optind < argc) configfile = argv[optind];
252     else configfile = "config.xml";
253 segfault 1.1 }
254    
255 fabian 1.34 /* Called once a second.
256 fabian 1.27 */
257 stdarg 1.139 static int core_secondly()
258 segfault 1.1 {
259 wcc 1.154 static int cnt = 0;
260     int miltime;
261 segfault 1.1
262 wcc 1.154 check_bind_secondly();
263     cnt++;
264     memcpy(&nowtm, localtime(&now), sizeof(struct tm));
265     if (nowtm.tm_min != lastmin) {
266     int i = 0;
267    
268     /* Once a minute */
269     lastmin = (lastmin + 1) % 60;
270     eggdrop_event("minutely");
271     check_bind_time(&nowtm);
272     /* In case for some reason more than 1 min has passed: */
273     while (nowtm.tm_min != lastmin) {
274     /* Timer drift, dammit */
275     putlog(LOG_DEBUG, "*", "timer: drift (lastmin=%d, now=%d)", lastmin, nowtm.tm_min);
276     i++;
277     lastmin = (lastmin + 1) % 60;
278     eggdrop_event("minutely");
279     }
280 wcc 1.157 if (i > 1) putlog(LOG_MISC, "*", _("Warning: timer drift (%d minutes)."), i);
281 segfault 1.1
282 wcc 1.154 miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
283     if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) { /* 5 minutes */
284     eggdrop_event("5minutely");
285     if (!miltime) { /* At midnight */
286     char s[25];
287    
288     strlcpy(s, ctime(&now), sizeof s);
289     putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
290     eggdrop_event("backup");
291     eggdrop_event("daily");
292     }
293     }
294     }
295     return(0);
296 segfault 1.1 }
297    
298 stdarg 1.140
299 stdarg 1.142 int file_check(const char *filename)
300     {
301     struct stat sbuf = {0};
302     int r;
303    
304     r = stat(filename, &sbuf);
305     if (r) return(-1);
306     errno = 0;
307     if (sbuf.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) return(-1);
308     return(0);
309     }
310    
311 wingman 1.171 static int create_userfile(void)
312 segfault 1.1 {
313 wingman 1.171 user_t *owner;
314     char handle[512], password[12];
315     int len;
316    
317     printf("\n");
318     if (user_count() != 0) {
319     printf("You are trying to create a new userfile, but the old one still exists (%s)!\n", core_config.userfile);
320     printf("Please remove the userfile, or do not pass the -m option.\n\n");
321     return 0;
322 wcc 1.154 }
323 wingman 1.171
324     printf("Hello! I see you are creating a new userfile.\n\n");
325     printf("Let's create the owner account.\n\n");
326     do {
327     printf("Enter the owner handle: ");
328     fflush(stdout);
329     fgets(handle, sizeof(handle), stdin);
330     for (len = 0; handle[len]; len++) {
331     if (!ispunct(handle[len]) && !isalnum(handle[len])) break;
332     }
333     if (len == 0) printf("Come on, enter a real handle.\n\n");
334     } while (len <= 0);
335     handle[len] = 0;
336    
337     owner = user_new(handle);
338     if (!owner) {
339     printf("Failed to create user record! Out of memory?\n\n");
340     return 0;
341 stdarg 1.145 }
342 wingman 1.171
343     user_rand_pass(password, sizeof(password));
344     user_set_pass(owner, password);
345     user_set_flags_str(owner, NULL, "+n");
346     printf("Your owner handle is '%s' and your password is '%s' (without the quotes).\n\n", handle, password);
347     memset(password, 0, sizeof(password));
348     str_redup(&core_config.owner, handle);
349     core_config_save();
350     user_save(core_config.userfile);
351    
352     return 1;
353     }
354 stdarg 1.145
355 wingman 1.171 static void init_signals(void)
356     {
357     struct sigaction sv;
358 wcc 1.154
359 fabian 1.27
360 wcc 1.154 sv.sa_handler = got_bus;
361     sigemptyset(&sv.sa_mask);
362 segfault 1.1 #ifdef SA_RESETHAND
363 wcc 1.154 sv.sa_flags = SA_RESETHAND;
364 segfault 1.1 #else
365 wcc 1.154 sv.sa_flags = 0;
366 segfault 1.1 #endif
367 wcc 1.154 sigaction(SIGBUS, &sv, NULL);
368    
369     sv.sa_handler = got_segv;
370     sigaction(SIGSEGV, &sv, NULL);
371 segfault 1.1 #ifdef SA_RESETHAND
372 wcc 1.154 sv.sa_flags = 0;
373 segfault 1.1 #endif
374 wcc 1.154
375     sv.sa_handler = got_fpe;
376     sigaction(SIGFPE, &sv, NULL);
377    
378     sv.sa_handler = got_term;
379     sigaction(SIGTERM, &sv, NULL);
380    
381     sv.sa_handler = got_hup;
382     sigaction(SIGHUP, &sv, NULL);
383    
384     sv.sa_handler = got_quit;
385     sigaction(SIGQUIT, &sv, NULL);
386    
387     sv.sa_handler = SIG_IGN;
388     sigaction(SIGPIPE, &sv, NULL);
389    
390 wingman 1.168 /* XXX: why is this disabled? */
391     #if 0
392     sv.sa_handler = got_ill;
393     sigaction(SIGILL, &sv, NULL);
394     #endif
395 wingman 1.171 }
396 wcc 1.154
397 wingman 1.171 static int init_bg_and_pid (void)
398     {
399     FILE *f;
400     int xx;
401     char s[25];
402    
403     if (backgrd)
404     bg_prepare_split();
405 stdarg 1.142
406 wingman 1.171 /* XXX: what shall we do if we've restarted and one changed our
407     * XXX: botname? Remove old pid_file and create new one? Then this
408     * XXX: is the wrong place. */
409 wcc 1.154 snprintf(pid_file, sizeof pid_file, "pid.%s", core_config.botname);
410    
411     f = fopen(pid_file, "r");
412     if (f != NULL) {
413     fgets(s, 10, f);
414     xx = atoi(s);
415     kill(xx, SIGCHLD); /* Meaningless kill to determine if pid is used */
416     if (errno != ESRCH) {
417 wcc 1.160 printf("I detect %s already running from this directory.\n", core_config.botname);
418     printf("If this is incorrect, please erase '%s'.\n", pid_file);
419 wcc 1.154 bg_send_quit(BG_ABORT);
420 wingman 1.171 return 0;
421 wcc 1.154 }
422     }
423 fabian 1.27
424 wcc 1.154 if (backgrd) { /* Move into background? */
425 fabian 1.38 #ifndef CYGWIN_HACKS
426 wcc 1.154 bg_do_split();
427     }
428     else {
429 fabian 1.5 #endif
430 wcc 1.154 xx = getpid();
431     if (xx != 0) {
432     FILE *fp;
433    
434     unlink(pid_file);
435     fp = fopen(pid_file, "w");
436     if (fp != NULL) {
437     fprintf(fp, "%u\n", xx);
438     if (fflush(fp)) {
439     /* Let the bot live since this doesn't appear to be a botchk */
440 wcc 1.160 printf("WARNING: Could not write pid file '%s'.\n", pid_file);
441 wcc 1.154 fclose(fp);
442     unlink(pid_file);
443     }
444     else fclose(fp);
445     }
446 wcc 1.160 else printf("WARNING: Could not write pid file '%s'.\n", pid_file);
447 fabian 1.38 #ifdef CYGWIN_HACKS
448 wcc 1.160 printf("Launched into the background (pid: %d).\n\n", xx);
449 fabian 1.38 #endif
450 wcc 1.154 }
451     }
452 stdarg 1.151
453 wcc 1.154 use_stderr = 0; /* Stop writing to stderr now */
454 fabian 1.38
455 wcc 1.154 if (backgrd) {
456     /* Try to disassociate from controlling terminal (finger cross) */
457 fabian 1.5 #if HAVE_SETPGID && !defined(CYGWIN_HACKS)
458 wcc 1.154 setpgid(0, 0);
459 segfault 1.1 #endif
460 wcc 1.154 /* Tcl wants the stdin, stdout and stderr file handles kept open. */
461     freopen("/dev/null", "r", stdin);
462     freopen("/dev/null", "w", stdout);
463     freopen("/dev/null", "w", stderr);
464 poptix 1.62 #ifdef CYGWIN_HACKS
465 wcc 1.154 FreeConsole();
466 poptix 1.62 #endif
467 wcc 1.154 }
468 fabian 1.27
469 wingman 1.171 return 1;
470     }
471    
472     static void core_shutdown_or_restart()
473     {
474     /* notifiy shutdown listeners */
475     check_bind_shutdown();
476    
477     putlog(LOG_MISC, "*", _("Saving user file..."));
478     user_save(core_config.userfile);
479 segfault 1.1
480 wingman 1.171 putlog(LOG_MISC, "*", _("Saving config file..."));
481     core_config_save();
482 wingman 1.167
483 wingman 1.171 /* shutdown logging */
484     logfile_shutdown();
485 wingman 1.167
486 wingman 1.171 /* shutdown libeggdrop */
487     eggdrop_shutdown();
488    
489     /* force an garbage run */
490     garbage_run();
491    
492     /* just remove pid file if didn't restart */
493     if (runmode != RUNMODE_RESTART)
494     unlink(pid_file);
495     }
496    
497    
498     int main(int argc, char **argv)
499     {
500     int timeout;
501    
502     #ifdef DEBUG
503     {
504     # include <sys/resource.h>
505     struct rlimit cdlim;
506 wingman 1.170
507 wingman 1.171 cdlim.rlim_cur = RLIM_INFINITY;
508     cdlim.rlim_max = RLIM_INFINITY;
509     setrlimit(RLIMIT_CORE, &cdlim);
510 stdarg 1.131 }
511 wingman 1.171 #endif
512    
513     init_signals();
514 wingman 1.167
515 wingman 1.171 #ifdef ENABLE_NLS
516     setlocale(LC_MESSAGES, "");
517     bindtextdomain(PACKAGE, LOCALEDIR);
518     textdomain(PACKAGE);
519     #endif
520    
521     /* Initialize ltdl. */
522     LTDL_SET_PRELOADED_SYMBOLS();
523     if (lt_dlinit()) {
524     printf("Fatal error initializing ltdl: %s\n", lt_dlerror());
525     return(-1);
526     }
527    
528     snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2004 Eggheads Development Team", VERSION);
529    
530     #ifdef STOP_UAC
531     {
532     int nvpair[2];
533 wingman 1.170
534 wingman 1.171 nvpair[0] = SSIN_UACPROC;
535     nvpair[1] = UAC_NOPRINT;
536     setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0);
537     }
538     #endif
539    
540     timer_update_now(&egg_timeval_now);
541     now = egg_timeval_now.sec;
542     memcpy(&nowtm, localtime(&now), sizeof(struct tm));
543     lastmin = nowtm.tm_min;
544    
545     srandom(now % (getpid() + getppid()));
546    
547     do_args(argc, argv);
548     printf("\n%s\n", version);
549     printf("WARNING: Do NOT run this DEVELOPMENT version for any purpose other than testing.\n\n");
550    
551     /* we may not ru as root */
552     if (((int) getuid() == 0) || ((int) geteuid() == 0)) {
553     fatal("Eggdrop will not run as root!", 0);
554     return -1;
555     }
556    
557     /* config file may not be world read/writeable */
558     if (file_check(configfile)) {
559     if (errno) perror(configfile);
560     else {
561     fprintf(stderr, "ERROR\n");
562     fprintf(stderr, "\tCheck file permissions on your config file!");
563     fprintf(stderr, "\tMake sure other groups and users cannot read/write it.\n");
564     return -1;
565     }
566     }
567    
568     /* set uptime */
569     online_since = now;
570    
571     do {
572     egg_timeval_t howlong;
573    
574     /* default select timeout is 1 sec */
575     howlong.sec = 1;
576     howlong.usec = 0;
577    
578     timer_create_repeater(&howlong, "main loop", core_secondly);
579    
580     /* init core */
581     core_init();
582    
583     /* set normal running mode */
584     runmode = RUNMODE_NORMAL;
585    
586     putlog(LOG_DEBUG, "*", "Entering main loop.");
587    
588     /* main loop */
589     while (runmode == RUNMODE_NORMAL) {
590     timer_update_now(&egg_timeval_now);
591     now = egg_timeval_now.sec;
592     random(); /* Woop, lets really jumble things */
593     timer_run();
594     if (timer_get_shortest(&howlong)) timeout = 1000;
595     else timeout = howlong.sec * 1000 + howlong.usec / 1000;
596     sockbuf_update_all(timeout);
597     garbage_run();
598     }
599    
600     /* Save user file, config file, ... */
601     core_shutdown_or_restart();
602    
603     /* the only chance to loop again is that running = 2, meaning
604     we have a restart */
605     } while (runmode == RUNMODE_RESTART);
606    
607 wingman 1.170 return 1;
608     }
609    
610     int core_init()
611 wingman 1.171 {
612     int i;
613     char *name;
614     void *config_root, *entry;
615     char s[25];
616    
617     /* init libeggdrop */
618     eggdrop_init();
619    
620     /* load config */
621     core_config_init(configfile);
622    
623     /* init background mode and pid file */
624     if (runmode != RUNMODE_RESTART)
625     init_bg_and_pid();
626    
627     /* init logging */
628     logfile_init();
629    
630     /* just issue this "Loading Eggdrop" message if we are not
631     * restarting */
632     if (runmode != RUNMODE_RESTART) {
633     strlcpy(s, ctime(&now), sizeof s);
634     strcpy(&s[11], &s[20]);
635     putlog(LOG_ALL, "*", "Loading Eggdrop %s (%s)", VERSION, s);
636     }
637    
638     /* load userlist */
639     if (core_config.userfile)
640     user_load(core_config.userfile);
641    
642     /* init core bindings */
643     core_binds_init();
644    
645     /* init core partyline */
646     core_party_init();
647    
648     /* did the user specify -m? */
649     if (make_userfile) {
650     if (!create_userfile())
651     return 0;
652     make_userfile = 0;
653     }
654    
655     /* Load core help */
656     help_load_by_module ("core");
657    
658     /* Put the module directory in the ltdl search path. */
659     if (core_config.module_path)
660     module_add_dir(core_config.module_path);
661    
662     /* Scan the autoload section of config. */
663     config_root = config_get_root("eggdrop");
664     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) {
665     name = NULL;
666     config_get_str(&name, entry, NULL);
667     module_load(name);
668     }
669     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
670     name = NULL;
671     config_get_str(&name, entry, NULL);
672     script_load(name);
673     }
674    
675     /* notify init listeners */
676 wingman 1.170 check_bind_init();
677 wingman 1.171
678     /* start terminal */
679     if (runmode != RUNMODE_RESTART)
680     if (terminal_mode)
681     terminal_init();
682    
683     return 1;
684     }
685 wingman 1.170
686 wingman 1.171 int core_restart(const char *nick)
687     {
688     putlog(LOG_MISC, "*", "Restarting...");
689     runmode = RUNMODE_RESTART;
690 wingman 1.170 return 1;
691     }
692    
693     int core_shutdown(int how, const char *nick, const char *reason)
694     {
695 wingman 1.171 if (how == SHUTDOWN_SIGTERM)
696     putlog(LOG_MISC, "*", ("Received TERM signal, shutting down."));
697     else if (how != SHUTDOWN_RESTART)
698     putlog(LOG_MISC, "*", ("Shutdown requested by %s: %s"), nick,
699     (reason) ? reason : _("No reason"));
700 wingman 1.170
701 wingman 1.171 /* check how to shut down */
702 wingman 1.170 switch (how) {
703    
704 wingman 1.171 case (SHUTDOWN_RESTART):
705     runmode = RUNMODE_RESTART;
706     break;
707    
708 wingman 1.170 case (SHUTDOWN_GRACEFULL):
709 wingman 1.171 runmode = RUNMODE_SHUTDOWN;
710 wingman 1.170 break;
711    
712 wingman 1.171 /* These two cases are treaded special because something
713     * unusual happened and we're better off if we exit() NOW
714     * than doing a gracefull shutdown with freeing all
715     * memory, closing all sockets, ... */
716 wingman 1.170 case (SHUTDOWN_HARD):
717 wingman 1.171 case (SHUTDOWN_SIGTERM):
718     runmode = RUNMODE_SHUTDOWN;
719     core_shutdown_or_restart();
720 wingman 1.170 exit(0);
721     break;
722 wingman 1.171
723 wingman 1.170 }
724    
725     return BIND_RET_LOG;
726 segfault 1.1 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23