patches/gdm-06-dbus.diff
author yippi
Fri, 21 Nov 2008 21:16:14 +0000
changeset 14638 27ceb9334364
parent 13753 0d5a7ded31e2
permissions -rw-r--r--
2008-11-21 Brian Cameron <[email protected]> * SUNWgnome-display-mgr.spec, ext-sources/svc-gdm, ext-sources/gdm.xml, base-specs/gdm.xml: Add /lib/svc/method/svc-gdm SMF method file so that the "stop" method does not cause errors on shutdown/restart. * patches/gdm-06-dbus.spec: Remove this patch. It is no longer needed for programs like GOK to startup from GDM since D-Bus autostart is working better now. Renumber other GDM patches.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14638
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     1
Index: daemon/gdm.c
13753
0d5a7ded31e2 2008-09-24 Brian Cameron <[email protected]>
yippi
parents: 13620
diff changeset
     2
===================================================================
14638
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     3
--- daemon/gdm.c	(revision 6598)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     4
+++ daemon/gdm.c	(working copy)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     5
@@ -147,6 +147,9 @@
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     6
 static gboolean gdm_restart_mode  = FALSE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     7
 static gboolean monte_carlo_sqrt2 = FALSE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     8
 
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
     9
+/* D-Bus PID value */
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    10
+static GPid dbus_pid;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    11
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    12
 /*
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    13
  * Lookup display number if the display number is
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    14
  * exists then clear the remove flag and return TRUE
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    15
@@ -294,6 +297,7 @@
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    16
 	gboolean first;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    17
 	GSList *displays;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    18
 	struct sigaction sig;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    19
+	int res;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    20
 
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    21
 	/* Remove all signal handlers, since we are freeing structures used by the handlers */
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    22
 	sig.sa_handler = SIG_DFL;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    23
@@ -310,6 +314,23 @@
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    24
 	sigaction (SIGXFSZ, &sig, NULL);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    25
 #endif
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    26
 
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    27
+	if (dbus_pid > 0) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    28
+		gdm_debug ("Stopping D-Bus daemon");
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    29
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    30
+		errno = 0;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    31
+                res = kill (dbus_pid, SIGTERM);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    32
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    33
+		if (res < 0) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    34
+			if (errno == ESRCH) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    35
+				gdm_debug ("Child process %d was already dead.",
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    36
+					(int)dbus_pid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    37
+			} else {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    38
+				gdm_debug ("Couldn't kill child process %d: %s",
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    39
+					dbus_pid, g_strerror (errno));
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    40
+			}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    41
+		}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    42
+	}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    43
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    44
 	displays = gdm_daemon_config_get_display_list ();
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    45
 
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    46
 	gdm_debug ("gdm_final_cleanup");
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    47
@@ -1559,6 +1580,207 @@
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    48
 	g_free (file);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    49
 }
13620
80df4aa16fbf 2008-09-17 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    50
 
14638
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    51
+typedef struct {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    52
+        const char *user_name;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    53
+        const char *group_name;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    54
+} SpawnChildData;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    55
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    56
+static void
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    57
+spawn_child_setup (SpawnChildData *data)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    58
+{
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    59
+        struct passwd *pwent;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    60
+        struct group  *grent;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    61
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    62
+        if (data->user_name == NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    63
+                return;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    64
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    65
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    66
+        pwent = getpwnam (data->user_name);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    67
+        if (pwent == NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    68
+                g_warning (_("User %s doesn't exist"),
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    69
+                           data->user_name);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    70
+                _exit (1);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    71
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    72
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    73
+        grent = getgrnam (data->group_name);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    74
+        if (grent == NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    75
+                g_warning (_("Group %s doesn't exist"),
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    76
+                           data->group_name);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    77
+                _exit (1);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    78
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    79
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    80
+        g_debug ("GdmWelcomeSession: Changing (uid:gid) for child process to (%d:%d)",
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    81
+                 pwent->pw_uid,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    82
+                 grent->gr_gid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    83
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    84
+        if (pwent->pw_uid != 0) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    85
+                if (setgid (grent->gr_gid) < 0)  {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    86
+                        g_warning (_("Couldn't set groupid to %d"),
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    87
+                                   grent->gr_gid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    88
+                        _exit (1);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    89
+                }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    90
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    91
+                if (initgroups (pwent->pw_name, pwent->pw_gid) < 0) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    92
+                        g_warning (_("initgroups () failed for %s"),
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    93
+                                   pwent->pw_name);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    94
+                        _exit (1);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    95
+                }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    96
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    97
+                if (setuid (pwent->pw_uid) < 0)  {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    98
+                        g_warning (_("Couldn't set userid to %d"),
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
    99
+                                   (int)pwent->pw_uid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   100
+                        _exit (1);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   101
+                }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   102
+        } else {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   103
+                gid_t groups[1] = { 0 };
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   104
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   105
+                if (setgid (0) < 0)  {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   106
+                        g_warning (_("Couldn't set groupid to 0"));
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   107
+                        /* Don't error out, it's not fatal, if it fails we'll
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   108
+                         * just still be */
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   109
+                }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   110
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   111
+                /* this will get rid of any suplementary groups etc... */
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   112
+                setgroups (1, groups);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   113
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   114
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   115
+        if (setsid () < 0) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   116
+                g_debug ("GdmWelcomeSession: could not set pid '%u' as leader of new session and process group - %s",
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   117
+                         (guint) getpid (), g_strerror (errno));
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   118
+                _exit (2);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   119
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   120
+}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   121
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   122
+static gboolean
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   123
+parse_value_as_integer (const char *value,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   124
+                        int        *intval)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   125
+{
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   126
+        char *end_of_valid_int;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   127
+        glong long_value;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   128
+        gint  int_value;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   129
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   130
+        errno = 0;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   131
+        long_value = strtol (value, &end_of_valid_int, 10);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   132
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   133
+        if (*value == '\0' || *end_of_valid_int != '\0') {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   134
+                return FALSE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   135
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   136
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   137
+        int_value = long_value;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   138
+        if (int_value != long_value || errno == ERANGE) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   139
+                return FALSE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   140
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   141
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   142
+        *intval = int_value;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   143
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   144
+        return TRUE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   145
+}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   146
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   147
+static gboolean
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   148
+parse_dbus_launch_output (const char *output,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   149
+                          char      **addressp,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   150
+                          GPid       *pidp)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   151
+{
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   152
+        GRegex     *re;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   153
+        GMatchInfo *match_info;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   154
+        gboolean    ret;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   155
+        gboolean    res;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   156
+        GError     *error;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   157
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   158
+        ret = FALSE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   159
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   160
+        error = NULL;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   161
+        re = g_regex_new ("DBUS_SESSION_BUS_ADDRESS=(.+)\nDBUS_SESSION_BUS_PID=([0-9]+)", 0, 0, &error);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   162
+        if (re == NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   163
+                g_critical ("%s", error->message);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   164
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   165
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   166
+        g_regex_match (re, output, 0, &match_info);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   167
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   168
+        res = g_match_info_matches (match_info);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   169
+        if (! res) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   170
+                g_warning ("Unable to parse output: %s", output);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   171
+                goto out;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   172
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   173
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   174
+        if (addressp != NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   175
+                *addressp = g_strdup (g_match_info_fetch (match_info, 1));
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   176
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   177
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   178
+        if (pidp != NULL) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   179
+                int      pid;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   180
+                gboolean result;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   181
+                result = parse_value_as_integer (g_match_info_fetch (match_info, 2), &pid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   182
+                if (result) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   183
+                        *pidp = pid;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   184
+                } else {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   185
+                        *pidp = 0;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   186
+                }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   187
+        }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   188
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   189
+        ret = TRUE;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   190
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   191
+ out:
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   192
+        g_match_info_free (match_info);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   193
+        g_regex_unref (re);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   194
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   195
+        return ret;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   196
+}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   197
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   198
+static void
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   199
+gdm_start_dbus (void)
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   200
+{
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   201
+   gboolean res;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   202
+   SpawnChildData data;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   203
+   GError    *error;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   204
+   char      *std_out;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   205
+   char      *std_err;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   206
+   int        exit_status;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   207
+   char     **argv;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   208
+   char      *dbus_bus_address;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   209
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   210
+   if (! g_shell_parse_argv ("/usr/bin/dbus-launch --exit-with-session", NULL, &argv, &error)) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   211
+      gdm_debug ("Problem starting D-Bus");
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   212
+   }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   213
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   214
+   data.user_name  = "gdm";
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   215
+   data.group_name = "gdm";
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   216
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   217
+   res = g_spawn_sync (NULL,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   218
+                       argv,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   219
+                       NULL,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   220
+                       G_SPAWN_SEARCH_PATH,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   221
+                       (GSpawnChildSetupFunc)spawn_child_setup,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   222
+                       &data,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   223
+                       &std_out,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   224
+                       &std_err,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   225
+                       &exit_status,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   226
+                       &error);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   227
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   228
+   if (! res) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   229
+      gdm_debug ("Unable to launch D-Bus daemon: %s", error->message);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   230
+      goto out;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   231
+   }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   232
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   233
+   res = parse_dbus_launch_output (std_out,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   234
+                                   &dbus_bus_address,
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   235
+                                   &dbus_pid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   236
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   237
+   if (! res) {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   238
+      gdm_debug ("Unable to launch D-Bus daemon");
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   239
+      goto out;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   240
+   }
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   241
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   242
+   gdm_debug ("Started D-Bus daemon on pid %d", dbus_pid);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   243
+   gdm_debug ("Setting DBUS_SESSION_BUS_ADDRESS to %s", dbus_bus_address);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   244
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   245
+   g_setenv ("DBUS_SESSION_BUS_ADDRESS", dbus_bus_address, TRUE);
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   246
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   247
+out:
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   248
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   249
+return;
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   250
+}
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   251
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   252
 int
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   253
 main (int argc, char *argv[])
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   254
 {
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   255
@@ -1826,6 +2048,8 @@
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   256
 		gdm_xdmcp_run ();
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   257
 	}
13620
80df4aa16fbf 2008-09-17 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
   258
 
14638
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   259
+        gdm_start_dbus ();
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   260
+
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   261
 	/* We always exit via exit (), and sadly we need to g_main_quit ()
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   262
 	 * at times not knowing if it's this main or a recursive one we're
27ceb9334364 2008-11-21 Brian Cameron <[email protected]>
yippi
parents: 13753
diff changeset
   263
 	 * quitting.