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>
12 os-posix.c | 7 +++++--
13 2 files changed, 7 insertions(+), 2 deletions(-)
15 diff --git a/meson.build b/meson.build
16 index 4d156d35ce..737ea9e5d7 100644
19 @@ -726,6 +726,7 @@ keyutils = dependency('libkeyutils', required: false,
20 has_gettid = cc.has_function('gettid')
22 libuuid = cc.find_library('uuid', required: true)
23 +libsystemd = cc.find_library('systemd', required: true)
24 libproxmox_backup_qemu = cc.find_library('proxmox_backup_qemu', required: true)
27 @@ -1539,6 +1540,7 @@ blockdev_ss.add(files(
28 # os-posix.c contains POSIX-specific functions used by qemu-storage-daemon,
30 blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c'))
31 +blockdev_ss.add(when: 'CONFIG_POSIX', if_true: libsystemd)
32 softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')])
34 common_ss.add(files('cpus-common.c'))
35 diff --git a/os-posix.c b/os-posix.c
36 index 1de2839554..ac4f652923 100644
43 +#include <systemd/sd-journal.h>
46 #include "qemu-common.h"
47 /* Needed early for CONFIG_BSD etc. */
48 @@ -288,9 +290,10 @@ void os_setup_post(void)
52 - /* In case -D is given do not redirect stderr to /dev/null */
53 + /* In case -D is given do not redirect stderr to journal */
56 + int journal_fd = sd_journal_stream_fd("QEMU", LOG_ERR, 0);
57 + dup2(journal_fd, 2);