Web lists-archives.com

How to redirect messages in ~/.xsession-errors to a FIFO device?




Basically, all messages returned by X-applications are redirected to the
~/.xsession-errors file. In some desktop environments this file is emptied with
each X session restart. At least that was the case of my Openbox + LightDM
setup. Now, I'm trying to migrate to KDE/Plasma5, and as a part of it, I
installed the SDDM login manager. I haven't really finished the migration
process yet, but since SDDM looks better than LightDM, I wanted to replace it.
Unfortunately, the ~/.xsession-errors file grows in size, and after a
few hours it's around 20-30 MiB, and the content of the file isn't removed with
each X session restart.

In the /etc/X11/Xsession file, there's something like this:
-----------------------------------
ERRFILE=$HOME/.xsession-errors
...
exec >>"$ERRFILE" 2>&1
-----------------------------------
Since I'm using FIFO devices for some rsyslog logs, I thought I also could use
one of such devices for the ~/.xsession-errors file content, but changing the
ERRFILE variable to some /dev/log-fifo device causes the start of the X session
to stall -- it hangs since the FIFO device needs (probably) some process to read
the content of the device, for instance, "cat /dev/log-fifo", but unfortunately
I can't add anything in the script after the above command so it could "cat" the
device (it works when I do it via TTY).

Is it even possible to redirect the content of the file to the FIFO device in
this way? I'm asking because I temporary created the following systemd .socket file:
---------------------------------------------------------
# cat /etc/systemd/system/log-xsession-errors.socket
[Unit]
Description=log-xsession-errors socket
DefaultDependencies=no
Before=sockets.target
PartOf=log-xsession-errors.service

[Socket]
ListenFIFO=/dev/log-xsession-errors
SocketMode=0600
SocketUser=morfik
SocketGroup=morfik
RemoveOnStop=true
PipeSize=1M

[Install]
WantedBy=sockets.target
---------------------------------------------------------
And some service for it:
---------------------------------------------------------
# cat /etc/systemd/system/log-xsession-errors.service
[Unit]
Description=log-xsession-errors service
DefaultDependencies=no

[Service]
ExecStart=/bin/true
RemainAfterExit=yes

[Install]
Also=log-xsession-errors.socket
---------------------------------------------------------
And in this solution, systemd creates the device and starts some process to
listen on it, and there's no problem with starting the X session because as soon
as some X messages show up, they're sent to the FIFO device, and that device has
1 MiB buffer set, and probably that's why it can hold the messages for some time
till a terminal with "cat" is started inside of the X session. I'm just
wondering whether similar solution can be achieved without systemd.

--
Morfik

Attachment: signature.asc
Description: OpenPGP digital signature