# This is a -*- shell-script -*- fragment called by /etc/X11/Xsession

trim=true
trimlimit=1048576

if [ true = "$trim" ] ; then
    size=$(stat -c%s "$HOME/.xsession-errors")
    if [ "$size" -ge $trimlimit ] ; then
    # Only trim on each login for now, to see if that is enough.
        cat > "$HOME/.xsession-errors" <<EOF
info: Truncated this file because it was more than $trimlimit bytes
EOF
    fi
else
    # Redirect all errors to /dev/null instead of $ERRFILE
    # (~/.xsession-errors by default), to avoid filling up users home
    # directory with error messages.  Allow the user to disable this by
    # creating ~/.xsession-errors-enable
    if [ ! -f "$HOME/.xsession-errors-enable" ] ; then
        # Report the change to the log file before disabling output to the file
        echo "info: Redirecting xsession messages to /dev/null."
        echo "info: touch '$HOME/.xsession-errors-enable' to disable this."
        exec >> /dev/null 2>&1
    fi
fi
