1 XCOMM!SHELL_CMD 2 3 XCOMM 4 XCOMM This is just a sample implementation of a slightly less primitive 5 XCOMM interface than xinit. It looks for user .xinitrc and .xserverrc 6 XCOMM files, then system xinitrc and xserverrc files, else lets xinit choose 7 XCOMM its default. The system xinitrc should probably do things like check 8 XCOMM for .Xresources files and merge them in, start up a window manager, 9 XCOMM and pop a clock and several xterms. 10 XCOMM 11 XCOMM Site administrators are STRONGLY urged to write nicer versions. 12 XCOMM 13 14 unset DBUS_SESSION_BUS_ADDRESS 15 unset SESSION_MANAGER 16 17 #ifdef __APPLE__ 18 19 XCOMM Check for /usr/bin/X11 and BINDIR in the path, if not add them. 20 XCOMM This allows startx to be placed in a place like /usr/bin or /usr/local/bin 21 XCOMM and people may use X without changing their PATH. 22 XCOMM Note that we put our own bin directory at the front of the path, and 23 XCOMM the standard system path at the back, since if you are using the Xorg 24 XCOMM server there's a pretty good chance you want to bias the Xorg clients 25 XCOMM over the old system's clients. 26 27 XCOMM First our compiled path 28 bindir=__bindir__ 29 30 case $PATH in 31 *:$bindir | *:$bindir:* | $bindir:*) ;; 32 *) PATH=$bindir:$PATH ;; 33 esac 34 35 XCOMM Now the "old" compiled path 36 oldbindir=/usr/X11R6/bin 37 38 if [ -d "$oldbindir" ] ; then 39 case $PATH in 40 *:$oldbindir | *:$oldbindir:* | $oldbindir:*) ;; 41 *) PATH=$PATH:$oldbindir ;; 42 esac 43 fi 44 45 XCOMM Bourne shell does not automatically export modified environment variables 46 XCOMM so export the new PATH just in case the user changes the shell 47 export PATH 48 #endif 49 50 userclientrc=$HOME/.xinitrc 51 sysclientrc=XINITDIR/xinitrc 52 53 userserverrc=$HOME/.xserverrc 54 sysserverrc=XINITDIR/xserverrc 55 defaultclient=XTERM 56 defaultserver=XSERVER 57 defaultclientargs="" 58 defaultserverargs="" 59 defaultdisplay="" 60 clientargs="" 61 serverargs="" 62 vtarg="" 63 64 #ifdef __APPLE__ 65 66 if [ "x$X11_PREFS_DOMAIN" = x ] ; then 67 export X11_PREFS_DOMAIN=BUNDLE_ID_PREFIX".X11" 68 fi 69 70 XCOMM Initialize defaults (this will cut down on "safe" error messages) 71 if ! defaults read $X11_PREFS_DOMAIN cache_fonts > /dev/null 2>&1 ; then 72 defaults write $X11_PREFS_DOMAIN cache_fonts -bool true 73 fi 74 75 if ! defaults read $X11_PREFS_DOMAIN no_auth > /dev/null 2>&1 ; then 76 defaults write $X11_PREFS_DOMAIN no_auth -bool false 77 fi 78 79 if ! defaults read $X11_PREFS_DOMAIN nolisten_tcp > /dev/null 2>&1 ; then 80 defaults write $X11_PREFS_DOMAIN nolisten_tcp -bool true 81 fi 82 83 if ! defaults read $X11_PREFS_DOMAIN enable_iglx > /dev/null 2>&1 ; then 84 defaults write $X11_PREFS_DOMAIN enable_iglx -bool false 85 fi 86 87 XCOMM First, start caching fonts 88 if [ x`defaults read $X11_PREFS_DOMAIN cache_fonts` = x1 ] ; then 89 if [ -x $bindir/font_cache ] ; then 90 $bindir/font_cache & 91 elif [ -x $bindir/font_cache.sh ] ; then 92 $bindir/font_cache.sh & 93 elif [ -x $bindir/fc-cache ] ; then 94 $bindir/fc-cache & 95 fi 96 fi 97 98 if [ -x __libexecdir__/privileged_startx ] ; then 99 # Don't push this into the background becasue it can cause 100 # a race to create /tmp/.X11-unix 101 __libexecdir__/privileged_startx 102 fi 103 104 if [ x`defaults read $X11_PREFS_DOMAIN no_auth` = x0 ] ; then 105 enable_xauth=1 106 else 107 enable_xauth=0 108 fi 109 110 if [ x`defaults read $X11_PREFS_DOMAIN nolisten_tcp` = x1 ] ; then 111 defaultserverargs="$defaultserverargs -nolisten tcp" 112 else 113 defaultserverargs="$defaultserverargs -listen tcp" 114 fi 115 116 if [ x`defaults read $X11_PREFS_DOMAIN enable_iglx` = x1 ] ; then 117 defaultserverargs="$defaultserverargs +iglx" 118 else 119 defaultserverargs="$defaultserverargs -iglx" 120 fi 121 122 XCOMM The second check is the real one. The first is to hopefully avoid 123 XCOMM needless syslog spamming. 124 if defaults read $X11_PREFS_DOMAIN 2> /dev/null | grep -q 'dpi' && defaults read $X11_PREFS_DOMAIN dpi > /dev/null 2>&1 ; then 125 defaultserverargs="$defaultserverargs -dpi `defaults read $X11_PREFS_DOMAIN dpi`" 126 fi 127 128 #else 129 enable_xauth=1 130 #endif 131 132 XCOMM Automatically determine an unused $DISPLAY 133 d=0 134 while true ; do 135 [ -e "/tmp/.X$d-lock" -o -S "/tmp/.X11-unix/X$d" ] || break 136 d=$(($d + 1)) 137 done 138 defaultdisplay=":$d" 139 unset d 140 141 whoseargs="client" 142 while [ x"$1" != x ]; do 143 case "$1" in 144 XCOMM '' required to prevent cpp from treating "/*" as a C comment. 145 /''*|\./''*) 146 if [ "$whoseargs" = "client" ]; then 147 if [ x"$client" = x ] && [ x"$clientargs" = x ]; then 148 client="$1" 149 else 150 clientargs="$clientargs $1" 151 fi 152 else 153 if [ x"$server" = x ] && [ x"$serverargs" = x ]; then 154 server="$1" 155 else 156 serverargs="$serverargs $1" 157 fi 158 fi 159 ;; 160 --) 161 whoseargs="server" 162 ;; 163 *) 164 if [ "$whoseargs" = "client" ]; then 165 clientargs="$clientargs $1" 166 else 167 XCOMM display must be the FIRST server argument 168 if [ x"$serverargs" = x ] && @@ 169 expr \( "$1" \) : ':[0-9][0-9]*$' > /dev/null 2>&1; then 170 display="$1" 171 else 172 serverargs="$serverargs $1" 173 fi 174 fi 175 ;; 176 esac 177 shift 178 done 179 180 XCOMM process client arguments 181 if [ x"$client" = x ]; then 182 client=$defaultclient 183 184 XCOMM For compatibility reasons, only use startxrc if there were no client command line arguments 185 if [ x"$clientargs" = x ]; then 186 if [ -f "$userclientrc" ]; then 187 client=$userclientrc 188 elif [ -f "$sysclientrc" ]; then 189 client=$sysclientrc 190 fi 191 fi 192 fi 193 194 XCOMM if no client arguments, use defaults 195 if [ x"$clientargs" = x ]; then 196 clientargs=$defaultclientargs 197 fi 198 199 XCOMM process server arguments 200 if [ x"$server" = x ]; then 201 server=$defaultserver 202 203 #ifdef __linux__ 204 XCOMM When starting the defaultserver start X on the current tty to avoid 205 XCOMM the startx session being seen as inactive: 206 XCOMM "https://bugzilla.redhat.com/show_bug.cgi?id=806491" 207 tty=$(tty) 208 if expr "$tty" : '/dev/tty[0-9][0-9]*$' > /dev/null; then 209 tty_num=$(echo "$tty" | grep -oE '[0-9]+$') 210 vtarg="vt$tty_num -keeptty" 211 fi 212 #endif 213 214 XCOMM For compatibility reasons, only use xserverrc if there were no server command line arguments 215 if [ x"$serverargs" = x -a x"$display" = x ]; then 216 if [ -f "$userserverrc" ]; then 217 server=$userserverrc 218 elif [ -f "$sysserverrc" ]; then 219 server=$sysserverrc 220 fi 221 fi 222 fi 223 224 XCOMM if no server arguments, use defaults 225 if [ x"$serverargs" = x ]; then 226 serverargs=$defaultserverargs 227 fi 228 229 XCOMM if no vt is specified add vtarg (which may be empty) 230 have_vtarg="no" 231 for i in $serverargs; do 232 if expr \( "$i" \) : 'vt[0-9][0-9]*$' > /dev/null; then 233 have_vtarg="yes" 234 fi 235 done 236 if [ "$have_vtarg" = "no" ]; then 237 serverargs="$serverargs $vtarg" 238 fi 239 240 XCOMM if no display, use default 241 if [ x"$display" = x ]; then 242 display=$defaultdisplay 243 fi 244 245 if [ x"$enable_xauth" = x1 ] ; then 246 if [ x"$XAUTHORITY" = x ]; then 247 XAUTHORITY=$HOME/.Xauthority 248 export XAUTHORITY 249 fi 250 251 removelist= 252 253 XCOMM set up default Xauth info for this machine 254 case `uname` in 255 Linux*) 256 if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then 257 hostname=`hostname -f` 258 else 259 hostname=`hostname` 260 fi 261 ;; 262 *) 263 hostname=`hostname` 264 ;; 265 esac 266 267 authdisplay=${display:-:0} 268 #if defined(HAS_COOKIE_MAKER) && defined(MK_COOKIE) 269 mcookie=`MK_COOKIE` 270 #else 271 if [ -r /dev/urandom ]; then 272 mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | /usr/bin/hexdump -e \\"%08x\\"` 273 else 274 mcookie=`dd if=/dev/random bs=16 count=1 2>/dev/null | /usr/bin/hexdump -e \\"%08x\\"` 275 fi 276 #endif 277 if test x"$mcookie" = x; then 278 echo "Couldn't create cookie" 279 exit 1 280 fi 281 dummy=0 282 283 XCOMM create a file with auth information for the server. ':0' is a dummy. 284 xserverauthfile=$HOME/.serverauth.$$ 285 trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM 286 xauth -q -f "$xserverauthfile" << EOF 287 add :$dummy . $mcookie 288 EOF 289 #if defined(__APPLE__) || defined(__CYGWIN__) 290 xserverauthfilequoted=$(echo ${xserverauthfile} | sed "s/'/'\\\\''/g") 291 serverargs=${serverargs}" -auth '"${xserverauthfilequoted}"'" 292 #else 293 serverargs=${serverargs}" -auth "${xserverauthfile} 294 #endif 295 296 XCOMM now add the same credentials to the client authority file 297 XCOMM if '$displayname' already exists do not overwrite it as another 298 XCOMM server may need it. Add them to the '$xserverauthfile' instead. 299 for displayname in $authdisplay $hostname/unix$authdisplay; do 300 authcookie=`XAUTH list "$displayname" @@ 301 | sed -n "s|.*$displayname[[:space:]*].*[[:space:]*]||p"` 2>/dev/null; 302 if [ "z${authcookie}" = "z" ] ; then 303 XAUTH -q << EOF 304 add $displayname . $mcookie 305 EOF 306 removelist="$displayname $removelist" 307 else 308 dummy=$(($dummy+1)); 309 XAUTH -q -f "$xserverauthfile" << EOF 310 add :$dummy . $authcookie 311 EOF 312 fi 313 done 314 fi 315 316 #if defined(__APPLE__) || defined(__CYGWIN__) 317 eval XINIT \"$client\" $clientargs -- \"$server\" $display $serverargs 318 #else 319 XINIT "$client" $clientargs -- "$server" $display $serverargs 320 #endif 321 retval=$? 322 323 if [ x"$enable_xauth" = x1 ] ; then 324 if [ x"$removelist" != x ]; then 325 XAUTH remove $removelist 326 fi 327 if [ x"$xserverauthfile" != x ]; then 328 rm -f "$xserverauthfile" 329 fi 330 fi 331 332 /* 333 * various machines need special cleaning up 334 */ 335 #ifdef __linux__ 336 if command -v deallocvt > /dev/null 2>&1; then 337 deallocvt 338 fi 339 #endif 340 341 #if defined(sun) 342 kbd_mode -a 343 #endif 344 345 exit $retval 346 347