--- startx.orig 2011-08-23 20:29:26.000000000 +0000 +++ startx 2011-03-16 14:19:10.000000000 +0000 @@ -3,171 +3,253 @@ # $Xorg: startx.cpp,v 1.3 2000/08/17 19:54:29 cpqbld Exp $ # # This is just a sample implementation of a slightly less primitive -# interface than xinit. It looks for user .xinitrc and .xserverrc +# interface than xinit. It looks for user .xinitrc and .xserverrc # files, then system xinitrc and xserverrc files, else lets xinit choose -# its default. The system xinitrc should probably do things like check +# its default. The system xinitrc should probably do things like check # for .Xresources files and merge them in, startup up a window manager, # and pop a clock and serveral xterms. # # Site administrators are STRONGLY urged to write nicer versions. # # $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $ -userclientrc=$HOME/.xinitrc -sysclientrc=/usr/lib/X11/xinit/xinitrc +# These files (if they exist) are used to set up the X related environment. We used to +# exec .xsession at this location, but that can interfere with choosing a session type +# through XDM/KDM/GDM so it was moved to after a requested session is started. Since +# that means that .xsession might never be run at all when using XDM/KDM/GDM, support +# for the xprofile was added to allow a way for the user to customize the X environment. +#if [ -r /etc/xprofile ] ; then +# . /etc/xprofile +#fi +#if [ -r $HOME/.xprofile ] ; then +# . $HOME/.xprofile +#fi +userclientrc=$HOME/.xinitrc userserverrc=$HOME/.xserverrc -sysserverrc=/usr/lib/X11/xinit/xserverrc -defaultclient=xterm +sysclientrc=/etc/X11/xinit/xinitrc +sysserverrc=/etc/X11/xinit/xserverrc +defaultclient=/usr/bin/xterm defaultserver=/usr/bin/X defaultclientargs="" defaultserverargs="" clientargs="" -serverargs="" - -if [ -f $userclientrc ]; then - defaultclientargs=$userclientrc -elif [ -f $sysclientrc ]; then - defaultclientargs=$sysclientrc +# be sure to sync the following line with the kde kdmrc +# serverargs="-dpi 120 -ac -nolisten tcp -logverbose 6" +serverargs="-dpi 120 -ac -nolisten tcp" +# if in an ssh session then stop right now +if [ -n "$SSH_CONNECTION" ] ; then + echo -e "${BOLDRED}You can't run X from within an SSH session. Exiting.${COLOR_RESET}" + exit 1 +fi +echo +# Create_Date_String +# Initialize_Status_Message startx +# Programmatically assign $DISPLAY to next available session. +DISPLAY=0 +while [ -e "/tmp/.X${DISPLAY}-lock" ] ; do + DISPLAY=$(( $DISPLAY + 1 )) +done +# Select one of the following schemes. The VT variable will be used to +# determine the virtual terminal (vt) number and also and inform the user +# of the respective Ctrl-Alt-Fn keyboard shortcut. + +# Scheme One: +# Calculate the vt the same way as X. Determine the number of available tty +# consoles and then add 1. Later in the script when launching X from xinit, +# the vt assignment will coincide as to what X normally would have assigned anyway. +# In other words, no damage done and no confusion to X. But determining the VT +# variable at this stage also helps inform the user of the Ctrl-Alt-Fn keyboard +# shortcut. +# NUMTTY=? +# VT=$(($NUMTTY+1)) + +# Scheme Two: +# Unless specifically instructed, X assigns the first vt number in sequence +# with the number of tty consoles. If 3 tty consoles are enabled in +# /etc/inittab, then X assigns the next vt to vt4. Most people never reduce +# the six tty consoles that most distros provide in /etc/inittab. But even +# if inittab is modified for fewer than 6 tty consoles, the following routine +# ensures the Ctrl-Alt-Fn keyboard shortcut remains consistent as if we still +# had the original 6. Therefore we increment the next display number by 7 +# to force the vt number. If choosing this option, and using XDM or KDM as +# login managers, be sure to also edit the respective Xsession config files to +# forcibly assign the vt consistent with this scheme. The tty number could be +# used here, but using the DISPLAY variable creates a nice correspondence with +# the function keys. That is, regardless of which tty X is launched from, the +# function keys remain consistent with the DISPLAY number. Thus, Display 0 will +# always be assigned vt7, Display 1 to vt8, Display 2 to vt9, etc. +VT=$(($DISPLAY+7)) + +# Scheme Three: +# Similar to the previous two schemes, we calculate the vt number using the ttys, but +# instead of incrementing by 1, we increment by 7. This schemed keeps the vt number +# consistent with the tty. That is, from tty1 we use vt7, tty2 we use vt8, etc. +# NUMTTY=? +# VT=$(($NUMTTY+7)) + +echo -e "Using X session DISPLAY ${BOLDWHITE}:${DISPLAY}${COLOR_RESET}." +# echo "startx: Using X session DISPLAY :${DISPLAY}." >> $STATUSFILE +echo -e "Using virtual terminal ${BOLDWHITE}vt$VT${COLOR_RESET}." +# echo "startx: Using virtual terminal vt$VT." >> $STATUSFILE +echo -e "Use ${BOLDYELLOW}(Ctrl)-Alt-F$VT${COLOR_RESET} to toggle to this virtual terminal." +# echo "startx: Use (Ctrl)-Alt-F$VT to toggle to this virtual terminal." >> $STATUSFILE +if [ -f $userclientrc ] ; then + defaultclientargs=$userclientrc +elif [ -f $sysclientrc ] ; then + defaultclientargs=$sysclientrc fi -if [ -f $userserverrc ]; then + +if [ -f $userserverrc ] ; then defaultserverargs=$userserverrc -elif [ -f $sysserverrc ]; then +elif [ -f $sysserverrc ] ; then defaultserverargs=$sysserverrc fi whoseargs="client" -while [ x"$1" != x ]; do +while [ x"$1" != x ] ; do case "$1" in - # '' required to prevent cpp from treating "/*" as a C comment. - /''*|\./''*) - if [ "$whoseargs" = "client" ]; then - if [ x"$clientargs" = x ]; then - client="$1" - else - clientargs="$clientargs $1" - fi - else - if [ x"$serverargs" = x ]; then - server="$1" - else - serverargs="$serverargs $1" - fi - fi - ;; - --) - whoseargs="server" - ;; - *) - if [ "$whoseargs" = "client" ]; then - clientargs="$clientargs $1" - else - # display must be the FIRST server argument - if [ x"$serverargs" = x ] && \ - expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then - display="$1" - else - serverargs="$serverargs $1" - fi - fi - ;; + # '' required to prevent cpp from treating "/*" as a C comment. + /''*|\./''*) + if [ "$whoseargs" = "client" ] ; then + if [ x"$clientargs" = x ] ; then + client="$1" + else + clientargs="$clientargs $1" + fi + else + if [ x"$serverargs" = x ] ; then + server="$1" + else + serverargs="$serverargs $1" + fi + fi + ;; + --) whoseargs="server" ;; + *) + if [ "$whoseargs" = "client" ] ; then + clientargs="$clientargs $1" + else + # display must be the FIRST server argument + if [ x"$serverargs" = x ] && \ + expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then + display="$1" + else + serverargs="$serverargs $1" + fi + fi + ;; esac shift done # process client arguments -if [ x"$client" = x ]; then - # if no client arguments either, use rc file instead - if [ x"$clientargs" = x ]; then - client="$defaultclientargs" - else - client=$defaultclient - fi +if [ x"$client" = x ] ; then + # if no client arguments either, use rc file instead + if [ x"$clientargs" = x ] ; then + client="$defaultclientargs" + else + client=$defaultclient + fi fi # process server arguments -if [ x"$server" = x ]; then - # if no server arguments or display either, use rc file instead - if [ x"$serverargs" = x -a x"$display" = x ]; then - server="$defaultserverargs" - else - server=$defaultserver - fi +if [ x"$server" = x ] ; then + # if no server arguments or display either, use rc file instead + if [ x"$serverargs" = x -a x"$DISPLAY" = x ] ; then + server="$defaultserverargs" + else + server=$defaultserver + fi fi -if [ x"$XAUTHORITY" = x ]; then - XAUTHORITY=$HOME/.Xauthority - export XAUTHORITY +if [ x"$XAUTHORITY" = x ] ; then + XAUTHORITY=$HOME/.Xauthority + export XAUTHORITY fi removelist= - # set up default Xauth info for this machine case `uname` in -Linux*) - if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then - hostname=`hostname -f` - else - hostname=`hostname` - fi - ;; -*) - hostname=`hostname` - ;; + Linux*) + if [ -z "`hostname --version 2>&1 | grep GNU`" ] ; then + hostname=`hostname -f` + else + hostname=`hostname` + fi + ;; + *) + hostname=`hostname` + ;; esac -authdisplay=${display:-:0} -mcookie=`/usr/bin/mcookie` +#authdisplay=${display:-:0} +authdisplay=${display:-:$DISPLAY} +mcookie=`mcookie` dummy=0 # create a file with auth information for the server. ':0' is a dummy. +# xserverauthfile=$HOME/.serverauth.$$ +# xserverauthfile=$XAUTHORITY xserverauthfile=$HOME/.Xserverauth rm -f $xserverauthfile -xauth -q -f $xserverauthfile << EOF -add :$dummy . $mcookie -EOF - -serverargs=${serverargs}" -auth "${xserverauthfile} +xauth -q -f $xserverauthfile 2>/dev/null add :$dummy . $mcookie +# serverargs=${serverargs}" -auth "${xserverauthfile} # now add the same credentials to the client authority file -# if '$displayname' already exists do not overwrite it as another +# if '$displayname' already exists don't overwrite it as another # server man need it. Add them to the '$xserverauthfile' instead. for displayname in $authdisplay $hostname$authdisplay; do - authcookie=`xauth list "$displayname" \ - | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null; - if [ "z${authcookie}" = "z" ] ; then - xauth -q << EOF -add $displayname . $mcookie -EOF - removelist="$displayname $removelist" - else - dummy=$(($dummy+1)); - xauth -q -f $xserverauthfile << EOF -add :$dummy . $authcookie -EOF - fi + authcookie=`/usr/bin/xauth list "$displayname" \ + | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null; + if [ "z${authcookie}" = "z" ] ; then + /usr/bin/xauth -q add $displayname . $mcookie + removelist="$displayname $removelist" + else + dummy=$((dummy+1)); + /usr/bin/xauth -q -f $xserverauthfile add :$dummy . $authcookie + fi done -xinit $client $clientargs -- $server $display $serverargs +echo -e "${BOLDWHITE}Client args:${COLOR_RESET} $client $clientargs" +# echo "startx: Client args: $client $clientargs" >> $STATUSFILE +echo -e "${BOLDWHITE}Server args:${COLOR_RESET} $server :$DISPLAY vt$VT $serverargs" +# echo "startx: Server args: $server :$DISPLAY vt$VT $serverargs" >> $STATUSFILE + +# enable this only for testing +# exit 0 + +# enable a short pause if you want viewers to read what is happening +# sleep 1 + +xinit $client $clientargs -- $server :$DISPLAY vt$VT $serverargs 2>/dev/null + +if [ "$?" = "0" ] ; then + echo + echo "startx: Seems everything went okay with this X session!" >> $STATUSFILE + echo -e "${BOLDWHITE}startx: Seems everything went okay with this X session!${COLOR_RESET}" +else + echo + echo "startx: Error! Could not start the X graphical environment!" >> $STATUSFILE + echo -e "${BOLDRED}startx: Error! Could not start the X graphical environment!${COLOR_RESET}" +fi +#Text_Break +echo -if [ x"$removelist" != x ]; then - xauth remove $removelist +if [ x"$removelist" != x ] ; then + /usr/bin/xauth remove $removelist fi -if [ x"$xserverauthfile" != x ]; then - rm -f $xserverauthfile +if [ x"$xserverauthfile" != x ] ; then + rm -f $xserverauthfile fi - - - - if command -v deallocvt > /dev/null 2>&1; then - deallocvt + deallocvt fi