Guest User

xsession

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