2 # Copyright 1999-2012 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License, v2
4 # $Header: /var/cvsroot/gentoo-x86/x11-base/xorg-server/files/xdm.initd-8,v 1.1 2012/05/01 22:08:46 chithanh Exp $
6 # This is here to serve as a note to myself, and future developers.
8 # Any Display manager (gdm,kdm,xdm) has the following problem: if
9 # it is started before any getty, and no vt is specified, it will
10 # usually run on vt2. When the getty on vt2 then starts, and the
11 # DM is already started, the getty will take control of the keyboard,
12 # leaving us with a "dead" keyboard.
14 # Resolution: add the following line to /etc/inittab
16 # x:a:once:/etc/X11/startDM.sh
18 # and have /etc/X11/startDM.sh start the DM in daemon mode if
19 # a lock is present (with the info of what DM should be started),
20 # else just fall through.
22 # How this basically works, is the "a" runlevel is a additional
23 # runlevel that you can use to fork processes with init, but the
24 # runlevel never gets changed to this runlevel. Along with the "a"
25 # runlevel, the "once" key word means that startDM.sh will only be
26 # run when we specify it to run, thus eliminating respawning
27 # startDM.sh when "xdm" is not added to the default runlevel, as was
30 # This script then just calls "telinit a", and init will run
31 # /etc/X11/startDM.sh after the current runlevel completes (this
32 # script should only be added to the actual runlevel the user is
40 need localmount xdm-setup
42 # this should start as early as possible
43 # we can't do 'before *' as that breaks it
44 # (#139824) Start after ypbind and autofs for network authentication
45 # (#145219 #180163) Could use lirc mouse as input device
46 # (#70689 comment #92) Start after consolefont to avoid display corruption
47 # (#291269) Start after quota, since some dm need readable home
48 # (#390609) gdm-3 will fail when dbus is not running
49 # (#366753) starting keymaps after X causes problems
50 after bootmisc consolefont modules netmount
51 after readahead-list ypbind autofs openvpn gpm lircmd
56 use consolekit dbus xfs
62 MY_XDM=$(echo "${DISPLAYMANAGER}" | tr '[:upper:]' '[:lower:]')
64 # Load our root path from profile.env
66 PATH=${PATH}:$(. /etc/profile.env; echo "${ROOTPATH}")
72 PIDFILE=/var/run/kdm.pid
75 EXE=/usr/sbin/entranced
76 PIDFILE=/var/lib/entranced.pid
80 [ "${RC_UNAME}" != "Linux" ] && NAME=gdm-binary
81 PIDFILE=/var/run/gdm.pid
89 PIDFILE=/var/run/gpe-dm.pid
92 EXE=/usr/sbin/lxdm-binary
93 PIDFILE=/var/run/lxdm.pid
94 START_STOP_ARGS="--background"
98 PIDFILE=/var/run/lightdm.pid
99 START_STOP_ARGS="--background"
102 # first find out if there is such executable
103 EXE="$(command -v ${MY_XDM} 2>/dev/null)"
104 PIDFILE="/var/run/${MY_XDM}.pid"
106 # warn user that he is doing sick things if the exe was not found
107 if [ -z "${EXE}" ]; then
108 echo "ERROR: Your XDM value is invalid."
109 echo " No ${MY_XDM} executable could be found on your system."
114 if ! [ -x "${EXE}" ]; then
116 PIDFILE=/var/run/xdm.pid
117 if ! [ -x "/usr/bin/xdm" ]; then
118 echo "ERROR: Please set your DISPLAYMANAGER variable in /etc/conf.d/xdm,"
119 echo " or install x11-apps/xdm package"
125 # Check to see if something is defined on our VT
127 if [ -e /etc/inittab ] ; then
128 grep -Eq "^[^#]+.*\<tty$1\>" /etc/inittab
129 elif [ -e /etc/ttys ] ; then
130 grep -q "^ttyv$(($1 - 1))" /etc/ttys
137 local EXE NAME PIDFILE
140 if [ -f /etc/.noxdm ]; then
141 einfo "Skipping ${EXE##*/}, /etc/.noxdm found or \"nox\" bootparam passed."
146 ebegin "Setting up ${EXE##*/}"
148 # save the prefered DM
149 save_options "service" "${EXE}"
150 save_options "name" "${NAME}"
151 save_options "pidfile" "${PIDFILE}"
152 save_options "start_stop_args" "${START_STOP_ARGS}"
154 if [ -n "${CHECKVT-y}" ] ; then
155 if vtstatic "${CHECKVT:-7}" ; then
156 if [ -x /sbin/telinit ] && [ "${SOFTLEVEL}" != "BOOT" ] && [ "${RC_SOFTLEVEL}" != "BOOT" ]; then
157 ewarn "Something is already defined on VT ${CHECKVT:-7}, will start X later"
158 telinit a >/dev/null 2>&1
161 eerror "Something is already defined on VT ${CHECKVT:-7}, not starting"
176 if type fgconsole >/dev/null 2>&1; then
177 curvt=$(fgconsole 2>/dev/null)
181 /dev/ttyv[0-9]*) curvt=${curvt#/dev/ttyv} ;;
186 local myexe myname mypidfile myservice
187 myexe=$(get_options "service")
188 myname=$(get_options "name")
189 mypidfile=$(get_options "pidfile")
190 myservice=${myexe##*/}
192 [ -z "${myexe}" ] && return 0
194 ebegin "Stopping ${myservice}"
196 if start-stop-daemon --quiet --test --stop --exec "${myexe}"; then
197 start-stop-daemon --stop --exec "${myexe}" --retry TERM/5/TERM/5 \
198 ${mypidfile:+--pidfile} ${mypidfile} \
199 ${myname:+--name} ${myname}
203 # switch back to original vt
204 if [ -n "${curvt}" ]; then
205 if type chvt >/dev/null 2>&1; then
208 vidcontrol -s "$((curvt + 1))"
212 eend ${retval} "Error stopping ${myservice}"