From nobody Tue Feb 10 06:52:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646420378; cv=none; d=zohomail.com; s=zohoarc; b=Hr02e4zjdhqrLnEye73oQVM3GU0MhoXPtIl1JCg/Nko02htvTG3J4XtHezH5OYyoSoAHfvXQB3IYZfk/Qkz364tp/pJmbL0/Mc+kG6balkVgP9BVBMtB6/5g3Ko+zMlI7fWWqn/TZm1iM0KSdTu3gNhmhw2Rz105ZB7T+BF3aYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646420378; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dr7TgERg2M+5Wx15veC+gXsvWxwtL5g/gm+1KkXlVBQ=; b=hX7r07l25YmZQNejiSe6DBIWVPChT3UnxfSorityVETXdK+HQoR6YlobS0Fw0LX+xKdcOqvw6b4EMfwNpsQaNVrbOHbaxPq7GlE7WQBvchv53f8h5DkeBtAUTU9SU8KpSK2Jw62W0cxwPdZGG45R9ohw42XDDngInTEZfFPnB1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646420378770574.1514594582275; Fri, 4 Mar 2022 10:59:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-XIUKEQVDNMqGBI6xtB6S9w-1; Fri, 04 Mar 2022 13:59:34 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9B061006AA7; Fri, 4 Mar 2022 18:59:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B676106F975; Fri, 4 Mar 2022 18:59:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3247A1809CB4; Fri, 4 Mar 2022 18:59:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 224IxSI4031831 for ; Fri, 4 Mar 2022 13:59:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F10087B90; Fri, 4 Mar 2022 18:59:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.194.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AB5787B87; Fri, 4 Mar 2022 18:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646420378; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Dr7TgERg2M+5Wx15veC+gXsvWxwtL5g/gm+1KkXlVBQ=; b=aXezxgZpvi58VQeRjC9XkSTBIjFFsJKSAfGLh57XZrOxpe7UhKQeGYeKPdMUlSaNL+jBAT oze4OwRJFWOBKRVE5Fpk5coekrSG2hVSfcS6AiBSfFe5Rqmns5xx8aLkW2V6zM3l1oC++m yeRhPe33jhkC3kYGcCa//T+8BIKOlaY= X-MC-Unique: XIUKEQVDNMqGBI6xtB6S9w-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code Date: Fri, 4 Mar 2022 18:56:16 +0000 Message-Id: <20220304185620.3272401-5-berrange@redhat.com> In-Reply-To: <20220304185620.3272401-1-berrange@redhat.com> References: <20220304185620.3272401-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , libvir-list@redhat.com, Stefan Weil , Hanna Reitz , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646420380492100001 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=C3=A9 Reviewed-by: Eric Blake --- 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 { =20 extern const QEMULogItem qemu_log_items[]; =20 +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 =3D 0; static GArray *debug_regions; +static bool stdio_disabled; + +void qemu_log_stdio_disable(void) +{ + stdio_disabled =3D true; +} =20 /* 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 =3D 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 =3D stderr; } /* must avoid mmap() usage of glibc by setting a buffer "by hand" = */ --=20 2.34.1