/[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.184 - (hide annotations) (download) (as text)
Sun Sep 26 09:42:09 2004 UTC (14 years, 10 months ago) by stdarg
Branch: MAIN
Changes since 1.183: +9 -9 lines
File MIME type: text/x-chdr
* module_load checks modname_LTX_start in addition to start.
* add linked list info to xml nodes
* there were some memory errors somewhere... no idea where... so for now I've changed it back to the old config api and commented out the help system

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23