summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremy@yuffie.local>2007-12-15 15:01:02 -0800
committerJeremy Huddleston <jeremy@yuffie.local>2007-12-15 15:01:02 -0800
commitf5db2f6bc21b8d589b92c0f1d60bd6ec8da21ae0 (patch)
tree160161b98aef2e8ad4a2d6f5d10a3678c64b4e7a
parentc0246278393f9440717eea292a3d31440f7972dd (diff)
downloadxorg-app-xinit-f5db2f6bc21b8d589b92c0f1d60bd6ec8da21ae0.tar.gz
Added Apple launchd support
-rw-r--r--.gitignore3
-rw-r--r--Makefile.am48
-rw-r--r--configure.ac28
-rw-r--r--cpprules.in36
-rw-r--r--launchd/Makefile.am13
-rw-r--r--launchd/org.x.X11.plist.cpp24
-rw-r--r--launchd/x11-exec.c71
-rw-r--r--xinit.c4
8 files changed, 187 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 4b927e4..6356185 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,6 @@ xinit
xinit.1
xinitrc
*~
+*.o
+launchd/org.x.X11.plist
+launchd/x11-exec
diff --git a/Makefile.am b/Makefile.am
index 5becb5e..fe39364 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -38,39 +38,7 @@ appman_PRE = \
appman_DATA = $(appman_PRE:man=@APP_MAN_SUFFIX@)
-# Translate XCOMM into pound sign with sed, rather than passing -DXCOMM=XCOMM
-# to cpp, because that trick does not work on all ANSI C preprocessors.
-# Delete line numbers from the cpp output (-P is not portable, I guess).
-# Allow XCOMM to be preceded by whitespace and provide a means of generating
-# output lines with trailing backslashes.
-# Allow XHASH to always be substituted, even in cases where XCOMM isn't.
-
-CPP_SED_MAGIC = $(SED) -e '/^\# *[0-9][0-9]* *.*$$/d' \
- -e '/^\#line *[0-9][0-9]* *.*$$/d' \
- -e '/^[ ]*XCOMM$$/s/XCOMM/\#/' \
- -e '/^[ ]*XCOMM[^a-zA-Z0-9_]/s/XCOMM/\#/' \
- -e '/^[ ]*XHASH/s/XHASH/\#/' \
- -e '/\@\@$$/s/\@\@$$/\\/'
-
-# Strings to replace in man pages
-XORGRELSTRING = @PACKAGE_STRING@
- XORGMANNAME = X Version 11
-
-MANDEFS = \
- -D__xorgversion__="\"$(XORGRELSTRING)\" \"$(XORGMANNAME)\"" \
- -D__appmansuffix__=$(APP_MAN_SUFFIX) \
- -D__filemansuffix__=$(FILE_MAN_SUFFIX) \
- -D__libmansuffix__=$(LIB_MAN_SUFFIX) \
- -D__miscmansuffix__=$(MISC_MAN_SUFFIX) \
- -D__XSERVERNAME__=Xorg -D__XCONFIGFILE__=xorg.conf \
- -D__xinitdir__=$(XINITDIR) \
- -D__bindir__=$(bindir) \
- -DSHELL_CMD=$(SHELL_CMD) $(ARCHMANDEFS)
-
-SUFFIXES = .$(APP_MAN_SUFFIX) .man
-
-.man.$(APP_MAN_SUFFIX):
- $(RAWCPP) $(RAWCPPFLAGS) $(MANDEFS) $(EXTRAMANDEFS) < $< | $(CPP_SED_MAGIC) > $@
+include $(top_srcdir)/cpprules.in
xinitrcdir = $(XINITDIR)
@@ -84,15 +52,12 @@ PROGCPPDEFS = \
-DXAUTH=@XAUTH@ \
-DXINIT=@XINIT@
-SCRIPTDEFS = \
+CPP_FILES_FLAGS = \
-DXINITDIR=$(XINITDIR) $(PROGCPPDEFS) -DLIBDIR=$(libdir) \
-DSHELL_CMD=$(SHELL_CMD) $(STARTX_COOKIE_FLAGS)
-xinitrc: xinitrc.cpp
- $(RAWCPP) $(SCRIPTDEFS) < $(srcdir)/xinitrc.cpp | $(CPP_SED_MAGIC) > $@
-
+xinitrc: xinitrc.cpp Makefile
startx: startx.cpp Makefile
- $(RAWCPP) $(SCRIPTDEFS) < $(srcdir)/startx.cpp | $(CPP_SED_MAGIC) > $@
xinitrc_DATA = xinitrc
@@ -107,3 +72,10 @@ ChangeLog:
(GIT_DIR=$(top_srcdir)/.git git-log > .changelog.tmp && mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) || (touch ChangeLog; echo 'git directory not found: installing possibly empty changelog.' >&2)
dist-hook: ChangeLog
+
+if LAUNCHD
+LAUNCHD_SUBDIRS = launchd
+endif
+
+SUBDIRS = $(LAUNCHD_SUBDIRS)
+DIST_SUBDIRS = launchd
diff --git a/configure.ac b/configure.ac
index 05a7d17..34f021e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,6 +91,33 @@ 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)]),
+ [ launchagentsdir="${withval}" ],
+ [ launchagentsdir="/Library/LaunchAgents" ])
+AC_SUBST([launchagentsdir])
+
+if test "x$LAUNCHD" = "xauto"; then
+ unset LAUNCHD
+ AC_CHECK_PROG(LAUNCHD, [launchd], [yes], [no])
+fi
+
+if test "x$LAUNCHD" = "xyes" ; then
+ AC_DEFINE(HAVE_LAUNCHD, 1, [launchd support available])
+
+ # For now, this is how we find X11.app on OS-X...
+ # A future version of launchd should let us do this cleaner
+ case $host_os in
+ darwin*)
+ XSERVER=\'\`'$(libexecdir)/x11-exec'\`\'
+ AM_CONDITIONAL(APPLE, true)
+ ;;
+ esac
+fi
+AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
+
# Checks for pkg-config packages
PKG_CHECK_MODULES(XINIT, x11)
@@ -148,3 +175,4 @@ XORG_MANPAGE_SECTIONS
XORG_RELEASE_VERSION
AC_OUTPUT([Makefile])
+AC_OUTPUT([launchd/Makefile])
diff --git a/cpprules.in b/cpprules.in
new file mode 100644
index 0000000..2e50207
--- /dev/null
+++ b/cpprules.in
@@ -0,0 +1,36 @@
+# Translate XCOMM into pound sign with sed, rather than passing -DXCOMM=XCOMM
+# to cpp, because that trick does not work on all ANSI C preprocessors.
+# Delete line numbers from the cpp output (-P is not portable, I guess).
+# Allow XCOMM to be preceded by whitespace and provide a means of generating
+# output lines with trailing backslashes.
+# Allow XHASH to always be substituted, even in cases where XCOMM isn't.
+
+CPP_SED_MAGIC = $(SED) -e '/^\# *[0-9][0-9]* *.*$$/d' \
+ -e '/^\#line *[0-9][0-9]* *.*$$/d' \
+ -e '/^[ ]*XCOMM$$/s/XCOMM/\#/' \
+ -e '/^[ ]*XCOMM[^a-zA-Z0-9_]/s/XCOMM/\#/' \
+ -e '/^[ ]*XHASH/s/XHASH/\#/' \
+ -e '/\@\@$$/s/\@\@$$/\\/'
+
+# Strings to replace in man pages
+XORGRELSTRING = @PACKAGE_STRING@
+ XORGMANNAME = X Version 11
+
+MANDEFS = \
+ -D__xorgversion__="\"$(XORGRELSTRING)\" \"$(XORGMANNAME)\"" \
+ -D__appmansuffix__=$(APP_MAN_SUFFIX) \
+ -D__filemansuffix__=$(FILE_MAN_SUFFIX) \
+ -D__libmansuffix__=$(LIB_MAN_SUFFIX) \
+ -D__miscmansuffix__=$(MISC_MAN_SUFFIX) \
+ -D__XSERVERNAME__=Xorg -D__XCONFIGFILE__=xorg.conf \
+ -D__xinitdir__=$(XINITDIR) \
+ -D__bindir__=$(bindir) \
+ -DSHELL_CMD=$(SHELL_CMD) $(ARCHMANDEFS)
+
+SUFFIXES = .$(APP_MAN_SUFFIX) .man .cpp
+
+.cpp:
+ $(RAWCPP) $(RAWCPPFLAGS) $(CPP_FILES_FLAGS) < $< | $(CPP_SED_MAGIC) > $@
+
+.man.$(APP_MAN_SUFFIX):
+ $(RAWCPP) $(RAWCPPFLAGS) $(MANDEFS) $(EXTRAMANDEFS) < $< | $(CPP_SED_MAGIC) > $@
diff --git a/launchd/Makefile.am b/launchd/Makefile.am
new file mode 100644
index 0000000..6a420e6
--- /dev/null
+++ b/launchd/Makefile.am
@@ -0,0 +1,13 @@
+if APPLE
+libexec_PROGRAMS = x11-exec
+x11_exec_LDFLAGS = -framework CoreServices
+endif
+
+launchagents_PRE = org.x.X11.plist.pre
+launchagents_DATA = $(launchagents_PRE:plist.pre=plist)
+
+CPP_FILES_FLAGS = -D__bindir__="$(bindir)"
+
+CLEANFILES = $(launchagents_DATA)
+
+include $(top_srcdir)/cpprules.in
diff --git a/launchd/org.x.X11.plist.cpp b/launchd/org.x.X11.plist.cpp
new file mode 100644
index 0000000..822f1f7
--- /dev/null
+++ b/launchd/org.x.X11.plist.cpp
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//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.X11</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>__bindir__/startx</string>
+ <string>--</string>
+ <string>-launchd</string>
+ </array>
+ <key>Sockets</key>
+ <dict>
+ <key>:0</key>
+ <dict>
+ <key>SecureSocketWithKey</key>
+ <string>DISPLAY</string>
+ </dict>
+ </dict>
+ <key>ServiceIPC</key>
+ <true/>
+</dict>
+</plist>
diff --git a/launchd/x11-exec.c b/launchd/x11-exec.c
new file mode 100644
index 0000000..60e3934
--- /dev/null
+++ b/launchd/x11-exec.c
@@ -0,0 +1,71 @@
+/* x11-exec.c -- Find X11.app by bundle-id and report its path.
+ This is so launchd can correctly find X11.app, even if the user moved it.
+
+ Copyright (c) 2007 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 <CoreServices/CoreServices.h>
+#include <stdio.h>
+
+#define kX11AppBundleId "org.x.X11"
+#define kX11AppBundlePath "/Contents/MacOS/X11"
+
+int main(int argc, char **argv) {
+ char x11_path[PATH_MAX];
+ char** args = NULL;
+ CFURLRef appURL = NULL;
+ OSStatus osstatus = LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil, nil, &appURL);
+
+ switch (osstatus) {
+ case noErr:
+ if (appURL == NULL) {
+ fprintf(stderr, "%s: Invalid response from LSFindApplicationForInfo(%s)\n",
+ argv[0], kX11AppBundleId);
+ exit(1);
+ }
+
+ if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
+ fprintf(stderr, "%s: Error resolving URL for %s\n", argv[0], kX11AppBundleId);
+ exit(2);
+ }
+
+ printf("%s/%s\n", x11_path, kX11AppBundlePath);
+
+ exit(0);
+ break;
+ case kLSApplicationNotFoundErr:
+ fprintf(stderr, "%s: Unable to find application for %s\n", argv[0], kX11AppBundleId);
+ exit(4);
+ default:
+ fprintf(stderr, "%s: Unable to find application for %s, error code = %d\n",
+ argv[0], kX11AppBundleId, osstatus);
+ exit(5);
+ }
+ /* not reached */
+}
+
+
diff --git a/xinit.c b/xinit.c
index 39ab3ec..e4bdc6d 100644
--- a/xinit.c
+++ b/xinit.c
@@ -171,7 +171,7 @@ char *displayNum;
char *program;
Display *xd; /* server connection */
#ifndef SYSV
-#if defined(__CYGWIN__) || defined(SVR4) || defined(_POSIX_SOURCE) || defined(CSRG_BASED) || defined(__UNIXOS2__) || defined(Lynx)
+#if defined(__CYGWIN__) || defined(SVR4) || defined(_POSIX_SOURCE) || defined(CSRG_BASED) || defined(__UNIXOS2__) || defined(Lynx) || defined(__APPLE__)
int status;
#else
union wait status;
@@ -495,7 +495,7 @@ processTimeout(int timeout, char *string)
break;
alarm(0);
#else /* SYSV */
-#if defined(SVR4) || defined(_POSIX_SOURCE) || defined(Lynx)
+#if defined(SVR4) || defined(_POSIX_SOURCE) || defined(Lynx) || defined(__APPLE__)
if ((pidfound = waitpid(serverpid, &status, WNOHANG)) == serverpid)
break;
#else