16

Is there any way to completely disable the .xsession-errors file? I have it as a symlink to /tmp so that my laptop hard disk can (hopefully) go to sleep for once, but at least 95% of the stuff in the file (it fills up at about 500k an hour) is...

(nautilus:1618): GLib-GObject-CRITICAL **: g_value_get_object: assertion `G_VALUE_HOLDS_OBJECT (value)' failed

which is total garbage to me. I have tried doing a symlink to /dev/null but that does not work (the resulting link is overwritten), and I also do not want the activity so that hopefully my laptop can go to sleep for once.

I am using Ubuntu 11.04, with no special add-ons to Nautilus.

7
  • That trick does not work for me, because on startup /etc/X11/Xsession does not check what the symbolic link is pointing to. For me it creates a new .xsession-errors regular file, and has .xsession-errors.old linked to /dev/null. That is not what I want. I want .xsession-errors redirected to /dev/null - permantently unless I explicitly change it myself.
    – bjem
    Jan 8, 2012 at 4:38
  • Just to clarify @j-johan-edwards. I tested your command and it works fine, I just want it to be permanent.
    – bjem
    Jan 8, 2012 at 4:43
  • Does 11.04 use GDM or LightDM as its display manager?
    – detly
    Jan 8, 2012 at 5:41
  • I think mine is GDM, if that is the default. I have not changed it except to get away from the Unity desktop.
    – bjem
    Jan 8, 2012 at 10:21
  • Yes, my one is GDM. Apparently the path to .xsession-errors is hard coded(?!) into its source code. Is there a good way to run a script after GDM loads to redirect .xsession-errors to /dev/null?
    – bjem
    Jan 11, 2012 at 2:36

7 Answers 7

10

I found an interim solution.

I put a small script in /etc/X11/Xsession.d called 91redirect-xsession-errors that does the job for now, but if you want to have your own custom symlink for .xession-errors it does not work for that (I tried and it did not output any data).

#!/bin/sh

# Redirect $HOME/.xsession-errors to /dev/null.
# BJEM 11 January 2012

XSESSION_ERRFILE=$HOME/.xsession-errors

# This does not seem to work for a regular file,
# i.e. if you want to symlink $HOME/.xsession-errors
# to another file.  I do not know why.
XSESSION_ERRFILE_FINAL=/dev/null

# Creates target file if it does not exist.
touch "$XSESSION_ERRFILE_FINAL"

# Link .xsession-errors file to the desired target
# no matter what.
ln -sf "$XSESSION_ERRFILE_FINAL" "$XSESSION_ERRFILE"

# Test case.
#gedit &

##### END OF FILE #####

It's a bit 'rough and ready' but it does the job for me. Note that this is the only file that has been altered.

1
  • Unfortunately I didn't notice @earlonrails answer. /etc/X11/Xsession wil create the file in /tmp if it's a symbolic link so this method is useless.
    – int_ua
    Jul 5, 2019 at 19:35
7
+200

There is a file called /etc/X11/Xsession. Which will create the symlink to a tmp file. IE. Starts on line number 61

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

You can cp this Xsession file to Xsession.bak. Then go a head and point your ERRFILE to /dev/null IE. Line 83

exec >> /dev/null 2>&1
4
  • 1
    Thank you! I wish I'd noticed this answer earlier. I'll award you 200 reputation. I've made a patch that checks for environment variable $NOXSESSIONERRORS paste.ubuntu.com/p/TFxZ344k2p this way we can hope to make it upstream.
    – int_ua
    Jul 5, 2019 at 20:08
  • 1
    Thanks a lot! This was a big issue for me years ago when I worked for a company that made kiosks. We would run them from compact flash cards, usually used for cameras. These cards would only have a certain number of writes to them before they would fail write to the cards. Therefore deleting the file many times, as some others suggest, only makes the problem worse. Jul 9, 2019 at 21:21
  • I've made a merge request into the closest thing I could find to upstream: salsa.debian.org/xorg-team/xorg/merge_requests/7 Please add your story about kiosks there.
    – int_ua
    Jul 12, 2019 at 12:46
  • Thanks for the solution! However, this seems like a bug in Ubuntu, or rather Debian because I'm encountering it there. Unless I'm missing something, this should have been fixed a long time ago...
    – A. Donda
    Dec 21, 2021 at 3:47
3

In case you still need a solution that keeps logs and has a proper rotation (as it should be for any logged data).

Here is my approach:

replace

exec >>"$ERRFILE" 2>&1

with

exec > >(logger -t xsession-$USER) 2>&1

in the /etc/X11/Xsession file

That will send all logs to the local syslog server, which can send the logs to the /var/log/syslog file by default and have proper logrotate rules

Alternatively, you can route these messages to a separate file, using syslog configuration and have separate logrotate rules for it altogether.

2

This worked for me: execute with sudo

  1. cd to user folder

  2. create new .xsession-errors file e.g.

    echo test>.xsession-errors

  3. chmod 000 .xsession-errors

  4. Add immutable attribute - even root will not be able write to the file

    chattr +i .xsession-errors

0

This issue follows me around on Arch KDE, Neon KDE and now MX KDE. My primary concern here is that the log file is wasting my SSD writes since I like to keep up with long up-times and the issue exacerbates over time. After some days it's going to boost into overdrive and waste my writes.

  1. I have put this in my /etc/fstab to create a 10MB RAM drive.
tmpfs   /media/mkey/tmp tmpfs   size=10000000   0       0
  1. I have created a mkey_custom.sh script in my home directory
#!/bin/bash

touch /media/mkey/tmp/.xsession-errors
touch /media/mkey/tmp/.xsession-errors.old

ln -sf /media/mkey/tmp/.xsession-errors /home/mkey/.xsession-errors
ln -sf /media/mkey/tmp/.xsession-errors.old /home/mkey/.xsession-errors.old
  1. I have created a mkey_custom.service file
[Unit]
Description=mkey custom service

[Service]
Type=simple
ExecStart=/bin/bash /home/mkey/mkey_custom.sh

[Install]
WantedBy=basic.target
  1. Finally, to install and run the service I used the following
cp mkey_custom.service /etc/systemd/system/mkey_custom.service
chmod 644 /etc/systemd/system/mkey_custom.service
systemctl enable mkey_custom.service

I found that I needed to run the script as a service as running it during startup would be too late. The OS would already start writing to the /home location, so any redirects at that point were in vain.

If after a reboot I check the /home/mkey/.xsession-errors file properties I will see that it now points to right where I want it /media/mkey/tmp/.xsession-errors and that it's being written to.

0

I was able to recover the disk space using truncate.

If you want to limit the space used for logging, you could do this in a loop or cron. For diagnostic purposes, it might be worthwhile to tail the file before truncating.

Optional: Use a hard-link to create a second filename for .xsession-errors in case, for some reason, truncate replaces the file without actually truncating the underlying file (this way you won't lose access to the file if it becomes unlinked without being deleted/truncated).

mkdir --parents .xsession-errors.backup
tail --lines=10000 .xsession-errors >$(mktemp --tmpdir=. .xsession-errors.backup/XXXXXX)
ln .xsession-errors .xsession-errors.truncate
truncate --size=0 .xsession-errors.truncate
rm --force .xsession-errors.truncate

Based on the explanation at What is xsession-errors?, these log items are not necessarily system related. It could be some individual application that has gone into a death loop. You can find out which application by looking for the PID at the start of the log lines. Then you probably just want to kill it.

2
  • There's lots of approaches documented in the various 'duplicate' questions. Jul 7, 2022 at 2:25
  • The tail-to-backup isn't going to work if the disk is already full. Nov 12, 2022 at 19:04
-1

I faced same problem in redhat linux 6.4 server but i can find which folder or user takes more space by using this command "find / -xdev -type f -size +100000000c -exec ls -lh {} \;" then i deleted manually x session errors by using rm -rf command

1
  • 1
    This answer does not say HOW to stop the errors. It only says how to delete them. Please update your answer.
    – Kaz Wolfe
    Aug 27, 2014 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .