void weechat_create_home_dir () { char *ptr_weechat_home, *config_weechat_home; struct stat statinfo; /* * weechat_home is not set yet: look for environment variable * "WEECHAT_HOME" */ if (!weechat_home) { ptr_weechat_home = getenv ("WEECHAT_HOME"); if (ptr_weechat_home && ptr_weechat_home[0]) weechat_set_home_path (ptr_weechat_home); } /* weechat_home is still not set: try to use compile time default */ if (!weechat_home) { config_weechat_home = WEECHAT_HOME; if (!config_weechat_home[0]) { string_fprintf (stderr, _("Error: WEECHAT_HOME is undefined, check build " "options\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } weechat_set_home_path (config_weechat_home); } /* if home already exists, it has to be a directory */ if (stat (weechat_home, &statinfo) == 0) { if (!S_ISDIR (statinfo.st_mode)) { string_fprintf (stderr, _("Error: home (%s) is not a directory\n"), weechat_home); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } } /* create home directory; error is fatal */ if (!util_mkdir (weechat_home, 0755)) { string_fprintf (stderr, _("Error: cannot create directory \"%s\"\n"), weechat_home); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_startup_message (); /* display WeeChat startup message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warning about wrong $TERM */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_force_plugin_autoload, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
void debug_sigsegv () { debug_dump (1); unhook_all (); gui_main_end (0); string_iconv_fprintf ( stderr, "\n" "*** Very bad! WeeChat is crashing (SIGSEGV received)\n"); if (!log_crash_rename ()) { string_iconv_fprintf ( stderr, "*** Full crash dump was saved to %s/weechat.log file.\n", weechat_home); } string_iconv_fprintf ( stderr, "***\n" "*** Please help WeeChat developers to fix this bug:\n" "*** 1. If you have a core file, please run: gdb /path/to/weechat core\n" "*** then issue command: \"bt full\" and send result to developers\n" "*** (see user's guide for more info about report of crashes).\n" "*** 2. Otherwise send backtrace (below), only if it is a complete trace.\n" "*** Keep the crash log file, just in case developers ask you some info\n" "*** (be careful, private info like passwords may be in this file).\n\n"); weechat_backtrace (); /* shutdown with error code */ weechat_shutdown (EXIT_FAILURE, 1); }
void debug_sigsegv () { debug_dump (1); unhook_all (); gui_main_end (0); string_iconv_fprintf (stderr, "\n"); string_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n"); if (!log_crash_rename ()) string_iconv_fprintf (stderr, "*** Full crash dump was saved to %s/weechat.log file.\n", weechat_home); string_iconv_fprintf (stderr, "***\n"); string_iconv_fprintf (stderr, "*** Please help WeeChat developers to fix this bug:\n"); string_iconv_fprintf (stderr, "*** 1. If you have a core file, please run: gdb weechat-curses core\n"); string_iconv_fprintf (stderr, "*** then issue \"bt\" command and send result to developers\n"); string_iconv_fprintf (stderr, "*** To enable core files with bash shell: ulimit -c 10000\n"); string_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n"); string_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n"); string_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n"); weechat_backtrace (); /* shutdown with error code */ weechat_shutdown (EXIT_FAILURE, 1); }
void weechat_set_home_path (char *home_path) { char *ptr_home; int dir_length; if (home_path[0] == '~') { /* replace leading '~' by $HOME */ ptr_home = getenv ("HOME"); if (!ptr_home) { string_fprintf (stderr, _("Error: unable to get HOME directory\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } dir_length = strlen (ptr_home) + strlen (home_path + 1) + 1; weechat_home = malloc (dir_length); if (weechat_home) { snprintf (weechat_home, dir_length, "%s%s", ptr_home, home_path + 1); } } else { weechat_home = strdup (home_path); } if (!weechat_home) { string_fprintf (stderr, _("Error: not enough memory for home directory\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } }
void weechat_end (void (*gui_end_cb)(int clean_exit)) { gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ if (gui_end_cb) (*gui_end_cb) (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (-1, 0); /* end other things */ }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); weechat_locale_ok = (setlocale (LC_ALL, "") != NULL); /* init gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGQUIT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warnings about $TERM (if wrong) */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
void weechat_create_home_dir () { char *ptr_home, *config_weechat_home = WEECHAT_HOME; int dir_length; struct stat statinfo; if (!weechat_home) { if (strlen (config_weechat_home) == 0) { string_iconv_fprintf (stderr, _("Error: WEECHAT_HOME is undefined, check " "build options\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } if (config_weechat_home[0] == '~') { /* replace leading '~' by $HOME */ ptr_home = getenv ("HOME"); if (!ptr_home) { string_iconv_fprintf (stderr, _("Error: unable to get HOME directory\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } dir_length = strlen (ptr_home) + strlen (config_weechat_home + 1) + 1; weechat_home = malloc (dir_length); if (weechat_home) { snprintf (weechat_home, dir_length, "%s%s", ptr_home, config_weechat_home + 1); } } else { weechat_home = strdup (config_weechat_home); } if (!weechat_home) { string_iconv_fprintf (stderr, _("Error: not enough memory for home " "directory\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } } /* if home already exists, it has to be a directory */ if (stat (weechat_home, &statinfo) == 0) { if (!S_ISDIR (statinfo.st_mode)) { string_iconv_fprintf (stderr, _("Error: home (%s) is not a directory\n"), weechat_home); weechat_shutdown (EXIT_FAILURE, 0); } } /* create home directory; error is fatal */ if (!util_mkdir (weechat_home, 0755)) { string_iconv_fprintf (stderr, _("Error: cannot create directory \"%s\"\n"), weechat_home); weechat_shutdown (EXIT_FAILURE, 0); } }
void weechat_parse_args (int argc, char *argv[]) { int i; weechat_argv0 = (argv && argv[0]) ? strdup (argv[0]) : NULL; weechat_upgrading = 0; weechat_home = NULL; weechat_server_cmd_line = 0; weechat_auto_load_plugins = 1; weechat_plugin_no_dlclose = 0; for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-c") == 0) || (strcmp (argv[i], "--colors") == 0)) { gui_color_display_terminal_colors (); weechat_shutdown (EXIT_SUCCESS, 0); } else if ((strcmp (argv[i], "-d") == 0) || (strcmp (argv[i], "--dir") == 0)) { if (i + 1 < argc) weechat_home = strdup (argv[++i]); else { string_iconv_fprintf (stderr, _("Error: missing argument for \"%s\" " "option\n"), argv[i]); weechat_shutdown (EXIT_FAILURE, 0); } } else if ((strcmp (argv[i], "-h") == 0) || (strcmp (argv[i], "--help") == 0)) { weechat_display_usage (argv[0]); weechat_shutdown (EXIT_SUCCESS, 0); } else if ((strcmp (argv[i], "-l") == 0) || (strcmp (argv[i], "--license") == 0)) { weechat_display_copyright (); string_iconv_fprintf (stdout, "\n"); string_iconv_fprintf (stdout, "%s%s", WEECHAT_LICENSE_TEXT); weechat_shutdown (EXIT_SUCCESS, 0); } else if (strcmp (argv[i], "--no-dlclose") == 0) { /* * Valgrind works better when dlclose() is not done after plugins * are unloaded, it can display stack for plugins,* otherwise * you'll see "???" in stack for functions of unloaded plugins. * This option disables the call to dlclose(), * it must NOT be used for other purposes! */ weechat_plugin_no_dlclose = 1; } else if (strcmp (argv[i], "--no-gnutls") == 0) { /* * Electric-fence is not working fine when gnutls loads * certificates and Valgrind reports many memory errors with gnutls. * This option disables the init/deinit of gnutls, * it must NOT be used for other purposes! */ weechat_no_gnutls = 1; } else if (strcmp (argv[i], "--no-gcrypt") == 0) { /* * Valgrind reports many memory errors with gcrypt. * This option disables the init/deinit of gcrypt, * it must NOT be used for other purposes! */ weechat_no_gcrypt = 1; } else if ((strcmp (argv[i], "-p") == 0) || (strcmp (argv[i], "--no-plugin") == 0)) { weechat_auto_load_plugins = 0; } else if ((strcmp (argv[i], "-r") == 0) || (strcmp (argv[i], "--run-command") == 0)) { if (i + 1 < argc) weechat_startup_commands = strdup (argv[++i]); else { string_iconv_fprintf (stderr, _("Error: missing argument for \"%s\" " "option\n"), argv[i]); weechat_shutdown (EXIT_FAILURE, 0); } } else if (strcmp (argv[i], "--upgrade") == 0) { weechat_upgrading = 1; } else if ((strcmp (argv[i], "-v") == 0) || (strcmp (argv[i], "--version") == 0)) { string_iconv_fprintf (stdout, version_get_version ()); fprintf (stdout, "\n"); weechat_shutdown (EXIT_SUCCESS, 0); } } }
int main (int argc, char *argv[]) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); util_catch_signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */ util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump for SIGSEGV signal */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_main_pre_init (&argc, &argv); /* pre-initialize interface */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ gui_main_init (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ gui_main_loop (); /* WeeChat main loop */ gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ gui_main_end (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make C compiler happy */ }