3 XCOMM $Xorg: startx.cpp,v 1.3 2000/08/17 19:54:29 cpqbld Exp $
5 XCOMM This is just a sample implementation of a slightly less primitive
6 XCOMM interface than xinit. It looks for user .xinitrc and .xserverrc
7 XCOMM files, then system xinitrc and xserverrc files, else lets xinit choose
8 XCOMM its default. The system xinitrc should probably do things like check
9 XCOMM for .Xresources files and merge them in, startup up a window manager,
10 XCOMM and pop a clock and serveral xterms.
12 XCOMM Site administrators are STRONGLY urged to write nicer versions.
14 XCOMM $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $
16 unset DBUS_SESSION_BUS_ADDRESS
19 #if defined(__SCO__) || defined(__UNIXWARE__) || defined(__APPLE__)
21 XCOMM Check for /usr/bin/X11 and BINDIR in the path, if not add them.
22 XCOMM This allows startx to be placed in a place like /usr/bin or /usr/local/bin
23 XCOMM and people may use X without changing their PATH.
24 XCOMM Note that we put our own bin directory at the front of the path, and
25 XCOMM the standard system path at the back, since if you are using the Xorg
26 XCOMM server theres a pretty good chance you want to bias the Xorg clients
27 XCOMM over the old system's clients.
29 XCOMM First our compiled path
33 *:$bindir | *:$bindir:* | $bindir:*) ;;
34 *) PATH=$bindir:$PATH ;;
37 XCOMM Now the "old" compiled path
39 oldbindir=/usr/X11R6/bin
41 oldbindir=/usr/bin/X11
44 if [ -d "$oldbindir" ] ; then
46 *:$oldbindir | *:$oldbindir:* | $oldbindir:*) ;;
47 *) PATH=$PATH:$oldbindir ;;
51 XCOMM Bourne shell does not automatically export modified environment variables
52 XCOMM so export the new PATH just in case the user changes the shell
56 #if defined(__SCO__) || defined(__UNIXWARE__)
57 XCOMM Set up the XMERGE env var so that dos merge is happy under X
59 if [ -f /usr/lib/merge/xmergeset.sh ]; then
60 . /usr/lib/merge/xmergeset.sh
61 elif [ -f /usr/lib/merge/console.disp ]; then
62 XMERGE=`cat /usr/lib/merge/console.disp`
66 userclientrc=$HOME/.startxrc
67 sysclientrc=LIBDIR/sys.startxrc
68 scouserclientrc=$HOME/.xinitrc
69 scosysclientrc=XINITDIR/xinitrc
71 userclientrc=$HOME/.xinitrc
72 sysclientrc=XINITDIR/xinitrc
75 userserverrc=$HOME/.xserverrc
76 sysserverrc=XINITDIR/xserverrc
87 XCOMM Initialize defaults (this will cut down on "safe" error messages)
88 if ! defaults read org.x.X11 cache_fonts >& /dev/null ; then
89 defaults write org.x.X11 cache_fonts -bool true
92 if ! defaults read org.x.X11 no_auth >& /dev/null ; then
93 defaults write org.x.X11 no_auth -bool false
96 if ! defaults read org.x.X11 nolisten_tcp >& /dev/null ; then
97 defaults write org.x.X11 nolisten_tcp -bool true
100 XCOMM First, start caching fonts
101 if [ x`defaults read org.x.X11 cache_fonts` = x1 ] ; then
102 if [ -x /usr/X11/bin/font_cache ] ; then
103 /usr/X11/bin/font_cache &
104 elif [ -x /usr/X11/bin/font_cache.sh ] ; then
105 /usr/X11/bin/font_cache.sh &
106 elif [ -x /usr/X11/bin/fc-cache ] ; then
107 /usr/X11/bin/fc-cache &
111 if [ -x XINITDIR/privileged_startx ] ; then
112 # Don't push this into the background becasue it can cause
113 # a race to create /tmp/.X11-unix
114 XINITDIR/privileged_startx
117 if [ x`defaults read org.x.X11 no_auth` = x0 ] ; then
123 if [ x`defaults read org.x.X11 nolisten_tcp` = x1 ] ; then
124 defaultserverargs="$defaultserverargs -nolisten tcp"
127 for ((d=0; ; d++)) ; do
128 [[ -e /tmp/.X$d-lock ]] || break
137 if [ -f $userclientrc ]; then
138 defaultclientargs=$userclientrc
139 elif [ -f $sysclientrc ]; then
140 defaultclientargs=$sysclientrc
141 #if defined(__SCO__) || defined(__UNIXWARE__)
142 elif [ -f $scouserclientrc ]; then
143 defaultclientargs=$scouserclientrc
144 elif [ -f $scosysclientrc ]; then
145 defaultclientargs=$scosysclientrc
149 #if defined(__SCO__) || defined(__UNIXWARE__)
151 XCOMM SCO -t option: do not start an X server
153 -t) if [ -n "$DISPLAY" ]; then
157 echo "DISPLAY environment variable not set"
165 while [ x"$1" != x ]; do
167 XCOMM '' required to prevent cpp from treating "/*" as a C comment.
169 if [ "$whoseargs" = "client" ]; then
170 if [ x"$clientargs" = x ]; then
173 clientargs="$clientargs $1"
176 if [ x"$serverargs" = x ]; then
179 serverargs="$serverargs $1"
187 if [ "$whoseargs" = "client" ]; then
188 clientargs="$clientargs $1"
190 XCOMM display must be the FIRST server argument
191 if [ x"$serverargs" = x ] && @@
192 expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
195 serverargs="$serverargs $1"
203 XCOMM process client arguments
204 if [ x"$client" = x ]; then
205 XCOMM if no client arguments either, use rc file instead
206 if [ x"$clientargs" = x ]; then
207 client="$defaultclientargs"
209 client=$defaultclient
213 XCOMM process server arguments
214 if [ x"$server" = x ]; then
215 server=$defaultserver
217 XCOMM if no server arguments or display either, use defaults
218 if [ x"$serverargs" = x -a x"$display" = x ]; then
219 XCOMM For compatibility reasons, only use xserverrc if there were no server command line arguments
220 if [ -f $userserverrc ]; then
222 elif [ -f $sysserverrc ]; then
226 serverargs=$defaultserverargs
227 display=$defaultdisplay
231 if [ x"$enable_xauth" = x1 ] ; then
232 if [ x"$XAUTHORITY" = x ]; then
233 XAUTHORITY=$HOME/.Xauthority
239 XCOMM set up default Xauth info for this machine
242 if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
243 hostname=`hostname -f`
253 authdisplay=${display:-:0}
254 #if defined(HAS_COOKIE_MAKER) && defined(MK_COOKIE)
257 if [ -r /dev/urandom ]; then
258 mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"`
260 mcookie=`dd if=/dev/random bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"`
263 if test x"$mcookie" = x; then
264 echo "Couldn't create cookie"
269 XCOMM create a file with auth information for the server. ':0' is a dummy.
270 xserverauthfile=$HOME/.serverauth.$$
271 trap "rm -f $xserverauthfile" HUP INT QUIT ILL TRAP KILL BUS TERM
272 xauth -q -f $xserverauthfile << EOF
273 add :$dummy . $mcookie
275 serverargs=${serverargs}" -auth "${xserverauthfile}
277 XCOMM now add the same credentials to the client authority file
278 XCOMM if '$displayname' already exists do not overwrite it as another
279 XCOMM server man need it. Add them to the '$xserverauthfile' instead.
280 for displayname in $authdisplay $hostname$authdisplay; do
281 authcookie=`XAUTH list "$displayname" @@
282 | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null;
283 if [ "z${authcookie}" = "z" ] ; then
285 add $displayname . $mcookie
287 removelist="$displayname $removelist"
290 XAUTH -q -f $xserverauthfile << EOF
291 add :$dummy . $authcookie
297 #if defined(__SCO__) || defined(__UNIXWARE__)
298 if [ "$REMOTE_SERVER" = "TRUE" ]; then
299 exec SHELL_CMD ${client}
301 XINIT $client $clientargs -- $server $display $serverargs
304 XINIT $client $clientargs -- $server $display $serverargs
307 if [ x"$enable_xauth" = x1 ] ; then
308 if [ x"$removelist" != x ]; then
309 XAUTH remove $removelist
311 if [ x"$xserverauthfile" != x ]; then
312 rm -f $xserverauthfile
317 * various machines need special cleaning up
320 if command -v deallocvt > /dev/null 2>&1; then