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.

jrg
  • 61,707
bjem
  • 431

7 Answers7

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.

bjem
  • 431
8

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
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.

stimur
  • 131
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

dlin
  • 3,900
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.

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.

mkey
  • 101
-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