* Gaim is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "conversation.h" #include "gtkeventloop.h" #include "gtksavedstatuses.h" #include "gtkwhiteboard.h" #ifdef HAVE_STARTUP_NOTIFICATION # define SN_API_NOT_YET_FROZEN # include <libsn/sn-launchee.h> #ifdef HAVE_STARTUP_NOTIFICATION static SnLauncheeContext *sn_context = NULL; static SnDisplay *sn_display = NULL; * Lists of signals we wish to catch and those we wish to ignore. * Each list terminated with -1 static int catch_sig_list[] = { static int ignore_sig_list[] = { dologin_named(const char *name) if (name != NULL) { /* list of names given */ names = g_strsplit(name, ",", 64); for (i = 0; names[i] != NULL; i++) { account = gaim_accounts_find(names[i], NULL); if (account != NULL) { /* found a user */ gaim_account_connect(account); } else { /* no name given, use the first account */ accounts = gaim_accounts_get_all(); account = (GaimAccount *)accounts->data; gaim_account_connect(account); pid = waitpid(-1, &status, WNOHANG); } while (pid != 0 && pid != (pid_t)-1); if ((pid == (pid_t) - 1) && (errno != ECHILD)) { snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); gaim_debug_warning("sighandler", "Caught signal %d\n", sig); gaim_connections_disconnect_all(); fprintf(stderr, "%s", segfault_message); signal(SIGCHLD, sighandler); /* restore signal catching on this one! */ gaim_debug_warning("sighandler", "Caught signal %d\n", sig); gaim_connections_disconnect_all(); gaim_plugins_unload_all(); gaim_gtk_blist_setup_sort_methods(); /* use the nice PNG icon for all the windows */ icon_path = g_build_filename(DATADIR, "pixmaps", "gaim", "icons", "online.png", NULL); icon = gdk_pixbuf_new_from_file(icon_path, NULL); icons = g_list_append(icons,icon); gtk_window_set_default_icon_list(icons); g_object_unref(G_OBJECT(icon)); gaim_debug_error("ui_main", "Failed to load the default window icon!\n"); gaim_debug_set_ui_ops(gaim_gtk_debug_get_ui_ops()); /* Set the UI operation structures. */ gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); gaim_xfers_set_ui_ops(gaim_gtk_xfers_get_ui_ops()); gaim_blist_set_ui_ops(gaim_gtk_blist_get_ui_ops()); gaim_notify_set_ui_ops(gaim_gtk_notify_get_ui_ops()); gaim_privacy_set_ui_ops(gaim_gtk_privacy_get_ui_ops()); gaim_request_set_ui_ops(gaim_gtk_request_get_ui_ops()); gaim_sound_set_ui_ops(gaim_gtk_sound_get_ui_ops()); gaim_connections_set_ui_ops(gaim_gtk_connections_get_ui_ops()); gaim_whiteboard_set_ui_ops(gaim_gtk_whiteboard_get_ui_ops()); gaim_idle_set_ui_ops(gaim_gtk_idle_get_ui_ops()); gaim_gtk_connection_init(); gaim_gtk_conversations_init(); gaim_gtk_roomlist_init(); /* Save the plugins we have loaded for next time. */ gaim_gtk_conversations_uninit(); gaim_gtk_status_uninit(); gaim_gtk_connection_uninit(); gaim_gtk_account_uninit(); static GaimCoreUiOps core_ops = gaim_gtk_core_get_ui_ops(void) show_usage(const char *name, gboolean terse) text = g_strdup_printf(_("Gaim %s. Try `%s -h' for more information.\n"), VERSION, name); text = g_strdup_printf(_("Gaim %s\n" "Usage: %s [OPTION]...\n\n" " -c, --config=DIR use DIR for config files\n" " -d, --debug print debugging messages to stdout\n" " -h, --help display this help and exit\n" " -n, --nologin don't automatically login\n" " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" " account(s) to use, separated by commas)\n" " -v, --version display the current version and exit\n"), VERSION, name); gaim_print_utf8_to_console(stdout, text); #ifdef HAVE_STARTUP_NOTIFICATION sn_error_trap_push(SnDisplay *display, Display *xdisplay) sn_error_trap_pop(SnDisplay *display, Display *xdisplay) startup_notification_complete(void) xdisplay = GDK_DISPLAY(); sn_display = sn_display_new(xdisplay, sn_launchee_context_new_from_environment(sn_display, DefaultScreen(xdisplay)); sn_launchee_context_complete(sn_context); sn_launchee_context_unref(sn_context); sn_display_unref(sn_display); #endif /* HAVE_STARTUP_NOTIFICATION */ static char *gaim_find_binary_location(void *symbol, void *data) static char *fullname = NULL; static gboolean first = TRUE; char *basebuf, *linkbuf, *fullbuf; /* We've already been through this. */ basebuf = g_find_program_in_path(argv0); /* But we still need to deal with symbolic links */ while ((st.st_mode & S_IFLNK) == S_IFLNK) { linkbuf = g_malloc(1024); written = readlink(basebuf, linkbuf, 1024 - 1); /* This really shouldn't happen, but do we * need something better here? */ if (linkbuf[0] == G_DIR_SEPARATOR) { fullbuf = g_strdup(linkbuf); char *dirbuf = g_path_get_dirname(basebuf); fullbuf = g_strdup_printf("%s%s%s", dirbuf, G_DIR_SEPARATOR_S, /* There's no memory leak here. Really! */ #endif /* #ifndef _WIN32 */ /* FUCKING GET ME A TOWEL! */ int gaim_main(HINSTANCE hint, int argc, char *argv[]) int main(int argc, char *argv[]) gboolean opt_help = FALSE; gboolean opt_login = FALSE; gboolean opt_nologin = FALSE; gboolean opt_version = FALSE; char *opt_config_dir_arg = NULL; char *opt_login_arg = NULL; char *opt_session_arg = NULL; int sig_indx; /* for setting up signal catching */ RETSIGTYPE (*prev_sig_disp)(int); char *segfault_message_tmp; struct option long_options[] = { {"config", required_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"login", optional_argument, NULL, 'l'}, {"nologin", no_argument, NULL, 'n'}, {"session", required_argument, NULL, 's'}, {"version", no_argument, NULL, 'v'}, #ifdef GAIM_FATAL_ASSERTS /* Make g_return_... functions fatal. */ g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); /* Locale initialization is not complete here. See gtk_init_check() */ /* We translate this here in case the crash breaks gettext. */ segfault_message_tmp = g_strdup_printf(_( "Gaim has segfaulted and attempted to dump a core file.\n" "This is a bug in the software and has happened through\n" "no fault of your own.\n\n" "If you can reproduce the crash, please notify the gaim\n" "developers by reporting a bug at\n" "Please make sure to specify what you were doing at the time\n" "and post the backtrace from the core file. If you do not know\n" "how to get the backtrace, please read the instructions at\n" "If you need further assistance, please IM either SeanEgn or \n" "LSchiere (via AIM). Contact information for Sean and Luke \n" "on other protocols is at\n" GAIM_WEBSITE, GAIM_WEBSITE, GAIM_WEBSITE /* we have to convert the message (UTF-8 to console charset) early because after a segmentation fault it's not a good practice to allocate memory */ segfault_message = g_locale_from_utf8(segfault_message_tmp, if (segfault_message != NULL) { g_free(segfault_message_tmp); /* use 'segfault_message_tmp' (UTF-8) as a fallback */ g_warning("%s\n", error->message); segfault_message = segfault_message_tmp; /* Don't mark this for translation. */ segfault_message = g_strdup( "Hi, user. We need to talk.\n" "I think something's gone wrong here. It's probably my fault.\n" "No, really, it's not you... it's me... no no no, I think we get along well\n" "it's just that.... well, I want to see other people. I... what?!? NO! I \n" "haven't been cheating on you!! How many times do you want me to tell you?! And\n" "for the last time, it's just a rash!\n" /* Let's not violate any PLA's!!!! */ /* jseymour: whatever the fsck that means */ /* Robot101: for some reason things like gdm like to block * * useful signals like SIGCHLD, so we unblock all the ones we * * declare a handler for. thanks JSeymour and Vann. */ if (sigemptyset(&sigset)) { snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", catch_sig_list[sig_indx]); if(sigaddset(&sigset, catch_sig_list[sig_indx])) { snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", catch_sig_list[sig_indx]); for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", ignore_sig_list[sig_indx]); if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); /* scan command-line options */ while ((opt = getopt_long(argc, argv, long_options, NULL)) != -1) { case 'c': /* config dir */ g_free(opt_config_dir_arg); opt_config_dir_arg = g_strdup(optarg); case 'n': /* no autologin */ case 'l': /* login, option username */ opt_login_arg = g_strdup(optarg); case 's': /* use existing session ID */ opt_session_arg = g_strdup(optarg); case '?': /* show terse help */ show_usage(argv[0], TRUE); show_usage(argv[0], FALSE); /* show version message */ printf("Gaim %s\n", VERSION); /* set a user-specified config directory */ if (opt_config_dir_arg != NULL) { gaim_util_set_user_dir(opt_config_dir_arg); * We're done piddling around with command line arguments. gaim_debug_set_enabled(debug_enabled); search_path = g_build_filename(gaim_user_dir(), "gtkrc-2.0", NULL); gtk_rc_add_default_file(search_path); gui_check = gtk_init_check(&argc, &argv); char *display = gdk_get_display(); printf("Gaim %s\n", VERSION); g_warning("cannot open display: %s", display ? display : "unset"); /** TODO: Move this to a wgaim_gtk_init() if we need such a thing */ gaim_debug_info("wgaim", "GTK+ :%u.%u.%u\n", gtk_major_version, gtk_minor_version, gtk_micro_version); gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); * Set plugin search directories. Give priority to the plugins * in user's home directory. search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); gaim_plugins_add_search_path(search_path); gaim_plugins_add_search_path(LIBDIR); if (!gaim_core_init(GAIM_GTK_UI)) { "Initialization of the Gaim core failed. Dumping core.\n" "Please report this!\n"); /* TODO: Move blist loading into gaim_blist_init() */ gaim_set_blist(gaim_blist_new()); /* TODO: Move prefs loading into gaim_prefs_init() */ gaim_gtk_prefs_update_old(); /* load plugins we had when we quit */ gaim_plugins_load_saved("/gaim/gtk/plugins/loaded"); /* TODO: Move pounces loading into gaim_pounces_init() */ gaim_gtk_session_init(argv[0], opt_session_arg, opt_config_dir_arg); if (opt_session_arg != NULL) { if (opt_config_dir_arg != NULL) { g_free(opt_config_dir_arg); opt_config_dir_arg = NULL; * We want to show the blist early in the init process so the * user feels warm and fuzzy (not cold and prickley). if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled")) gaim_gtk_debug_window_show(); dologin_ret = dologin_named(opt_login_arg); if (opt_login_arg != NULL) { /* Set all accounts to "offline" */ GaimSavedStatus *saved_status; /* If we've used this type+message before, lookup the transient status */ saved_status = gaim_savedstatus_find_transient_by_type_and_message( GAIM_STATUS_OFFLINE, NULL); /* If this type+message is unique then create a new transient saved status */ if (saved_status == NULL) saved_status = gaim_savedstatus_new(NULL, GAIM_STATUS_OFFLINE); /* Set the status for each account */ gaim_savedstatus_activate(saved_status); /* Everything is good to go--sign on already */ if (!gaim_prefs_get_bool("/core/savedstatus/startup_current_status")) gaim_savedstatus_activate(gaim_savedstatus_get_startup()); gaim_accounts_restore_current_statuses(); if (gaim_accounts_get_all_active() == NULL) gaim_gtk_accounts_window_show(); #ifdef HAVE_STARTUP_NOTIFICATION startup_notification_complete(); g_free(segfault_message);