home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / X11 / Xsession < prev    next >
Encoding:
Text File  |  2006-10-12  |  4.1 KB  |  137 lines

  1. #!/bin/sh
  2. #
  3. # /etc/X11/Xsession
  4. #
  5. # global Xsession file -- used by display managers and xinit (startx)
  6.  
  7. # $Id: Xsession 967 2005-12-27 07:20:55Z dnusinow $
  8.  
  9. set -e
  10.  
  11. PROGNAME=Xsession
  12.  
  13. message () {
  14.   # pretty-print messages of arbitrary length; use xmessage if it
  15.   # is available and $DISPLAY is set
  16.   MESSAGE="$PROGNAME: $*"
  17.   echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
  18.   if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
  19.     echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
  20.   fi
  21. }
  22.  
  23. message_nonl () {
  24.   # pretty-print messages of arbitrary length (no trailing newline); use
  25.   # xmessage if it is available and $DISPLAY is set
  26.   MESSAGE="$PROGNAME: $*"
  27.   echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2;
  28.   if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
  29.     echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
  30.   fi
  31. }
  32.  
  33. errormsg () {
  34.   # exit script with error
  35.   message "$*"
  36.   exit 1
  37. }
  38.  
  39. internal_errormsg () {
  40.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  41.   # One big call to message() for the sake of xmessage; if we had two then
  42.   # the user would have dismissed the error we want reported before seeing the
  43.   # request to report it.
  44.   errormsg "$*" \
  45.            "Please report the installed version of the \"x11-common\"" \
  46.            "package and the complete text of this error message to" \
  47.            "<debian-x@lists.debian.org>."
  48. }
  49.  
  50. run_parts () {
  51.   # until run-parts --noexec is implemented
  52.   if [ -z "$1" ]; then
  53.     internal_errormsg "run_parts() called without an argument."
  54.   fi
  55.   if [ ! -d "$1" ]; then
  56.     internal_errormsg "run_parts() called, but \"$1\" does not exist or is" \
  57.                       "not a directory."
  58.   fi
  59.   for F in $(/bin/ls $1); do
  60.     if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then
  61.       if [ -f "$1/$F" ]; then
  62.         echo "$1/$F"
  63.       fi
  64.     fi
  65.   done
  66. }
  67.  
  68. # initialize variables for use by all session scripts
  69.  
  70. OPTIONFILE=/etc/X11/Xsession.options
  71.  
  72. SYSRESOURCES=/etc/X11/Xresources
  73. USRRESOURCES=$HOME/.Xresources
  74.  
  75. SYSSESSIONDIR=/etc/X11/Xsession.d
  76. USERXSESSION=$HOME/.xsession
  77. ALTUSERXSESSION=$HOME/.Xsession
  78. ERRFILE=$HOME/.xsession-errors
  79.  
  80. # attempt to create an error file; abort if we cannot
  81. if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] &&
  82.   [ ! -L "$ERRFILE" ]; then
  83.   chmod 600 "$ERRFILE"
  84. elif ERRFILE=$(tempfile 2> /dev/null); then
  85.   if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
  86.     message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
  87.              "\"$ERRFILE\"; look for session log/errors in" \
  88.              "\"$TMPDIR/xsession-$USER\"."
  89.   fi
  90. else
  91.   errormsg "unable to create X session log/error file; aborting."
  92. fi
  93.  
  94. # truncate ERRFILE if it is too big to avoid disk usage DoS
  95. if [ "`stat -c%s \"$ERRFILE\"`" -gt 500000 ]; then
  96.   T=`mktemp -p "$HOME"`
  97.   tail -c 500000 "$ERRFILE" > "$T" && mv -f "$T" "$ERRFILE" || rm -f "$T"
  98. fi
  99.  
  100. exec >>"$ERRFILE" 2>&1
  101.  
  102. echo "$PROGNAME: X session started for $LOGNAME at $(date)"
  103.  
  104. # sanity check; is our session script directory present?
  105. if [ ! -d "$SYSSESSIONDIR" ]; then
  106.   errormsg "no \"$SYSSESSIONDIR\" directory found; aborting."
  107. fi
  108.  
  109. # Attempt to create a file of non-zero length in /tmp; a full filesystem can
  110. # cause mysterious X session failures.  We do not use touch, :, or test -w
  111. # because they won't actually create a file with contents.  We also let standard
  112. # error from tempfile and echo go to the error file to aid the user in
  113. # determining what went wrong.
  114. WRITE_TEST=$(tempfile)
  115. if ! echo "*" >>"$WRITE_TEST"; then
  116.   message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit" \
  117.           "with an error"
  118. fi
  119. rm -f "$WRITE_TEST"
  120.  
  121. # use run-parts to source every file in the session directory; we source
  122. # instead of executing so that the variables and functions defined above
  123. # are available to the scripts, and so that they can pass variables to each
  124. # other
  125. SESSIONFILES=$(run_parts $SYSSESSIONDIR)
  126. if [ -n "$SESSIONFILES" ]; then
  127.   set +e
  128.   for SESSIONFILE in $SESSIONFILES; do
  129.     . $SESSIONFILE
  130.   done
  131.   set -e
  132. fi
  133.  
  134. exit 0
  135.  
  136. # vim:set ai et sts=2 sw=2 tw=80:
  137.