Move code used to launch X to cdm-xlaunch(1), since it's relatively

independent code and thus would be sometimes useful for running as a
standalone program.
pull/7/head
Casper Ti. Vector 12 years ago
parent d61d3ad3fb
commit f54e4a2ccd

@ -197,43 +197,11 @@ xstart() {
serverargs=":${display} ${serverargs} vt$((xtty+display))"
if $(yesno consolekit); then #do first to avoid race conditions
ebegin "Waiting for ConsoleKit to register X session (timeout ${cktimeout}s)..."
sleep $cktimeout &
clockpid=$!
#have to store pid of dbus-monitor this way since dbus-monitor will run until killed.
fifo=$(mktemp --dry-run)
mkfifo --mode=700 $fifo
(dbus-monitor --system type=signal,interface=org.freedesktop.ConsoleKit.Seat,member=SessionAdded & echo $! > $fifo ) | \
sed -un 's|[[:space:]]*object path \"\(/[a-zA-Z0-9/]*\)\"|\1|p' | while read object; do
if dbus-send --system --print-reply --dest=org.freedesktop.ConsoleKit "$object" org.freedesktop.ConsoleKit.Session.GetX11Display | \
grep -qF "$display"; then break
fi
done &
read dbuspid < $fifo
rm -f $fifo
$(yesno consolekit) && launchflags="-c -t $cktimeout"
if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then
ewarn "\`cdm-xlaunch' exited unsuccessfully."
exit 1
fi
# Conform to POSIX and do not use `>&' here.
sh -i -c "(startx $wm_bin -- ${serverargs} > /dev/null 2>&1 &)"
if [[ -n $clockpid ]]; then
#if wait returns with a value >128, it was interrupted by the trap, so registration was sucessful.
if wait $clockpid; then
eend "Timed out, giving up.\nCheck to see if you are wrapping your session with ck-launch-session or increase the timeout."
kill $dbuspid
exit 1
else
eend 0
kill $dbuspid $clockpid
exit 0
fi
fi
exit 0
}
mainmenu

@ -0,0 +1,92 @@
#!/bin/bash
#
# CDM: The Console Display Manager
#
# Copyright (C) 2009-2011, Daniel J Griffiths <ghost1227@archlinux.us>
# Thanks to:
#
# Andrwe beta-testing and submitting the fix for the all
# important X incrementation function
# brisbin33 code cleanup
# tigrmesh finding a critical issue with the gnome-session handler
# Profjim several incredibly useful patches
# lambchops468 consolekit and hibernation patches
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
name=$(basename "$0")
consolekit=false
cktimeout=30
source /etc/init.d/functions.sh
args=`getopt -n "$name" -o ct: -l consolekit,timeout: -- "$@"` || exit 1
eval set -- "$args"
for arg in "$@"
do
case $arg in
'--consolekit' | '-c')
consolekit=true; shift
;;
'--timeout' | '-t')
shift
cktimeout=$1; shift
;;
'--')
shift
break
;;
esac
done
# Do first to avoid race conditions.
if $consolekit; then
ebegin "$name: waiting for ConsoleKit to register X session"
sleep "$cktimeout" & clockpid=$!
dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX)
if ! mkfifo "$dbuspidfifo"; then
eend "$name: failed to create FIFO \`$fifo'."
exit 1
fi
(dbus-monitor --system 'type=signal,interface=org.freedesktop.ConsoleKit.Seat,member=SessionAdded' & echo $! > "$dbuspidfifo") |
sed -un 's@[[:space:]]*object path \"\(/[a-zA-Z0-9/]*\)\"@\1@p' | while read object; do
if dbus-send --system --print-reply --dest='org.freedesktop.ConsoleKit' "$object" 'org.freedesktop.ConsoleKit.Session.GetX11Display' |
grep -qF "$display"
then
kill "$clockpid"
break
fi
done &
dbuspid=$(<"$dbuspidfifo"); rm -f "$dbuspidfifo"
fi
# Conform to POSIX and do not use `>&' here.
sh -i -c "(startx $* > /dev/null 2>&1 &)"
# If `wait' returns with a value >128, it was interrupted by the trap, so registration was sucessful.
if [[ -n "$clockpid" ]]; then
if wait "$clockpid" >& /dev/null
then
kill "$dbuspid"
eend "$name: ConsoleKit registration timed out."
exit 1
else
kill "$dbuspid"
eend 0
exit 0
fi
fi
Loading…
Cancel
Save