From nobody Tue Sep 9 23:39:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1738158418141195.56347975138272; Wed, 29 Jan 2025 05:46:58 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7D0CB160B; Wed, 29 Jan 2025 08:46:57 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D6B8817FF; Wed, 29 Jan 2025 08:42:31 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1B49D166C; Wed, 29 Jan 2025 08:42:27 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E98FD17E7 for ; Wed, 29 Jan 2025 08:42:10 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-428-IiVTdpWcNbWYhGeuZIixMw-1; Wed, 29 Jan 2025 08:42:09 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F90918009A8 for ; Wed, 29 Jan 2025 13:42:08 +0000 (UTC) Received: from localhost (unknown [10.39.208.35]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 825B019560A3; Wed, 29 Jan 2025 13:42:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738158130; h=from:from: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; bh=yYzeaZhZka5739BBCheWq4eD9WDOo+yNxpd4X9uRq6I=; b=d79j5NiWps79uyxFaAFfM2v0YOGCUPmtViEjPmuEG+j151wDLDm1bGUvVjzdq/h4z4ox/K 1c7HM3lDEThlmmEze4cv5h+iSO6VuOTDLIN9qos68EtbBN5RE01ZA1ONMR8HEk0MqSEMLC 3YtBrszuIDFW1JHXsFnCXtwe6KcjG8Y= X-MC-Unique: IiVTdpWcNbWYhGeuZIixMw-1 X-Mimecast-MFC-AGG-ID: IiVTdpWcNbWYhGeuZIixMw From: marcandre.lureau@redhat.com To: devel@lists.libvirt.org Subject: [PATCH 14/19] qemu/dbus: log daemon stdout/err Date: Wed, 29 Jan 2025 17:40:36 +0400 Message-ID: <20250129134042.1282472-15-marcandre.lureau@redhat.com> In-Reply-To: <20250129134042.1282472-1-marcandre.lureau@redhat.com> References: <20250129134042.1282472-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: e21rr8qyFyRYIf1UUloO48P_agImm7To7X105Lasf9M_1738158128 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WRVGNPG3NFEZQSOFNO7AKAL76DFVBPXS X-Message-ID-Hash: WRVGNPG3NFEZQSOFNO7AKAL76DFVBPXS X-MailFrom: marcandre.lureau@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1738158419957019000 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Currently, if dbus-daemon writes on errfd, it will SIGPIPE. Signed-off-by: Marc-Andr=C3=A9 Lureau --- src/qemu/qemu_dbus.c | 61 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c index 4a019ae092..0e22392e6f 100644 --- a/src/qemu/qemu_dbus.c +++ b/src/qemu/qemu_dbus.c @@ -18,12 +18,17 @@ =20 #include =20 +#include +#include +#include + #include "qemu_dbus.h" #include "qemu_security.h" =20 #include "virlog.h" #include "virtime.h" #include "virpidfile.h" +#include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -67,6 +72,14 @@ qemuDBusCreateConfPath(virQEMUDriverConfig *cfg, } =20 =20 +static char * +qemuDBusCreateLogFilename(virQEMUDriverConfig *cfg, + const char *shortName) +{ + return qemuDBusCreateFilename(cfg->dbusStateDir, shortName, ".log"); +} + + char * qemuDBusGetAddress(virQEMUDriver *driver, virDomainObj *vm) @@ -183,10 +196,11 @@ qemuDBusStart(virQEMUDriver *driver, g_autofree char *pidfile =3D NULL; g_autofree char *configfile =3D NULL; g_autofree char *sockpath =3D NULL; + g_autofree char *logpath =3D NULL; g_autofree char *address =3D NULL; virTimeBackOffVar timebackoff; const unsigned long long timeout =3D 500 * 1000; /* ms */ - VIR_AUTOCLOSE errfd =3D -1; + VIR_AUTOCLOSE logfd =3D -1; pid_t cpid =3D -1; int ret =3D -1; =20 @@ -219,10 +233,40 @@ qemuDBusStart(virQEMUDriver *driver, if (qemuSecurityDomainSetPathLabel(driver, vm, configfile, false) < 0) goto cleanup; =20 + logpath =3D qemuDBusCreateLogFilename(cfg, shortName); + + if (cfg->stdioLogD) { + g_autoptr(virLogManager) logManager =3D virLogManagerNew(driver->p= rivileged); + + if (!logManager) + goto cleanup; + + if ((logfd =3D virLogManagerDomainOpenLogFile(logManager, + "qemu", + vm->def->uuid, + vm->def->name, + logpath, + 0, + NULL, NULL)) < 0) + goto cleanup; + } else { + if ((logfd =3D open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUS= R | S_IWUSR)) < 0) { + virReportSystemError(errno, _("failed to create logfile %1$s"), + logpath); + goto cleanup; + } + if (virSetCloseExec(logfd) < 0) { + virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), + logpath); + goto cleanup; + } + } + cmd =3D virCommandNew(dbusDaemonPath); virCommandClearCaps(cmd); virCommandSetPidFile(cmd, pidfile); - virCommandSetErrorFD(cmd, &errfd); + virCommandSetOutputFD(cmd, &logfd); + virCommandSetErrorFD(cmd, &logfd); virCommandDaemonize(cmd); virCommandAddArgFormat(cmd, "--config-file=3D%s", configfile); =20 @@ -239,22 +283,15 @@ qemuDBusStart(virQEMUDriver *driver, if (virTimeBackOffStart(&timebackoff, 1, timeout) < 0) goto cleanup; while (virTimeBackOffWait(&timebackoff)) { - char errbuf[1024] =3D { 0 }; - if (virFileExists(sockpath)) break; =20 if (virProcessKill(cpid, 0) =3D=3D 0) continue; =20 - if (saferead(errfd, errbuf, sizeof(errbuf) - 1) < 0) { - virReportSystemError(errno, - _("dbus-daemon %1$s died unexpectedly"), - dbusDaemonPath); - } else { - virReportError(VIR_ERR_OPERATION_FAILED, - _("dbus-daemon died and reported: %1$s"), errbu= f); - } + virReportSystemError(errno, + _("dbus-daemon %1$s died unexpectedly, check = the log"), + dbusDaemonPath); =20 goto cleanup; } --=20 2.47.0