Xsession 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. PROGNAME=Xsession
  8. message () {
  9. # pretty-print messages of arbitrary length; use xmessage if it
  10. # is available and $DISPLAY is set
  11. MESSAGE="$PROGNAME: $*"
  12. echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
  13. if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
  14. echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
  15. fi
  16. }
  17. message_nonl () {
  18. # pretty-print messages of arbitrary length (no trailing newline); use
  19. # xmessage if it is available and $DISPLAY is set
  20. MESSAGE="$PROGNAME: $*"
  21. echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2;
  22. if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
  23. echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
  24. fi
  25. }
  26. errormsg () {
  27. # exit script with error
  28. message "$*"
  29. exit 1
  30. }
  31. internal_errormsg () {
  32. # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  33. # One big call to message() for the sake of xmessage; if we had two then
  34. # the user would have dismissed the error we want reported before seeing the
  35. # request to report it.
  36. errormsg "$*" \
  37. "Please report the installed version of the \"x11-common\"" \
  38. "package and the complete text of this error message to" \
  39. "<debian-x@lists.debian.org>."
  40. }
  41. # initialize variables for use by all session scripts
  42. OPTIONFILE=/etc/X11/Xsession.options
  43. SYSRESOURCES=/etc/X11/Xresources
  44. USRRESOURCES=$HOME/.Xresources
  45. SYSSESSIONDIR=/etc/X11/Xsession.d
  46. USERXSESSION=$HOME/.xsession
  47. USERXSESSIONRC=$HOME/.xsessionrc
  48. ALTUSERXSESSION=$HOME/.Xsession
  49. ERRFILE=$HOME/.xsession-errors
  50. # attempt to create an error file; abort if we cannot
  51. if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] &&
  52. [ ! -L "$ERRFILE" ]; then
  53. chmod 600 "$ERRFILE"
  54. elif ERRFILE=$(tempfile 2> /dev/null); then
  55. if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
  56. message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
  57. "\"$ERRFILE\"; look for session log/errors in" \
  58. "\"$TMPDIR/xsession-$USER\"."
  59. fi
  60. else
  61. errormsg "unable to create X session log/error file; aborting."
  62. fi
  63. exec >>"$ERRFILE" 2>&1
  64. echo "$PROGNAME: X session started for $LOGNAME at $(date)"
  65. # Load profile
  66. for file in "/etc/profile" "$HOME/.profile"; do
  67. if [ -f "$file" ] && ! . "$file"; then
  68. echo "Error loading $file"
  69. fi
  70. done
  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=$(mktemp)
  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. for SESSIONFILE in $SESSIONFILES; do
  93. . $SESSIONFILE
  94. done
  95. fi
  96. exit 0
  97. # vim:set ai et sts=2 sw=2 tw=80: