From nobody Sun Oct 5 00:07:11 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1759495648; cv=none; d=zohomail.com; s=zohoarc; b=PdeP78bhHoD7UgK4+PFOpdgC3rAirQb1kAbxgwUVU0cKhq763jKQpDWU3CM/Qjs5qrKHQI6EZG99OrbWjWVWaj4kkX1FVP8cCOJ9dA4D92HimMK7nzqEqU7wN+Sq7ulv91ZHJ92n0I622v2YQytDI7l43S+djYdbZg47NRVwnzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759495648; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=sTRkdZqChpaKq1NPaVRsVenhbLwcBPxXXwC/vyR/zvY=; b=C0Rm7m8ReMEYo3DS2EBdrMiUbI4QPjx8kqCCwaMW/oUUWe4EqSKiQdboDlN/Lfv5un43elcvjBx/F6cE9EWWgtMB2shz8AveWKGS3v6tOHdO+MS4Mp0s3KkrU9lvppp3h+fpmfwGxPpzFcIlC3jvtHyXrl7BTTxlq5p9afxesEQ= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1759495648309467.2876161589502; Fri, 3 Oct 2025 05:47:28 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 34ED9441CC; Fri, 3 Oct 2025 08:47:27 -0400 (EDT) Received: from [172.19.199.17] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id D9ACC4423D; Fri, 3 Oct 2025 08:45:11 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id A2A1B41BA4; Fri, 3 Oct 2025 08:43:43 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DE25043DDC for ; Fri, 3 Oct 2025 08:43:38 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-GlT8YHVBNr6nTKmL5J5DvA-1; Fri, 03 Oct 2025 08:43:37 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02B08195608C for ; Fri, 3 Oct 2025 12:43:35 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.145]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB9281800576; Fri, 3 Oct 2025 12:43:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759495418; 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; bh=sTRkdZqChpaKq1NPaVRsVenhbLwcBPxXXwC/vyR/zvY=; b=FRQtXZDlDMLmNJ7qWbxvDwYb9udUYGxwl82FbHRGEzfksf08eA7A0rOWZrx40/In4K7yOr wVu+nx3Pj13A6QuZ8yjFa3hMO3gVVXXHfXdFqqLEapqxnfS6RpWGu78DE3plVMQ3uD8yJM TVWGO42F4lFwDwSN9PgrSeo1AiVP8W4= X-MC-Unique: GlT8YHVBNr6nTKmL5J5DvA-1 X-Mimecast-MFC-AGG-ID: GlT8YHVBNr6nTKmL5J5DvA_1759495415 To: devel@lists.libvirt.org Subject: [PATCH] src: report error from failing to add timer/FD watches Date: Fri, 3 Oct 2025 13:43:31 +0100 Message-ID: <20251003124331.3207700-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6Po9bnpc-jRwS4acibMPTCKT7YImy4_i1393vIr_JBo_1759495415 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7GX4J5FI5DPLLCOVVPJB6NXZH6PVVDIQ X-Message-ID-Hash: 7GX4J5FI5DPLLCOVVPJB6NXZH6PVVDIQ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1759495649839116600 From: Daniel P. Berrang=C3=A9 The virEventAddHandle/Timeout APIs are unusual in that they do not report errors on failure, because they call through to function callbacks which might be provided externally to libvirt and thus won't be using libvirt's error reporting APIs. This is a rather unfortunate design characteristic as we can see most callers forgot about this special behaviour and so we are lacking error reporting in many cases. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/libxl/libxl_driver.c | 2 ++ src/logging/log_cleaner.c | 4 ++++ src/logging/log_handler.c | 4 ++++ src/lxc/lxc_controller.c | 5 ++++- src/node_device/node_device_udev.c | 10 +++++++++- src/remote/remote_ssh_helper.c | 10 ++++++++-- src/rpc/virkeepalive.c | 5 ++++- src/rpc/virnetclientstream.c | 2 ++ src/rpc/virnetserverclient.c | 5 ++++- src/rpc/virnetserverservice.c | 2 ++ 10 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 308c0372aa..6a2e2ab964 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -170,6 +170,7 @@ libxlFDRegisterEventHook(void *priv, info->id =3D virEventAddHandle(fd, vir_events, libxlFDEventCallback, info, libxlOSEventHookInfoFree); if (info->id < 0) { + VIR_WARN("Failed to add event watch for FD %d", fd); VIR_FREE(info); return -1; } @@ -255,6 +256,7 @@ libxlTimeoutRegisterEventHook(void *priv, info->id =3D virEventAddTimeout(timeout, libxlTimerCallback, info, libxlOSEventHookInfoFree); if (info->id < 0) { + VIR_WARN("Failed to add event timer"); VIR_FREE(info); return -1; } diff --git a/src/logging/log_cleaner.c b/src/logging/log_cleaner.c index d247fdf829..7110dfcff6 100644 --- a/src/logging/log_cleaner.c +++ b/src/logging/log_cleaner.c @@ -251,6 +251,10 @@ virLogCleanerInit(virLogHandler *handler) handler->cleanup_log_timer =3D virEventAddTimeout(CLEANER_LOG_TIMEOUT_= MS, virLogCleanerTimer, handler, NULL); + if (handler->cleanup_log_timer < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add log cleanup timer")); + } return handler->cleanup_log_timer; } =20 diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 71517bbbe5..6ad3e33ee8 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -302,6 +302,8 @@ virLogHandlerNewPostExecRestart(virJSONValue *object, virLogHandlerDomainLogFileEve= nt, handler, NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to add watch on log FD %1$d"), file->= pipefd); VIR_DELETE_ELEMENT(handler->files, handler->nfiles - 1, handle= r->nfiles); goto error; } @@ -386,6 +388,8 @@ virLogHandlerDomainOpenLogFile(virLogHandler *handler, virLogHandlerDomainLogFileEvent, handler, NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to add watch on log FD %1$d"), file->pipe= fd); VIR_DELETE_ELEMENT(handler->files, handler->nfiles - 1, handler->n= files); goto error; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index fb7f8e0bc2..ae00f36eb3 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -206,8 +206,11 @@ static virLXCController *virLXCControllerNew(const cha= r *name) =20 if ((ctrl->timerShutdown =3D virEventAddTimeout(-1, virLXCControllerQuitTime= r, ctrl, - NULL)) < 0) + NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add shutdown timer")); goto error; + } =20 cleanup: virLXCControllerDriverFree(driver); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 30c2ddf568..85468150c1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2318,6 +2318,10 @@ scheduleMdevctlUpdate(udevEventData *data) virEventRemoveTimeout(data->mdevctlTimeout); data->mdevctlTimeout =3D virEventAddTimeout(100, submitMdevctlUpdate, data, NULL); + if (data->mdevctlTimeout < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add mdev update timer")); + } } =20 =20 @@ -2609,8 +2613,12 @@ nodeStateInitialize(bool privileged, priv->watch =3D virEventAddHandle(udev_monitor_get_fd(priv->udev_monit= or), VIR_EVENT_HANDLE_READABLE, udevEventHandleCallback, virObjectRef(= priv), virObjectUnref); - if (priv->watch =3D=3D -1) + if (priv->watch =3D=3D -1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to add watch on udev FD %1$d"), + udev_monitor_get_fd(priv->udev_monitor)); goto unlock; + } =20 if (mdevctlEnableMonitor(priv) < 0) goto unlock; diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c index 2d332a39b6..48896fd559 100644 --- a/src/remote/remote_ssh_helper.c +++ b/src/remote/remote_ssh_helper.c @@ -316,15 +316,21 @@ virRemoteSSHHelperRun(virNetSocket *sock) VIR_EVENT_HANDLE_READABLE, virRemoteSSHHelperEventOnStd= in, &proxy, - NULL)) < 0) + NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add watch on stdin")); goto cleanup; + } =20 if ((proxy.stdoutWatch =3D virEventAddHandle(STDOUT_FILENO, 0, virRemoteSSHHelperEventOnSt= dout, &proxy, - NULL)) < 0) + NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add watch on stdout")); goto cleanup; + } =20 if (virNetSocketAddIOCallback(proxy.sock, VIR_EVENT_HANDLE_READABLE, diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c index d96bd347ad..690bc08b2e 100644 --- a/src/rpc/virkeepalive.c +++ b/src/rpc/virkeepalive.c @@ -276,8 +276,11 @@ virKeepAliveStart(virKeepAlive *ka, ka->intervalStart =3D now - (ka->interval - timeout); ka->timer =3D virEventAddTimeout(timeout * 1000, virKeepAliveTimer, ka, virObjectUnref); - if (ka->timer < 0) + if (ka->timer < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add keepalive timer")); goto cleanup; + } =20 /* the timer now has another reference to this object */ virObjectRef(ka); diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 98034d737d..380b785869 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -725,6 +725,8 @@ int virNetClientStreamEventAddCallback(virNetClientStre= am *st, virNetClientStreamEventTimer, st, virObjectUnref)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add timer to event loop")); virObjectUnref(st); goto cleanup; } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 355aab4b04..e2967e5e1f 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -396,8 +396,11 @@ virNetServerClientNewInternal(unsigned long long id, =20 client->sockTimer =3D virEventAddTimeout(-1, virNetServerClientSockTim= erFunc, client, NULL); - if (client->sockTimer < 0) + if (client->sockTimer < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add socket timer")); goto error; + } =20 /* Prepare one for packet receive */ if (!(client->rx =3D virNetMessageNew(true))) diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 682b2091c1..babdedee35 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -154,6 +154,8 @@ virNetServerServiceNewSocket(virNetSocket **socks, svc->timer =3D virEventAddTimeout(-1, virNetServerServiceTimerFunc, svc, virObjectUnref); if (svc->timer < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add service timer")); virObjectUnref(svc); goto error; } --=20 2.50.1