]> git.draconx.ca Git - gentoo-draconx.git/blob - x11-base/xorg-server/files/xdm.initd-3
34719773173a9e0e7ef13c50d80d073e91c612d1
[gentoo-draconx.git] / x11-base / xorg-server / files / xdm.initd-3
1 #!/sbin/runscript
2 # Copyright 1999-2004 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,v 1.1 2010/04/13 10:07:39 scarabeus Exp $
5
6 # This is here to serve as a note to myself, and future developers.
7 #
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.
13 #
14 # Resolution: add the following line to /etc/inittab
15 #
16 #  x:a:once:/etc/X11/startDM.sh
17 #
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.
21 #
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
28 # done previously.
29 #
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
33 # using).
34 #
35 # Martin Schlemmer
36 # aka Azarah
37 # 04 March 2002
38
39 depend() {
40         need localmount xdm-setup
41
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         after bootmisc consolefont modules netmount
49         after readahead-list ypbind autofs openvpn gpm lircmd
50         after quota
51         before alsasound
52
53         # Start before X
54         use consolekit xfs
55 }
56
57 setup_dm() {
58         local MY_XDM
59         
60         MY_XDM=$(echo "${DISPLAYMANAGER}" | tr '[:upper:]' '[:lower:]')
61
62         # Load our root path from profile.env
63         # Needed for kdm
64         PATH=${PATH}:$(. /etc/profile.env; echo "${ROOTPATH}")
65
66         NAME=
67         case "${MY_XDM}" in
68                 kdm|kde)
69                         EXE="$(which kdm)"
70                         PIDFILE=/var/run/kdm.pid
71                         ;;
72                 kdm-*)
73                         EXE="/usr/kde/${MY_XDM#kdm-}/bin/kdm"
74                         PIDFILE=/var/run/kdm.pid
75                         ;;
76                 entrance*)
77                         EXE=/usr/sbin/entranced
78                         PIDFILE=/var/lib/entranced.pid
79                         ;;
80                 gdm|gnome)
81                         EXE=/usr/bin/gdm
82                         [ "${RC_UNAME}" != "Linux" ] && NAME=gdm-binary
83                         PIDFILE=/var/run/gdm.pid
84                         ;;
85                 wdm)
86                         EXE=/usr/bin/wdm
87                         PIDFILE=
88                         ;;
89                 gpe)
90                         EXE=/usr/bin/gpe-dm
91                         PIDFILE=/var/run/gpe-dm.pid
92                         ;;
93                 *)
94                         # first find out if there is such executable
95                         EXE="$(which ${MY_XDM} 2>/dev/null)"
96                         PIDFILE="/var/run/${MY_XDM}.pid"
97
98                         # warn user that he is doing sick things if the exe was not found
99                         if [ -z "${EXE}" ]; then
100                                 echo "ERROR: Your XDM value is invalid."
101                                 echo "  No ${MY_XDM} executable could be found on your system."
102                         fi
103                         ;;
104         esac
105
106         if ! [ -x "${EXE}" ]; then
107                 EXE=/usr/bin/xdm
108                 PIDFILE=/var/run/xdm.pid
109                 if ! [ -x "/usr/bin/xdm" ]; then
110                         echo "ERROR: Please set your DISPLAYMANAGER variable in /etc/conf.d/xdm,"
111                         echo "  or install x11-apps/xdm package"
112                         eend 255
113                 fi
114         fi
115 }
116
117 # Check to see if something is defined on our VT
118 vtstatic() {
119         if [ -e /etc/inittab ] ; then
120                 grep -Eq "^[^#]+.*\<tty$1\>" /etc/inittab
121         elif [ -e /etc/ttys ] ; then
122                 grep -q "^ttyv$(($1 - 1))" /etc/ttys
123         else
124                 return 1
125         fi
126 }
127
128 start() {
129         local EXE NAME PIDFILE
130         setup_dm
131
132         if [ -f /etc/.noxdm ]; then
133                 einfo "Skipping ${EXE##*/}, /etc/.noxdm found or \"nox\" bootparam passed."
134                 rm /etc/.noxdm
135                 return 0
136         fi
137
138         ebegin "Setting up ${EXE##*/}"
139
140         # save the prefered DM
141         save_options "service" "${EXE}"
142         save_options "name"    "${NAME}"
143         save_options "pidfile" "${PIDFILE}"
144
145         if [ -n "${CHECKVT-y}" ] ; then
146                 if vtstatic "${CHECKVT:-7}" ; then
147                         if [ -x /sbin/telinit ] && [ "${SOFTLEVEL}" != "BOOT" ] && [ "${RC_SOFTLEVEL}" != "BOOT" ]; then
148                                 ewarn "Something is already defined on VT ${CHECKVT:-7}, will start X later"
149                                 telinit a >/dev/null 2>&1
150                                 return 0
151                         else
152                                 eerror "Something is already defined on VT ${CHECKVT:-7}, not starting"
153                                 return 1
154                         fi
155                 fi
156         fi
157
158         /etc/X11/startDM.sh
159         eend 0
160 }
161
162 stop() {
163         local curvt retval
164
165         retval=0
166         if [ -t 0 ]; then
167                 if type fgconsole >/dev/null 2>&1; then
168                         curvt=$(fgconsole 2>/dev/null)
169                 else
170                         curvt=$(tty)
171                         case "${curvt}" in
172                                 /dev/ttyv[0-9]*) curvt=${curvt#/dev/ttyv} ;;
173                                 *) curvt= ;;
174                         esac
175                 fi
176         fi
177         local myexe myname mypidfile myservice
178         myexe=$(get_options "service")
179         myname=$(get_options "name")
180         mypidfile=$(get_options "pidfile")
181         myservice=${myexe##*/}
182
183         [ -z "${myexe}" ] && return 0
184
185         ebegin "Stopping ${myservice}"
186
187         if start-stop-daemon --quiet --test --stop --exec "${myexe}"; then
188                 start-stop-daemon --stop --exec "${myexe}" --retry TERM/5/TERM/5 \
189                         ${mypidfile:+--pidfile} ${mypidfile} \
190                         ${myname:+--name} ${myname}
191                 retval=${?}
192         fi
193
194         # switch back to original vt
195         if [ -n "${curvt}" ]; then
196                 if type chvt >/dev/null 2>&1; then
197                         chvt "${curvt}"
198                 else
199                         vidcontrol -s "$((curvt + 1))"
200                 fi
201         fi
202
203         eend ${retval} "Error stopping ${myservice}"
204         return ${retval}
205 }
206
207 # vim: set ts=4 :