g_log_writer_is_journald fails if a Journal Namespace is used
For my Glib program I configured a dedicated instance of journald using Journal Namespaces
GLib fails to recognize stderr as a journald socket and prints debug messages in plain text. It happens because the namespace is appended to the unix socket path: /run/systemd/journal.nicetunnel/stdout
. The following fixed it for me:
diff --git a/glib/gmessages.c b/glib/gmessages.c
index 7affcd4d9..374b23ae4 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -2228,7 +2228,7 @@ g_log_writer_is_journald (gint output_fd)
addr_len = sizeof(addr);
err = getpeername (output_fd, &addr.sa, &addr_len);
if (err == 0 && addr.storage.ss_family == AF_UNIX)
- return g_str_has_prefix (addr.un.sun_path, "/run/systemd/journal/");
+ return g_str_has_prefix (addr.un.sun_path, "/run/systemd/journal");
#endif
return FALSE;
(although journal_sendv
still has the hardcoded socket path "/run/systemd/journal/socket")
Config files:
/etc/systemd/journald@nicetunnel.conf
:
[Journal]
Storage=volatile
RuntimeMaxUse=20M
/etc/systemd/system/nicetunnel.service
:
[Unit]
Description=My Test Service
[Service]
ExecStart=/home/il/builds/nicetunnel/build-msan/src/nicetunnel --peer-addr 127.0.0.1:1194 --stun-addr basinsrv
Environment="G_MESSAGES_DEBUG=nicetunnel"
LogNamespace=nicetunnel
User=il