PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/X11/Xsession

http://github.com/brinkman83/bashrc
Shell | 119 lines | 70 code | 20 blank | 29 comment | 17 complexity | 50678401170c9c701d2375bd279690c5 MD5 | raw file
  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
  9set -e
 10
 11PROGNAME=Xsession
 12
 13message () {
 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
 23message_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
 33errormsg () {
 34  # exit script with error
 35  message "$*"
 36  exit 1
 37}
 38
 39internal_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# initialize variables for use by all session scripts
 51
 52OPTIONFILE=/etc/X11/Xsession.options
 53
 54SYSRESOURCES=/etc/X11/Xresources
 55USRRESOURCES=$HOME/.Xresources
 56
 57SYSSESSIONDIR=/etc/X11/Xsession.d
 58USERXSESSION=$HOME/.xsession
 59USERXSESSIONRC=$HOME/.xsessionrc
 60ALTUSERXSESSION=$HOME/.Xsession
 61ERRFILE=$HOME/.xsession-errors
 62
 63# attempt to create an error file; abort if we cannot
 64if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] &&
 65  [ ! -L "$ERRFILE" ]; then
 66  chmod 600 "$ERRFILE"
 67elif ERRFILE=$(tempfile 2> /dev/null); then
 68  if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
 69    message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
 70             "\"$ERRFILE\"; look for session log/errors in" \
 71             "\"$TMPDIR/xsession-$USER\"."
 72  fi
 73else
 74  errormsg "unable to create X session log/error file; aborting."
 75fi
 76
 77# truncate ERRFILE if it is too big to avoid disk usage DoS
 78if [ "`stat -c%s \"$ERRFILE\"`" -gt 500000 ]; then
 79  T=`mktemp -p "$HOME"`
 80  tail -c 500000 "$ERRFILE" > "$T" && mv -f "$T" "$ERRFILE" || rm -f "$T"
 81fi
 82
 83exec >>"$ERRFILE" 2>&1
 84
 85echo "$PROGNAME: X session started for $LOGNAME at $(date)"
 86
 87# sanity check; is our session script directory present?
 88if [ ! -d "$SYSSESSIONDIR" ]; then
 89  errormsg "no \"$SYSSESSIONDIR\" directory found; aborting."
 90fi
 91
 92# Attempt to create a file of non-zero length in /tmp; a full filesystem can
 93# cause mysterious X session failures.  We do not use touch, :, or test -w
 94# because they won't actually create a file with contents.  We also let standard
 95# error from tempfile and echo go to the error file to aid the user in
 96# determining what went wrong.
 97WRITE_TEST=$(tempfile)
 98if ! echo "*" >>"$WRITE_TEST"; then
 99  message "warning: unable to write to ${WRITE_TEST%/*}; X session may exit" \
100          "with an error"
101fi
102rm -f "$WRITE_TEST"
103
104# use run-parts to source every file in the session directory; we source
105# instead of executing so that the variables and functions defined above
106# are available to the scripts, and so that they can pass variables to each
107# other
108SESSIONFILES=$(run-parts --list $SYSSESSIONDIR)
109if [ -n "$SESSIONFILES" ]; then
110  set +e
111  for SESSIONFILE in $SESSIONFILES; do
112    . $SESSIONFILE
113  done
114  set -e
115fi
116
117exit 0
118
119# vim:set ai et sts=2 sw=2 tw=80: