* * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU General Public License

/* * When the signal handler gets a shutdown signal, it calls * this function to inform GsmManager to not restart * applications in the off chance a handler is already queued * to dispatch following the below call to gtk_main_quit. */gsm_manager_set_phase(manager,GSM_MANAGER_PHASE_EXIT);

staticgbooleanrequire_dbus_session(intargc,char**argv,GError**error){char**new_argv;inti;if(g_getenv("DBUS_SESSION_BUS_ADDRESS"))returnTRUE;/* Just a sanity check to prevent infinite recursion if * dbus-launch fails to set DBUS_SESSION_BUS_ADDRESS */g_return_val_if_fail(!g_str_has_prefix(argv[0],"dbus-launch"),TRUE);/* +2 for our new arguments, +1 for NULL */new_argv=g_malloc(argc+3*sizeof(*argv));

new_argv[i+2]=NULL;if(!execvp("dbus-launch",new_argv)){g_set_error(error,G_SPAWN_ERROR,G_SPAWN_ERROR_FAILED,"No session bus and could not exec dbus-launch: %s",g_strerror(errno));returnFALSE;}/* Should not be reached */returnTRUE;}

/* Rebind stdout/stderr to the journal explicitly, so that * journald picks ups the nicer "gnome-session" as the program * name instead of whatever shell script GDM happened to use. */#ifdef HAVE_SYSTEMDif(!debug){intjournalfd;journalfd=sd_journal_stream_fd(PACKAGE,LOG_INFO,0);if(journalfd>=0){dup2(journalfd,1);dup2(journalfd,2);}}#endif

/* From 3.14 GDM sets XDG_CURRENT_DESKTOP. For compatibility with * older versions of GDM, other display managers, and startx, * set a fallback value if we don't find it set. */if(g_getenv("XDG_CURRENT_DESKTOP")==NULL)gsm_util_setenv("XDG_CURRENT_DESKTOP","GNOME");

/* hack to fix keyring until we can reorder things in 3.20 * https://bugzilla.gnome.org/show_bug.cgi?id=738205 */if(g_strcmp0(g_getenv("XDG_SESSION_TYPE"),"wayland")==0&&g_getenv("GSM_SKIP_SSH_AGENT_WORKAROUND")==NULL){char*ssh_socket;ssh_socket=g_build_filename(g_get_user_runtime_dir(),"keyring","ssh",NULL);gsm_util_setenv("SSH_AUTH_SOCK",ssh_socket);g_free(ssh_socket);}

/* Talk to logind before acquiring a name, since it does synchronous * calls at initialization time that invoke a main loop and if we * already owned a name, then we would service too early during * that main loop. */g_object_unref(gsm_get_system());