Skip to content

Instantly share code, notes, and snippets.

@hilbix
Created December 14, 2016 08:43
Show Gist options
  • Save hilbix/1fd1af0b67e94725da17d3cf61d8b755 to your computer and use it in GitHub Desktop.
Save hilbix/1fd1af0b67e94725da17d3cf61d8b755 to your computer and use it in GitHub Desktop.
Prevent systemd-logind from spamming dmesg
#!/bin/bash
#
# Public Domain
#
# Prevent systemd-logind to spam dmesg
#
# Run this from something which catches the output, like
# https://github.com/hilbix/ptybuffer/blob/master/script/autostart.sh
mkdir -pm755 /run/systemd/journal
rm -f /run/systemd/journal/socket
date
( ( sleep 3; killall -1 systemd-logind ) & )
exec socat -d -d unix-recv:/run/systemd/journal/socket -
@hilbix
Copy link
Author

hilbix commented Nov 2, 2017

Only use this if you get SPAM in dmesg like:

[2520193.073770] systemd-logind[4353]: Removed session 49518.
[2520284.667454] systemd-logind[4353]: New session 49521 of user tino.

This means, you have no logger of systemd loaded. The output of above script will look like:

2017/11/02 21:12:48 socat[28456] N received packet with 265 bytes from AF=1 "<anon>"
PRIORITY=6
SYSLOG_FACILITY=4
CODE_FILE=../src/login/logind-session.c
CODE_LINE=684
CODE_FUNCTION=session_finalize
SYSLOG_IDENTIFIER=systemd-logind
MESSAGE_ID=3354939424b4456d9802ca8333ed424a
SESSION_ID=49521
USER_ID=tino
LEADER=26748
MESSAGE=Removed session 49521.
2017/11/02 21:12:49 socat[28456] N received packet with 271 bytes from AF=1 "<anon>"
PRIORITY=6
SYSLOG_FACILITY=4
CODE_FILE=../src/login/logind-session.c
CODE_LINE=581
CODE_FUNCTION=session_start
SYSLOG_IDENTIFIER=systemd-logind
MESSAGE_ID=8d45620c1a4348dbb17410da57c60c66
SESSION_ID=49529
USER_ID=tino
LEADER=29175
MESSAGE=New session 49529 of user tino.

Please note:

The sleep 3 and the script above is not ideal. The correct thing to do would be:

  1. Check, if /run/systemd/journal/socket exists and is functional.

  2. If functional, leave alone. Else remove and re-create the socket as shown above.

  3. Check if /run/systemd/journal/socket now is functional. If so, reload systemd-logind as shown.

The problem is how to find out if a Unix-DGRAM-socket is functional from plain shell level.
Perhaps best would be to write a small wrapper which:

  • Open the socket and try to send to it. If this works, periodically (each minute or so) re-check it.
  • If the socket becomes disfunctional, re-create it, receive all data and send it to stdout.
  • After recreation, fork some script, once, which then can do the refresh.

This might then lead to something like:

fake-journald /run/systemd/journal/socket /usr/bin/killall -1 systemd-logind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment