From nobody Sun Feb 8 22:35:31 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=1641304063; cv=none; d=zohomail.com; s=zohoarc; b=VT3nlZirxO4FowdEeC9FgbkiAgsEFPjPT9DufekwDjZYeI2V6fEQ7ZutfKhslWNBes71Bnigrk2uV/p6EVkYBT7MsXnIM62k+FnFcnvKaqcGrdOAb9Dpa8upc4CD0m4Pu24ouDZYSy3pLGX1NZv7FQ3lIdciNPcTfyZV0Uod0mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641304063; h=Content-Type:Content-Transfer-Encoding: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=zrjXqaIqUOctMCS37pCeAcugJq4sPZE5TpLRy0M4FkA=; b=FOcx8ArnW3xbN6+jggUF+uTUl6coza+6IwwKCnOR1fmbHYzXrN/elhltYCPO8ZDDQGM5v8A0t533c4+rslt5FTNAhqsD8dHBRJrxyONZa4k7Of4XIRRFLM0CclHswexpJHI8OY/rd20SEig653Mw2oZtkZopL9A8LG2p1ELCFLk= 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 1641304063312397.62492892752437; Tue, 4 Jan 2022 05:47:43 -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-389-N10YStVpOS6ikjSc2lSAag-1; Tue, 04 Jan 2022 08:47:40 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 62D8881CCB5; Tue, 4 Jan 2022 13:47:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 048482B3CA; Tue, 4 Jan 2022 13:47:35 +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 99B6A4A708; Tue, 4 Jan 2022 13:47:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 204DlMh9019605 for ; Tue, 4 Jan 2022 08:47:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7829E492CAB; Tue, 4 Jan 2022 13:47:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73288492CA9 for ; Tue, 4 Jan 2022 13:47:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A390805BFC for ; Tue, 4 Jan 2022 13:47:22 +0000 (UTC) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-60-3QT0RGbFNK-48m46kUTSSQ-1; Tue, 04 Jan 2022 08:47:21 -0500 Received: by mail-wr1-f69.google.com with SMTP id c16-20020adfa310000000b001a2349890e1so11675438wrb.0 for ; Tue, 04 Jan 2022 05:47:20 -0800 (PST) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id w17sm39450521wmc.14.2022.01.04.05.47.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 05:47:18 -0800 (PST) Received: from wheatley.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 6F9372FEE741 for ; Tue, 4 Jan 2022 14:47:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641304062; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=zrjXqaIqUOctMCS37pCeAcugJq4sPZE5TpLRy0M4FkA=; b=ESVc7gjwzwLEG5ZQUJCXVCEIa89xH09opfugVOfKhUSfUfaK15lo+aP2uxzIqw/3xONX9b bYsFCDqR9ugxlXyIEwexyza9IVWMNVMVUMHbOLze55pJgWs3hYfy2JPwAfuWt1dRb1jG8L qPfyhcqmyWLhwiUaTXyC+PGtnZZWEGY= X-MC-Unique: N10YStVpOS6ikjSc2lSAag-1 X-MC-Unique: 3QT0RGbFNK-48m46kUTSSQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zrjXqaIqUOctMCS37pCeAcugJq4sPZE5TpLRy0M4FkA=; b=AMjTil4U+LGC+yGTYKbXnNNtwdP7HGOzVdhYu7rJ3aJkQNJwerABA4L0dDcPDlUyjX k5k1fQb401Kp2ArhbTIoKJfWs9Lw80NbR6Rt41VOSsHt0F1pYvaDzwM0OcRFzmeNvzO1 Iy/ueCqq268JgdNmoCCEhQLSZ4zaUZRInLFMsXzxB9BgEImm8uswpI8fKtN0SE101y9S vZDJh54sOS5rHmH0Jkm0rhN5rXLtQOlLpg5ozYzCUSPTsovaiUuSL/XIM5/nLROtqC0v q3iFAWJ4cZYo1R3YU6LNuz1UE77sg9Fr1wqBOOqW+BJCmWJh8+Pc43vWiCohWB/l+3Nk B8Qw== X-Gm-Message-State: AOAM5307JWqB6b5DUFTj4H7h6r7jaxSe7YJlPFJDNFa84Q4qvDBL1LyO sT9GCiF8vYqMUm6wNOyTNpn9pMLXb/h9kfP8O0RDQu/9yqkB2ayMEoNEIW252EbEvEQICjPTOCD TeqnyxiZ7JlGiZkkOgrbyEJRrkwGHTe3V0RclWuMZGX/KpxpOthcpU2q3ydVSvTPwfyNKiko= X-Received: by 2002:adf:d1c1:: with SMTP id b1mr41848255wrd.491.1641304039997; Tue, 04 Jan 2022 05:47:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvfXhKKqGzk47sm0SAx8ptnEDWEmWPXcu7qqbKPfl47HNeskzbnmtm/Td9hTPePtvNkn4TSw== X-Received: by 2002:adf:d1c1:: with SMTP id b1mr41848235wrd.491.1641304039769; Tue, 04 Jan 2022 05:47:19 -0800 (PST) From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH 5/8] Exit on errors from virDaemonSetupLogging Date: Tue, 4 Jan 2022 14:47:09 +0100 Message-Id: <578c4c445345f56fa55262b0d357077238dcac70.1641303832.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-loop: libvir-list@redhat.com 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.23 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1641304064172100001 Content-Type: text/plain; charset="utf-8" This prevents starting any daemons with improper logging settings. This is desirable on its own, but will be even more beneficial when more functions = start reporting errors and failing on them, coming up in following patches Signed-off-by: Martin Kletzander Reviewed-by: Erik Skultety --- src/locking/lock_daemon.c | 15 ++++++++------- src/logging/log_daemon.c | 15 ++++++++------- src/remote/remote_daemon.c | 15 ++++++++------- src/util/virdaemon.c | 31 ++++++++++++++++++++----------- src/util/virdaemon.h | 14 +++++++------- 5 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 107fb22bc2c9..ea81940a4325 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -913,13 +913,14 @@ int main(int argc, char **argv) { } VIR_FREE(remote_config_file); =20 - virDaemonSetupLogging("virtlockd", - config->log_level, - config->log_filters, - config->log_outputs, - privileged, - verbose, - godaemon); + if (virDaemonSetupLogging("virtlockd", + config->log_level, + config->log_filters, + config->log_outputs, + privileged, + verbose, + godaemon) < 0) + exit(EXIT_FAILURE); =20 if (!pid_file && virPidFileConstructPath(privileged, diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index de6bf082e89b..fe7fa8534aec 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -719,13 +719,14 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } =20 - virDaemonSetupLogging("virtlogd", - config->log_level, - config->log_filters, - config->log_outputs, - privileged, - verbose, - godaemon); + if (virDaemonSetupLogging("virtlogd", + config->log_level, + config->log_filters, + config->log_outputs, + privileged, + verbose, + godaemon) < 0) + exit(EXIT_FAILURE); =20 if (!pid_file && virPidFileConstructPath(privileged, diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 4e10f3ad2307..8a4610da83c8 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -936,13 +936,14 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } =20 - virDaemonSetupLogging(DAEMON_NAME, - config->log_level, - config->log_filters, - config->log_outputs, - privileged, - verbose, - godaemon); + if (virDaemonSetupLogging(DAEMON_NAME, + config->log_level, + config->log_filters, + config->log_outputs, + privileged, + verbose, + godaemon) < 0) + exit(EXIT_FAILURE); =20 /* Let's try to initialize global variable that holds the host's boot = time. */ if (virHostBootTimeInit() < 0) { diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c index bb2df2eb2cab..795206301227 100644 --- a/src/util/virdaemon.c +++ b/src/util/virdaemon.c @@ -151,7 +151,7 @@ virDaemonForkIntoBackground(const char *argv0) * but if verbose or error debugging is asked for then also output * informational and debug messages. Default size if 64 kB. */ -void +int virDaemonSetupLogging(const char *daemon_name, unsigned int log_level, char *log_filters, @@ -160,7 +160,8 @@ virDaemonSetupLogging(const char *daemon_name, bool verbose, bool godaemon) { - virLogReset(); + if (virLogReset() < 0) + return -1; =20 /* * Libvirtd's order of precedence is: @@ -169,15 +170,17 @@ virDaemonSetupLogging(const char *daemon_name, * Given the precedence, we must process the variables in the opposite * order, each one overriding the previous. */ - if (log_level !=3D 0) - virLogSetDefaultPriority(log_level); + if (log_level !=3D 0 && + virLogSetDefaultPriority(log_level) < 0) + return -1; =20 /* In case the config is empty, both filters and outputs will become e= mpty, * however we can't start with empty outputs, thus we'll need to defin= e and * setup a default one. */ - ignore_value(virLogSetFilters(log_filters)); - ignore_value(virLogSetOutputs(log_outputs)); + if (virLogSetFilters(log_filters) < 0 || + virLogSetOutputs(log_outputs) < 0) + return -1; =20 /* If there are some environment variables defined, use those instead = */ virLogSetFromEnv(); @@ -185,16 +188,22 @@ virDaemonSetupLogging(const char *daemon_name, /* * Command line override for --verbose */ - if ((verbose) && (virLogGetDefaultPriority() > VIR_LOG_INFO)) - virLogSetDefaultPriority(VIR_LOG_INFO); + if (verbose && + virLogGetDefaultPriority() > VIR_LOG_INFO && + virLogSetDefaultPriority(VIR_LOG_INFO) < 0) + return -1; =20 /* Define the default output. This is only applied if there was no set= ting * from either the config or the environment. */ - virLogSetDefaultOutput(daemon_name, godaemon, privileged); + if (virLogSetDefaultOutput(daemon_name, godaemon, privileged) < 0) + return -1; + + if (virLogGetNbOutputs() =3D=3D 0 && + virLogSetOutputs(virLogGetDefaultOutput()) < 0) + return -1; =20 - if (virLogGetNbOutputs() =3D=3D 0) - virLogSetOutputs(virLogGetDefaultOutput()); + return 0; } =20 =20 diff --git a/src/util/virdaemon.h b/src/util/virdaemon.h index d032b8ddb3b9..9ed0942d6d0e 100644 --- a/src/util/virdaemon.h +++ b/src/util/virdaemon.h @@ -58,13 +58,13 @@ VIR_ENUM_IMPL(virDaemonErr, =20 int virDaemonForkIntoBackground(const char *argv0); =20 -void virDaemonSetupLogging(const char *daemon_name, - unsigned int log_level, - char *log_filters, - char *log_outputs, - bool privileged, - bool verbose, - bool godaemon); +int virDaemonSetupLogging(const char *daemon_name, + unsigned int log_level, + char *log_filters, + char *log_outputs, + bool privileged, + bool verbose, + bool godaemon); =20 int virDaemonUnixSocketPaths(const char *sock_prefix, bool privileged, --=20 2.34.1