qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 4/8] util: remove use of is_daemonized flag from logging code
Date: Fri,  4 Mar 2022 18:56:16 +0000	[thread overview]
Message-ID: <20220304185620.3272401-5-berrange@redhat.com> (raw)
In-Reply-To: <20220304185620.3272401-1-berrange@redhat.com>

We want to decouple knowledge of daemonization from other code. What the
logging code really wants to know is whether it can use stdio or not.
Add an API to let the logging code be informed of this fact explicitly.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/qemu/log.h |  1 +
 softmmu/vl.c       |  3 +++
 util/log.c         | 12 +++++++++---
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/qemu/log.h b/include/qemu/log.h
index 9b80660207..a35e11a788 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -147,6 +147,7 @@ typedef struct QEMULogItem {
 
 extern const QEMULogItem qemu_log_items[];
 
+void qemu_log_stdio_disable(void);
 void qemu_set_log(int log_flags);
 void qemu_log_needs_buffers(void);
 void qemu_set_log_filename(const char *filename, Error **errp);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 1fe028800f..f6f33e15e4 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3664,6 +3664,9 @@ void qemu_init(int argc, char **argv, char **envp)
                     error_report("Option not supported in this build");
                     exit(1);
                 }
+                if (is_daemonized()) {
+                    qemu_log_stdio_disable();
+                }
             }
         }
     }
diff --git a/util/log.c b/util/log.c
index 2ee1500bee..a123622ee3 100644
--- a/util/log.c
+++ b/util/log.c
@@ -33,6 +33,12 @@ QemuLogFile *qemu_logfile;
 int qemu_loglevel;
 static int log_append = 0;
 static GArray *debug_regions;
+static bool stdio_disabled;
+
+void qemu_log_stdio_disable(void)
+{
+    stdio_disabled = true;
+}
 
 /* Return the number of characters emitted.  */
 int qemu_log(const char *fmt, ...)
@@ -92,7 +98,7 @@ void qemu_set_log(int log_flags)
      *   If we are daemonized,
      *     we will only log if there is a logfilename.
      */
-    if (qemu_loglevel && (!is_daemonized() || logfilename)) {
+    if (qemu_loglevel && (!stdio_disabled || logfilename)) {
         need_to_open_file = true;
     }
     QEMU_LOCK_GUARD(&qemu_logfile_mutex);
@@ -110,7 +116,7 @@ void qemu_set_log(int log_flags)
                 _exit(1);
             }
             /* In case we are a daemon redirect stderr to logfile */
-            if (is_daemonized()) {
+            if (stdio_disabled) {
                 dup2(fileno(logfile->fd), STDERR_FILENO);
                 fclose(logfile->fd);
                 /* This will skip closing logfile in qemu_log_close() */
@@ -118,7 +124,7 @@ void qemu_set_log(int log_flags)
             }
         } else {
             /* Default to stderr if no log file specified */
-            assert(!is_daemonized());
+            assert(!stdio_disabled);
             logfile->fd = stderr;
         }
         /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
-- 
2.34.1



  parent reply	other threads:[~2022-03-04 19:07 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 ` Daniel P. Berrangé [this message]
2022-03-04 21:46   ` [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code 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 ` [PATCH v2 6/8] chardev: add API to block use of the stdio implementation Daniel P. Berrangé
2022-03-04 22:03   ` 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-5-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).