From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
libvir-list@redhat.com, "Stefan Weil" <sw@weilnetz.de>,
"Hanna Reitz" <hreitz@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [PATCH v2 6/8] chardev: add API to block use of the stdio implementation
Date: Fri, 4 Mar 2022 18:56:18 +0000 [thread overview]
Message-ID: <20220304185620.3272401-7-berrange@redhat.com> (raw)
In-Reply-To: <20220304185620.3272401-1-berrange@redhat.com>
When daemonizing QEMU it is not possible to use the stdio chardev
backend because the file descriptors are connected to /dev/null.
Currently the chardev checks for this scenario directly, but to
decouple it from the system emulator daemonizing code, we reverse
the relationship. Now the system emulator calls a helper to
explicitly disable use of the stdio backend.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
chardev/char-stdio.c | 12 ++++++++++--
include/chardev/char-stdio.h | 29 +++++++++++++++++++++++++++++
softmmu/vl.c | 2 ++
3 files changed, 41 insertions(+), 2 deletions(-)
create mode 100644 include/chardev/char-stdio.h
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 403da308c9..bab0f5ade1 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -28,6 +28,7 @@
#include "qemu/sockets.h"
#include "qapi/error.h"
#include "chardev/char.h"
+#include "chardev/char-stdio.h"
#ifdef _WIN32
#include "chardev/char-win.h"
@@ -37,6 +38,13 @@
#include "chardev/char-fd.h"
#endif
+static bool stdio_disabled;
+
+void qemu_chr_stdio_disable(void)
+{
+ stdio_disabled = true;
+}
+
#ifndef _WIN32
/* init terminal so that we can grab keys */
static struct termios oldtty;
@@ -90,8 +98,8 @@ static void qemu_chr_open_stdio(Chardev *chr,
ChardevStdio *opts = backend->u.stdio.data;
struct sigaction act;
- if (is_daemonized()) {
- error_setg(errp, "cannot use stdio with -daemonize");
+ if (stdio_disabled) {
+ error_setg(errp, "cannot use stdio with this configuration");
return;
}
diff --git a/include/chardev/char-stdio.h b/include/chardev/char-stdio.h
new file mode 100644
index 0000000000..eae93a2900
--- /dev/null
+++ b/include/chardev/char-stdio.h
@@ -0,0 +1,29 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef CHAR_STDIO_H
+#define CHAR_STDIO_H
+
+void qemu_chr_stdio_disable(void);
+
+#endif /* CHAR_STDIO_H */
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 30342b9df2..12b714795d 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -69,6 +69,7 @@
#include "exec/gdbstub.h"
#include "qemu/timer.h"
#include "chardev/char.h"
+#include "chardev/char-stdio.h"
#include "qemu/bitmap.h"
#include "qemu/log.h"
#include "sysemu/blockdev.h"
@@ -3667,6 +3668,7 @@ void qemu_init(int argc, char **argv, char **envp)
}
if (is_daemonized()) {
qemu_log_stdio_disable();
+ qemu_chr_stdio_disable();
}
}
}
--
2.34.1
next prev parent reply other threads:[~2022-03-04 19:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-04 18:56 [PATCH v2 0/8] softmmu: move and refactor -runas, -chroot and -daemonize Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 1/8] softmmu: remove deprecated --enable-fips option Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 2/8] os-posix: refactor code handling the -runas argument Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 3/8] os-posix: refactor code handling the -chroot argument Daniel P. Berrangé
2022-03-04 18:56 ` [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code Daniel P. Berrangé
2022-03-04 21:46 ` Eric Blake
2022-03-04 18:56 ` [PATCH v2 5/8] softmmu: refactor use of is_daemonized() method Daniel P. Berrangé
2022-03-04 22:02 ` Eric Blake
2022-03-04 18:56 ` Daniel P. Berrangé [this message]
2022-03-04 22:03 ` [PATCH v2 6/8] chardev: add API to block use of the stdio implementation Eric Blake
2022-03-04 18:56 ` [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code Daniel P. Berrangé
2022-03-04 22:09 ` Eric Blake
2022-03-04 18:56 ` [PATCH v2 8/8] softmmu: remove is_daemonized() method Daniel P. Berrangé
2022-03-04 22:11 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220304185620.3272401-7-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=libvir-list@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).