startx (5677B)
1 #!/usr/bin/sh 2 3 # 4 # This is just a sample implementation of a slightly less primitive 5 # interface than xinit. It looks for user .xinitrc and .xserverrc 6 # files, then system xinitrc and xserverrc files, else lets xinit choose 7 # its default. The system xinitrc should probably do things like check 8 # for .Xresources files and merge them in, start up a window manager, 9 # and pop a clock and several xterms. 10 # 11 # Site administrators are STRONGLY urged to write nicer versions. 12 # 13 14 unset DBUS_SESSION_BUS_ADDRESS 15 unset SESSION_MANAGER 16 userclientrc=$HOME/.config/x11/xinitrc 17 sysclientrc=/etc/X11/xinit/xinitrc 18 19 userserverrc=$HOME/.xserverrc 20 sysserverrc=/etc/X11/xinit/xserverrc 21 defaultclient=xterm 22 defaultserver=/usr/bin/X 23 defaultclientargs="" 24 defaultserverargs="" 25 defaultdisplay="" 26 clientargs="" 27 serverargs="" 28 vtarg="" 29 enable_xauth=1 30 31 32 # Automatically determine an unused $DISPLAY 33 d=0 34 while true ; do 35 [ -e "/tmp/.X$d-lock" -o -S "/tmp/.X11-unix/X$d" ] || 36 37 grep -q "/tmp/.X11-unix/X$d" "/proc/net/unix" || 38 39 break 40 d=$(($d + 1)) 41 done 42 defaultdisplay=":$d" 43 unset d 44 45 whoseargs="client" 46 while [ x"$1" != x ]; do 47 case "$1" in 48 # '' required to prevent cpp from treating "/*" as a C comment. 49 /''*|\./''*) 50 if [ "$whoseargs" = "client" ]; then 51 if [ x"$client" = x ] && [ x"$clientargs" = x ]; then 52 client="$1" 53 else 54 clientargs="$clientargs $1" 55 fi 56 else 57 if [ x"$server" = x ] && [ x"$serverargs" = x ]; then 58 server="$1" 59 else 60 serverargs="$serverargs $1" 61 fi 62 fi 63 ;; 64 --) 65 whoseargs="server" 66 ;; 67 *) 68 if [ "$whoseargs" = "client" ]; then 69 clientargs="$clientargs $1" 70 else 71 # display must be the FIRST server argument 72 if [ x"$serverargs" = x ] && \ 73 expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then 74 display="$1" 75 else 76 serverargs="$serverargs $1" 77 fi 78 fi 79 ;; 80 esac 81 shift 82 done 83 84 # process client arguments 85 if [ x"$client" = x ]; then 86 client=$defaultclient 87 88 # For compatibility reasons, only use startxrc if there were no client command line arguments 89 if [ x"$clientargs" = x ]; then 90 if [ -f "$userclientrc" ]; then 91 client=$userclientrc 92 elif [ -f "$sysclientrc" ]; then 93 client=$sysclientrc 94 fi 95 fi 96 fi 97 98 # if no client arguments, use defaults 99 if [ x"$clientargs" = x ]; then 100 clientargs=$defaultclientargs 101 fi 102 103 # process server arguments 104 if [ x"$server" = x ]; then 105 server=$defaultserver 106 107 108 # When starting the defaultserver start X on the current tty to avoid 109 # the startx session being seen as inactive: 110 # "https://bugzilla.redhat.com/show_bug.cgi?id=806491" 111 tty=$(tty) 112 if expr "$tty" : '/dev/tty[0-9][0-9]*$' > /dev/null; then 113 tty_num=$(echo "$tty" | grep -oE '[0-9]+$') 114 vtarg="vt$tty_num -keeptty" 115 fi 116 117 118 # For compatibility reasons, only use xserverrc if there were no server command line arguments 119 if [ x"$serverargs" = x -a x"$display" = x ]; then 120 if [ -f "$userserverrc" ]; then 121 server=$userserverrc 122 elif [ -f "$sysserverrc" ]; then 123 server=$sysserverrc 124 fi 125 fi 126 fi 127 128 # if no server arguments, use defaults 129 if [ x"$serverargs" = x ]; then 130 serverargs=$defaultserverargs 131 fi 132 133 # if no vt is specified add vtarg (which may be empty) 134 have_vtarg="no" 135 for i in $serverargs; do 136 if expr "$i" : 'vt[0-9][0-9]*$' > /dev/null; then 137 have_vtarg="yes" 138 fi 139 done 140 if [ "$have_vtarg" = "no" -a x"$vtarg" != x ]; then 141 serverargs="$serverargs $vtarg" 142 # Fedora specific mod to make X run as non root 143 export XORG_RUN_AS_USER_OK=1 144 fi 145 146 # if no display, use default 147 if [ x"$display" = x ]; then 148 display=$defaultdisplay 149 fi 150 151 if [ x"$enable_xauth" = x1 ] ; then 152 if [ x"$XAUTHORITY" = x ]; then 153 XAUTHORITY=$HOME/.cache/Xauthority 154 export XAUTHORITY 155 fi 156 157 removelist= 158 159 # set up default Xauth info for this machine 160 case `uname` in 161 Linux*) 162 if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then 163 hostname=`hostname -f` 164 else 165 hostname=`hostname` 166 fi 167 ;; 168 *) 169 hostname=`hostname` 170 ;; 171 esac 172 173 authdisplay=${display:-:0} 174 175 mcookie=`/usr/bin/mcookie` 176 177 178 179 180 181 182 183 if test x"$mcookie" = x; then 184 echo "Couldn't create cookie" 185 exit 1 186 fi 187 dummy=0 188 189 # create a file with auth information for the server. ':0' is a dummy. 190 xserverauthfile=$HOME/.cache/serverauth.$$ 191 trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM 192 xauth -q -f "$xserverauthfile" << EOF 193 add :$dummy . $mcookie 194 EOF 195 196 197 198 199 serverargs=${serverargs}" -auth "${xserverauthfile} 200 201 202 # now add the same credentials to the client authority file 203 # if '$displayname' already exists do not overwrite it as another 204 # server may need it. Add them to the '$xserverauthfile' instead. 205 for displayname in $authdisplay $hostname$authdisplay; do 206 authcookie=`xauth list "$displayname" \ 207 | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null; 208 if [ "z${authcookie}" = "z" ] ; then 209 xauth -q << EOF 210 add $displayname . $mcookie 211 EOF 212 removelist="$displayname $removelist" 213 else 214 dummy=$(($dummy+1)); 215 xauth -q -f "$xserverauthfile" << EOF 216 add :$dummy . $authcookie 217 EOF 218 fi 219 done 220 fi 221 222 223 224 225 xinit "$client" $clientargs -- "$server" $display $serverargs 226 227 retval=$? 228 229 if [ x"$enable_xauth" = x1 ] ; then 230 if [ x"$removelist" != x ]; then 231 xauth remove $removelist 232 fi 233 if [ x"$xserverauthfile" != x ]; then 234 rm -f "$xserverauthfile" 235 fi 236 fi 237 238 239 240 241 242 if command -v deallocvt > /dev/null 2>&1; then 243 deallocvt 244 fi 245 246 247 248 249 250 251 exit $retval