From nobody Sun May 5 19:35:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 162867543618053.5035712786306; Wed, 11 Aug 2021 02:50:36 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-aKe4vTMoND2eczRv0D6Hww-1; Wed, 11 Aug 2021 05:50:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 456B6801B3C; Wed, 11 Aug 2021 09:50:27 +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 8D4936A8E4; Wed, 11 Aug 2021 09:50:24 +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 9775C4BB7C; Wed, 11 Aug 2021 09:50:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17B9lMdR024599 for ; Wed, 11 Aug 2021 05:47:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62E5721EC5D6; Wed, 11 Aug 2021 09:47:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E27121EC5D3 for ; Wed, 11 Aug 2021 09:47:19 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 722C81066558 for ; Wed, 11 Aug 2021 09:47:19 +0000 (UTC) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.221]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-eOzP634HMK6rB4Ceg3LmwQ-1; Wed, 11 Aug 2021 05:47:17 -0400 Received: from sender by smtp.strato.de (RZmta 47.31.0 AUTH) with ESMTPSA id 50780dx7B9lFOtR (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 11 Aug 2021 11:47:15 +0200 (CEST) X-MC-Unique: aKe4vTMoND2eczRv0D6Hww-1 X-MC-Unique: eOzP634HMK6rB4Ceg3LmwQ-1 X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgth/Vb1F8stQtZtrd85TkPdCcwE/8Sb0gYpmAVb" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: libvir-list@redhat.com Subject: [PATCH v1] virdnsmasq: fix runtime search for executable Date: Wed, 11 Aug 2021 11:47:13 +0200 Message-Id: <20210811094713.19498-1-olaf@aepfle.de> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Olaf Hering 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.79 on 10.5.11.15 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-ZM-MESSAGEID: 1628675438726100001 Content-Type: text/plain; charset="utf-8" dnsmasq is an optional binary which does not neccessary exist during build. Signed-off-by: Olaf Hering --- src/util/virdnsmasq.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index f2f606913f..06d192c99d 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -729,8 +729,26 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool for= ce) return ret; } =20 +static char * +dnsmasqGetBinaryPath(void) +{ + static const char binary[] =3D DNSMASQ; + char *binary_path; + + if (g_path_is_absolute(binary)) + return g_strdup(binary); + + binary_path =3D virFindFileInPath(binary); + if (!binary_path) { + virReportSystemError(ENOENT, _("Cannot find '%s' in path"), binary= ); + binary_path =3D g_strdup(binary); + } + + return binary_path; +} + static dnsmasqCaps * -dnsmasqCapsNewEmpty(const char *binaryPath) +dnsmasqCapsNewEmpty(void) { dnsmasqCaps *caps; =20 @@ -739,14 +757,14 @@ dnsmasqCapsNewEmpty(const char *binaryPath) if (!(caps =3D virObjectNew(dnsmasqCapsClass))) return NULL; caps->flags =3D virBitmapNew(DNSMASQ_CAPS_LAST); - caps->binaryPath =3D g_strdup(binaryPath ? binaryPath : DNSMASQ); + caps->binaryPath =3D dnsmasqGetBinaryPath(); return caps; } =20 dnsmasqCaps * dnsmasqCapsNewFromBuffer(const char *buf) { - dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(DNSMASQ); + dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(); =20 if (!caps) return NULL; @@ -761,7 +779,7 @@ dnsmasqCapsNewFromBuffer(const char *buf) dnsmasqCaps * dnsmasqCapsNewFromBinary(void) { - dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(DNSMASQ); + dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(); =20 if (!caps) return NULL; @@ -776,7 +794,7 @@ dnsmasqCapsNewFromBinary(void) const char * dnsmasqCapsGetBinaryPath(dnsmasqCaps *caps) { - return caps ? caps->binaryPath : DNSMASQ; + return caps ? caps->binaryPath : dnsmasqGetBinaryPath(); } =20 unsigned long