/[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.178 - (hide annotations) (download) (as text)
Wed Jun 23 17:24:43 2004 UTC (15 years, 4 months ago) by wingman
Branch: MAIN
Changes since 1.177: +6 -6 lines
File MIME type: text/x-chdr
* Added xml_save_str to save xml_node_t into a char *

* Made xml reader more spec compliant and a first start of error handling.
  Now at least we handle some xml errors. Prior you just got "Error while
  loading config file.".

* Added top level elements to config.xml and users.xml.

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.178 static const char rcsid[] = "$Id: main.c,v 1.177 2004/06/22 23:20:23 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 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 wcc 1.156 static void do_args(int argc, char *const *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.166 if (optind < argc) configfile = argv[optind];
226     else configfile = "config.xml";
227 segfault 1.1 }
228    
229 fabian 1.34 /* Called once a second.
230 fabian 1.27 */
231 stdarg 1.139 static int core_secondly()
232 segfault 1.1 {
233 wcc 1.154 static int cnt = 0;
234     int miltime;
235 segfault 1.1
236 wcc 1.154 check_bind_secondly();
237     cnt++;
238     memcpy(&nowtm, localtime(&now), sizeof(struct tm));
239     if (nowtm.tm_min != lastmin) {
240     int i = 0;
241    
242     /* Once a minute */
243     lastmin = (lastmin + 1) % 60;
244     eggdrop_event("minutely");
245     check_bind_time(&nowtm);
246     /* In case for some reason more than 1 min has passed: */
247     while (nowtm.tm_min != lastmin) {
248     /* Timer drift, dammit */
249     putlog(LOG_DEBUG, "*", "timer: drift (lastmin=%d, now=%d)", lastmin, nowtm.tm_min);
250     i++;
251     lastmin = (lastmin + 1) % 60;
252     eggdrop_event("minutely");
253     }
254 wcc 1.157 if (i > 1) putlog(LOG_MISC, "*", _("Warning: timer drift (%d minutes)."), i);
255 segfault 1.1
256 wcc 1.154 miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
257 stdarg 1.172 if (nowtm.tm_min % 5 == 0) { /* 5 minutes */
258 wcc 1.154 eggdrop_event("5minutely");
259     if (!miltime) { /* At midnight */
260     char s[25];
261    
262     strlcpy(s, ctime(&now), sizeof s);
263     putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
264     eggdrop_event("backup");
265     eggdrop_event("daily");
266     }
267     }
268     }
269     return(0);
270 segfault 1.1 }
271    
272 stdarg 1.140
273 stdarg 1.142 int file_check(const char *filename)
274     {
275     struct stat sbuf = {0};
276     int r;
277    
278     r = stat(filename, &sbuf);
279     if (r) return(-1);
280     errno = 0;
281     if (sbuf.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) return(-1);
282     return(0);
283     }
284    
285 wingman 1.171 static int create_userfile(void)
286 segfault 1.1 {
287 wingman 1.171 user_t *owner;
288     char handle[512], password[12];
289     int len;
290    
291     printf("\n");
292     if (user_count() != 0) {
293     printf("You are trying to create a new userfile, but the old one still exists (%s)!\n", core_config.userfile);
294     printf("Please remove the userfile, or do not pass the -m option.\n\n");
295 stdarg 1.172 return(-1);
296 wcc 1.154 }
297 wingman 1.171
298     printf("Hello! I see you are creating a new userfile.\n\n");
299     printf("Let's create the owner account.\n\n");
300     do {
301     printf("Enter the owner handle: ");
302     fflush(stdout);
303     fgets(handle, sizeof(handle), stdin);
304     for (len = 0; handle[len]; len++) {
305 wingman 1.175 if (!ispunct(handle[len]) && !isalnum(handle[len])) break;
306 wingman 1.171 }
307     if (len == 0) printf("Come on, enter a real handle.\n\n");
308     } while (len <= 0);
309     handle[len] = 0;
310    
311     owner = user_new(handle);
312     if (!owner) {
313     printf("Failed to create user record! Out of memory?\n\n");
314 stdarg 1.172 return(-1);
315 stdarg 1.145 }
316 wingman 1.171
317     user_rand_pass(password, sizeof(password));
318     user_set_pass(owner, password);
319     user_set_flags_str(owner, NULL, "+n");
320     printf("Your owner handle is '%s' and your password is '%s' (without the quotes).\n\n", handle, password);
321     memset(password, 0, sizeof(password));
322     str_redup(&core_config.owner, handle);
323     core_config_save();
324     user_save(core_config.userfile);
325    
326 stdarg 1.172 return(0);
327 wingman 1.171 }
328 stdarg 1.145
329 wingman 1.171 static void init_signals(void)
330     {
331     struct sigaction sv;
332 wcc 1.154
333 fabian 1.27
334 wcc 1.154 sv.sa_handler = got_bus;
335     sigemptyset(&sv.sa_mask);
336 segfault 1.1 #ifdef SA_RESETHAND
337 wcc 1.154 sv.sa_flags = SA_RESETHAND;
338 segfault 1.1 #else
339 wcc 1.154 sv.sa_flags = 0;
340 segfault 1.1 #endif
341 wcc 1.154 sigaction(SIGBUS, &sv, NULL);
342    
343     sv.sa_handler = got_segv;
344     sigaction(SIGSEGV, &sv, NULL);
345 segfault 1.1 #ifdef SA_RESETHAND
346 wcc 1.154 sv.sa_flags = 0;
347 segfault 1.1 #endif
348 wcc 1.154
349     sv.sa_handler = got_fpe;
350     sigaction(SIGFPE, &sv, NULL);
351    
352     sv.sa_handler = got_term;
353     sigaction(SIGTERM, &sv, NULL);
354    
355     sv.sa_handler = got_hup;
356     sigaction(SIGHUP, &sv, NULL);
357    
358     sv.sa_handler = got_quit;
359     sigaction(SIGQUIT, &sv, NULL);
360    
361     sv.sa_handler = SIG_IGN;
362     sigaction(SIGPIPE, &sv, NULL);
363 wingman 1.171 }
364    
365     static void core_shutdown_or_restart()
366     {
367     /* notifiy shutdown listeners */
368     check_bind_shutdown();
369    
370     putlog(LOG_MISC, "*", _("Saving user file..."));
371     user_save(core_config.userfile);
372 segfault 1.1
373 wingman 1.171 putlog(LOG_MISC, "*", _("Saving config file..."));
374     core_config_save();
375 wingman 1.167
376 wingman 1.175 /* destroy terminal */
377     if (terminal_mode && runmode != RUNMODE_RESTART)
378     terminal_shutdown();
379    
380     /* unload core help */
381     help_unload_by_module("core");
382    
383 wingman 1.177 /* shutdown core binds */
384     core_binds_shutdown();
385    
386 wingman 1.171 /* shutdown logging */
387     logfile_shutdown();
388 wingman 1.167
389 wingman 1.171 /* shutdown libeggdrop */
390     eggdrop_shutdown();
391    
392 stdarg 1.172 /* force a garbage run */
393 wingman 1.171 garbage_run();
394    
395     /* just remove pid file if didn't restart */
396     if (runmode != RUNMODE_RESTART)
397     unlink(pid_file);
398     }
399    
400     int main(int argc, char **argv)
401     {
402     int timeout;
403 wingman 1.178
404 wingman 1.171 #ifdef DEBUG
405     {
406     # include <sys/resource.h>
407     struct rlimit cdlim;
408 wingman 1.170
409 wingman 1.171 cdlim.rlim_cur = RLIM_INFINITY;
410     cdlim.rlim_max = RLIM_INFINITY;
411     setrlimit(RLIMIT_CORE, &cdlim);
412 stdarg 1.131 }
413 wingman 1.171 #endif
414    
415     init_signals();
416 wingman 1.167
417 wingman 1.171 #ifdef ENABLE_NLS
418     setlocale(LC_MESSAGES, "");
419     bindtextdomain(PACKAGE, LOCALEDIR);
420     textdomain(PACKAGE);
421     #endif
422    
423     /* Initialize ltdl. */
424     LTDL_SET_PRELOADED_SYMBOLS();
425     if (lt_dlinit()) {
426     printf("Fatal error initializing ltdl: %s\n", lt_dlerror());
427     return(-1);
428     }
429    
430     snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2004 Eggheads Development Team", VERSION);
431    
432     #ifdef STOP_UAC
433     {
434     int nvpair[2];
435 wingman 1.170
436 wingman 1.171 nvpair[0] = SSIN_UACPROC;
437     nvpair[1] = UAC_NOPRINT;
438     setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0);
439     }
440     #endif
441    
442     timer_update_now(&egg_timeval_now);
443     now = egg_timeval_now.sec;
444     memcpy(&nowtm, localtime(&now), sizeof(struct tm));
445     lastmin = nowtm.tm_min;
446    
447     srandom(now % (getpid() + getppid()));
448    
449     do_args(argc, argv);
450     printf("\n%s\n", version);
451     printf("WARNING: Do NOT run this DEVELOPMENT version for any purpose other than testing.\n\n");
452    
453 stdarg 1.172 /* we may not run as root */
454 wingman 1.171 if (((int) getuid() == 0) || ((int) geteuid() == 0)) {
455 stdarg 1.173 fatal("Eggdrop will not run as root!");
456 wingman 1.171 return -1;
457     }
458    
459     /* config file may not be world read/writeable */
460     if (file_check(configfile)) {
461     if (errno) perror(configfile);
462     else {
463     fprintf(stderr, "ERROR\n");
464     fprintf(stderr, "\tCheck file permissions on your config file!");
465     fprintf(stderr, "\tMake sure other groups and users cannot read/write it.\n");
466     return -1;
467     }
468     }
469    
470     /* set uptime */
471     online_since = now;
472    
473     do {
474 wingman 1.175 int tid;
475 wingman 1.171 egg_timeval_t howlong;
476    
477     /* default select timeout is 1 sec */
478     howlong.sec = 1;
479     howlong.usec = 0;
480 stdarg 1.172
481 wingman 1.175 tid = timer_create_repeater(&howlong, "main loop", core_secondly);
482 stdarg 1.172
483 wingman 1.171 /* init core */
484 wingman 1.178 if (!core_init())
485     break;
486 wingman 1.171
487     /* set normal running mode */
488     runmode = RUNMODE_NORMAL;
489 stdarg 1.172
490 wingman 1.171 putlog(LOG_DEBUG, "*", "Entering main loop.");
491    
492 wingman 1.174 /* main loop */
493     while (!debug_run && runmode == RUNMODE_NORMAL) {
494 stdarg 1.173 /* Update the time. */
495 wingman 1.171 timer_update_now(&egg_timeval_now);
496     now = egg_timeval_now.sec;
497 stdarg 1.173
498     /* Run any expired timers. */
499 wingman 1.171 timer_run();
500 stdarg 1.173
501     /* Figure out how long to wait for activity. */
502 wingman 1.171 if (timer_get_shortest(&howlong)) timeout = 1000;
503     else timeout = howlong.sec * 1000 + howlong.usec / 1000;
504 stdarg 1.173
505     /* Wait and monitor sockets. */
506 wingman 1.171 sockbuf_update_all(timeout);
507 stdarg 1.173
508     /* Run any scheduled cleanups. */
509 wingman 1.171 garbage_run();
510     }
511 stdarg 1.172
512 wingman 1.175 /* shutdown secondly timer */
513     timer_destroy(tid);
514    
515 wingman 1.171 /* Save user file, config file, ... */
516     core_shutdown_or_restart();
517    
518     /* the only chance to loop again is that running = 2, meaning
519     we have a restart */
520     } while (runmode == RUNMODE_RESTART);
521 stdarg 1.172
522 wingman 1.174 if (debug_run)
523     mem_dbg_stats();
524    
525     return 0;
526 wingman 1.170 }
527    
528     int core_init()
529 wingman 1.171 {
530     int i;
531     char *name;
532     void *config_root, *entry;
533 stdarg 1.173 char datetime[25];
534     static int lockfd = -1;
535     struct flock lock;
536    
537 wingman 1.171 /* init libeggdrop */
538     eggdrop_init();
539    
540     /* load config */
541 wingman 1.178 if (core_config_init(configfile) != 0)
542     return (-1);
543 stdarg 1.172
544 stdarg 1.173 /* init logging */
545     logfile_init();
546    
547 stdarg 1.172 /* did the user specify -m? */
548     if (make_userfile) {
549     if (create_userfile()) return(-1);
550     make_userfile = 0;
551     }
552    
553 wingman 1.171 /* init background mode and pid file */
554 stdarg 1.173 if (runmode != RUNMODE_RESTART) {
555     if (backgrd) bg_begin_split();
556     }
557 stdarg 1.172
558 stdarg 1.173 /* Check lock file. */
559     if (core_config.lockfile && lockfd == -1) {
560     lockfd = open(core_config.lockfile, O_WRONLY | O_CREAT, S_IWUSR);
561     if (lockfd < 0) {
562     fatal("Could not open lock file!");
563     }
564     memset(&lock, 0, sizeof(lock));
565     lock.l_type = F_WRLCK;
566     if (fcntl(lockfd, F_SETLK, &lock) != 0) {
567     fatal("Lock file is already locked! Is eggdrop already running?");
568     }
569     }
570 wingman 1.171
571     /* just issue this "Loading Eggdrop" message if we are not
572     * restarting */
573     if (runmode != RUNMODE_RESTART) {
574 stdarg 1.173 strlcpy(datetime, ctime(&now), sizeof(datetime));
575     strcpy(&datetime[11], &datetime[20]);
576     putlog(LOG_ALL, "*", "Loading Eggdrop %s (%s)", VERSION, datetime);
577 wingman 1.171 }
578 stdarg 1.172
579 wingman 1.171 /* load userlist */
580     if (core_config.userfile)
581     user_load(core_config.userfile);
582 stdarg 1.172
583 wingman 1.171 /* init core bindings */
584     core_binds_init();
585 stdarg 1.172
586 wingman 1.171 /* init core partyline */
587     core_party_init();
588    
589     /* Load core help */
590     help_load_by_module ("core");
591    
592     /* Put the module directory in the ltdl search path. */
593     if (core_config.module_path)
594     module_add_dir(core_config.module_path);
595    
596     /* Scan the autoload section of config. */
597     config_root = config_get_root("eggdrop");
598     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) {
599     name = NULL;
600     config_get_str(&name, entry, NULL);
601     module_load(name);
602     }
603     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
604     name = NULL;
605     config_get_str(&name, entry, NULL);
606     script_load(name);
607     }
608    
609     /* notify init listeners */
610 wingman 1.170 check_bind_init();
611 wingman 1.171
612     /* start terminal */
613 stdarg 1.173 if (runmode != RUNMODE_RESTART) {
614     if (backgrd) bg_finish_split();
615     if (terminal_mode) terminal_init();
616     }
617 wingman 1.171
618     return 1;
619     }
620 wingman 1.170
621 wingman 1.171 int core_restart(const char *nick)
622     {
623     putlog(LOG_MISC, "*", "Restarting...");
624     runmode = RUNMODE_RESTART;
625 wingman 1.170 return 1;
626     }
627    
628     int core_shutdown(int how, const char *nick, const char *reason)
629     {
630 wingman 1.171 if (how == SHUTDOWN_SIGTERM)
631     putlog(LOG_MISC, "*", ("Received TERM signal, shutting down."));
632     else if (how != SHUTDOWN_RESTART)
633     putlog(LOG_MISC, "*", ("Shutdown requested by %s: %s"), nick,
634     (reason) ? reason : _("No reason"));
635 wingman 1.170
636 wingman 1.171 /* check how to shut down */
637 wingman 1.170 switch (how) {
638    
639 wingman 1.171 case (SHUTDOWN_RESTART):
640     runmode = RUNMODE_RESTART;
641     break;
642    
643 wingman 1.170 case (SHUTDOWN_GRACEFULL):
644 wingman 1.171 runmode = RUNMODE_SHUTDOWN;
645 wingman 1.170 break;
646    
647 wingman 1.171 /* These two cases are treaded special because something
648     * unusual happened and we're better off if we exit() NOW
649     * than doing a gracefull shutdown with freeing all
650     * memory, closing all sockets, ... */
651 wingman 1.170 case (SHUTDOWN_HARD):
652 wingman 1.171 case (SHUTDOWN_SIGTERM):
653     runmode = RUNMODE_SHUTDOWN;
654     core_shutdown_or_restart();
655 wingman 1.170 exit(0);
656     break;
657 wingman 1.171
658 wingman 1.170 }
659    
660     return BIND_RET_LOG;
661 segfault 1.1 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23