From nobody Thu May 2 10:07:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573728232; cv=none; d=zoho.com; s=zohoarc; b=GK4tW0kVp1Jwig8HhzQBtWfbReSV4yKA4dWzgPr2ZYKxgC7O7oyK+R4Qesu+dDk5fFwi8tT3TGgn4n5bURn6rvIohQIqhyfCGz5zUbg8teMwFvC8/iYyPpc2XQn5OtjoYh3he/eCteUci0av74vDmjuzUcBCp1K5Xf2CKyr/Uf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728232; 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=tkMTG8FfxCXIFQqtrg00CV2QThKsPQ35hwWMlkryFbQ=; b=SN4A4kRKMZIicMUgebWHw9vaW1JFvKOJJxU3VfEdcg1/AmbVf3Xaq0PyF9wy+CTqd7mC7uVMG80djttGgkmNdoLtGFPZYIGkFsOks5D+wjJjcsnUu58PgYnTN9V9hMKWXJrABF4s4t4kmeUibQVHlStEdojbwydeQD8hyPanVMw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573728232220864.6029760389807; Thu, 14 Nov 2019 02:43:52 -0800 (PST) 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-411-NZRZHVLXO46DdgmLBr6xlA-1; Thu, 14 Nov 2019 05:43:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D436C107BA9C; Thu, 14 Nov 2019 10:43:42 +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 AFE975C219; Thu, 14 Nov 2019 10:43:42 +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 6DEE64E56D; Thu, 14 Nov 2019 10:43:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAhcS3005609 for ; Thu, 14 Nov 2019 05:43:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 804645F76D; Thu, 14 Nov 2019 10:43:38 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AE5C5F799 for ; Thu, 14 Nov 2019 10:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728231; 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=tkMTG8FfxCXIFQqtrg00CV2QThKsPQ35hwWMlkryFbQ=; b=HqQS0tqWr+on7ghtQvhvJhRG+2OUDYV53ZXH+FQioXQ7Z7wd+QtAjY0Q+p1KQUoHk2Z577 n6tJ9R6GrTtlb7+oi3jvx4xDsSxrKBpDD1c83Hq0+P+ylHh5NH5ldH6Wda9QiaWVO0K1zo M9xwhS0bLSmLxYe3aInLspZfqkoCg58= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:29 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] rpc: use virStringSplit instead of strsep 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.16 X-MC-Unique: NZRZHVLXO46DdgmLBr6xlA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When parsing allowed authentication methods for the native ssh lib trasnports we used strsep. Since we have virStringSplit helper let's use that one. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- src/rpc/virnetsocket.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index c9b2a16fe5..21ef7a8034 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -944,9 +944,8 @@ virNetSocketNewConnectLibSSH2(const char *host, int ret =3D -1; int portN; - char *authMethodNext =3D NULL; - char *authMethodsCopy =3D NULL; - char *authMethod; + VIR_AUTOSTRINGLIST authMethodList =3D NULL; + char **authMethodNext; /* port number will be verified while opening the socket */ if (virStrToLong_i(port, NULL, 10, &portN) < 0) { @@ -987,11 +986,12 @@ virNetSocketNewConnectLibSSH2(const char *host, if (virNetSSHSessionSetChannelCommand(sess, command) !=3D 0) goto error; - authMethodsCopy =3D g_strdup(authMethods); + if (!(authMethodList =3D virStringSplit(authMethods, ",", 0))) + goto error; - authMethodNext =3D authMethodsCopy; + for (authMethodNext =3D authMethodList; *authMethodNext; authMethodNex= t++) { + const char *authMethod =3D *authMethodNext; - while ((authMethod =3D strsep(&authMethodNext, ","))) { if (STRCASEEQ(authMethod, "keyboard-interactive")) { ret =3D virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1= ); } else if (STRCASEEQ(authMethod, "password")) { @@ -1028,13 +1028,11 @@ virNetSocketNewConnectLibSSH2(const char *host, sock->sshSession =3D sess; *retsock =3D sock; - VIR_FREE(authMethodsCopy); return 0; error: virObjectUnref(sock); virObjectUnref(sess); - VIR_FREE(authMethodsCopy); return ret; } #else @@ -1079,9 +1077,8 @@ virNetSocketNewConnectLibssh(const char *host, int ret =3D -1; int portN; - char *authMethodNext =3D NULL; - char *authMethodsCopy =3D NULL; - char *authMethod; + VIR_AUTOSTRINGLIST authMethodList =3D NULL; + char **authMethodNext; /* port number will be verified while opening the socket */ if (virStrToLong_i(port, NULL, 10, &portN) < 0) { @@ -1121,11 +1118,12 @@ virNetSocketNewConnectLibssh(const char *host, if (virNetLibsshSessionSetChannelCommand(sess, command) !=3D 0) goto error; - authMethodsCopy =3D g_strdup(authMethods); + if (!(authMethodList =3D virStringSplit(authMethods, ",", 0))) + goto error; - authMethodNext =3D authMethodsCopy; + for (authMethodNext =3D authMethodList; *authMethodNext; authMethodNex= t++) { + const char *authMethod =3D *authMethodNext; - while ((authMethod =3D strsep(&authMethodNext, ","))) { if (STRCASEEQ(authMethod, "keyboard-interactive")) { ret =3D virNetLibsshSessionAuthAddKeyboardAuth(sess, -1); } else if (STRCASEEQ(authMethod, "password")) { @@ -1164,13 +1162,11 @@ virNetSocketNewConnectLibssh(const char *host, sock->ownsFd =3D false; *retsock =3D sock; - VIR_FREE(authMethodsCopy); return 0; error: virObjectUnref(sock); virObjectUnref(sess); - VIR_FREE(authMethodsCopy); return ret; } #else --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 10:07:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1573728230; cv=none; d=zoho.com; s=zohoarc; b=Bo3zi8L/usZMc7Kc5zD/VLPT5ZMxKAyDPEev3OELEfLkpofRy8DD3V8VzT6zOe9XJUb3zxwUzKEKHfrYqGrLud3hshC7qc8/BVx2UpP76Glaq93CWibZfmw2L5BPVSoEGRuxmtbc3t3OKC4Ey2jcnjlwiNKp8uFnhS4Y24oMp0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728230; 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=GVnmBoVL8ism24xFyIx2f1MXWv1CyBqle26TQP8RhFA=; b=GaCuKnJgB1q8Ditnmy4hf5MdFbI+MImoxUrynRt1VogFywM43CRCjpJwg9KP2SILRI0lEHUrs9FHtjeJNPZH/pDblU0H/IG79o1bTETsHjU38psY1p/7guwCibWvCq6yAXmc64HrdPTqce9pZv5TrmF+mf5IjWj4CNg9zYKSh0g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1573728230074377.6141230953017; Thu, 14 Nov 2019 02:43:50 -0800 (PST) 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-37-_R5_cI1aOEKygj9TMGfnsw-1; Thu, 14 Nov 2019 05:43:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B34C805A75; Thu, 14 Nov 2019 10:43:41 +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 261965C548; Thu, 14 Nov 2019 10:43:41 +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 D6D6B18089D0; Thu, 14 Nov 2019 10:43:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAhdlX005624 for ; Thu, 14 Nov 2019 05:43:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 51DFC5F762; Thu, 14 Nov 2019 10:43:39 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D10BE67596 for ; Thu, 14 Nov 2019 10:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728229; 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=GVnmBoVL8ism24xFyIx2f1MXWv1CyBqle26TQP8RhFA=; b=LwoTZ6kT/DalliZS4fyIE6q+uowW5njg2kcDgsYOW9I7Zd+K5JBiHyh8eMfV5p5ceAm2/k OV3t6C5cJu3GJp+WI3ZLyCUx1POZ2GlVYzgTdkkpe2WWqR2Bqol+rcTIOHA84ivc1Teq/E gI6nx9XcnlbCU3aI+dbDl/VSUtGLlGM= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:30 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] util: file: Use g_autofree in virFindFileInPath 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.16 X-MC-Unique: _R5_cI1aOEKygj9TMGfnsw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Simplify the final lookup loop by freeing memory automatically and thus being able to directly return the result. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- src/util/virfile.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index b1aeaa5851..072a299b39 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1634,10 +1634,9 @@ char * virFindFileInPath(const char *file) { const char *origpath =3D NULL; - char *path =3D NULL; + g_autofree char *path =3D NULL; char *pathiter; char *pathseg; - char *fullpath =3D NULL; if (file =3D=3D NULL) return NULL; @@ -1672,14 +1671,12 @@ virFindFileInPath(const char *file) */ pathiter =3D path; while ((pathseg =3D strsep(&pathiter, ":")) !=3D NULL) { - fullpath =3D g_strdup_printf("%s/%s", pathseg, file); + g_autofree char *fullpath =3D g_strdup_printf("%s/%s", pathseg, fi= le); if (virFileIsExecutable(fullpath)) - break; - VIR_FREE(fullpath); + return g_steal_pointer(&fullpath); } - VIR_FREE(path); - return fullpath; + return NULL; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 10:07:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573728233; cv=none; d=zoho.com; s=zohoarc; b=TBVqeR2YefawclFc5mxMM5YSJV0iJ0U6FN8eb8fMHFQBmWlgHd6D1N9MjK0B4KtWVKEfGA9un/AOFwDjlO8JIzu8W7ML2m+O6nAA1gNrI8FR+7cxEj1oEC5I1qMjgvVzTpIqiRtJVS5/0dSneQRper/nO3q67AZHv1wm5mi8p9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728233; 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=/pr3R8OGGtty7FoSWz5C8lUDyQ90xn+7107RIZf0PBE=; b=dKw4WZ2sEuzT0mtDVq/8iaNacX1r/Mh9X8vXuTAsZce1uYx7zw2X45+hhIJnNDjcVmphtTGbcHq+CwNBwqgBdBAU4Vow8j3k54JVx97l91a3i5PDmex4SDtvSIkx0yVGjH4TwA9RCM5hQfgR+oB9+LN70T56nSYro+TlWy0AuUw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573728233961938.9760255776985; Thu, 14 Nov 2019 02:43:53 -0800 (PST) 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-47-NfWZUsBMPu6n57Tc0dz-Fw-1; Thu, 14 Nov 2019 05:43:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 889AC107ACFC; Thu, 14 Nov 2019 10:43:44 +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 643C35C219; Thu, 14 Nov 2019 10:43:44 +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 23F7418089D7; Thu, 14 Nov 2019 10:43:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAheHg005632 for ; Thu, 14 Nov 2019 05:43:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1E3E45F76C; Thu, 14 Nov 2019 10:43:40 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D8215F762 for ; Thu, 14 Nov 2019 10:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728232; 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=/pr3R8OGGtty7FoSWz5C8lUDyQ90xn+7107RIZf0PBE=; b=JwZ61hZJJv9B2/cVnJHNctAHdn8kER1vqrrjKQcYbHT0/iJ4x5/V5ozay+DVjeWMYHGYj6 7B77adUBR5reyRTKyta8i4gyUgIMg8F6+Sj68vl7m45AJom7sUu7+5m/qJv094XbatYgVN Pyz36W5GeNw/SBXPdQPQyWQShm20Yus= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:31 +0100 Message-Id: <94f386ee24ae72fb8dbbab54ebac0c080e674c4b.1573727895.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] util: file: Simplify logic of shortuct cases in virFindFileInPath 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.16 X-MC-Unique: NfWZUsBMPu6n57Tc0dz-Fw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Combine the terms in the two sets of nested conditionals an don't reuse a variable for a more obvious control flow. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/util/virfile.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 072a299b39..c077639c1c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1644,20 +1644,16 @@ virFindFileInPath(const char *file) /* if we are passed an absolute path (starting with /), return a * copy of that path, after validating that it is executable */ - if (IS_ABSOLUTE_FILE_NAME(file)) { - char *ret =3D NULL; - if (virFileIsExecutable(file)) - ret =3D g_strdup(file); - return ret; - } + if (IS_ABSOLUTE_FILE_NAME(file) && virFileIsExecutable(file)) + return g_strdup(file); /* If we are passed an anchored path (containing a /), then there * is no path search - it must exist in the current directory */ - if (strchr(file, '/')) { - if (virFileIsExecutable(file)) - ignore_value(virFileAbsPath(file, &path)); - return path; + if (strchr(file, '/') && virFileIsExecutable(file)) { + char *abspath =3D NULL; + ignore_value(virFileAbsPath(file, &abspath)); + return abspath; } /* copy PATH env so we can tweak it */ --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 10:07:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1573728312; cv=none; d=zoho.com; s=zohoarc; b=LtwT/RWnuAuUENLlHmTrnJ1urEtL9e4nJ9ByPbU0vt1EO3PTJcflpLEXgscsxn4ogTk/YEZ9G6+JfoMvlA3j77+3tAdmdGY2oACholtaQJtFeYAcowC7AU+155JNn3dry6HR8vo7KsW65f5QOS5TxUYRzyTQaQ7poFZxfc2Ez2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728312; 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=uJCjT7hiIiOYqOnPy6sZr9Skuk9VNFK9Is5w2bgJDCY=; b=FC+kSA8aUnPsJ0BvPVc+GJBJKBoqEhPmRzmSx6gkDMTT6pklp2yK7iKVLjo/2G2H1ACc+pu07XqMqwbWj/d4L0IYV8xwFJhUayXRMWhx7F1MSDRKUkJ/JA+HQdmEvs7TR95krGB7YLjk8XeyBILRj02G6Of9Zw19MhtMoJqDYac= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157372831233536.72243599630917; Thu, 14 Nov 2019 02:45:12 -0800 (PST) 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-387-PEZjGiSUPziKBMs1khqTFA-1; Thu, 14 Nov 2019 05:43:55 -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 3462ADB70; Thu, 14 Nov 2019 10:43:49 +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 0B68834D33; Thu, 14 Nov 2019 10:43:49 +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 B90C81808855; Thu, 14 Nov 2019 10:43:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAhh3M005675 for ; Thu, 14 Nov 2019 05:43:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7B84D5F762; Thu, 14 Nov 2019 10:43:43 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06E1C5F76C for ; Thu, 14 Nov 2019 10:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728311; 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=uJCjT7hiIiOYqOnPy6sZr9Skuk9VNFK9Is5w2bgJDCY=; b=O0WUWPzgdF0cDEQZbqaDiHa3K1JMmhubRBQtS1gOfk9x9cA7r5LF+MlV39QrooXLOr6iy4 i0PNZCfyEa0nanqMQNWbneme9fLCZANjlT06rro2sFS5xD0jWy4TU89cPTvW1cYRZsUPyj EPWCQY1s3jA/bHJ3MDYaXYbPS1NxbCg= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] util: file: Replace use of 'strsep' with virStringSplit 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 X-MC-Unique: PEZjGiSUPziKBMs1khqTFA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use our helper instead of the gnulib one. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- src/util/virfile.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index c077639c1c..55705c8463 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1634,9 +1634,8 @@ char * virFindFileInPath(const char *file) { const char *origpath =3D NULL; - g_autofree char *path =3D NULL; - char *pathiter; - char *pathseg; + VIR_AUTOSTRINGLIST paths =3D NULL; + char **pathiter; if (file =3D=3D NULL) return NULL; @@ -1660,14 +1659,16 @@ virFindFileInPath(const char *file) origpath =3D getenv("PATH"); if (!origpath) origpath =3D "/bin:/usr/bin"; - path =3D g_strdup(origpath); /* for each path segment, append the file to search for and test for * it. return it if found. */ - pathiter =3D path; - while ((pathseg =3D strsep(&pathiter, ":")) !=3D NULL) { - g_autofree char *fullpath =3D g_strdup_printf("%s/%s", pathseg, fi= le); + + if (!(paths =3D virStringSplit(origpath, ":", 0))) + return NULL; + + for (pathiter =3D paths; *pathiter; pathiter++) { + g_autofree char *fullpath =3D g_strdup_printf("%s/%s", *pathiter, = file); if (virFileIsExecutable(fullpath)) return g_steal_pointer(&fullpath); } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 10:07:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573728303; cv=none; d=zoho.com; s=zohoarc; b=eAfV+dHSDa9xXvJQvk7lVUy+remwRvfpclBHsV+NorwIlFvy8l5rEvVW0akk+jmj31fCx+ZrIOe+mCZUyjM8LnWuVVguwnRS92s5eu7CulYx5HWvW/u2RooXo4fHM2LCTxYXCdsroFEbbJCi+CmWuYxdiZygoJ/M/fGNgTq55Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573728303; 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=k8IwMcPapiWzsl5N5WwEp/QmumK1nACf36Ybkc+IylQ=; b=Pg8h4wa/C///U1aqnXxhgurpy+qIv5HMIQ+xnPQ4JkBD3uCpYmOWj1zvHn5NxGT0SdRjoXg4Ch+HCYmtZR7XkzI3HqmtqZYbBVcFyj8pGHyE1xLDgOksB4StRKGE8J1baXG7DOr5haTW8+JNJuia9eub8U9eVIN9JK4Uoh1Pqv8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573728303025322.63923944569535; Thu, 14 Nov 2019 02:45:03 -0800 (PST) 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-351-3c4mf0_OM_KWXTMSYDTV9g-1; Thu, 14 Nov 2019 05:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 418888048E2; Thu, 14 Nov 2019 10:43:47 +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 12ED4610E5; Thu, 14 Nov 2019 10:43:47 +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 BF1F34E56E; Thu, 14 Nov 2019 10:43:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEAhiur005690 for ; Thu, 14 Nov 2019 05:43:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 47DB45F796; Thu, 14 Nov 2019 10:43:44 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C74635F76E for ; Thu, 14 Nov 2019 10:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573728301; 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=k8IwMcPapiWzsl5N5WwEp/QmumK1nACf36Ybkc+IylQ=; b=TaWkEA21mL+WbQDmc827PgG1rMz1aV19Xv/ytzBeuiy6waf6i0KCYAS8SRPQkVSIAi4IfN f5UoTnEwHVoIDHgX81lsUtJbuYsbwX3OPXNfYgoajpgxp+f8vRVdQ9FvopZXYnYtNqcaUl rrgroL8mKRHV6sOInA0hQ3r7Od+nhzI= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 14 Nov 2019 11:43:33 +0100 Message-Id: <8a2a48d7cd8fd5320deb5774abdd1581738ebca2.1573727895.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] gnulib: Remove use of 'strsep' module 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.12 X-MC-Unique: 3c4mf0_OM_KWXTMSYDTV9g-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We don't use strsep any more. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- bootstrap.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap.conf b/bootstrap.conf index f13fcae11a..e519c69d30 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -75,7 +75,6 @@ socket stat-time strchrnul strptime -strsep strtok_r sys_stat sys_wait --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list