Historical Function

Today, I delved into a tiny bit of X11/xorg plumbing to see if I could move this damnable .xsession-errors file to someplace more out of the way. For those of you not in the know about Linux or X11, it’s basically a holding tank of any GUI application errors that aren’t normally logged. To me, it seems vestigial of a time before centralized system logging via systemd, but who am I to question our forefathers?

Well, damn it, it’s open source! Lets see if I can fuck with it and make it do what I want it to do!

Turns out no. At least not easily.

Inside /etc/X11/Xsession (on Debian, anyway), exists the following bit of code to create or temporarily create an error log file:

ERRFILE=$HOME/.xsession-errors

# attempt to create an error file; abort if we cannot
if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] &&
  [ ! -L "$ERRFILE" ]; then
  chmod 600 "$ERRFILE"
elif ERRFILE=$(tempfile 2> /dev/null); then
  if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
    message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
             "\"$ERRFILE\"; look for session log/errors in" \
             "\"$TMPDIR/xsession-$USER\"."
  fi
else
  errormsg "unable to create X session log/error file; aborting."
fi

exec >>"$ERRFILE" 2>&1

The gist (haha) here is that if you don’t have one, make it, if you can’t make it, create a dummy one in the system temp folder and if that fails, just give up. All well and good, right? Right.

So, what happens if we, say, modify the ERRFILE path to something else? Well, I tried that and I got an unexpected result: The file being created correctly in the right location (yay) and an empty file created in the original location (boo).

Excuse me, what the actual fuck?

Right now, I’m kind of at an impasse here. It seems like changing the code above to do what I want it to do works but there is something probably hard-coded elsewhere that just goes “DUMP IT IN $HOME/.xsession-errors“, which is frustrating. I don’t know where else to look. If anyone has any ideas, let me know, I’d be glad to credit you.

Update

I thought I had a smoking gun. I redirected everything in my .xprofile to two different logs, manually. This logged correctly, but I still got a leftover file, let’s see who has it open:

Oh, hello i3bar….

So, I go and re-introduce my changes to Xsession, like so:

# Original
# ERRFILE=$HOME/.xsession-errors
ERRFILE=$HOME/.cache/xorg/errors

# attempt to create an error file; abort if we cannot
# if (umask 077 && touch "$ERRFILE") 2> /dev/null && [ -w "$ERRFILE" ] &&
#   [ ! -L "$ERRFILE" ]; then
#   chmod 600 "$ERRFILE"
# elif ERRFILE=$(tempfile 2> /dev/null); then
#   if ! ln -sf "$ERRFILE" "${TMPDIR:=/tmp}/xsession-$USER"; then
#     message "warning: unable to symlink \"$TMPDIR/xsession-$USER\" to" \
#              "\"$ERRFILE\"; look for session log/errors in" \
#              "\"$TMPDIR/xsession-$USER\"."
#   fi
# else
#   errormsg "unable to create X session log/error file; aborting."
# fi

exec >>"$ERRFILE" 2>&1

I checked and it dumps the standard rigamarole from X starting up. That’s good(tm). Problem is, I still get an (empty) .xsession-errors file.

Time to investigate sway/wayland.