LogInit: default to journal if MPD was started as systemd service

This commit is contained in:
Max Kellermann 2018-11-14 12:06:24 +01:00
parent 94c31d0da9
commit 8682183bc3
2 changed files with 15 additions and 0 deletions

1
NEWS
View File

@ -2,6 +2,7 @@ ver 0.21.3 (not yet released)
* output
- alsa: fix crash bug
- alsa: fix stuttering at start of playback
* log: default to journal if MPD was started as systemd service
ver 0.21.2 (2018/11/12)
* protocol

View File

@ -30,6 +30,10 @@
#include "util/RuntimeError.hxx"
#include "system/Error.hxx"
#ifdef ENABLE_SYSTEMD_DAEMON
#include <systemd/sd-daemon.h>
#endif
#include <assert.h>
#include <string.h>
#include <fcntl.h>
@ -139,6 +143,16 @@ log_init(const ConfigData &config, bool verbose, bool use_stdout)
if (param == nullptr) {
/* no configuration: default to syslog (if
available) */
#ifdef ENABLE_SYSTEMD_DAEMON
if (sd_booted() &&
getenv("NOTIFY_SOCKET") != nullptr) {
/* if MPD was started as a systemd
service, default to journal (which
is connected to fd=2) */
out_fd = STDOUT_FILENO;
return;
}
#endif
#ifndef HAVE_SYSLOG
throw std::runtime_error("config parameter 'log_file' not found");
#endif