3
* Copyright (c) 2003-2006 Benedikt Meurer <benny@xfce.org>
4
* Copyright (c) 2008 Brian Tarricone <bjt23@cornell.edu>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2, or (at your option)
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
49
#include <dbus/dbus-glib.h>
50
#include <dbus/dbus-glib-lowlevel.h>
52
#include <xfconf/xfconf.h>
57
#include <libxfce4util/libxfce4util.h>
58
#include <libxfce4ui/libxfce4ui.h>
60
#include <libxfsm/xfsm-util.h>
62
#include <xfce4-session/ice-layer.h>
63
#include <xfce4-session/shutdown.h>
64
#include <xfce4-session/sm-layer.h>
65
#include <xfce4-session/xfsm-dns.h>
66
#include <xfce4-session/xfsm-global.h>
67
#include <xfce4-session/xfsm-manager.h>
68
#include <xfce4-session/xfsm-startup.h>
69
#include "xfsm-error.h"
71
static gboolean opt_disable_tcp = FALSE;
72
static gboolean opt_version = FALSE;
74
static GOptionEntry option_entries[] =
76
{ "disable-tcp", '\0', 0, G_OPTION_ARG_NONE, &opt_disable_tcp, N_("Disable binding to TCP ports"), NULL },
77
{ "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL },
82
setup_environment (void)
89
/* check that no other session manager is running */
90
sm = g_getenv ("SESSION_MANAGER");
91
if (sm != NULL && strlen (sm) > 0)
93
fprintf (stderr, "xfce4-session: Another session manager is already running\n");
97
/* check if running in verbose mode */
98
if (g_getenv ("XFSM_VERBOSE") != NULL)
99
xfsm_enable_verbose ();
101
/* pass correct DISPLAY to children, in case of --display in argv */
102
xfce_setenv ("DISPLAY", gdk_display_get_name (gdk_display_get_default ()), TRUE);
104
/* this is for compatibility with the GNOME Display Manager */
105
lang = g_getenv ("GDM_LANG");
106
if (lang != NULL && strlen (lang) > 0)
108
xfce_setenv ("LANG", lang, TRUE);
109
xfce_unsetenv ("GDM_LANG");
112
/* check access to $ICEAUTHORITY or $HOME/.ICEauthority if unset */
113
if (g_getenv ("ICEAUTHORITY"))
114
authfile = g_strdup (g_getenv ("ICEAUTHORITY"));
116
authfile = xfce_get_homefile (".ICEauthority", NULL);
117
fd = open (authfile, O_RDWR | O_CREAT, 0600);
120
fprintf (stderr, "xfce4-session: Unable to access file %s: %s\n",
121
authfile, g_strerror (errno));
129
init_display (XfsmManager *manager,
131
XfconfChannel *channel,
132
gboolean disable_tcp)
136
engine = xfconf_channel_get_string (channel, "/splash/Engine", "mice");
138
splash_screen = xfsm_splash_screen_new (dpy, engine);
140
xfsm_splash_screen_next (splash_screen, _("Loading desktop settings"));
144
sm_init (channel, disable_tcp, manager);
146
/* start xfsettingsd */
147
if ( !g_spawn_command_line_async ("xfsettingsd", NULL))
149
g_warning ("Could not start xfsettingsd");
153
/* gtk resource files may have changed */
154
gtk_rc_reparse_all ();
159
xfsm_dbus_init (void)
161
DBusGConnection *dbus_conn;
163
GError *error = NULL;
165
xfsm_error_dbus_init ();
167
dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
168
if (G_UNLIKELY (!dbus_conn))
170
g_critical ("Unable to contact D-Bus session bus: %s", error ? error->message : "Unknown error");
172
g_error_free (error);
176
ret = dbus_bus_request_name (dbus_g_connection_get_connection (dbus_conn),
177
"org.xfce.SessionManager",
178
DBUS_NAME_FLAG_DO_NOT_QUEUE,
180
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
182
g_error ("Another session manager is already running");
188
xfsm_dbus_cleanup (void)
190
DBusGConnection *dbus_conn;
192
/* this is all not really necessary, but... */
194
dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
195
if (G_UNLIKELY (!dbus_conn))
198
dbus_bus_release_name (dbus_g_connection_get_connection (dbus_conn),
199
"org.xfce.SessionManager", NULL);
203
main (int argc, char **argv)
205
XfsmManager *manager;
206
XfsmShutdownType shutdown_type;
207
GError *error = NULL;
209
XfconfChannel *channel;
211
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
213
/* install required signal handlers */
214
signal (SIGPIPE, SIG_IGN);
216
if (!gtk_init_with_args (&argc, &argv, "", option_entries, GETTEXT_PACKAGE, &error)) {
217
g_error ("%s", error->message);
218
g_error_free (error);
224
g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ());
225
g_print ("%s\n", "Copyright (c) 2003-2011");
226
g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
227
g_print ("%s\n\n", _("Written by Benedikt Meurer <benny@xfce.org>."));
228
g_print (_("Built with Gtk+-%d.%d.%d, running with Gtk+-%d.%d.%d"),
229
GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
230
gtk_major_version, gtk_minor_version, gtk_micro_version);
232
g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
237
if (G_UNLIKELY (!xfconf_init (&error))) {
238
xfce_dialog_show_error (NULL, error, _("Unable to contact settings server"));
239
g_error_free (error);
242
/* fake a client id for the manager, so the legacy management does not
243
* recognize us to be a session client.
245
gdk_set_sm_client_id (xfsm_generate_client_id (NULL));
249
manager = xfsm_manager_new ();
250
setup_environment ();
252
channel = xfsm_open_config ();
254
dpy = gdk_display_get_default ();
255
init_display (manager, dpy, channel, opt_disable_tcp);
257
if (!opt_disable_tcp && xfconf_channel_get_bool (channel, "/security/EnableTcp", FALSE))
259
/* verify that the DNS settings are ok */
260
xfsm_splash_screen_next (splash_screen, _("Verifying DNS settings"));
264
xfsm_splash_screen_next (splash_screen, _("Loading session data"));
266
xfsm_startup_init (channel);
267
xfsm_manager_load (manager, channel);
268
xfsm_manager_restart (manager);
272
shutdown_type = xfsm_manager_get_shutdown_type (manager);
273
g_object_unref (manager);
274
g_object_unref (channel);
276
xfsm_dbus_cleanup ();
279
return xfsm_shutdown (shutdown_type);