error tags_search_init(void) { if (tags_search_refcount++ == 0) { error err; /* dependencies */ err = help_init(); if (err) return err; err = tags_common_init(); if (err) return err; LOCALS.tags_search_w = window_create("tags_search"); tags_search_set_handlers(1); err = help_add_window(LOCALS.tags_search_w, "tags_search"); if (err) return err; } return error_OK; }
static void init_commands(void) { attr_init(); bmap_init(); fadvise_init(); file_init(); freeze_init(); fsync_init(); getrusage_init(); help_init(); imap_init(); inject_init(); madvise_init(); mincore_init(); mmap_init(); open_init(); parent_init(); pread_init(); prealloc_init(); fiemap_init(); pwrite_init(); quit_init(); resblks_init(); sendfile_init(); shutdown_init(); truncate_init(); }
// Lua: res = help( [topic] ) static int elua_help( lua_State *L ) { const char *topic = NULL; if( lua_type( L, 1 ) == LUA_TSTRING ) topic = luaL_checkstring( L, 1 ); help_init( HELP_FILE_NAME ); term_set_mode( TERM_MODE_COLS ); term_enable_paging( TERM_PAGING_ON ); help_help( topic ); term_set_mode( TERM_MODE_ASCII ); term_enable_paging( TERM_PAGING_OFF ); help_close(); return 0; }
void help(char *command) { if(!command) help_ls(); else if(!strcmp(command, "help" )) help_help(); else if(!strcmp(command, "prompt" )) help_prompt(); else if(!strcmp(command, "init" )) help_init(); else if(!strcmp(command, "drop" )) help_drop(); else if(!strcmp(command, "create-service")) help_create_service(); else if(!strcmp(command, "list" )) help_list(); else if(!strcmp(command, "switch" )) help_switch(); else if(!strcmp(command, "back" )) help_back(); else if(!strcmp(command, "book" )) help_book(); else if(!strcmp(command, "service" )) help_service(); else if(!strcmp(command, "bill" )) help_bill(); else if(!strcmp(command, "checkout" )) help_checkout(); else error_print("Unknown command!"); }
error rotate_init(void) { error err; /* dependencies */ err = help_init(); if (err) return err; LOCALS.rotate_w = window_create("rotate"); rotate_set_handlers(1); err = help_add_window(LOCALS.rotate_w, "rotate"); if (err) return err; return error_OK; }
int main(int argc, char **argv) { int readonly = 0; int growable = 0; const char *sopt = "hVc:d:rsnmgkt:T:"; const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "offset", 1, NULL, 'o' }, { "cmd", 1, NULL, 'c' }, { "read-only", 0, NULL, 'r' }, { "snapshot", 0, NULL, 's' }, { "nocache", 0, NULL, 'n' }, { "misalign", 0, NULL, 'm' }, { "growable", 0, NULL, 'g' }, { "native-aio", 0, NULL, 'k' }, { "discard", 1, NULL, 'd' }, { "cache", 1, NULL, 't' }, { "trace", 1, NULL, 'T' }, { NULL, 0, NULL, 0 } }; int c; int opt_index = 0; int flags = BDRV_O_UNMAP; progname = basename(argv[0]); while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); exit(1); } break; case 'c': add_user_command(optarg); break; case 'r': readonly = 1; break; case 'm': misalign = 1; break; case 'g': growable = 1; break; case 'k': flags |= BDRV_O_NATIVE_AIO; break; case 't': if (bdrv_parse_cache_flags(optarg, &flags) < 0) { error_report("Invalid cache option: %s", optarg); exit(1); } break; case 'T': if (!trace_backend_init(optarg, NULL)) { exit(1); /* error message will have been printed */ } break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); case 'h': usage(progname); exit(0); default: usage(progname); exit(1); } } if ((argc - optind) > 1) { usage(progname); exit(1); } qemu_init_main_loop(); bdrv_init(); /* initialize commands */ quit_init(); help_init(); add_command(&open_cmd); add_command(&close_cmd); add_command(&read_cmd); add_command(&readv_cmd); add_command(&write_cmd); add_command(&writev_cmd); add_command(&multiwrite_cmd); add_command(&aio_read_cmd); add_command(&aio_write_cmd); add_command(&aio_flush_cmd); add_command(&flush_cmd); add_command(&truncate_cmd); add_command(&length_cmd); add_command(&info_cmd); add_command(&discard_cmd); add_command(&alloc_cmd); add_command(&map_cmd); add_command(&break_cmd); add_command(&resume_cmd); add_command(&wait_break_cmd); add_command(&abort_cmd); add_args_command(init_args_command); add_check_command(init_check_command); /* open the device */ if (!readonly) { flags |= BDRV_O_RDWR; } if ((argc - optind) == 1) { openfile(argv[optind], flags, growable); } command_loop(); /* * Make sure all outstanding requests complete before the program exits. */ bdrv_drain_all(); if (bs) { bdrv_delete(bs); } return 0; }
int main(int argc, char **argv) { int readonly = 0; int growable = 0; const char *sopt = "hVc:rsnmgk"; const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "offset", 1, NULL, 'o' }, { "cmd", 1, NULL, 'c' }, { "read-only", 0, NULL, 'r' }, { "snapshot", 0, NULL, 's' }, { "nocache", 0, NULL, 'n' }, { "misalign", 0, NULL, 'm' }, { "growable", 0, NULL, 'g' }, { "native-aio", 0, NULL, 'k' }, { NULL, 0, NULL, 0 } }; int c; int opt_index = 0; int flags = 0; progname = basename(argv[0]); while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE; break; case 'c': add_user_command(optarg); break; case 'r': readonly = 1; break; case 'm': misalign = 1; break; case 'g': growable = 1; break; case 'k': flags |= BDRV_O_NATIVE_AIO; break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); case 'h': usage(progname); exit(0); default: usage(progname); exit(1); } } if ((argc - optind) > 1) { usage(progname); exit(1); } bdrv_init(); /* initialize commands */ quit_init(); help_init(); add_command(&open_cmd); add_command(&close_cmd); add_command(&read_cmd); add_command(&readv_cmd); add_command(&write_cmd); add_command(&writev_cmd); add_command(&multiwrite_cmd); add_command(&aio_read_cmd); add_command(&aio_write_cmd); add_command(&aio_flush_cmd); add_command(&flush_cmd); add_command(&truncate_cmd); add_command(&length_cmd); add_command(&info_cmd); add_command(&alloc_cmd); add_args_command(init_args_command); add_check_command(init_check_command); /* open the device */ if (!readonly) { flags |= BDRV_O_RDWR; } if ((argc - optind) == 1) openfile(argv[optind], flags, growable); command_loop(); /* * Make sure all outstanding requests get flushed the program exits. */ qemu_aio_flush(); if (bs) bdrv_close(bs); return 0; }
int main(int argc, char *argv[]) { FILE *fp; #if USING_DMALLOC dmalloc_debug(1); #endif /* start the clock (which is used by the Logit fnc) */ (void) refetch_ticker(); GetArgs(argc, argv); if (conf_file_read(confname)) { Logit("Failed to read config file \"%s\"", confname); strcpy(confname, "./nngs.cnf"); conf_file_write(confname); Logit("Created \"%s\"", confname); } Logit("Starting %s (%s %s) From: %s" , conffile.version_string, conffile.compile_date, conffile.compile_time, confname); if (daemonise()) { Logit("Failed to daemonise, giving up"); main_exit(1); } conf_file_write("written.cnf"); signal(SIGTERM, TerminateServer); signal(SIGINT, TerminateServer); #if 0 signal(SIGPIPE, SIG_IGN); #else signal(SIGPIPE, BrokenPipe); #endif signal(SIGCHLD, reapchild); mink_init(); startuptime = time(NULL); srand(startuptime); read_ban_ip_list(); if (!all_the_internets() ) { fprintf(stderr, "Network initialize failed on ports %s.\n" , conffile.server_ports); main_exit(1); } player_high = 0; game_high = 0; bytes_sent = 0; bytes_received = 0; #ifdef SGI /*mallopt(100, 1);*/ /* Turn on malloc(3X) debugging (Irix only) */ #endif command_init(); EmoteInit(conffile.emotes_file); help_init(); /*Logit("commands_init()");*/ commands_init(); /*Logit("channel_init()");*/ channel_init(); /*Logit("player_array_init()");*/ player_array_init(); player_init(); ladder_init(NUM_LADDERS); Ladder9 = ladder_new(LADDERSIZE); Ladder19 = ladder_new(LADDERSIZE); completed_games = 0; num_logins = num_logouts = new_players = 0; num_9 = 0; fp = xyfopen(FILENAME_LADDER9, "r"); if (fp) { num_9 = ladder_load(fp, Ladder9); Logit("%d players loaded from file %s", num_9, filename() ); fclose(fp); } num_19 = 0; fp = xyfopen(FILENAME_LADDER19, "r"); if (fp) { num_19 = ladder_load(fp, Ladder19); Logit("%d players loaded from file %s", num_19, filename() ); fclose(fp); } /* mink_init();*/ if (conffile.admin_name) create_admin_account(conffile.admin_name ); Logit("Server up and running."); main_event_loop(); Logit("Closing down."); net_closeAll(); main_exit(0); return 0; }
int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) { int i, n; char *name; u_char func, *kp; u_short *p_keys, val; if (letter_offsets[0] == -1) help_init(); if (type == KT_LATIN) { if (ch == SPACE) { spk_special_handler = NULL; synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP)); return 1; } ch |= 32; /* lower case */ if (ch < 'a' || ch > 'z') return -1; if (letter_offsets[ch - 'a'] == -1) { synth_printf(spk_msg_get(MSG_NO_COMMAND), ch); synth_printf("\n"); return 1; } cur_item = letter_offsets[ch - 'a']; } else if (type == KT_CUR) { if (ch == 0 && (MSG_FUNCNAMES_START + cur_item + 1) <= MSG_FUNCNAMES_END) cur_item++; else if (ch == 3 && cur_item > 0) cur_item--; else return -1; } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && !spk_special_handler) { spk_special_handler = spk_handle_help; synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO)); build_key_data(); /* rebuild each time in case new mapping */ return 1; } else { name = NULL; if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) { synth_printf("%s\n", spk_msg_get(MSG_KEYNAMES_START + key - 1)); return 1; } for (i = 0; funcvals[i] != 0 && !name; i++) { if (ch == funcvals[i]) name = spk_msg_get(MSG_FUNCNAMES_START + i); } if (!name) return -1; kp = spk_our_keys[key] + 1; for (i = 0; i < nstates; i++) { if (ch == kp[i]) break; } key += (state_tbl[i] << 8); say_key(key); synth_printf(spk_msg_get(MSG_KEYDESC), name); synth_printf("\n"); return 1; } name = spk_msg_get(MSG_FUNCNAMES_START + cur_item); func = funcvals[cur_item]; synth_printf("%s", name); if (key_offsets[func] == 0) { synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED)); return 1; } p_keys = key_data + key_offsets[func]; for (n = 0; p_keys[n]; n++) { val = p_keys[n]; if (n > 0) synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION)); say_key(val); } return 1; }
#include <stdlib.h> #include <glib.h> #include <gmodule.h> #include <check.h> #include <string.h> #include <stdio.h> #include "help.h" START_TEST(test_help_initfree) help_t * h, *r; r = help_init(&h, "/dev/null"); fail_if(r == NULL); fail_if(r != h); help_free(&h); fail_if(h != NULL); END_TEST START_TEST(test_help_nonexistent) help_t * h, *r; r = help_init(&h, "/dev/null"); fail_unless(help_get(&h, "nonexistent") == NULL); fail_if(r == NULL); END_TEST Suite *help_suite(void) { Suite *s = suite_create("Help"); TCase *tc_core = tcase_create("Core"); suite_add_tcase(s, tc_core);
/* Our main help-viewer function. */ void do_help(void) { int kbinput = ERR; bool old_no_help = ISSET(NO_HELP); size_t line = 0; /* The line number in help_text of the first displayed help * line. This variable is zero-based. */ size_t last_line = 0; /* The line number in help_text of the last help line. This * variable is zero-based. */ int oldmenu = currmenu; /* The menu we were called from. */ const char *ptr; /* The current line of the help text. */ size_t old_line = (size_t)-1; /* The line we were on before the current line. */ functionptrtype func; /* The function of the key the user typed in. */ /* Don't show a cursor in the help screen. */ curs_set(0); blank_edit(); blank_statusbar(); /* Set help_text as the string to display. */ help_init(); assert(help_text != NULL); if (ISSET(NO_HELP)) { /* Make sure that the help screen's shortcut list will actually * be displayed. */ UNSET(NO_HELP); window_init(); } bottombars(MHELP); wnoutrefresh(bottomwin); while (TRUE) { size_t i; ptr = help_text; /* Find the line number of the last line of the help text. */ for (last_line = 0; *ptr != '\0'; last_line++) { ptr += help_line_len(ptr); if (*ptr == '\n') ptr++; } if (last_line > 0) last_line--; /* Redisplay if the text was scrolled or an invalid key was pressed. */ if (line != old_line || kbinput == ERR) { blank_edit(); ptr = help_text; /* Advance in the text to the first line to be displayed. */ for (i = 0; i < line; i++) { ptr += help_line_len(ptr); if (*ptr == '\n') ptr++; } /* Now display as many lines as the window will hold. */ for (i = 0; i < editwinrows && *ptr != '\0'; i++) { size_t j = help_line_len(ptr); mvwaddnstr(edit, i, 0, ptr, j); ptr += j; if (*ptr == '\n') ptr++; } } wnoutrefresh(edit); old_line = line; lastmessage = HUSH; kbinput = get_kbinput(edit); #ifndef NANO_TINY if (kbinput == KEY_WINCH) { kbinput = ERR; continue; /* Redraw the screen. */ } #endif #ifndef DISABLE_MOUSE if (kbinput == KEY_MOUSE) { int mouse_x, mouse_y; get_mouseinput(&mouse_x, &mouse_y, TRUE); continue; /* Redraw the screen. */ } #endif func = parse_help_input(&kbinput); if (func == total_refresh) { total_redraw(); } else if (func == do_up_void) { if (line > 0) line--; } else if (func == do_down_void) { if (line + (editwinrows - 1) < last_line) line++; } else if (func == do_page_up) { if (line > editwinrows - 2) line -= editwinrows - 2; else line = 0; } else if (func == do_page_down) { if (line + (editwinrows - 1) < last_line) line += editwinrows - 2; } else if (func == do_first_line) { line = 0; } else if (func == do_last_line) { if (line + (editwinrows - 1) < last_line) line = last_line - (editwinrows - 1); } else if (func == do_exit) { /* Exit from the help viewer. */ break; } else unbound_key(kbinput); } if (old_no_help) { blank_bottombars(); wnoutrefresh(bottomwin); currmenu = oldmenu; SET(NO_HELP); window_init(); } else bottombars(oldmenu); #ifndef DISABLE_BROWSER if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR) browser_refresh(); else #endif edit_refresh(); /* We're exiting from the help screen. */ free(help_text); }
int main(int argc, char **argv) { int xx, i; #ifdef STOP_UAC int nvpair[2]; #endif char buf[520], s[25]; FILE *f; #ifndef ENABLE_STRIP struct rlimit cdlim; #endif /* Don't allow Eggdrop to run as root. */ if (((int) getuid() == 0) || ((int) geteuid() == 0)) fatal("ERROR: Eggdrop will not run as root!", 0); #ifndef ENABLE_STRIP cdlim.rlim_cur = RLIM_INFINITY; cdlim.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &cdlim); #endif #include "patch.h" /* Version info! */ egg_snprintf(ver, sizeof ver, "eggdrop v%s", egg_version); egg_snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2005 Eggheads", egg_version); /* Now add on the patchlevel (for Tcl) */ sprintf(&egg_version[strlen(egg_version)], " %u", egg_numver); strcat(egg_version, egg_xtra); #ifdef STOP_UAC nvpair[0] = SSIN_UACPROC; nvpair[1] = UAC_NOPRINT; setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0); #endif /* Set up error / signal traps. */ setup_signal_traps(); /* Initialize a few variables before main loop. */ cache_miss = 0; cache_hit = 0; chanset = NULL; now = time(NULL); egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm)); lastmin = nowtm.tm_min; /* Initialize random number generator. */ srandom((unsigned int) (now % (getpid() + getppid()))); init_mem(); init_language(1); /* Process command line arguments. */ process_args(argc, argv); printf("\n%s\n", version); init_dcc_max(); init_userent(); logfile_init(0); init_bots(); init_net(); init_modules(); if (backgrd) bg_prepare_split(); init_tcl(argc, argv); init_language(0); help_init(); traffic_init(); logfile_init(1); #ifdef STATIC link_statics(); #endif strncpyz(s, ctime(&now), sizeof s); strcpy(&s[11], &s[20]); putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s); /* Read configuration data. */ readconfig(); /* Check for encryption module. */ if (!encrypt_pass) { printf(MOD_NOCRYPT); bg_send_quit(BG_ABORT); exit(1); } putlog(LOG_MISC, "*", "=== %s: %d channels, %d users.", botnetnick, count_channels(), count_users(userlist)); if (!pid_file[0]) egg_snprintf(pid_file, sizeof pid_file, "pid.%s", botnetnick); /* Check for pre-existing eggdrop! */ f = fopen(pid_file, "r"); if (f != NULL) { fgets(s, 10, f); xx = atoi(s); kill(xx, SIGCHLD); /* Meaningless kill to determine if PID is used. */ if (errno != ESRCH) { printf(EGG_RUNNING1, botnetnick); printf(EGG_RUNNING2, pid_file); bg_send_quit(BG_ABORT); exit(1); } } /* Move into background? */ if (backgrd) { #ifndef CYGWIN_HACKS bg_do_split(); } else { #endif xx = getpid(); if (xx != 0) { FILE *fp; /* Write PID to file. */ unlink(pid_file); fp = fopen(pid_file, "w"); if (fp != NULL) { fprintf(fp, "%u\n", xx); if (fflush(fp)) { /* Let the bot live since this doesn't appear to be a botchk. */ printf("Cannot not write to '%s' (PID file).\n", pid_file); fclose(fp); unlink(pid_file); } else fclose(fp); } else printf("Cannot not write to '%s' (PID file).\n", pid_file); #ifdef CYGWIN_HACKS printf("Launched into the background (PID: %d)\n\n", xx); #endif } } use_stderr = 0; /* Stop writing to stderr now */ if (backgrd) { /* Ok, try to disassociate from controlling terminal (finger cross) */ #if defined(HAVE_SETPGID) && !defined(CYGWIN_HACKS) setpgid(0, 0); #endif /* Tcl wants the stdin, stdout and stderr file handles kept open. */ freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); #ifdef CYGWIN_HACKS FreeConsole(); #endif } /* Terminal emulating dcc chat */ if (!backgrd && term_z) { int n = new_dcc(&DCC_CHAT, sizeof(struct chat_info)); dcc[n].addr = iptolong(getmyip()); dcc[n].sock = STDOUT; dcc[n].timeval = now; dcc[n].u.chat->con_flags = conmask; dcc[n].u.chat->strip_flags = STRIP_ALL; dcc[n].status = STAT_ECHO; strcpy(dcc[n].nick, "HQ"); strcpy(dcc[n].host, "llama@console"); /* HACK: Workaround not to pass literal "HQ" as a non-const arg */ dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); /* Make sure there's an innocuous HQ user if needed */ if (!dcc[n].user) { userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_PARTY); dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); } setsock(STDOUT, 0); /* Entry in net table */ dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n"); dcc_chatter(n); } then = now; online_since = now; autolink_cycle(NULL); /* Hurry and connect to tandem bots. */ add_help_reference("cmds1.help"); add_help_reference("cmds2.help"); add_help_reference("core.help"); /* Create hooks. */ add_hook(HOOK_SECONDLY, (Function) core_secondly); add_hook(HOOK_MINUTELY, (Function) core_minutely); add_hook(HOOK_HOURLY, (Function) core_hourly); add_hook(HOOK_REHASH, (Function) event_rehash); add_hook(HOOK_PRE_REHASH, (Function) event_prerehash); add_hook(HOOK_USERFILE, (Function) event_save); add_hook(HOOK_BACKUP, (Function) backupuserfile); add_hook(HOOK_DAILY, (Function) event_logfile); add_hook(HOOK_DAILY, (Function) traffic_reset); add_hook(HOOK_LOADED, (Function) event_loaded); call_hook(HOOK_LOADED); debug0("main: entering loop"); while (1) { int socket_cleanup = 0; #ifdef USE_TCL_EVENTS /* Process a single Tcl event. */ Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT); #endif now = time(NULL); random(); /* Every second... */ if (now != then) { call_hook(HOOK_SECONDLY); then = now; } /* Only do this every so often. */ if (!socket_cleanup) { socket_cleanup = 5; /* Remove dead dcc entries. */ dcc_remove_lost(); /* Check for server or dcc activity. */ dequeue_sockets(); } else { socket_cleanup--; } /* Free unused structures. */ garbage_collect(); xx = sockgets(buf, &i); if (xx >= 0) { /* Non-error */ int idx; for (idx = 0; idx < dcc_total; idx++) { if (dcc[idx].sock != xx) continue; if (dcc[idx].type && dcc[idx].type->activity) { traffic_update_in(dcc[idx].type, (strlen(buf) + 1)); /* Traffic stats. */ dcc[idx].type->activity(idx, buf, i); } else { putlog(LOG_MISC, "*", "!!! untrapped dcc activity: type %s, sock %d", dcc[idx].type->name, dcc[idx].sock); } break; } } else if (xx == -1) { /* EOF */ int idx; if (i == STDOUT && !backgrd) fatal("END OF FILE ON TERMINAL", 0); for (idx = 0; idx < dcc_total; idx++) { if (dcc[idx].sock != i) continue; if (dcc[idx].type && dcc[idx].type->eof) { dcc[idx].type->eof(idx); } else { putlog(LOG_MISC, "*", "*** ATTENTION: DEAD SOCKET (%d) OF TYPE %s UNTRAPPED", i, dcc[idx].type ? dcc[idx].type->name : "*UNKNOWN*"); killsock(i); lostdcc(idx); } idx = dcc_total + 1; } if (idx == dcc_total) { putlog(LOG_MISC, "*", "(@) EOF socket %d, not a dcc socket, not anything.", i); close(i); killsock(i); } } else if (xx == -2 && errno != EINTR) { /* select() error */ putlog(LOG_MISC, "*", "* Socket error #%d; recovering.", errno); for (i = 0; i < dcc_total; i++) { if ((fcntl(dcc[i].sock, F_GETFD, 0) == -1) && (errno == EBADF)) { putlog(LOG_MISC, "*", "DCC socket %d (type %d, name '%s') expired -- pfft", dcc[i].sock, dcc[i].type, dcc[i].nick); killsock(dcc[i].sock); lostdcc(i); i--; } } } else if (xx == -3) { call_hook(HOOK_IDLE); socket_cleanup = 0; /* If we've been idle, cleanup & flush */ } if (do_restart) { if (do_restart == -2) { rehash(); } else { int f = 1; module_entry *p; Function startfunc; char name[256]; check_tcl_event("prerestart"); /* Unload as many modules as possible */ while (f) { f = 0; for (p = module_list; p != NULL; p = p->next) { dependancy *d = dependancy_list; int ok = 1; while (ok && d) { if (d->needed == p) ok = 0; d = d->next; } if (ok) { strcpy(name, p->name); if (module_unload(name, botnetnick) == NULL) { f = 1; break; } } } } /* Make sure we don't have any modules left hanging around other than * "eggdrop" and the two that are supposed to be. */ for (f = 0, p = module_list; p; p = p->next) { if (strcmp(p->name, "eggdrop") && strcmp(p->name, "encryption") && strcmp(p->name, "uptime")) { f++; } } if (f != 0) { putlog(LOG_MISC, "*", MOD_STAGNANT); } /* Flush log files to disk. */ flushlogs(); /* Clean up Tcl stuff. */ kill_tcl(); /* Initialize stuff again. */ init_tcl(argc, argv); init_language(0); help_init(); traffic_init(); logfile_init(1); /* This resets our modules which we didn't unload (encryption and uptime). */ for (p = module_list; p; p = p->next) { if (p->funcs) { startfunc = p->funcs[MODCALL_START]; startfunc(NULL); } } rehash(); restart_chons(); call_hook(HOOK_LOADED); } do_restart = 0; } } }
void Commands::init() { help_init(); }
int main( int argc, char *argv[] ) { int i = 0; char *old_cwd = NULL; struct sigaction sig, old; /* Required to make iconv to ASCII//TRANSLIT work. This makes BitlBee system-locale-sensitive. :-( */ setlocale( LC_CTYPE, "" ); if( argc > 1 && strcmp( argv[1], "-x" ) == 0 ) return crypt_main( argc, argv ); log_init(); global.conf_file = g_strdup( CONF_FILE_DEF ); global.conf = conf_load( argc, argv ); if( global.conf == NULL ) return( 1 ); b_main_init(); /* libpurple doesn't like fork()s after initializing itself, so if we use it, do this init a little later (in case we're running in ForkDaemon mode). */ #ifndef WITH_PURPLE nogaim_init(); #endif /* Ugly Note: libotr and gnutls both use libgcrypt. libgcrypt has a process-global config state whose initialization happpens twice if libotr and gnutls are used together. libotr installs custom memory management functions for libgcrypt while our gnutls module uses the defaults. Therefore we initialize OTR after SSL. *sigh* */ ssl_init(); #ifdef OTR_BI otr_init(); #endif /* And in case OTR is loaded as a plugin, it'll also get loaded after this point. */ srand( time( NULL ) ^ getpid() ); global.helpfile = g_strdup( HELP_FILE ); if( help_init( &global.help, global.helpfile ) == NULL ) log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage ); if( global.storage == NULL ) { log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); return( 1 ); } if( global.conf->runmode == RUNMODE_INETD ) { log_link( LOGLVL_ERROR, LOGOUTPUT_IRC ); log_link( LOGLVL_WARNING, LOGOUTPUT_IRC ); i = bitlbee_inetd_init(); log_message( LOGLVL_INFO, "%s %s starting in inetd mode.", PACKAGE, BITLBEE_VERSION ); } else if( global.conf->runmode == RUNMODE_DAEMON ) { log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE ); i = bitlbee_daemon_init(); log_message( LOGLVL_INFO, "%s %s starting in daemon mode.", PACKAGE, BITLBEE_VERSION ); } else if( global.conf->runmode == RUNMODE_FORKDAEMON ) { log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE ); /* In case the operator requests a restart, we need this. */ old_cwd = g_malloc( 256 ); if( getcwd( old_cwd, 255 ) == NULL ) { log_message( LOGLVL_WARNING, "Could not save current directory: %s", strerror( errno ) ); g_free( old_cwd ); old_cwd = NULL; } i = bitlbee_daemon_init(); log_message( LOGLVL_INFO, "%s %s starting in forking daemon mode.", PACKAGE, BITLBEE_VERSION ); } if( i != 0 ) return( i ); if( ( global.conf->user && *global.conf->user ) && ( global.conf->runmode == RUNMODE_DAEMON || global.conf->runmode == RUNMODE_FORKDAEMON ) && ( !getuid() || !geteuid() ) ) { struct passwd *pw = NULL; pw = getpwnam( global.conf->user ); if( pw ) { initgroups( global.conf->user, pw->pw_gid ); setgid( pw->pw_gid ); setuid( pw->pw_uid ); } else { log_message( LOGLVL_WARNING, "Failed to look up user %s.", global.conf->user ); } } /* Catch some signals to tell the user what's happening before quitting */ memset( &sig, 0, sizeof( sig ) ); sig.sa_handler = sighandler; sigaction( SIGCHLD, &sig, &old ); sigaction( SIGPIPE, &sig, &old ); sig.sa_flags = SA_RESETHAND; sigaction( SIGINT, &sig, &old ); sigaction( SIGILL, &sig, &old ); sigaction( SIGBUS, &sig, &old ); sigaction( SIGFPE, &sig, &old ); sigaction( SIGSEGV, &sig, &old ); sigaction( SIGTERM, &sig, &old ); sigaction( SIGQUIT, &sig, &old ); sigaction( SIGXCPU, &sig, &old ); if( !getuid() || !geteuid() ) log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); b_main_run(); /* Mainly good for restarting, to make sure we close the help.txt fd. */ help_free( &global.help ); if( global.restart ) { char *fn = ipc_master_save_state(); char *env; env = g_strdup_printf( "_BITLBEE_RESTART_STATE=%s", fn ); putenv( env ); g_free( fn ); /* Looks like env should *not* be freed here as putenv doesn't make a copy. Odd. */ i = chdir( old_cwd ); close( global.listen_socket ); if( execv( argv[0], argv ) == -1 ) /* Apparently the execve() failed, so let's just jump back into our own/current main(). */ /* Need more cleanup code to make this work. */ return 1; /* main( argc, argv ); */ } return( 0 ); }