summaryrefslogtreecommitdiff
path: root/app/xinit/privileged_startx
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2009-05-03 13:17:38 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2009-05-03 13:17:38 +0000
commitcb30426369feb6c054f91003ddd7be346fbf6158 (patch)
treeb3b56e9fa443c01b9869ca7d1274b1f5a6e61a43 /app/xinit/privileged_startx
parent42f51ca8ac9c0f97101006a1892350b599b579c3 (diff)
update to xinit 1.1.1
Diffstat (limited to 'app/xinit/privileged_startx')
-rw-r--r--app/xinit/privileged_startx/20-font_cache.cpp4
-rw-r--r--app/xinit/privileged_startx/Makefile.am9
-rw-r--r--app/xinit/privileged_startx/Makefile.in21
-rw-r--r--app/xinit/privileged_startx/client.c6
-rw-r--r--app/xinit/privileged_startx/org.x.privileged_startx.plist.cpp19
-rw-r--r--app/xinit/privileged_startx/server.c68
6 files changed, 103 insertions, 24 deletions
diff --git a/app/xinit/privileged_startx/20-font_cache.cpp b/app/xinit/privileged_startx/20-font_cache.cpp
index c13384b63..6d43e107b 100644
--- a/app/xinit/privileged_startx/20-font_cache.cpp
+++ b/app/xinit/privileged_startx/20-font_cache.cpp
@@ -27,9 +27,9 @@ 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 &
+ BINDIR/font_cache -s &
elif [ -x BINDIR/font_cache.sh ] ; then
BINDIR/font_cache.sh -s &
-elif [ -x /usr/X11/bin/fc-cache ] ; then
+elif [ -x BINDIR/fc-cache ] ; then
BINDIR/fc-cache &
fi
diff --git a/app/xinit/privileged_startx/Makefile.am b/app/xinit/privileged_startx/Makefile.am
index 6a143ca18..2d6854473 100644
--- a/app/xinit/privileged_startx/Makefile.am
+++ b/app/xinit/privileged_startx/Makefile.am
@@ -34,9 +34,12 @@ 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)"
+if TIGER_LAUNCHD
+CPP_FILES_FLAGS += -DTIGER_LAUNCHD
+endif
+
dist_privileged_startx_SOURCES = \
server.c \
client.c \
@@ -70,5 +73,5 @@ EXTRA_DIST = \
privileged_startx.defs \
privileged_startx_types.h
-$(BUILT_SOURCES): privileged_startx.defs
- mig -sheader privileged_startxServer.h privileged_startx.defs
+$(BUILT_SOURCES): $(srcdir)/privileged_startx.defs
+ mig -sheader privileged_startxServer.h $(srcdir)/privileged_startx.defs
diff --git a/app/xinit/privileged_startx/Makefile.in b/app/xinit/privileged_startx/Makefile.in
index 2b832c1e8..5b8e9984b 100644
--- a/app/xinit/privileged_startx/Makefile.in
+++ b/app/xinit/privileged_startx/Makefile.in
@@ -75,6 +75,7 @@ host_triplet = @host@
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(top_srcdir)/cpprules.in
xinitrc_PROGRAMS = privileged_startx$(EXEEXT)
+@TIGER_LAUNCHD_TRUE@am__append_1 = -DTIGER_LAUNCHD
subdir = privileged_startx
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -147,6 +148,7 @@ EGREP = @EGREP@
EXEEXT = @EXEEXT@
FILE_MAN_DIR = @FILE_MAN_DIR@
FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
@@ -184,6 +186,8 @@ SHELL = @SHELL@
SHELL_CMD = @SHELL_CMD@
STARTX_COOKIE_FLAGS = @STARTX_COOKIE_FLAGS@
STRIP = @STRIP@
+TIGER_LAUNCHD_FALSE = @TIGER_LAUNCHD_FALSE@
+TIGER_LAUNCHD_TRUE = @TIGER_LAUNCHD_TRUE@
TWM = @TWM@
VERSION = @VERSION@
WM = @WM@
@@ -198,8 +202,6 @@ XRDB = @XRDB@
XSERVER = @XSERVER@
XTERM = @XTERM@
ac_ct_CC = @ac_ct_CC@
-ac_ct_STRIP = @ac_ct_STRIP@
-ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
@@ -214,12 +216,16 @@ build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
+htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
@@ -227,12 +233,15 @@ launchagentsdir = @launchagentsdir@
launchdaemonsdir = @launchdaemonsdir@
libdir = @libdir@
libexecdir = @libexecdir@
+localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
+psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
@@ -265,7 +274,9 @@ xinitrcdir = $(libdir)/X11/xinit
privstartxdir = $(xinitrcdir)/privileged_startx.d
privstartx_SCRIPTS = 10-tmpdirs 20-font_cache
AM_CPPFLAGS = -DXINITDIR=\"$(xinitrcdir)\" -DSCRIPTDIR=\"$(privstartxdir)\" -DBINDIR=\"$(bindir)\"
-CPP_FILES_FLAGS = -DXINITDIR="$(xinitrcdir)" -DSCRIPTDIR="$(privstartxdir)" -DBINDIR="$(bindir)"
+CPP_FILES_FLAGS = -DXINITDIR="$(xinitrcdir)" \
+ -DSCRIPTDIR="$(privstartxdir)" -DBINDIR="$(bindir)" \
+ $(am__append_1)
dist_privileged_startx_SOURCES = \
server.c \
client.c \
@@ -605,8 +616,8 @@ uninstall-am: uninstall-info-am uninstall-launchdaemonsDATA \
10-tmpdirs: 10-tmpdirs.cpp Makefile
20-font_cache: 20-font_cache.cpp Makefile
-$(BUILT_SOURCES): privileged_startx.defs
- mig -sheader privileged_startxServer.h privileged_startx.defs
+$(BUILT_SOURCES): $(srcdir)/privileged_startx.defs
+ mig -sheader privileged_startxServer.h $(srcdir)/privileged_startx.defs
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/app/xinit/privileged_startx/client.c b/app/xinit/privileged_startx/client.c
index 2a24a7086..a33dd02c5 100644
--- a/app/xinit/privileged_startx/client.c
+++ b/app/xinit/privileged_startx/client.c
@@ -34,6 +34,8 @@
#include <stdlib.h>
#include <stdbool.h>
+#include <AvailabilityMacros.h>
+
#include "privileged_startx.h"
int client_main(void) {
@@ -42,7 +44,11 @@ int client_main(void) {
kr = bootstrap_look_up(bootstrap_port, BOOTSTRAP_NAME, &mp);
if (kr != KERN_SUCCESS) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
fprintf(stderr, "bootstrap_look_up(): %s\n", bootstrap_strerror(kr));
+#else
+ fprintf(stderr, "bootstrap_look_up(): %ul\n", (unsigned long)kr);
+#endif
exit(EXIT_FAILURE);
}
diff --git a/app/xinit/privileged_startx/org.x.privileged_startx.plist.cpp b/app/xinit/privileged_startx/org.x.privileged_startx.plist.cpp
index e878dc3e3..7400cc4af 100644
--- a/app/xinit/privileged_startx/org.x.privileged_startx.plist.cpp
+++ b/app/xinit/privileged_startx/org.x.privileged_startx.plist.cpp
@@ -4,18 +4,25 @@
<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>
+#ifdef TIGER_LAUNCHD
+ <key>KeepAlive</key>
+ <true/>
+#else
+ <key>MachServices</key>
+ <dict>
+ <key>org.x.privileged_startx</key>
+ <true/>
+ </dict>
<key>TimeOut</key>
- <integer>60</integer>
+ <integer>120</integer>
+ <key>EnableTransactions</key>
+ <true/>
+#endif
</dict>
</plist>
diff --git a/app/xinit/privileged_startx/server.c b/app/xinit/privileged_startx/server.c
index 7afd42418..6dd4f2b8c 100644
--- a/app/xinit/privileged_startx/server.c
+++ b/app/xinit/privileged_startx/server.c
@@ -40,7 +40,6 @@
#include <sys/time.h>
#include <launch.h>
#include <asl.h>
-#include <pthread.h>
#include <errno.h>
#include "privileged_startx.h"
@@ -51,6 +50,10 @@ union MaxMsgSize {
union __ReplyUnion__privileged_startx_subsystem rep;
};
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
+#include <pthread.h>
+static void* idle_thread(void* param __attribute__((unused)));
+
/* globals to trigger idle exit */
#define DEFAULT_IDLE_TIMEOUT 60 /* 60 second timeout, then the server exits */
@@ -61,6 +64,7 @@ struct idle_globals {
};
struct idle_globals idle_globals;
+#endif
#ifndef SCRIPTDIR
#define SCRIPTDIR="/usr/X11/lib/X11/xinit/privileged_startx.d"
@@ -69,13 +73,46 @@ struct idle_globals idle_globals;
/* Default script dir */
const char *script_dir = SCRIPTDIR;
-static void* idle_thread(void* param __attribute__((unused)));
+#ifndef LAUNCH_JOBKEY_MACHSERVICES
+static mach_port_t checkin_or_register(char *bname) {
+ kern_return_t kr;
+ mach_port_t mp;
+
+ /* If we're started by launchd or the old mach_init */
+ kr = bootstrap_check_in(bootstrap_port, bname, &mp);
+ if (kr == KERN_SUCCESS)
+ return mp;
+
+ /* We probably were not started by launchd or the old mach_init */
+ kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &mp);
+ if (kr != KERN_SUCCESS) {
+ fprintf(stderr, "mach_port_allocate(): %s\n", mach_error_string(kr));
+ exit(EXIT_FAILURE);
+ }
+
+ kr = mach_port_insert_right(mach_task_self(), mp, mp, MACH_MSG_TYPE_MAKE_SEND);
+ if (kr != KERN_SUCCESS) {
+ fprintf(stderr, "mach_port_insert_right(): %s\n", mach_error_string(kr));
+ exit(EXIT_FAILURE);
+ }
+
+ kr = bootstrap_register(bootstrap_port, bname, mp);
+ if (kr != KERN_SUCCESS) {
+ fprintf(stderr, "bootstrap_register(): %s\n", mach_error_string(kr));
+ exit(EXIT_FAILURE);
+ }
+
+ return mp;
+}
+#endif
int server_main(const char *dir) {
mach_msg_size_t mxmsgsz = sizeof(union MaxMsgSize) + MAX_TRAILER_SIZE;
mach_port_t mp;
kern_return_t kr;
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
long idle_timeout = DEFAULT_IDLE_TIMEOUT;
+#endif
launch_data_t config = NULL, checkin = NULL;
checkin = launch_data_new_string(LAUNCH_KEY_CHECKIN);
@@ -85,6 +122,13 @@ int server_main(const char *dir) {
exit(EXIT_FAILURE);
}
+ if(dir) {
+ script_dir = dir;
+ asl_log(NULL, NULL, ASL_LEVEL_DEBUG,
+ "script directory set: %s", script_dir);
+ }
+
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
launch_data_t tmv;
tmv = launch_data_dict_lookup(config, LAUNCH_JOBKEY_TIMEOUT);
if (tmv) {
@@ -93,12 +137,6 @@ int server_main(const char *dir) {
"idle timeout set: %ld seconds", idle_timeout);
}
- if(dir) {
- script_dir = dir;
- asl_log(NULL, NULL, ASL_LEVEL_DEBUG,
- "script directory set: %s", script_dir);
- }
-
launch_data_t svc;
svc = launch_data_dict_lookup(config, LAUNCH_JOBKEY_MACHSERVICES);
if (!svc) {
@@ -114,6 +152,10 @@ int server_main(const char *dir) {
}
mp = launch_data_get_machport(svc);
+#else
+ mp = checkin_or_register("org.x.privileged_startx");
+#endif
+
if (mp == MACH_PORT_NULL) {
asl_log(NULL, NULL, ASL_LEVEL_ERR, "NULL mach service: %s",
BOOTSTRAP_NAME);
@@ -129,12 +171,14 @@ int server_main(const char *dir) {
exit(EXIT_FAILURE);
}
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
/* spawn a thread to monitor our idle timeout */
pthread_t thread;
idle_globals.mp = mp;
idle_globals.timeout = idle_timeout;
gettimeofday(&idle_globals.lastmsg, NULL);
pthread_create(&thread, NULL, &idle_thread, NULL);
+#endif
/* Main event loop */
kr = mach_msg_server(privileged_startx_server, mxmsgsz, mp, 0);
@@ -161,8 +205,10 @@ kern_return_t do_privileged_startx(mach_port_t test_port __attribute__((unused))
const char * path_argv[2] = {script_dir, NULL};
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
/* Store that we were called, so the idle timer will reset */
gettimeofday(&idle_globals.lastmsg, NULL);
+#endif
/* script_dir contains a set of files to run with root privs when X11 starts */
ftsp = fts_open(path_argv, FTS_PHYSICAL, ftscmp);
@@ -222,6 +268,7 @@ kern_return_t do_privileged_startx(mach_port_t test_port __attribute__((unused))
}
kern_return_t do_idle_exit(mach_port_t test_port __attribute__((unused))) {
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
struct timeval now;
gettimeofday(&now, NULL);
@@ -231,8 +278,12 @@ kern_return_t do_idle_exit(mach_port_t test_port __attribute__((unused))) {
}
return KERN_SUCCESS;
+#else
+ return KERN_FAILURE;
+#endif
}
+#ifdef LAUNCH_JOBKEY_MACHSERVICES
static void *idle_thread(void* param __attribute__((unused))) {
for(;;) {
struct timeval now;
@@ -248,3 +299,4 @@ static void *idle_thread(void* param __attribute__((unused))) {
}
return NULL;
}
+#endif