xorg-x11-xinit/xinit-1.0.2-2-poke-ck.patch
2007-04-02 21:45:28 +00:00

168 lines
3.9 KiB
Diff

diff --git a/Makefile.am b/Makefile.am
diff --git a/configure.ac b/configure.ac
index 55648bc..07e40cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,7 +91,7 @@ AC_ARG_WITH(xinit,
[XINIT="$DEFAULT_XINIT"])
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XINIT, x11)
+PKG_CHECK_MODULES(XINIT, x11 ck-connector)
case $host_os in
*bsd*)
diff --git a/startx.cpp b/startx.cpp
index eba83b8..f091fa5 100644
--- a/startx.cpp
+++ b/startx.cpp
@@ -217,6 +217,12 @@ done
#endif
+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 818f754..de97791 100644
--- a/xinit.c
+++ b/xinit.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
/* $Xorg: xinit.c,v 1.5 2001/02/09 02:05:49 xorgcvs Exp $ */
/* $XdotOrg: $ */
@@ -37,6 +38,13 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include <ctype.h>
+#define USE_CONKIT
+#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>
@@ -558,6 +566,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[])
{
@@ -685,6 +726,12 @@ startServer(char *server[])
break;
}
+#ifdef USE_CONKIT
+ if (serverpid != -1 ) {
+ register_new_session_with_console_kit ();
+ }
+#endif /* USE_CONKIT */
+
return(serverpid);
}
@@ -748,6 +795,13 @@ shutdown(void)
clientpid);
}
+#ifdef USE_CONKIT
+ if (ckc != NULL) {
+ ck_connector_unref (ckc);
+ ckc = NULL;
+ }
+#endif
+
if (serverpid < 0)
return;
errno = 0;
@@ -784,6 +838,13 @@ shutdown(void)
* make a new copy of environment that has room for DISPLAY
*/
+
+#ifdef USE_CONKIT
+#define NUM_EXTRA_ENV_VARS 3
+#else
+#define NUM_EXTRA_ENV_VARS 2
+#endif
+
static void
set_environment(void)
{
@@ -795,11 +856,11 @@ set_environment(void)
for (oldPtr = environ; *oldPtr; oldPtr++) ;
nenvvars = (oldPtr - environ);
- newenviron = (char **) malloc ((nenvvars + 2) * 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 + 2);
+ program, nenvvars + NUM_EXTRA_ENV_VARS);
exit (1);
}
@@ -809,9 +870,17 @@ 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++) {
+#ifdef USE_CONKIT
+ if (strncmp (*oldPtr, "DISPLAY=", 8) != 0 && strncmp (*oldPtr, "XDG_SESSION_COOKIE=", 19) != 0) {
+#else
if (strncmp (*oldPtr, "DISPLAY=", 8) != 0) {
+#endif
*newPtr++ = *oldPtr;
}
}