summaryrefslogtreecommitdiff
blob: 645e4e532ffb870033816f1d2a449027f43786d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
diff --git a/Makefile.am b/Makefile.am
index babc2f3..9b912a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,8 +24,8 @@ XINITDIR = $(libdir)/X11/xinit
 bin_PROGRAMS = xinit
 bin_SCRIPTS = startx
 
-xinit_CFLAGS = $(XINIT_CFLAGS) -DXINITDIR=\"$(XINITDIR)\" -DBINDIR=\"$(bindir)\"
-xinit_LDADD = $(XINIT_LIBS)
+xinit_CFLAGS = $(XINIT_CFLAGS) $(CK_CFLAGS) -DXINITDIR=\"$(XINITDIR)\" -DBINDIR=\"$(bindir)\"
+xinit_LDADD = $(XINIT_LIBS) $(CK_LIBS)
 
 xinit_SOURCES =	\
         xinit.c
diff --git a/configure.ac b/configure.ac
index 1aee1d2..5775db3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,7 @@ DEFAULT_XMODMAP=xmodmap
 DEFAULT_TWM=twm
 DEFAULT_XCLOCK=xclock
 DEFAULT_XTERM=xterm
+DEFAULT_CK=yes
 # You always want to specify the full path to the X server
 DEFAULT_XSERVER=${bindir}/X
 DEFAULT_XAUTH=xauth
@@ -104,6 +105,20 @@ esac
 AC_SUBST(XINIT_CFLAGS)
 AC_SUBST(XINIT_LIBS)
 
+# Check for ConsoleKit
+AC_ARG_WITH(consolekit,
+	 AS_HELP_STRING([--with-consolekit], [Use ConsoleKit in xinit]),
+	[CK="$withval"],
+	[CK="$DEFAULT_CK"])
+if test "x$CK" != xno ; then
+	PKG_CHECK_MODULES(CK, ck-connector,
+		have_conkit=yes,
+		[have_conkit=no; echo no])
+	if test "x$have_conkit" = xyes ; then
+		AC_DEFINE(USE_CONKIT, 1, [Define if you have ConsoleKit])
+	fi
+fi
+
 AC_PATH_PROGS(MCOOKIE, [mcookie], [$MCOOKIE],
   [$PATH:/bin:/usr/bin:/usr/lib:/usr/libexec:/usr/local/bin])
 if test "x$MCOOKIE" != x ; then
diff --git a/startx.cpp b/startx.cpp
index 42421ef..998c7f8 100644
--- a/startx.cpp
+++ b/startx.cpp
@@ -222,6 +222,12 @@ EOF
     fi
 done
 
+if [ x"$display" != x ]; then
+    export DISPLAY=$display
+else
+    export DISPLAY=:0
+fi
+
 #if defined(__SCO__) || defined(__UNIXWARE__)
 if [ "$REMOTE_SERVER" = "TRUE" ]; then
         exec SHELL_CMD ${client}
diff --git a/xinit.c b/xinit.c
index 46dee54..c2c4527 100644
--- a/xinit.c
+++ b/xinit.c
@@ -39,6 +39,12 @@ in this Software without prior written authorization from The Open Group.
 #include <ctype.h>
 #include <stdint.h>
 
+#ifdef USE_CONKIT
+#include <ck-connector.h>
+#include <X11/Xatom.h>
+static CkConnector *ckc = NULL;
+#endif /* USE_CONKIT */
+
 #ifdef X_POSIX_C_SOURCE
 #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
 #include <signal.h>
@@ -521,6 +527,39 @@ processTimeout(int timeout, char *string)
 	return( serverpid != pidfound );
 }
 
+
+#ifdef USE_CONKIT
+static void
+register_new_session_with_console_kit (void)
+{
+	static char conkitbuf[256];
+	DBusError   error;
+
+	ckc = ck_connector_new ();
+	if (ckc == NULL) {
+		Error ("Cannot register with ConsoleKit: OOM creating CkConnector\n");
+		goto out;
+	}
+
+	dbus_error_init (&error);
+	if (!ck_connector_open_session (ckc, &error)) {
+		Error ("Cannot register with ConsoleKit: %s: %s\n", error.name, error.message);
+		goto out;
+	}
+
+	/* If we managed to register with ConsoleKit, put the
+	 * environment variable XDG_SESSION_COOKIE=cookie as second
+	 * element in newenviron. See set_environment() where we
+	 * earlier have made sure there is room...
+	 */
+	conkitbuf[sizeof (conkitbuf) - 1] = '\0';
+	snprintf (conkitbuf, sizeof (conkitbuf) - 1, "XDG_SESSION_COOKIE=%s", ck_connector_get_cookie (ckc));
+	newenviron[1] = conkitbuf;
+out:
+	;
+}
+#endif /* USE_CONKIT */
+
 static int
 startServer(char *server[])
 {
@@ -631,6 +670,12 @@ startServer(char *server[])
 		break;
 	}
 
+#ifdef USE_CONKIT
+	if (serverpid != -1 ) {
+		register_new_session_with_console_kit ();
+	}
+#endif /* USE_CONKIT */
+
 	return(serverpid);
 }
 
@@ -775,6 +820,13 @@ shutdown(void)
 				clientpid);
 	}
 
+#ifdef USE_CONKIT
+	if (ckc != NULL) {
+		ck_connector_unref (ckc);
+		ckc = NULL;
+	}
+#endif
+
 	if (serverpid < 0)
 		return;
 	errno = 0;
@@ -811,6 +863,13 @@ shutdown(void)
  * make a new copy of environment that has room for DISPLAY
  */
 
+
+#ifdef USE_CONKIT
+#define NUM_EXTRA_ENV_VARS 4
+#else
+#define NUM_EXTRA_ENV_VARS 3
+#endif
+
 static void 
 set_environment(void)
 {
@@ -822,11 +881,11 @@ set_environment(void)
     for (oldPtr = environ; *oldPtr; oldPtr++) ;
 
     nenvvars = (oldPtr - environ);
-    newenviron = (char **) malloc ((nenvvars + 3) * sizeof(char **));
+    newenviron = (char **) malloc ((nenvvars + NUM_EXTRA_ENV_VARS) * sizeof(char **));
     if (!newenviron) {
 	fprintf (stderr,
 		 "%s:  unable to allocate %d pointers for environment\n",
-		 program, nenvvars + 3);
+		 program, nenvvars + NUM_EXTRA_ENV_VARS);
 	exit (1);
     }
 
@@ -836,10 +895,18 @@ set_environment(void)
     newPtr = newenviron;
     *newPtr++ = displaybuf;
 
+#ifdef USE_CONKIT
+    *newPtr++ = "XDG_SESSION_COOKIE=";
+#endif
+
     /* copy pointers to other variables */
     for (oldPtr = environ; *oldPtr; oldPtr++) {
 	if (strncmp (*oldPtr, "DISPLAY=", 8) != 0
-	 && strncmp (*oldPtr, "WINDOWPATH=", 11) != 0) {
+	 && strncmp (*oldPtr, "WINDOWPATH=", 11) != 0
+#ifdef USE_CONKIT
+	 && strncmp (*oldPtr, "XDG_SESSION_COOKIE=", 19) != 0
+#endif
+	 ) {
 	    *newPtr++ = *oldPtr;
 	}
     }