[PATCH v2 6/8] chardev: add API to block use of the stdio implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux