1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Reiter <s.reiter@proxmox.com>
3 Date: Tue, 12 Jan 2021 14:12:20 +0100
4 Subject: [PATCH] PVE: redirect stderr to journal when daemonized
6 QEMU uses the logging for error messages usually, so LOG_ERR is most
9 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
10 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
13 os-posix.c | 7 +++++--
14 2 files changed, 7 insertions(+), 2 deletions(-)
16 diff --git a/meson.build b/meson.build
17 index d3783a83e4..715245ba20 100644
20 @@ -1268,6 +1268,7 @@ keyutils = dependency('libkeyutils', required: false,
21 has_gettid = cc.has_function('gettid')
23 libuuid = cc.find_library('uuid', required: true)
24 +libsystemd = cc.find_library('systemd', required: true)
25 libproxmox_backup_qemu = cc.find_library('proxmox_backup_qemu', required: true)
28 @@ -2861,6 +2862,7 @@ if have_block
29 # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
31 blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
32 + blockdev_ss.add(when: 'CONFIG_POSIX', if_true: libsystemd)
33 softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
36 diff --git a/os-posix.c b/os-posix.c
37 index 24692c8593..d1bc5ac12d 100644
44 +#include <systemd/sd-journal.h>
47 #include "qemu-common.h"
48 /* Needed early for CONFIG_BSD etc. */
49 @@ -291,9 +293,10 @@ void os_setup_post(void)
53 - /* In case -D is given do not redirect stderr to /dev/null */
54 + /* In case -D is given do not redirect stderr to journal */
57 + int journal_fd = sd_journal_stream_fd("QEMU", LOG_ERR, 0);
58 + dup2(journal_fd, 2);