[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xinit: Changes to 'upstream-unstable'



 Makefile.am                                         |   12 
 configure.ac                                        |   38 +--
 org.x.X11.plist.cpp                                 |   27 --
 org.x.startx.plist.cpp                              |   25 ++
 privileged_startx/10-tmpdirs.cpp                    |   37 ++
 privileged_startx/20-font_cache.cpp                 |   35 ++
 privileged_startx/Makefile.am                       |   74 +++++
 privileged_startx/client.c                          |   56 ++++
 privileged_startx/org.x.privileged_startx.plist.cpp |   21 +
 privileged_startx/privileged_startx.c               |   59 ++++
 privileged_startx/privileged_startx.defs            |   40 +++
 privileged_startx/privileged_startx_types.h         |    6 
 privileged_startx/server.c                          |  250 ++++++++++++++++++++
 startx.cpp                                          |   29 +-
 xinit.c                                             |   89 +------
 xinitrc.cpp                                         |   12 
 16 files changed, 682 insertions(+), 128 deletions(-)

New commits:
commit 3c5e2ed686bd3ab39e2c1e87feffb5990603cf3c
Author: Adam Jackson <ajax@redhat.com>
Date:   Wed May 21 14:34:52 2008 -0400

    xinit 1.0.9

diff --git a/configure.ac b/configure.ac
index b3ba68e..42c3b60 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ([2.57])
-AC_INIT(xinit,[1.0.8], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],xinit)
+AC_INIT(xinit,[1.0.9], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],xinit)
 AM_INIT_AUTOMAKE([dist-bzip2])
 AM_MAINTAINER_MODE
 

commit c07501f69239e9c1448736ad7e689a2c3da49af9
Author: Adam Jackson <ajax@redhat.com>
Date:   Wed May 21 14:29:55 2008 -0400

    Unset session environment variables so startx works within a running session.

diff --git a/startx.cpp b/startx.cpp
index fde780f..9266341 100644
--- a/startx.cpp
+++ b/startx.cpp
@@ -13,6 +13,9 @@ XCOMM Site administrators are STRONGLY urged to write nicer versions.
 XCOMM
 XCOMM $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $
 
+unset DBUS_SESSION_BUS_ADDRESS
+unset SESSION_MANAGER
+
 #if defined(__SCO__) || defined(__UNIXWARE__) || defined(__APPLE__)
 
 XCOMM Check for /usr/bin/X11 and BINDIR in the path, if not add them.

commit ef2610f44c7cf40489203fddc77ddcdfb7764eed
Author: Alan Coopersmith <alan.coopersmith@sun.com>
Date:   Tue May 13 16:28:33 2008 -0700

    Use /bin/ksh instead of /bin/sh on Solaris

diff --git a/configure.ac b/configure.ac
index 5ad468b..b3ba68e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,9 +154,13 @@ if test "x$MCOOKIE" != x ; then
 fi
 AC_SUBST(STARTX_COOKIE_FLAGS)
 
-# Additional substitutions in xinitrc & man pages
+# Additional substitutions in startx, xinitrc & man pages
 case $host_os in
-    *sco*)	
+    *solaris*)
+	SHELL_CMD="/bin/ksh"
+	ARCHMANDEFS=""
+	;;
+    *sco*)
 	SHELL_CMD="/bin/ksh"
 	ARCHMANDEFS="-D__SCOMAN__"
 	;;

commit d3bc7001315a8ba13be073af86fe710740b2d4c3
Author: Alan Coopersmith <alan.coopersmith@sun.com>
Date:   Tue May 13 16:25:49 2008 -0700

    Check for proper cookie creation on all platforms

diff --git a/startx.cpp b/startx.cpp
index c93812f..fde780f 100644
--- a/startx.cpp
+++ b/startx.cpp
@@ -256,11 +256,11 @@ if [ x"$enable_xauth" = x1 ] ; then
     else
         mcookie=`dd if=/dev/random bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"`
     fi
+#endif
     if test x"$mcookie" = x; then
         echo "Couldn't create cookie"
         exit 1
     fi
-#endif
     dummy=0
 
     XCOMM create a file with auth information for the server. ':0' is a dummy.

commit ef7abe2e72074f8252f0812ab2ca05dff7e76a38
Author: Alan Coopersmith <alan.coopersmith@sun.com>
Date:   Tue May 13 16:25:22 2008 -0700

    Use od on /dev/random to generate cookie on Solaris

diff --git a/configure.ac b/configure.ac
index b476c1c..5ad468b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,6 +144,9 @@ case $host_os in
 	*openbsd*)
 	MCOOKIE='/usr/sbin/openssl rand -hex 16'
 	;;
+	*solaris*)
+	MCOOKIE="/usr/bin/od -X -A n -N 16 /dev/urandom | /usr/bin/tr -d ' '"
+	;;
 esac
 
 if test "x$MCOOKIE" != x ; then

commit e0e89545db1fc08ffe49b2b24455bb30137da671
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Mon May 12 13:17:46 2008 -0700

    Apple: Don't need to spew unneccessary 'directory exists' messages.

diff --git a/privileged_startx/10-tmpdirs.cpp b/privileged_startx/10-tmpdirs.cpp
index dd5071c..e30abac 100755
--- a/privileged_startx/10-tmpdirs.cpp
+++ b/privileged_startx/10-tmpdirs.cpp
@@ -30,7 +30,7 @@ XCOMM Make sure these are owned by root
 for dir in /tmp/.ICE-unix /tmp/.X11-unix /tmp/.font-unix ; do
 	# Use mktemp rather than mkdir to avoid possible security issue
 	# if $dir exists and is a symlink
-	if mktemp -d ${dir} > /dev/null ; then
+	if mktemp -d ${dir} >& /dev/null ; then
 		chmod 1777 $dir
 		chown root:wheel $dir
 	fi

commit 85561f8347b33422dd4b0ea11911347c0666e409
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Tue May 6 00:07:18 2008 -0700

    Apple: No need for these bits being here in xinit as of xserver-1.4.0-apple9

diff --git a/xinit.c b/xinit.c
index 6940c89..523cfd5 100644
--- a/xinit.c
+++ b/xinit.c
@@ -39,16 +39,6 @@ in this Software without prior written authorization from The Open Group.
 #include <ctype.h>
 #include <stdint.h>
 
-#ifdef __APPLE__
-#include <AvailabilityMacros.h>
-#endif
-
-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-#include <CoreServices/CoreServices.h>
-#define kX11AppBundleId "org.x.X11"
-#define kX11AppBundlePath "/Contents/MacOS/X11"
-#endif
-
 #ifdef X_POSIX_C_SOURCE
 #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
 #include <signal.h>
@@ -180,9 +170,6 @@ static char **client = clientargv + 2;		/* make sure room for sh .xinitrc args *
 static char *displayNum = NULL;
 static char *program = NULL;
 static Display *xd = NULL;			/* server connection */
-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-static char x11_path[PATH_MAX + 1];
-#endif
 #ifndef SYSV
 #if defined(__CYGWIN__) || defined(SVR4) || defined(_POSIX_SOURCE) || defined(CSRG_BASED) || defined(__UNIXOS2__) || defined(Lynx) || defined(__APPLE__)
 int status;
@@ -232,54 +219,10 @@ sigUsr1(int sig)
 #endif
 }
 
-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-static void set_x11_path() {
-    CFURLRef appURL = NULL;
-    OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL);
-
-    switch (osstatus) {
-        case noErr:
-            if (appURL == NULL) {
-                fprintf(stderr, "xinit: Invalid response from LSFindApplicationForInfo(%s)\n", 
-                        kX11AppBundleId);
-                exit(1);
-            }
-            
-            if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
-                fprintf(stderr, "xinit: Error resolving URL for %s\n", kX11AppBundleId);
-                exit(2);
-            }
-            
-            strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
-#ifdef DEBUG
-            fprintf(stderr, "xinit: X11.app = %s\n", x11_path);
-#endif
-            break;
-        case kLSApplicationNotFoundErr:
-            fprintf(stderr, "xinit: Unable to find application for %s\n", kX11AppBundleId);
-            exit(4);
-        default:
-            fprintf(stderr, "xinit: Unable to find application for %s, error code = %d\n", 
-                    kX11AppBundleId, (int)osstatus);
-            exit(5);
-    }
-}
-#endif
-
 static void 
 Execute(char **vec,		/* has room from up above */
 	char **envp)
 {
-#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
-    /* This is ugly, but currently, we need to trick OS-X into thinking X is in
-     * the X11.app bundle.  Hopefully UI, icons, etc will eventually be set
-     * by Xquartz, but this is how we're doing it for now. -JH
-     */
-    if(!strcmp(vec[0], "/usr/X11/bin/X") || !strcmp(vec[0], "/usr/X11/bin/Xquartz") || !strcmp(vec[0], "X") || !strcmp(vec[0], "Xquartz")) {
-        setenv("CFProcessPath", x11_path, 1);
-        fprintf(stderr, "xinit: Detected Xquartz startup, setting CFProcessPath=%s\n", x11_path);
-    }
-#endif
     Execvpe (vec[0], vec, envp);
 #ifndef __UNIXOS2__
     if (access (vec[0], R_OK) == 0) {
@@ -308,10 +251,6 @@ main(int argc, char *argv[], char *envp[])
 	int start_of_client_args, start_of_server_args;
 	struct sigaction sa;
 
-#ifdef __APPLE__
-    set_x11_path();
-#endif
-
 #ifdef __UNIXOS2__
 	envsave = envp;	/* circumvent an EMX problem */
 

commit 280774466dc9f57b4b46c618345f7938290dbb2c
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Fri Apr 25 19:00:23 2008 -0700

    Apple: Added some OSX version protection, so this will still compile on Tiger and below.

diff --git a/Makefile.am b/Makefile.am
index d514251..c778487 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,7 +27,7 @@ bin_SCRIPTS = startx
 xinit_CFLAGS = $(XINIT_CFLAGS) -DXINITDIR=\"$(XINITDIR)\" -DBINDIR=\"$(bindir)\"
 xinit_LDADD = $(XINIT_LIBS)
 
-if APPLE
+if APPLE_LEOPARD
 xinit_LDFLAGS = -framework CoreServices
 endif
 
diff --git a/configure.ac b/configure.ac
index f33fd13..b476c1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,18 +109,15 @@ if test "x$LAUNCHD" = "xyes" ; then
 	AC_DEFINE(HAVE_LAUNCHD, 1, [launchd support available])
 
 	case $host_os in
-		darwin*)
-			# For now, this is how we find X11.app on OS-X...
-			# A future version of launchd should let us do this cleaner
-			#XSERVER=\'\`'$(libexecdir)/x11-exec'\`\'
-			AM_CONDITIONAL(APPLE, true)
+		darwin9*|darwin1*)
+			AM_CONDITIONAL(APPLE_LEOPARD, true)
 		;;
 		*)
-			AM_CONDITIONAL(APPLE, false)
+			AM_CONDITIONAL(APPLE_LEOPARD, false)
 		;;
 	esac
 else
-	AM_CONDITIONAL(APPLE,false)
+	AM_CONDITIONAL(APPLE_LEOPARD,false)
         launchagentsdir=""
         launchdaemonsdir=""
 fi
diff --git a/xinit.c b/xinit.c
index 3de74c3..6940c89 100644
--- a/xinit.c
+++ b/xinit.c
@@ -40,6 +40,10 @@ in this Software without prior written authorization from The Open Group.
 #include <stdint.h>
 
 #ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#endif
+
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
 #include <CoreServices/CoreServices.h>
 #define kX11AppBundleId "org.x.X11"
 #define kX11AppBundlePath "/Contents/MacOS/X11"
@@ -176,7 +180,7 @@ static char **client = clientargv + 2;		/* make sure room for sh .xinitrc args *
 static char *displayNum = NULL;
 static char *program = NULL;
 static Display *xd = NULL;			/* server connection */
-#ifdef __APPLE__
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
 static char x11_path[PATH_MAX + 1];
 #endif
 #ifndef SYSV
@@ -228,7 +232,7 @@ sigUsr1(int sig)
 #endif
 }
 
-#ifdef __APPLE__
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
 static void set_x11_path() {
     CFURLRef appURL = NULL;
     OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL);
@@ -266,7 +270,7 @@ static void
 Execute(char **vec,		/* has room from up above */
 	char **envp)
 {
-#ifdef __APPLE__
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
     /* This is ugly, but currently, we need to trick OS-X into thinking X is in
      * the X11.app bundle.  Hopefully UI, icons, etc will eventually be set
      * by Xquartz, but this is how we're doing it for now. -JH

commit 0806ae2ecfdcb4ad5f3b7a66dcc9bc5d29d72649
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Fri Apr 25 15:12:54 2008 -0700

    Apple: Use CFProcessPath instead of argv[0] trick.

diff --git a/xinit.c b/xinit.c
index d8e7c47..3de74c3 100644
--- a/xinit.c
+++ b/xinit.c
@@ -177,7 +177,7 @@ static char *displayNum = NULL;
 static char *program = NULL;
 static Display *xd = NULL;			/* server connection */
 #ifdef __APPLE__
-static char x11_path[PATH_MAX];
+static char x11_path[PATH_MAX + 1];
 #endif
 #ifndef SYSV
 #if defined(__CYGWIN__) || defined(SVR4) || defined(_POSIX_SOURCE) || defined(CSRG_BASED) || defined(__UNIXOS2__) || defined(Lynx) || defined(__APPLE__)
@@ -266,18 +266,17 @@ static void
 Execute(char **vec,		/* has room from up above */
 	char **envp)
 {
-    char *file = vec[0];
 #ifdef __APPLE__
     /* This is ugly, but currently, we need to trick OS-X into thinking X is in
      * the X11.app bundle.  Hopefully UI, icons, etc will eventually be set
      * by Xquartz, but this is how we're doing it for now. -JH
      */
-    if(!strcmp(file, "/usr/X11/bin/X") || !strcmp(file, "/usr/X11/bin/Xquartz") || !strcmp(file, "X") || !strcmp(file, "Xquartz")) {
-        vec[0] = x11_path;
-        fprintf(stderr, "xinit: Detected Xquartz startup, setting file=%s, argv[0]=%s\n", file, vec[0]);
+    if(!strcmp(vec[0], "/usr/X11/bin/X") || !strcmp(vec[0], "/usr/X11/bin/Xquartz") || !strcmp(vec[0], "X") || !strcmp(vec[0], "Xquartz")) {
+        setenv("CFProcessPath", x11_path, 1);
+        fprintf(stderr, "xinit: Detected Xquartz startup, setting CFProcessPath=%s\n", x11_path);
     }
 #endif
-    Execvpe (file, vec, envp);
+    Execvpe (vec[0], vec, envp);
 #ifndef __UNIXOS2__
     if (access (vec[0], R_OK) == 0) {
 	vec--;				/* back it up to stuff shell in */

commit edc3112679af749f0c6fc54b2eec1b89aaf0d0c8
Author: Matthieu Herrb <matthieu.herrb@laas.fr>
Date:   Sun Apr 20 17:30:14 2008 +0200

    Replace sprintf() and strcpy() with snprintf().

diff --git a/xinit.c b/xinit.c
index 61cd378..d8e7c47 100644
--- a/xinit.c
+++ b/xinit.c
@@ -412,10 +412,11 @@ main(int argc, char *argv[], char *envp[])
 
 	    xinitrcbuf[0] = '\0';
 	    if ((cp = getenv ("XINITRC")) != NULL) {
-		strcpy (xinitrcbuf, cp);
+		(void) snprintf (xinitrcbuf, sizeof(xinitrcbuf), "%s", cp);
 		required = True;
 	    } else if ((cp = getenv ("HOME")) != NULL) {
-		(void) sprintf (xinitrcbuf, "%s/%s", cp, XINITRC);
+		(void) snprintf (xinitrcbuf, sizeof(xinitrcbuf),
+				 "%s/%s", cp, XINITRC);
 	    }
 	    if (xinitrcbuf[0]) {
 		if (access (xinitrcbuf, F_OK) == 0) {
@@ -439,10 +440,11 @@ main(int argc, char *argv[], char *envp[])
 
 	    xserverrcbuf[0] = '\0';
 	    if ((cp = getenv ("XSERVERRC")) != NULL) {
-		strcpy (xserverrcbuf, cp);
+		(void) snprintf (xserverrcbuf, sizeof(xserverrcbuf), "%s", cp);
 		required = True;
 	    } else if ((cp = getenv ("HOME")) != NULL) {
-		(void) sprintf (xserverrcbuf, "%s/%s", cp, XSERVERRC);
+		(void) snprintf (xserverrcbuf, sizeof(xserverrcbuf),
+				 "%s/%s", cp, XSERVERRC);
 	    }
 	    if (xserverrcbuf[0]) {
 		if (access (xserverrcbuf, F_OK) == 0) {
@@ -705,6 +707,7 @@ setWindowPath(void)
 	unsigned long num;
 	char nums[10];
 	int numn;
+	size_t len;
 	prop = XInternAtom(xd, "XFree86_VT", False);
 	if (prop == None) {
 #ifdef DEBUG
@@ -760,11 +763,18 @@ setWindowPath(void)
 	windowpath = getenv("WINDOWPATH");
 	numn = snprintf(nums, sizeof(nums), "%lu", num);
 	if (!windowpath) {
-		newwindowpath = malloc(10 + 1 + numn + 1);
-		sprintf(newwindowpath, "WINDOWPATH=%s", nums);
+		len = 10 + 1 + numn + 1;
+		newwindowpath = malloc(len);
+		if (newwindowpath == NULL) 
+		    return;
+		snprintf(newwindowpath, len, "WINDOWPATH=%s", nums);
 	} else {
-		newwindowpath = malloc(10 + 1 + strlen(windowpath) + 1 + numn + 1);
-		sprintf(newwindowpath, "WINDOWPATH=%s:%s", windowpath, nums);
+		len = 10 + 1 + strlen(windowpath) + 1 + numn + 1;
+		newwindowpath = malloc(len);
+		if (newwindowpath == NULL)
+		    return;
+		snprintf(newwindowpath, len, "WINDOWPATH=%s:%s", 
+			 windowpath, nums);
 	}
 	*newenvironlast++ = newwindowpath;
 	*newenvironlast = NULL;
@@ -887,8 +897,7 @@ set_environment(void)
     }
 
     /* put DISPLAY=displayname as first element */
-    strcpy (displaybuf, "DISPLAY=");
-    strcpy (displaybuf + 8, displayNum);
+    snprintf (displaybuf, sizeof(displaybuf), "DISPLAY=%s", displayNum);
     newPtr = newenviron;
     *newPtr++ = displaybuf;
 

commit 47d561fd6efb8923cfbace6fea40dfeb314b4662
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Sat Apr 19 08:50:45 2008 -0700

    Cleaned up handling of defaultserver{,args}
    Per comments from Jeremy Reed on the list... basically doing for everyone what I do for Apple

diff --git a/startx.cpp b/startx.cpp
index 7e67769..c93812f 100644
--- a/startx.cpp
+++ b/startx.cpp
@@ -75,6 +75,7 @@ defaultclient=XTERM
 defaultserver=XSERVER
 defaultclientargs=""
 defaultserverargs=""
+defaultdisplay=":0"
 clientargs=""
 serverargs=""
 
@@ -216,13 +217,9 @@ XCOMM process server arguments
 if [ x"$server" = x ]; then
     XCOMM if no server arguments or display either, use rc file instead
     if [ x"$serverargs" = x -a x"$display" = x ]; then
-#ifdef __APPLE__
 	server=$defaultserver
 	serverargs=$defaultserverargs
-	display="$defaultdisplay"
-#else
-	server="$defaultserverargs"
-#endif
+	display=$defaultdisplay
     else
 	server=$defaultserver
     fi

commit f6e75ebf5f7f245e1cdeb883a1d2db74f2451fd4
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Sat Apr 19 08:47:20 2008 -0700

    Apple: Fixed make dist to include a missing header and not include generated sources

diff --git a/privileged_startx/Makefile.am b/privileged_startx/Makefile.am
index 0a3956d..6a143ca 100644
--- a/privileged_startx/Makefile.am
+++ b/privileged_startx/Makefile.am
@@ -37,13 +37,15 @@ AM_CPPFLAGS = -DXINITDIR=\"$(xinitrcdir)\" -DSCRIPTDIR=\"$(privstartxdir)\" -DBI
 
 CPP_FILES_FLAGS = -DXINITDIR="$(xinitrcdir)" -DSCRIPTDIR="$(privstartxdir)" -DBINDIR="$(bindir)"
 
-privileged_startx_SOURCES =	\
-	privileged_startxServer.c \
-	privileged_startxUser.c \
+dist_privileged_startx_SOURCES = \
 	server.c \
 	client.c \
 	privileged_startx.c
 
+nodist_privileged_startx_SOURCES = \
+	privileged_startxServer.c \
+	privileged_startxUser.c
+
 BUILT_SOURCES = \
 	privileged_startxServer.c \
 	privileged_startxUser.c \
@@ -56,9 +58,17 @@ launchdaemons_DATA = $(launchdaemons_PRE:plist.cpp=plist)
 10-tmpdirs: 10-tmpdirs.cpp Makefile
 20-font_cache: 20-font_cache.cpp Makefile
 
-CLEANFILES = $(privstartx_SCRIPTS) $(BUILT_SOURCES) $(launchdaemons_DATA)
+CLEANFILES = \
+	$(privstartx_SCRIPTS) \
+	$(BUILT_SOURCES) \
+	$(launchdaemons_DATA)
 
-EXTRA_DIST = 10-tmpdirs.cpp 20-font_cache.cpp org.x.privileged_startx.plist.cpp privileged_startx.defs
+EXTRA_DIST = \
+	10-tmpdirs.cpp \
+	20-font_cache.cpp \
+	org.x.privileged_startx.plist.cpp \
+	privileged_startx.defs \
+	privileged_startx_types.h
 
 $(BUILT_SOURCES): privileged_startx.defs
 	mig -sheader privileged_startxServer.h privileged_startx.defs

commit 2b06b58a328e13df4704df8a48d4cd0b1100ba7e
Author: Jeremy Huddleston <jeremyhu@freedesktop.org>
Date:   Thu Apr 17 17:19:41 2008 -0700

    Apple: Added privileged_startx

diff --git a/Makefile.am b/Makefile.am
index ae259bd..d514251 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,10 +63,14 @@ CPP_FILES_FLAGS = \
 	-D__bindir__="$(bindir)"
 
 if LAUNCHD
-launchagents_PRE = org.x.startx.plist.pre
-launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
+launchagents_PRE = org.x.startx.plist.cpp
+launchagents_DATA = $(launchagents_PRE:plist.cpp=plist)
+
+SUBDIRS = privileged_startx
 endif
 
+DIST_SUBDIRS = privileged_startx
+
 xinitrc: xinitrc.cpp Makefile
 startx: startx.cpp Makefile
 
diff --git a/configure.ac b/configure.ac
index f473580..f33fd13 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,12 +92,13 @@ AC_ARG_WITH(xinit,
 	[XINIT="$withval"],
 	[XINIT="$DEFAULT_XINIT"])
 
-AC_ARG_WITH(launchd,          AS_HELP_STRING([--with-launchd], [Build with suppo
-rt for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
-AC_ARG_WITH(launchagents-dir,AS_HELP_STRING([--with-launchagents-dir=PATH], [Pat
-h to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]),
+AC_ARG_WITH(launchd,            AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
+AC_ARG_WITH(launchagents-dir,   AS_HELP_STRING([--with-launchagents-dir=PATH], [Path to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]),
                                 [ launchagentsdir="${withval}" ],
                                 [ launchagentsdir="/Library/LaunchAgents" ])
+AC_ARG_WITH(launchdaemons-dir,  AS_HELP_STRING([--with-launchdaemons-dir=PATH], [Path to launchd's LaunchDaemonss directory (default: /Library/LaunchDaemons)]),
+                                [ launchdaemonsdir="${withval}" ],
+                                [ launchdaemonsdir="/Library/LaunchDaemons" ])
 
 if test "x$LAUNCHD" = "xauto"; then
 	unset LAUNCHD
@@ -121,8 +122,10 @@ if test "x$LAUNCHD" = "xyes" ; then
 else
 	AM_CONDITIONAL(APPLE,false)
         launchagentsdir=""
+        launchdaemonsdir=""
 fi
 AC_SUBST([launchagentsdir])
+AC_SUBST([launchdaemonsdir])
 AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
 
 # Checks for pkg-config packages
@@ -182,3 +185,4 @@ XORG_MANPAGE_SECTIONS
 XORG_RELEASE_VERSION
 
 AC_OUTPUT([Makefile])
+AC_OUTPUT([privileged_startx/Makefile])
diff --git a/privileged_startx/10-tmpdirs.cpp b/privileged_startx/10-tmpdirs.cpp
new file mode 100755
index 0000000..dd5071c
--- /dev/null
+++ b/privileged_startx/10-tmpdirs.cpp
@@ -0,0 +1,37 @@
+XCOMM!/bin/sh
+XCOMM Copyright (c) 2008 Apple Inc.
+XCOMM
+XCOMM Permission is hereby granted, free of charge, to any person
+XCOMM obtaining a copy of this software and associated documentation files
+XCOMM (the "Software"), to deal in the Software without restriction,
+XCOMM including without limitation the rights to use, copy, modify, merge,
+XCOMM publish, distribute, sublicense, and/or sell copies of the Software,
+XCOMM and to permit persons to whom the Software is furnished to do so,
+XCOMM subject to the following conditions:
+XCOMM
+XCOMM The above copyright notice and this permission notice shall be
+XCOMM included in all copies or substantial portions of the Software.
+XCOMM
+XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+XCOMM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+XCOMM NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+XCOMM HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+XCOMM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+XCOMM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+XCOMM DEALINGS IN THE SOFTWARE.
+XCOMM
+XCOMM Except as contained in this notice, the name(s) of the above
+XCOMM copyright holders shall not be used in advertising or otherwise to
+XCOMM promote the sale, use or other dealings in this Software without
+XCOMM prior written authorization.
+
+XCOMM Make sure these are owned by root
+for dir in /tmp/.ICE-unix /tmp/.X11-unix /tmp/.font-unix ; do
+	# Use mktemp rather than mkdir to avoid possible security issue
+	# if $dir exists and is a symlink
+	if mktemp -d ${dir} > /dev/null ; then
+		chmod 1777 $dir
+		chown root:wheel $dir
+	fi
+done
diff --git a/privileged_startx/20-font_cache.cpp b/privileged_startx/20-font_cache.cpp
new file mode 100755
index 0000000..c13384b
--- /dev/null
+++ b/privileged_startx/20-font_cache.cpp
@@ -0,0 +1,35 @@
+XCOMM!/bin/sh
+XCOMM Copyright (c) 2008 Apple Inc.
+XCOMM
+XCOMM Permission is hereby granted, free of charge, to any person
+XCOMM obtaining a copy of this software and associated documentation files
+XCOMM (the "Software"), to deal in the Software without restriction,
+XCOMM including without limitation the rights to use, copy, modify, merge,
+XCOMM publish, distribute, sublicense, and/or sell copies of the Software,
+XCOMM and to permit persons to whom the Software is furnished to do so,
+XCOMM subject to the following conditions:
+XCOMM
+XCOMM The above copyright notice and this permission notice shall be
+XCOMM included in all copies or substantial portions of the Software.
+XCOMM
+XCOMM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+XCOMM EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+XCOMM MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+XCOMM NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+XCOMM HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+XCOMM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+XCOMM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+XCOMM DEALINGS IN THE SOFTWARE.
+XCOMM
+XCOMM Except as contained in this notice, the name(s) of the above
+XCOMM copyright holders shall not be used in advertising or otherwise to
+XCOMM promote the sale, use or other dealings in this Software without
+XCOMM prior written authorization.
+
+if [ -x BINDIR/font_cache ] ; then
+	BINDIR/font_cache &
+elif [ -x BINDIR/font_cache.sh ] ; then
+	BINDIR/font_cache.sh -s &
+elif [ -x /usr/X11/bin/fc-cache ] ; then
+	BINDIR/fc-cache &
+fi
diff --git a/privileged_startx/Makefile.am b/privileged_startx/Makefile.am
new file mode 100644
index 0000000..0a3956d
--- /dev/null
+++ b/privileged_startx/Makefile.am
@@ -0,0 +1,64 @@
+# Copyright (c) 2008 Apple Inc.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+# HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name(s) of the above
+# copyright holders shall not be used in advertising or otherwise to
+# promote the sale, use or other dealings in this Software without
+# prior written authorization.
+
+include $(top_srcdir)/cpprules.in
+
+xinitrcdir = $(libdir)/X11/xinit
+privstartxdir = $(xinitrcdir)/privileged_startx.d
+
+xinitrc_PROGRAMS = privileged_startx
+privstartx_SCRIPTS = 10-tmpdirs 20-font_cache
+
+AM_CPPFLAGS = -DXINITDIR=\"$(xinitrcdir)\" -DSCRIPTDIR=\"$(privstartxdir)\" -DBINDIR=\"$(bindir)\"
+
+CPP_FILES_FLAGS = -DXINITDIR="$(xinitrcdir)" -DSCRIPTDIR="$(privstartxdir)" -DBINDIR="$(bindir)"
+
+privileged_startx_SOURCES =	\
+	privileged_startxServer.c \
+	privileged_startxUser.c \
+	server.c \
+	client.c \
+	privileged_startx.c
+
+BUILT_SOURCES = \
+	privileged_startxServer.c \
+	privileged_startxUser.c \
+	privileged_startxServer.h \
+	privileged_startx.h
+
+launchdaemons_PRE = org.x.privileged_startx.plist.cpp
+launchdaemons_DATA = $(launchdaemons_PRE:plist.cpp=plist)
+
+10-tmpdirs: 10-tmpdirs.cpp Makefile
+20-font_cache: 20-font_cache.cpp Makefile
+
+CLEANFILES = $(privstartx_SCRIPTS) $(BUILT_SOURCES) $(launchdaemons_DATA)
+
+EXTRA_DIST = 10-tmpdirs.cpp 20-font_cache.cpp org.x.privileged_startx.plist.cpp privileged_startx.defs
+
+$(BUILT_SOURCES): privileged_startx.defs
+	mig -sheader privileged_startxServer.h privileged_startx.defs
diff --git a/privileged_startx/client.c b/privileged_startx/client.c
new file mode 100644
index 0000000..2a24a70
--- /dev/null
+++ b/privileged_startx/client.c
@@ -0,0 +1,56 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <mach/mach.h>
+#include <mach/mach_error.h>
+#include <servers/bootstrap.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+#include "privileged_startx.h"
+
+int client_main(void) {
+    kern_return_t kr;
+    mach_port_t mp;
+    
+    kr = bootstrap_look_up(bootstrap_port, BOOTSTRAP_NAME, &mp);
+    if (kr != KERN_SUCCESS) {
+        fprintf(stderr, "bootstrap_look_up(): %s\n", bootstrap_strerror(kr));
+        exit(EXIT_FAILURE);
+    }
+    
+    kr = privileged_startx(mp);
+    if (kr != KERN_SUCCESS) {
+        fprintf(stderr, "privileged_startx client: %s\n", mach_error_string(kr));
+        exit(EXIT_FAILURE);
+    }
+    
+    exit(EXIT_SUCCESS);
+}
diff --git a/privileged_startx/org.x.privileged_startx.plist.cpp b/privileged_startx/org.x.privileged_startx.plist.cpp
new file mode 100644
index 0000000..e878dc3
--- /dev/null
+++ b/privileged_startx/org.x.privileged_startx.plist.cpp
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
+<plist version="1.0">
+<dict>
+	<key>Label</key>
+		<string>org.x.privileged_startx</string>
+	<key>MachServices</key>
+		<dict>
+			<key>org.x.privileged_startx</key>
+				<true/>
+		</dict>
+	<key>ProgramArguments</key>
+		<array>
+			<string>XINITDIR/privileged_startx</string>
+			<string>-d</string>
+			<string>SCRIPTDIR</string>
+		</array>
+	<key>TimeOut</key>
+		<integer>60</integer>
+</dict>
+</plist>
diff --git a/privileged_startx/privileged_startx.c b/privileged_startx/privileged_startx.c
new file mode 100644
index 0000000..725a1b0
--- /dev/null
+++ b/privileged_startx/privileged_startx.c
@@ -0,0 +1,59 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#ifndef SCRIPTDIR
+#define SCRIPTDIR="/usr/X11/lib/X11/xinit/privileged_startx.d"
+#endif
+
+static void usage(const char *prog) {
+    fprintf(stderr, "%s: usage\n", prog);
+    fprintf(stderr, "    %s [-d [<script dir>]]\n\n", prog);
+    fprintf(stderr, "              -d: Passed when called from launchd to denote server-mode.\n");
+    fprintf(stderr, "    <script dir>: Directory to use instead of %s\n", SCRIPTDIR);
+}
+
+int client_main(void);
+int server_main(const char *dir);
+
+int main(int argc, char *argv[]) {
+
+    if(argc == 1) {
+        return client_main();
+    } else if(!strncmp(argv[1], "-d", 2)) {
+        if(argc == 2)
+            return server_main(NULL);
+        else if(argc == 3)
+            return server_main(argv[2]);
+    }
+
+    usage(argv[0]);
+    return 1;
+}
diff --git a/privileged_startx/privileged_startx.defs b/privileged_startx/privileged_startx.defs
new file mode 100644
index 0000000..86f2b3a
--- /dev/null
+++ b/privileged_startx/privileged_startx.defs
@@ -0,0 +1,40 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+import "privileged_startx_types.h";
+
+subsystem privileged_startx 12345;
+serverprefix do_;
+
+routine privileged_startx(
+	port		:	mach_port_t);
+
+routine idle_exit(
+	port		:	mach_port_t);
diff --git a/privileged_startx/privileged_startx_types.h b/privileged_startx/privileged_startx_types.h
new file mode 100644
index 0000000..fef7195
--- /dev/null
+++ b/privileged_startx/privileged_startx_types.h
@@ -0,0 +1,6 @@
+#ifndef _PRIV_STARTX_TYPES_H_
+#define _PRIV_STARTX_TYPES_H_
+
+#define BOOTSTRAP_NAME "org.x.privileged_startx"
+
+#endif
diff --git a/privileged_startx/server.c b/privileged_startx/server.c
new file mode 100644
index 0000000..7afd424
--- /dev/null
+++ b/privileged_startx/server.c
@@ -0,0 +1,250 @@
+/* Copyright (c) 2008 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *


Reply to: