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