/[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.189 - (hide annotations) (download) (as text)
Tue Nov 14 14:51:24 2006 UTC (12 years, 8 months ago) by sven
Branch: MAIN
Changes since 1.188: +4 -1 lines
File MIME type: text/x-chdr

Misc:
 * Bind table flag BIND_BREAKABLE now includes BIND_STACKABLE, doesn't make
   sense otherwise.
 * If the line buffer contains more than one line of text do a check if the
   index is still valid after every callback (the sockbuf might have been
   deleted).
 * Added a "Doxygen" file in the root dir. It will generate html output in
   doc/developer/html. (The dir will be created by doxygen.)

Partyline stuff:
 * Partychan join and quit functions have an extra parameter indicating if
   the event is triggered because of someone joining/quitting or botnet
   restructuring.
 * Renamed partychan_msg() to chan_msg and made it static. It can now either
   msg the whole channel or just everyone on the local bot on the channel.
 * New functions partychan_msg() (works like before) and localchan_msg() to
   send it to every local user of the chan.
 * Added stuff to the partymember struct: A pointer to the bot the user is
   on, a malloc'd string containing the full unique name in the form
   "id:nick@bot", a pointer into this string to the full name "nick@bot"
   and a pointer to the common name of the user, "nick" for local users and
   "nick@bot" for users on other bots.
 * The id of a partymember is no longer unique, only unique to the bot the
   user is on. The nick was never unique. TODO: Change the script modules
   to take care of that!
 * A partymember is now part of two double linked lists: A list of all
   partymembers and a list of all partymembers on the bot.
 * Removed the partymember_lookup_* functions. partymember_lookup() takes
   cares of all the stuff.
 * Added functions to count all users on a bot and delete all users on a bot.

Ircpartyline:
 * IRC requires nicks to be unique for everyone and useing the usual "@" in
   the "nick@bot" form doesn't work at all on IRC. Therefor the nick format
   is now: "nick*bot:id" for remote users and "nick:id" for local users.

Script stuff:
 * Added a new script parameter: 'B': A bot.
 * TODO: Change the script modules to use it!

Botnet stuff:
 * Added botnet.[ch]. Fully documented!
 * Changed the oldbotnet module to use the new botnet API. Only very basic
   stuff works atm: Bot links, unlinks, partymember joins, quits and chatter.
   But at least it doesn't matter any more if the bot is a leaf or a hub.

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23