[Bug 1789] New: startx doesn't automatically pick an unused VT

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Sat Nov 6 06:38:57 PST 2004


Please do not reply to this email: if you want to comment on the bug, go to          
the URL shown below and enter yourcomments there.   
 
https://freedesktop.org/bugzilla/show_bug.cgi?id=1789        
   
           Summary: startx doesn't automatically pick an unused VT
           Product: xorg
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P4
         Component: Server/general
        AssignedTo: xorg-bugzilla-noise at freedesktop.org
        ReportedBy: logrus at tiscali.ch


For those of us dinosaurs who do not use xdm style display
controllers and who and log in multiple times on a given computer
using multiple separate x sessions, the stock startx script 
needs to be explicitly told which VT to use.  
This should be automatic.

The following version of startx will do this, as well as closing
down the automatic X11 LISTEN behaviour (which is rarely needed anyway). 
It has been in daily use on ~15 machines over the past several years.


#################################
#!/bin/sh
#
# $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
# files, then system xinitrc and xserverrc files, else lets xinit choose
# 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.7 2001/04/19 15:08:32 dawes Exp $
#
# PEK May 26, 2002: starting to follow the advice above...
#       - adding automatic display choice
#       - add nolisten option
#          If there is a $HOME/.xserverrc, the user is responsible
#          for the nolisten specifications
#          If there is a /etc/X11/xinit/xserverrc, the sysadmin
#          will be responsible for the  nolisten specifications
#       - remove xauth stuff: use ssh anyway!
#
#
bindir=/usr/X11R6/bin
#
userclientrc=$HOME/.xinitrc
sysclientrc=/etc/X11/xinit/xinitrc
defaultclientargs=""
clientargs=""
#
userserverrc=$HOME/.xserverrc
sysserverrc=/etc/X11/xinit/xserverrc
defaultserverargs="-nolisten tcp"
serverargs=""

if [ -f $userclientrc ]; then
   defaultclientargs=$userclientrc
   else if [ -f $sysclientrc ]; then
       defaultclientargs=$sysclientrc
   fi
fi

if [ -f $userserverrc ]; then
   defaultserverargs=$userserverrc
   else if [ -f $sysserverrc ]; then
      defaultserverargs=$sysserverrc
   fi
fi

#
# parse the arguments and put them in the right place
# pull out the display number specially...
#
whoseargs="client"
while [ "x$1" != "x" ]; do
    case "$1" in
    --)
        whoseargs="server"
        ;;
    *)
        if [ "$whoseargs" = "client" ]; then
            clientargs="$clientargs $1"
        else
            serverargs="$serverargs $1"
            case "$1" in
            :[0-9]*)
                display="$1"
                ;;
            esac
        fi
        ;;
    esac
    shift
done

if [ x"$clientargs" = x ]; then
    clientargs="$defaultclientargs"
fi

# if no serverrc file specified, then $defaultserverargs
# will be the "-nolisten tcp" option
# if there were user or system serverrc files, then the default
# picks up the file name as per the original startx file
# so append $defaultserverargs
serverargs="$serverargs $defaultserverargs"
    
if [ X"$XAUTHORITY" = X ]; then
    export XAUTHORITY=$HOME/.Xauthority
fi

#
# Now search in $display to see if there is a display
# specified: If the user has given us one then check it.
# else check for the first free display.  see /tmp/.X$n-lock file
#
if [ "x$display" = x ]; then # no display given
   for num in {0,1,2,3,4,5,6,7,8,9}; do
      if [ ! -f /tmp/.X$num-lock ]; then
         display=:$num
         echo " Found display $display available and will use it"
         serverargs="$display $serverargs"
         break
      fi
   done
   if [ "x$display" = x ]; then
      echo "Unable to get a free display, help!"
      echo "Please have someone check the status of the"
      echo "/tmp/.Xn-lock files to find what is wrong"
      echo "I see lock files:"
      /bin/ls -AlF /tmp/.X*-lock
      exit 10
   fi
else                            # special display demanded
   echo "Checking if $display is a good display..."
   num=`echo $display | sed s/://`
   if [ -f /tmp/.X$num-lock ]; then
      echo "User provided display $display is in use!"
      echo "Try another number, or let me pick one automatically"
      echo "(i.e., don't specify one on the command line)."
      exit 11
   fi
   echo " O.K., display $display is unused. I'll use it!"
fi                              # display if

# set up default Xauth info for this machine
mcookie=`mcookie`
for displayname in $display `hostname -f`$display; do
    if ! xauth list "$displayname" | grep "$displayname " >/dev/null 2>&1; then
        xauth add $displayname . $mcookie
        removelist="$displayname $removelist"
    fi
done

xinit $clientargs -- $serverargs

if command -v deallocvt > /dev/null 2>&1; then
    deallocvt
fi        
   
   
--         
Configure bugmail: https://freedesktop.org/bugzilla/userprefs.cgi?tab=email       
   
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the xorg-bugzilla-noise mailing list