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