~ubuntu-branches/ubuntu/vivid/xfce4-session/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/05_force-xfsettingsd-start.patch/xfce4-session/main.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-05-18 20:21:52 UTC
  • mfrom: (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20120518202152-7bm9pla0j3ccfsnk
Tags: 4.10.0-1ubuntu1
* Merge from Debian experimental, remaining Ubuntu changes:
  - debian/control: build-depends on libgnome-keyring-dev to enable GNOME
    Keyring services support.
  - debian/rules: pass --enable-libgnome-keyring to dh_auto_configure.
  - debian/patches:
    + xubuntu_ignore-gdm-lang.patch: do not set $LANG to $GDM_LANG, there's
      already an xsession script to do that, and $GDM_LANG might not contain
      a valid locale code.

* debian/patches:
  - xubuntu_set-xdg-current-desktop.patch: added. Taken from xfce4-utils,
    export XDG_CURRENT_DESKTOP=XFCE, can be useful with alacarte and
    gnome-menus. lp #927172

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
 
/*-
3
 
 * Copyright (c) 2003-2006 Benedikt Meurer <benny@xfce.org>
4
 
 * Copyright (c) 2008 Brian Tarricone <bjt23@cornell.edu>
5
 
 * All rights reserved.
6
 
 *
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)
10
 
 * any later version.
11
 
 *
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.
16
 
 *
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,
20
 
 * MA 02110-1301 USA.
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
#ifdef HAVE_ERRNO_H
28
 
#include <errno.h>
29
 
#endif
30
 
#ifdef HAVE_FCNTL_H
31
 
#include <fcntl.h>
32
 
#endif
33
 
#ifdef HAVE_MEMORY_H
34
 
#include <memory.h>
35
 
#endif
36
 
#ifdef HAVE_SIGNAL_H
37
 
#include <signal.h>
38
 
#endif
39
 
#ifdef HAVE_STDLIB_H
40
 
#include <stdlib.h>
41
 
#endif
42
 
#ifdef HAVE_STRING_H
43
 
#include <string.h>
44
 
#endif
45
 
#ifdef HAVE_UNISTD_H
46
 
#include <unistd.h>
47
 
#endif
48
 
 
49
 
#include <dbus/dbus-glib.h>
50
 
#include <dbus/dbus-glib-lowlevel.h>
51
 
 
52
 
#include <xfconf/xfconf.h>
53
 
 
54
 
#include <gdk/gdkx.h>
55
 
#include <gtk/gtk.h>
56
 
 
57
 
#include <libxfce4util/libxfce4util.h>
58
 
#include <libxfce4ui/libxfce4ui.h>
59
 
 
60
 
#include <libxfsm/xfsm-util.h>
61
 
 
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"
70
 
 
71
 
static gboolean opt_disable_tcp = FALSE;
72
 
static gboolean opt_version = FALSE;
73
 
 
74
 
static GOptionEntry option_entries[] =
75
 
{
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 },
78
 
  { NULL }
79
 
};
80
 
 
81
 
static void
82
 
setup_environment (void)
83
 
{
84
 
  const gchar *lang;
85
 
  const gchar *sm;
86
 
  gchar       *authfile;
87
 
  int          fd;
88
 
 
89
 
  /* check that no other session manager is running */
90
 
  sm = g_getenv ("SESSION_MANAGER");
91
 
  if (sm != NULL && strlen (sm) > 0)
92
 
    {
93
 
      fprintf (stderr, "xfce4-session: Another session manager is already running\n");
94
 
      exit (EXIT_FAILURE);
95
 
    }
96
 
 
97
 
  /* check if running in verbose mode */
98
 
  if (g_getenv ("XFSM_VERBOSE") != NULL)
99
 
    xfsm_enable_verbose ();
100
 
 
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);
103
 
 
104
 
  /* this is for compatibility with the GNOME Display Manager */
105
 
  lang = g_getenv ("GDM_LANG");
106
 
  if (lang != NULL && strlen (lang) > 0)
107
 
    {
108
 
      xfce_setenv ("LANG", lang, TRUE);
109
 
      xfce_unsetenv ("GDM_LANG");
110
 
    }
111
 
 
112
 
  /* check access to $ICEAUTHORITY or $HOME/.ICEauthority if unset */
113
 
  if (g_getenv ("ICEAUTHORITY"))
114
 
    authfile = g_strdup (g_getenv ("ICEAUTHORITY"));
115
 
  else
116
 
    authfile = xfce_get_homefile (".ICEauthority", NULL);
117
 
  fd = open (authfile, O_RDWR | O_CREAT, 0600);
118
 
  if (fd < 0)
119
 
    {
120
 
      fprintf (stderr, "xfce4-session: Unable to access file %s: %s\n",
121
 
               authfile, g_strerror (errno));
122
 
      exit (EXIT_FAILURE);
123
 
    }
124
 
  g_free (authfile);
125
 
  close (fd);
126
 
}
127
 
 
128
 
static void
129
 
init_display (XfsmManager   *manager,
130
 
              GdkDisplay    *dpy,
131
 
              XfconfChannel *channel,
132
 
              gboolean       disable_tcp)
133
 
{
134
 
  gchar *engine;
135
 
 
136
 
  engine = xfconf_channel_get_string (channel, "/splash/Engine", "mice");
137
 
 
138
 
  splash_screen = xfsm_splash_screen_new (dpy, engine);
139
 
  g_free (engine);
140
 
  xfsm_splash_screen_next (splash_screen, _("Loading desktop settings"));
141
 
 
142
 
  gdk_flush ();
143
 
 
144
 
  sm_init (channel, disable_tcp, manager);
145
 
 
146
 
  /* start xfsettingsd */
147
 
  if ( !g_spawn_command_line_async ("xfsettingsd", NULL))
148
 
  {
149
 
    g_warning ("Could not start xfsettingsd");
150
 
  }
151
 
 
152
 
 
153
 
  /* gtk resource files may have changed */
154
 
  gtk_rc_reparse_all ();
155
 
}
156
 
 
157
 
 
158
 
static void
159
 
xfsm_dbus_init (void)
160
 
{
161
 
  DBusGConnection *dbus_conn;
162
 
  int              ret;
163
 
  GError          *error = NULL;
164
 
 
165
 
  xfsm_error_dbus_init ();
166
 
 
167
 
  dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
168
 
  if (G_UNLIKELY (!dbus_conn))
169
 
    {
170
 
      g_critical ("Unable to contact D-Bus session bus: %s", error ? error->message : "Unknown error");
171
 
      if (error)
172
 
        g_error_free (error);
173
 
      return;
174
 
    }
175
 
 
176
 
  ret = dbus_bus_request_name (dbus_g_connection_get_connection (dbus_conn),
177
 
                               "org.xfce.SessionManager",
178
 
                               DBUS_NAME_FLAG_DO_NOT_QUEUE,
179
 
                               NULL);
180
 
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
181
 
    {
182
 
      g_error ("Another session manager is already running");
183
 
      exit (1);
184
 
    }
185
 
}
186
 
 
187
 
static void
188
 
xfsm_dbus_cleanup (void)
189
 
{
190
 
  DBusGConnection *dbus_conn;
191
 
 
192
 
  /* this is all not really necessary, but... */
193
 
 
194
 
  dbus_conn = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
195
 
  if (G_UNLIKELY (!dbus_conn))
196
 
    return;
197
 
 
198
 
  dbus_bus_release_name (dbus_g_connection_get_connection (dbus_conn),
199
 
                         "org.xfce.SessionManager", NULL);
200
 
}
201
 
 
202
 
int
203
 
main (int argc, char **argv)
204
 
{
205
 
  XfsmManager     *manager;
206
 
  XfsmShutdownType shutdown_type;
207
 
  GError          *error = NULL;
208
 
  GdkDisplay      *dpy;
209
 
  XfconfChannel   *channel;
210
 
 
211
 
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
212
 
 
213
 
  /* install required signal handlers */
214
 
  signal (SIGPIPE, SIG_IGN);
215
 
 
216
 
  if (!gtk_init_with_args (&argc, &argv, "", option_entries, GETTEXT_PACKAGE, &error)) {
217
 
    g_error ("%s", error->message);
218
 
    g_error_free (error);
219
 
    return EXIT_FAILURE;
220
 
  }
221
 
 
222
 
  if (opt_version)
223
 
    {
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);
231
 
      g_print ("\n");
232
 
      g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
233
 
      g_print ("\n");
234
 
      return EXIT_SUCCESS;
235
 
    }
236
 
 
237
 
  if (G_UNLIKELY (!xfconf_init (&error))) {
238
 
    xfce_dialog_show_error (NULL, error, _("Unable to contact settings server"));
239
 
    g_error_free (error);
240
 
  }
241
 
 
242
 
  /* fake a client id for the manager, so the legacy management does not
243
 
   * recognize us to be a session client.
244
 
   */
245
 
  gdk_set_sm_client_id (xfsm_generate_client_id (NULL));
246
 
 
247
 
  xfsm_dbus_init ();
248
 
 
249
 
  manager = xfsm_manager_new ();
250
 
  setup_environment ();
251
 
 
252
 
  channel = xfsm_open_config ();
253
 
 
254
 
  dpy = gdk_display_get_default ();
255
 
  init_display (manager, dpy, channel, opt_disable_tcp);
256
 
 
257
 
  if (!opt_disable_tcp && xfconf_channel_get_bool (channel, "/security/EnableTcp", FALSE))
258
 
    {
259
 
      /* verify that the DNS settings are ok */
260
 
      xfsm_splash_screen_next (splash_screen, _("Verifying DNS settings"));
261
 
      xfsm_dns_check ();
262
 
    }
263
 
 
264
 
  xfsm_splash_screen_next (splash_screen, _("Loading session data"));
265
 
 
266
 
  xfsm_startup_init (channel);
267
 
  xfsm_manager_load (manager, channel);
268
 
  xfsm_manager_restart (manager);
269
 
 
270
 
  gtk_main ();
271
 
 
272
 
  shutdown_type = xfsm_manager_get_shutdown_type (manager);
273
 
  g_object_unref (manager);
274
 
  g_object_unref (channel);
275
 
 
276
 
  xfsm_dbus_cleanup ();
277
 
  ice_cleanup ();
278
 
 
279
 
  return xfsm_shutdown (shutdown_type);
280
 
}