Go to the source code of this file.
Defines | |
#define | SHUTDOWN_GRACEFULL 0 |
#define | SHUTDOWN_HARD 1 |
#define | SHUTDOWN_RESTART 2 |
#define | SHUTDOWN_SIGTERM 3 |
Functions | |
void | fatal (const char *errmsg) |
int | core_init () |
int | core_restart (const char *nick) |
int | core_shutdown (int how, const char *nick, const char *reason) |
#define SHUTDOWN_GRACEFULL 0 |
#define SHUTDOWN_HARD 1 |
#define SHUTDOWN_RESTART 2 |
#define SHUTDOWN_SIGTERM 3 |
int core_init | ( | ) |
Definition at line 518 of file main.c.
References backgrd, bg_begin_split(), bg_finish_split(), core_config_t::botname, botnet_set_name(), check_bind_init(), config_exists(), config_get_root(), config_get_str(), config_root, configfile, core_binds_init(), core_config, core_config_init(), core_party_init(), create_userfile(), eggdrop_init(), fatal(), help_load_by_module(), core_config_t::help_path, help_set_default_path(), core_config_t::lockfile, LOG_ALL, logfile_init(), make_userfile, module_add_dir(), module_load(), core_config_t::module_path, now, NULL, putlog(), runmode, RUNMODE_RESTART, script_load(), terminal_init(), terminal_mode, user_load(), and core_config_t::userfile.
Referenced by main().
00519 { 00520 int i; 00521 char *name; 00522 void *config_root, *entry; 00523 char datetime[25]; 00524 static int lockfd = -1; 00525 struct flock lock; 00526 00527 /* init libeggdrop */ 00528 eggdrop_init(); 00529 00530 /* load config */ 00531 if (core_config_init(configfile) != 0) 00532 return (-1); 00533 00534 /* init logging */ 00535 logfile_init(); 00536 00537 /* did the user specify -m? */ 00538 if (make_userfile) { 00539 if (create_userfile()) return(-1); 00540 make_userfile = 0; 00541 } 00542 00543 /* init background mode and pid file */ 00544 if (runmode != RUNMODE_RESTART) { 00545 if (backgrd) bg_begin_split(); 00546 } 00547 00548 /* Check lock file. */ 00549 if (core_config.lockfile && lockfd == -1) { 00550 lockfd = open(core_config.lockfile, O_WRONLY | O_CREAT, S_IWUSR); 00551 if (lockfd < 0) { 00552 fatal("Could not open lock file!"); 00553 } 00554 memset(&lock, 0, sizeof(lock)); 00555 lock.l_type = F_WRLCK; 00556 if (fcntl(lockfd, F_SETLK, &lock) != 0) { 00557 fatal("Lock file is already locked! Is eggdrop already running?"); 00558 } 00559 } 00560 00561 /* just issue this "Loading Eggdrop" message if we are not 00562 * restarting */ 00563 if (runmode != RUNMODE_RESTART) { 00564 strlcpy(datetime, ctime(&now), sizeof(datetime)); 00565 strcpy(&datetime[11], &datetime[20]); 00566 putlog(LOG_ALL, "*", "Loading Eggdrop %s (%s)", VERSION, datetime); 00567 } 00568 00569 /* load userlist */ 00570 if (core_config.userfile) 00571 user_load(core_config.userfile); 00572 00573 /* init core bindings */ 00574 core_binds_init(); 00575 00576 /* init core partyline */ 00577 core_party_init(); 00578 00579 /* Load core help */ 00580 help_load_by_module ("core"); 00581 00582 /* Put the module directory in the ltdl search path. */ 00583 if (core_config.module_path) module_add_dir(core_config.module_path); 00584 00585 /* Set a botname. */ 00586 if (core_config.botname) botnet_set_name(core_config.botname); 00587 00588 /* Initialize help system. */ 00589 if (core_config.help_path) { 00590 help_set_default_path(core_config.help_path); 00591 /* Load all help files here... */ 00592 } 00593 00594 /* Scan the autoload section of config. */ 00595 config_root = config_get_root("eggdrop"); 00596 for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) { 00597 name = NULL; 00598 config_get_str(&name, entry, NULL); 00599 module_load(name); 00600 /* For now we'll just load these help files... */ 00601 help_load_by_module(name); 00602 } 00603 for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) { 00604 name = NULL; 00605 config_get_str(&name, entry, NULL); 00606 script_load(name); 00607 } 00608 00609 /* notify init listeners */ 00610 check_bind_init(); 00611 00612 /* start terminal */ 00613 if (runmode != RUNMODE_RESTART) { 00614 if (backgrd) bg_finish_split(); 00615 } 00616 if (terminal_mode) terminal_init(); 00617 00618 return (0); 00619 }
int core_restart | ( | const char * | nick | ) |
Definition at line 621 of file main.c.
References LOG_MISC, putlog(), runmode, and RUNMODE_RESTART.
Referenced by party_restart().
00622 { 00623 putlog(LOG_MISC, "*", "Restarting..."); 00624 runmode = RUNMODE_RESTART; 00625 return (0); 00626 }
int core_shutdown | ( | int | how, | |
const char * | nick, | |||
const char * | reason | |||
) |
Definition at line 628 of file main.c.
References _, BIND_RET_LOG, core_shutdown_or_restart(), LOG_MISC, putlog(), runmode, RUNMODE_RESTART, RUNMODE_SHUTDOWN, SHUTDOWN_GRACEFULL, SHUTDOWN_HARD, SHUTDOWN_RESTART, and SHUTDOWN_SIGTERM.
Referenced by got_term(), and party_die().
00629 { 00630 if (how == SHUTDOWN_SIGTERM) 00631 putlog(LOG_MISC, "*", ("Received TERM signal, shutting down.")); 00632 else if (how != SHUTDOWN_RESTART) 00633 putlog(LOG_MISC, "*", ("Shutdown requested by %s: %s"), nick, 00634 (reason) ? reason : _("No reason")); 00635 00636 /* check how to shut down */ 00637 switch (how) { 00638 00639 case (SHUTDOWN_RESTART): 00640 runmode = RUNMODE_RESTART; 00641 break; 00642 00643 case (SHUTDOWN_GRACEFULL): 00644 runmode = RUNMODE_SHUTDOWN; 00645 break; 00646 00647 /* These two cases are treaded special because something 00648 * unusual happened and we're better off if we exit() NOW 00649 * than doing a gracefull shutdown with freeing all 00650 * memory, closing all sockets, ... */ 00651 case (SHUTDOWN_HARD): 00652 case (SHUTDOWN_SIGTERM): 00653 runmode = RUNMODE_SHUTDOWN; 00654 core_shutdown_or_restart(); 00655 exit(0); 00656 break; 00657 00658 } 00659 00660 return BIND_RET_LOG; 00661 }
void fatal | ( | const char * | errmsg | ) |
Definition at line 82 of file main.c.
References flushlogs(), LOG_MISC, and putlog().
Referenced by bg_begin_split(), core_init(), got_bus(), got_fpe(), and got_segv().