From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1611937017; cv=none; d=zohomail.com; s=zohoarc; b=DN0ppo0xN1BQkmtqSM9R/qlzHwOImXcPw6qou5+HbwaNXLe1pP9FGJFcODYYTjDOJL/hZw0axKtyzwvYHIhbhMGeASiVVRD7FLdcaG8z5q+LiYp3k67ClSqplnFBEmnQgAshIYrtbVncked9lncYwodbMMAa3+u0FV2/o4GH8aA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937017; h=Content-Type:Content-Transfer-Encoding:Cc: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=J/esfX5b+3QcJ+5KbkySD1q3b44t+aIECV7uwfyAOAM=; b=LU0IRl/3PIaPKX8EQ5oyWWdCfJ2c7e+ZlQrtZs4pMWNlYGk9XvbqS7UEjvDeBWQr/JriqwF6pgqxXxsI4BWCneVdOI/CrKLBQqQW2G3DpvO0lzY+eNFfwLMgH21VCv73lh+AWJigsoxZIOyL3Lz2c3PMkB2V0POztLNXCdaRQDg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1611937017737956.4159581901075; Fri, 29 Jan 2021 08:16:57 -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-22-LFJuB2RSNaCnTSyGs7_Nyw-1; Fri, 29 Jan 2021 11:16:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34AE3107ACE6; Fri, 29 Jan 2021 16:16:43 +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 08E4E646D6; Fri, 29 Jan 2021 16:16:43 +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 C04621809C9F; Fri, 29 Jan 2021 16:16:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGZhD010227 for ; Fri, 29 Jan 2021 11:16:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 20C7360CE6; Fri, 29 Jan 2021 16:16:35 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60DE260CE0; Fri, 29 Jan 2021 16:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937015; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J/esfX5b+3QcJ+5KbkySD1q3b44t+aIECV7uwfyAOAM=; b=CjJMpmQxYUKLNDIrS6+m0q/fvmpHoiKG9LOewu2jaxPqI4ZuMBGBeENcj86xxLSAcK1zEV J4354EP0MkAruYZxbQw1nxtt27v/R9o/W464LJ0fE0JOIo84E3j4rT3KMw3gmsYlrdW4r7 jsulqFgilG24beCjiW3kcQlkk6X3Z0M= X-MC-Unique: LFJuB2RSNaCnTSyGs7_Nyw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 01/19] commandhelper: Remove origenv variable Date: Fri, 29 Jan 2021 17:16:11 +0100 Message-Id: <20210129161629.604823-2-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index ba5681b715..c2040b76f0 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -60,7 +60,6 @@ static int envsort(const void *a, const void *b) int main(int argc, char **argv) { size_t i, n; int open_max; - char **origenv; char **newenv =3D NULL; char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); @@ -92,23 +91,16 @@ int main(int argc, char **argv) { } } =20 - origenv =3D environ; - n =3D 0; - while (*origenv !=3D NULL) { - n++; - origenv++; + for (n =3D 0; environ[n]; n++) { } =20 if (!(newenv =3D malloc(sizeof(*newenv) * n))) abort(); =20 - origenv =3D environ; - n =3D i =3D 0; - while (*origenv !=3D NULL) { - newenv[i++] =3D *origenv; - n++; - origenv++; + for (i =3D 0; i < n; i++) { + newenv[i] =3D environ[i]; } + qsort(newenv, n, sizeof(newenv[0]), envsort); =20 for (i =3D 0; i < n; i++) { --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937017; cv=none; d=zohomail.com; s=zohoarc; b=VSFbKNb3smSWRTC4RcOwHhBy3hjfsXD6BkDs3wLDPYaEYCuKCuEfWqEA3A/IngGWyMshNHaXSbFo5DWafgEA72C+7a7+11vhYclSkH/3gK1Jf88iGQmqLPoqTEkwVyMqGUYOMBqke1Oh0njXaEgt4UqnJARxYk5iwLxaj2lg2ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937017; h=Content-Type:Content-Transfer-Encoding:Cc: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=HUEjt0/dlyoGfpsud669Ve6lso2wyTmsZF+nAUHY484=; b=XznGUCVYvR7mTgPJsQhy2yw8UCwHpimd3IND4F0fC6PEKJYy0KTVoQpIFf4SZzJpwrjarxgZsr5/1uMf2Weu6/7hCcg89io89oDuF2USwK0HBArFMXSrGTS2cO9n08VlAasUPMeXOlwW3aC8SIrnIsDC3Ub7WejzyK4KMIpmCa4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937017459211.57152729361303; Fri, 29 Jan 2021 08:16:57 -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-527-6Q62zc2QNDKGQ1Fqja4rfw-1; Fri, 29 Jan 2021 11:16:53 -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 E756A8030A8; Fri, 29 Jan 2021 16:16:45 +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 BE22C1F46C; Fri, 29 Jan 2021 16:16:45 +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 8383750043; Fri, 29 Jan 2021 16:16:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGaHl010238 for ; Fri, 29 Jan 2021 11:16:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3638260CE0; Fri, 29 Jan 2021 16:16:36 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76CE0646D6; Fri, 29 Jan 2021 16:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937015; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HUEjt0/dlyoGfpsud669Ve6lso2wyTmsZF+nAUHY484=; b=CHNr5qQbHHC4rzk9hWVXQSyz4BVwEjfKGkPHvVAcntq9zP5orpJB8CBL35TMl8K3AgS6XV v0QP9s3e+jVtfnXzDdC4EwgEtiF8+o914hx5GxHYFsfXgOladAKteeY0X7Ae1dQW0yMqYg TDd80JuhB+sql4SXNKcTyjF8nvv9jxM= X-MC-Unique: 6Q62zc2QNDKGQ1Fqja4rfw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 02/19] commandhelper: Remove numpollfds variable Date: Fri, 29 Jan 2021 17:16:12 +0100 Message-Id: <20210129161629.604823-3-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index c2040b76f0..2b937979c0 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -67,7 +67,6 @@ int main(int argc, char **argv) { int readfds[3] =3D { STDIN_FILENO, }; int numreadfds =3D 1; struct pollfd fds[3]; - int numpollfds =3D 0; char *buffers[3] =3D {NULL, NULL, NULL}; size_t buflen[3] =3D {0, 0, 0}; char c; @@ -167,21 +166,20 @@ int main(int argc, char **argv) { fflush(stderr); =20 for (i =3D 0; i < numreadfds; i++) { - fds[numpollfds].fd =3D readfds[i]; - fds[numpollfds].events =3D POLLIN; - fds[numpollfds].revents =3D 0; - numpollfds++; + fds[i].fd =3D readfds[i]; + fds[i].events =3D POLLIN; + fds[i].revents =3D 0; } =20 for (;;) { unsigned ctr =3D 0; =20 - if (poll(fds, numpollfds, -1) < 0) { + if (poll(fds, numreadfds, -1) < 0) { printf("poll failed: %s\n", strerror(errno)); goto cleanup; } =20 - for (i =3D 0; i < numpollfds; i++) { + for (i =3D 0; i < numreadfds; i++) { short revents =3D POLLIN | POLLHUP | POLLERR; =20 # ifdef __APPLE__ @@ -212,7 +210,7 @@ int main(int argc, char **argv) { } } } - for (i =3D 0; i < numpollfds; i++) { + for (i =3D 0; i < numreadfds; i++) { if (fds[i].events) { ctr++; break; @@ -222,7 +220,7 @@ int main(int argc, char **argv) { break; } =20 - for (i =3D 0; i < numpollfds; i++) { + for (i =3D 0; i < numreadfds; i++) { if (fwrite(buffers[i], 1, buflen[i], stdout) !=3D buflen[i]) goto cleanup; if (fwrite(buffers[i], 1, buflen[i], stderr) !=3D buflen[i]) --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937012; cv=none; d=zohomail.com; s=zohoarc; b=VPRldoq2FNm/cqWYikNxd5U9/NvupxW1oLaGUXpCMLTPnTqqUivI8B9mkdf661tR/DU4rLmxdSmBKynJb9r+Jp4WLpnAJNfXXHFBATn7agCb4MoCHKtj7OnLSsWquT6cf0rdR3MQ6QuVQ+IpPZuexNaw3kYycUvyXKbFNanEgxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937012; h=Content-Type:Content-Transfer-Encoding:Cc: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=H4G0jqCILoZ9Mxps/xnoT3YbFnw9ZEe8WL3S2S0rf08=; b=l4AqHkZURLhjIZdSJvbYvjK0pYd1Ncr7zkvO76MXkFY4aFv3/JTqBtskS69MErrjxatdEH7Yant72dCxgifu4QljgQgPaOYuyaFXbepJ3gXkSlpDo0utSgz7NSP2NNpcq2LNj1iSgdK0DQ4rsgijzwSDkwmFAdalkFTi51qG9NI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937012457112.97683895692137; Fri, 29 Jan 2021 08:16: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-536-DTOvutlRMbmBABkfV7gWmg-1; Fri, 29 Jan 2021 11:16:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D5771005504; Fri, 29 Jan 2021 16:16:40 +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 7B6385D9F8; Fri, 29 Jan 2021 16:16:40 +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 120D85003F; Fri, 29 Jan 2021 16:16:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGb2d010245 for ; Fri, 29 Jan 2021 11:16:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4911460CE0; Fri, 29 Jan 2021 16:16:37 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89EB860871; Fri, 29 Jan 2021 16:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937011; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=H4G0jqCILoZ9Mxps/xnoT3YbFnw9ZEe8WL3S2S0rf08=; b=OuqlGiiADVov3yeGHvGAtt4rRxWxKpA28YGdvGyfEDPXN3oJixKFvlIK7b7B1jrUH/yWJz HfneiEX9Tu2QnOuoiZpzk4NZ9mG1F4i+FrkE/rUepbTyv0IRU2E+HB+L1ZYkBab5cEo9T6 v9hDuna97INSAvppTywJ557MCls/IwQ= X-MC-Unique: DTOvutlRMbmBABkfV7gWmg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 03/19] commandhelper: Simplify envsort Date: Fri, 29 Jan 2021 17:16:13 +0100 Message-Id: <20210129161629.604823-4-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.14 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) Content-Type: text/plain; charset="utf-8" Comparing only the keys produces the same result as comparing keys and value. The latter saves two invocations of each `strndup` and `free`. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 2b937979c0..05e3879688 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -39,22 +39,7 @@ static int envsort(const void *a, const void *b) { const char *const*astrptr =3D a; const char *const*bstrptr =3D b; - const char *astr =3D *astrptr; - const char *bstr =3D *bstrptr; - char *aeq =3D strchr(astr, '=3D'); - char *beq =3D strchr(bstr, '=3D'); - char *akey; - char *bkey; - int ret; - - if (!(akey =3D strndup(astr, aeq - astr))) - abort(); - if (!(bkey =3D strndup(bstr, beq - bstr))) - abort(); - ret =3D strcmp(akey, bkey); - free(akey); - free(bkey); - return ret; + return strcmp(*astrptr, *bstrptr); } =20 int main(int argc, char **argv) { --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937020; cv=none; d=zohomail.com; s=zohoarc; b=Q8gfQokrG6WVBFUunrdTsWTzJ7YQCz6wFMm3q0hmY1blvMAhGHFrlXTB1mtoq9hh+edqeMqqHPxFIWUdCyuACOadwg3GPEW0ocKVMgF77yVCKfLOZ1B4t6aZg07SMVj6ggq4TfTP8jjK/OZH+iFFG20C3eFyB9fdgzbUSFd/QBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937020; h=Content-Type:Content-Transfer-Encoding:Cc: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=+iaG6y4SvHsKFIwzM2IKwOgN5Y9bc01Rw4YROjkZbo0=; b=gk22guhXSb3uUxHeUYrU+pta3ZMeUjX1VVMOmZGc8UD27tiUaleE9DGTTmPnw3ao/JiDePc6fK8Nn4CLL+oa8qtN2NsBjp7Hf53ed2iryOQAWAd/Qj1Nzl3ae8fLPkvmqria9gdBFO7pqfFYjjnR2mQST1y2fZqOeQ3E7BmK5JI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937020512856.3386905818835; Fri, 29 Jan 2021 08:17:00 -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-207-ZIgnxXGFMY-8U6snj6vy4g-1; Fri, 29 Jan 2021 11:16:56 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0BBB101AFC8; Fri, 29 Jan 2021 16:16:44 +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 BF5C11962F; Fri, 29 Jan 2021 16:16: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 8939D50041; Fri, 29 Jan 2021 16:16:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGc6t010258 for ; Fri, 29 Jan 2021 11:16:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5C01E6E523; Fri, 29 Jan 2021 16:16:38 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BAAC60871; Fri, 29 Jan 2021 16:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937019; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+iaG6y4SvHsKFIwzM2IKwOgN5Y9bc01Rw4YROjkZbo0=; b=N4Cyq0cwCSg6WH0eqiIELbhAk98Cry3w/BDJUpgoe17+uXAvlcG1sgm3LyNAlGxM0qIEsl mEUb6o3c3SQjAxZfDeJW5OaG2lmoHa0U47qbotgvitW4e01qoBghkNEJfBrQaPpei+cxSL 0+DZWGHcIn7NRBsCW7ak4d1aJp6iW1s= X-MC-Unique: ZIgnxXGFMY-8U6snj6vy4g-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 04/19] commandhelper: Consolidate error paths Date: Fri, 29 Jan 2021 17:16:14 +0100 Message-Id: <20210129161629.604823-5-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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) Content-Type: text/plain; charset="utf-8" Preparation for later conversion to g_auto* memory handling. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 05e3879688..2be121ce2c 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -61,7 +61,7 @@ int main(int argc, char **argv) { ssize_t got; =20 if (!log) - return ret; + goto cleanup; =20 for (i =3D 1; i < argc; i++) { fprintf(log, "ARG:%s\n", argv[i]); @@ -79,7 +79,7 @@ int main(int argc, char **argv) { } =20 if (!(newenv =3D malloc(sizeof(*newenv) * n))) - abort(); + goto cleanup; =20 for (i =3D 0; i < n; i++) { newenv[i] =3D environ[i]; @@ -222,8 +222,10 @@ int main(int argc, char **argv) { cleanup: for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) free(buffers[i]); - fclose(log); - free(newenv); + if (newenv) + free(newenv); + if (log) + fclose(log); return ret; } =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937022; cv=none; d=zohomail.com; s=zohoarc; b=WhdRyYUJy6oVLj0uoBUvSavE4iF8tWDLPder78w5fXFRa8LpviclKMDsrKfXpBwZbj/6VT7Iy+QiUWyaCQkjfxB9Wiujxv73SDXM4WtjqENYQCDTixPP/cK9zaZEBMHSiNS5lwUTUYChBrBDNz4YAOOarmJZLN7Cscbr8PJkTLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937022; h=Content-Type:Content-Transfer-Encoding:Cc: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=txnk+JzSmc19MDl7eoYrDtWSiMWtfxZqWCbqp6fnySc=; b=f3XTEP6YbxLxr9HYemHTio/iRyPygQ4/ry+bdFTcT2/SWAvMvxft2gY3N6Pff6bj83sim0hFEsPQ+2PQKwM5684HT4a8u4Ww88uci83roL4WcwPpikk0Avcp/lCemPQGJqSLUMvjWfgk89ZCIACvVA5kw3c2vbPy5dXF/+0Ao5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937022282236.4518759483194; Fri, 29 Jan 2021 08:17:02 -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-401-N2fz_OJNMVeuMMTLqN0F4w-1; Fri, 29 Jan 2021 11:16:58 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2C208066F5; Fri, 29 Jan 2021 16:16:48 +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 9D52210023B8; Fri, 29 Jan 2021 16:16:48 +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 650F81809CA3; Fri, 29 Jan 2021 16:16:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGgvN010276 for ; Fri, 29 Jan 2021 11:16:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3207360CD2; Fri, 29 Jan 2021 16:16:42 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 763BF77714; Fri, 29 Jan 2021 16:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937021; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=txnk+JzSmc19MDl7eoYrDtWSiMWtfxZqWCbqp6fnySc=; b=G4aO8H2dVGnMy0dfTdPj3ZsxjpUIuNEMIzPyVjtMSoBRlPFw99KuKjFBqwafNOS9CSb6NX Pi2I0GFjWT7LUi4znjGQNp7LrhFy5GZT1H34XyARKl7ClzZnDmr87n2I8mzW1oEWgpo1UX QBC5oQlDWFV9ZDPJe2HVVHJb8b5IXBM= X-MC-Unique: N2fz_OJNMVeuMMTLqN0F4w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 05/19] commandhelper: Consolidate argument parsing Date: Fri, 29 Jan 2021 17:16:15 +0100 Message-Id: <20210129161629.604823-6-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.22 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 2be121ce2c..a964420d81 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -56,6 +56,7 @@ int main(int argc, char **argv) { size_t buflen[3] =3D {0, 0, 0}; char c; bool daemonize_check =3D false; + bool close_stdin =3D false; size_t daemonize_retries =3D 3; char buf[1024]; ssize_t got; @@ -72,6 +73,8 @@ int main(int argc, char **argv) { goto cleanup; } else if (STREQ(argv[i], "--check-daemonize")) { daemonize_check =3D true; + } else if (STREQ(argv[i], "--close-stdin")) { + close_stdin =3D true; } } =20 @@ -139,7 +142,7 @@ int main(int argc, char **argv) { =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 - if (argc > 1 && STREQ(argv[1], "--close-stdin")) { + if (close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; usleep(100*1000); --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937027; cv=none; d=zohomail.com; s=zohoarc; b=DD1fiWTGDX4dcoYheFf3AG2RZx0GHOvNF5j2y2CRKWEIFK6qcNRmNQbLU7HcUh1/Bzrm/8sLoem+L9Pb1QZhUzjJOG5mShjZWWuTuMwxaaHkNlGUbYgEFgSzp0OInV+PUAwPA9mSbuae4C4oNsPMSuC+PbNQmPDfZ/Da+kT0tgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937027; h=Content-Type:Content-Transfer-Encoding:Cc: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=CS5xg3Dkc2injmMGlrHjiJEC3AHAEW+pfLckuTzHkM8=; b=BQ5PfmKSpzY2ITqRwyu59WxnvQVvwfLinwnhI/FjFFckkdM6Af/SSUeJTlMn0IfJ40MRVevEo+vMvVlQIlzDSPYUeRL9nlIxO6iRE0R12JrzG55p1tcneOZm21AbIN0gnqrRvn0qrDafkfjwsEt6cQM4NY4t1JMwE+d4jlv2Q38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937027297539.9392338098307; Fri, 29 Jan 2021 08:17:07 -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-457-NWJnUSFnObKzV14sg13ViQ-1; Fri, 29 Jan 2021 11:17:03 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98B61107ACE3; Fri, 29 Jan 2021 16:16:51 +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 791A7646D6; Fri, 29 Jan 2021 16:16:51 +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 40AFA1809CA6; Fri, 29 Jan 2021 16:16:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGhwM010285 for ; Fri, 29 Jan 2021 11:16:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 436A960871; Fri, 29 Jan 2021 16:16:43 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86D5A60CE6; Fri, 29 Jan 2021 16:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937026; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CS5xg3Dkc2injmMGlrHjiJEC3AHAEW+pfLckuTzHkM8=; b=AynTBBmlgOvGzUMv2gDIfc4He16Jv/QNnOXlcWhEnma6DOLbs3fJCxWbtzqJNap2YkcL6t AFRVgcwYb/YtcaxJXayn5CXahhTRm+Gy5bYevr+fZjSGjw9kV46s2OCGriF3ElyQKCPDEx cxaCAgpIW6vsvMPuvlFAl1CtK/LBzh4= X-MC-Unique: NWJnUSFnObKzV14sg13ViQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 06/19] commandhelper: Split argument parsing and printing Date: Fri, 29 Jan 2021 17:16:16 +0100 Message-Id: <20210129161629.604823-7-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index a964420d81..a77bee931f 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -65,8 +65,6 @@ int main(int argc, char **argv) { goto cleanup; =20 for (i =3D 1; i < argc; i++) { - fprintf(log, "ARG:%s\n", argv[i]); - if (STREQ(argv[i - 1], "--readfd") && sscanf(argv[i], "%u%c", &readfds[numreadfds++], &c) !=3D 1) { printf("Could not parse fd %s\n", argv[i]); @@ -78,6 +76,10 @@ int main(int argc, char **argv) { } } =20 + for (i =3D 1; i < argc; i++) { + fprintf(log, "ARG:%s\n", argv[i]); + } + for (n =3D 0; environ[n]; n++) { } =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937023; cv=none; d=zohomail.com; s=zohoarc; b=LWuhmHHY3dMWpunrBLPMdx2Js5czTdJ0QP1SPAsxQ0YsfPiSJTOwZY2Infobb62blpO/b+k7QjgWuoXkNxLufTyn3mGgtyas5rmKdRSbF0G8n92Ft/9e4AE9DjboSlwNVFmSMOM0NBKinOuYuwMNiqSgsw1brb1cPIWfqX2Jj/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937023; h=Content-Type:Content-Transfer-Encoding:Cc: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=rQfq8n0sMRPFvtx0r5qujm7mIyKwqIqxIYR7WeTd40A=; b=VHK/AuN8lamMfZY15CYURBMUY9eom0iqndeh3Nztf6TcETKXHkgJ9LBFb8TTgbj/2tvUdEWg0lprbh65SgKxvdTWfdIl+Ozg3WpLg5kmpOnJzyy0MBoSPM8kQh/VoQH961ZGSuvmJSrHqwZ9/+OcyLfw896JE0QCR3L0JNtofMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937023661250.5312806653634; Fri, 29 Jan 2021 08:17: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-569-ExOgmZ4zPBGhUwRjCegOzg-1; Fri, 29 Jan 2021 11:16:59 -0500 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 C2F43BBEF2; Fri, 29 Jan 2021 16:16:47 +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 9E2BE5D72E; Fri, 29 Jan 2021 16:16: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 68FAA1809CA1; Fri, 29 Jan 2021 16:16:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGik5010294 for ; Fri, 29 Jan 2021 11:16:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 546B560CE0; Fri, 29 Jan 2021 16:16:44 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A1D060871; Fri, 29 Jan 2021 16:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937022; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rQfq8n0sMRPFvtx0r5qujm7mIyKwqIqxIYR7WeTd40A=; b=N9I2T0Rt1xe4h3GTTgro8Jlox0jqYVuyixZnaaHROsViP7k8FeT4Z/XbMAfqSaTZUzQi2a chfIWPfaeB7R/lDhrLmzVzQgwPmZlu5vyAUIZuXioJnKPZtojh4t1FmCuhaaqr73tLeL5e Tf3UyqIwnl4B2HbAIC+QzEeQSe5qsVs= X-MC-Unique: ExOgmZ4zPBGhUwRjCegOzg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 07/19] commandhelper: Factor out parseArguments Date: Fri, 29 Jan 2021 17:16:17 +0100 Message-Id: <20210129161629.604823-8-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 83 +++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index a77bee931f..c44322502f 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -35,6 +35,51 @@ extern char **environ; =20 # define VIR_FROM_THIS VIR_FROM_NONE =20 +struct Arguments { + int readfds[3]; + int numreadfds; + bool daemonize_check; + bool close_stdin; +}; + +static struct Arguments *parseArguments(int argc, char** argv) +{ + struct Arguments* args =3D NULL; + int ret =3D -1; + size_t i; + + if (!(args =3D calloc(1, sizeof(*args)))) + goto cleanup; + + args->numreadfds =3D 1; + args->readfds[0] =3D STDIN_FILENO; + + for (i =3D 1; i < argc; i++) { + if (STREQ(argv[i - 1], "--readfd")) { + char c; + + if (1 !=3D sscanf(argv[i], "%u%c", + &args->readfds[args->numreadfds++], &c)) { + printf("Could not parse fd %s\n", argv[i]); + goto cleanup; + } + } else if (STREQ(argv[i], "--check-daemonize")) { + args->daemonize_check =3D true; + } else if (STREQ(argv[i], "--close-stdin")) { + args->close_stdin =3D true; + } + } + + ret =3D 0; + + cleanup: + if (ret =3D=3D 0) + return args; + + free(args); + return NULL; +} + static int envsort(const void *a, const void *b) { const char *const*astrptr =3D a; @@ -43,39 +88,23 @@ static int envsort(const void *a, const void *b) } =20 int main(int argc, char **argv) { + struct Arguments *args =3D parseArguments(argc, argv); size_t i, n; int open_max; char **newenv =3D NULL; char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; - int readfds[3] =3D { STDIN_FILENO, }; - int numreadfds =3D 1; struct pollfd fds[3]; char *buffers[3] =3D {NULL, NULL, NULL}; size_t buflen[3] =3D {0, 0, 0}; - char c; - bool daemonize_check =3D false; - bool close_stdin =3D false; size_t daemonize_retries =3D 3; char buf[1024]; ssize_t got; =20 - if (!log) + if (!log || !args) goto cleanup; =20 - for (i =3D 1; i < argc; i++) { - if (STREQ(argv[i - 1], "--readfd") && - sscanf(argv[i], "%u%c", &readfds[numreadfds++], &c) !=3D 1) { - printf("Could not parse fd %s\n", argv[i]); - goto cleanup; - } else if (STREQ(argv[i], "--check-daemonize")) { - daemonize_check =3D true; - } else if (STREQ(argv[i], "--close-stdin")) { - close_stdin =3D true; - } - } - for (i =3D 1; i < argc; i++) { fprintf(log, "ARG:%s\n", argv[i]); } @@ -116,7 +145,7 @@ int main(int argc, char **argv) { while (true) { bool daemonized =3D getpgrp() !=3D getppid(); =20 - if (daemonize_check && !daemonized && daemonize_retries-- > 0) { + if (args->daemonize_check && !daemonized && daemonize_retries-- > = 0) { usleep(100*1000); continue; } @@ -144,7 +173,7 @@ int main(int argc, char **argv) { =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 - if (close_stdin) { + if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; usleep(100*1000); @@ -155,8 +184,8 @@ int main(int argc, char **argv) { fprintf(stderr, "BEGIN STDERR\n"); fflush(stderr); =20 - for (i =3D 0; i < numreadfds; i++) { - fds[i].fd =3D readfds[i]; + for (i =3D 0; i < args->numreadfds; i++) { + fds[i].fd =3D args->readfds[i]; fds[i].events =3D POLLIN; fds[i].revents =3D 0; } @@ -164,12 +193,12 @@ int main(int argc, char **argv) { for (;;) { unsigned ctr =3D 0; =20 - if (poll(fds, numreadfds, -1) < 0) { + if (poll(fds, args->numreadfds, -1) < 0) { printf("poll failed: %s\n", strerror(errno)); goto cleanup; } =20 - for (i =3D 0; i < numreadfds; i++) { + for (i =3D 0; i < args->numreadfds; i++) { short revents =3D POLLIN | POLLHUP | POLLERR; =20 # ifdef __APPLE__ @@ -200,7 +229,7 @@ int main(int argc, char **argv) { } } } - for (i =3D 0; i < numreadfds; i++) { + for (i =3D 0; i < args->numreadfds; i++) { if (fds[i].events) { ctr++; break; @@ -210,7 +239,7 @@ int main(int argc, char **argv) { break; } =20 - for (i =3D 0; i < numreadfds; i++) { + for (i =3D 0; i < args->numreadfds; i++) { if (fwrite(buffers[i], 1, buflen[i], stdout) !=3D buflen[i]) goto cleanup; if (fwrite(buffers[i], 1, buflen[i], stderr) !=3D buflen[i]) @@ -227,6 +256,8 @@ int main(int argc, char **argv) { cleanup: for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) free(buffers[i]); + if (args) + free(args); if (newenv) free(newenv); if (log) --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937031; cv=none; d=zohomail.com; s=zohoarc; b=Wi44MyRLD7M8xfRnGKQBJCV8huDg6myjBmnV8UC2lpF2KLyK9WSVY0pkiAaIYPdGd1ld/3s67uzmHi3aukFf67oUktQJvMrvtYBovZDP00qYRWnUBNyxYHBpdQw0gvGzpj8JyiwnuHeRYHjsIk+e2fpG5R0Yrm3Xlu1s3QBenXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937031; h=Content-Type:Content-Transfer-Encoding:Cc: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=Dad0WEqRnbo/3JfZw8BuYm+1Yhj9FlRPYxhW569Khl8=; b=hZBinRfN7/Ltc+TZ6tDQhw29bTj2VNvNtbSZju7dXBmYct7dTBoRPnYW13vNGgP5fRmAI3Rtd3pYWJHa7gBLnBDGtrSsRfTPbqRfxwEBfXGLezkN+HnOIOu+JIJfqnvaQn+FsUZDf/LrJfERvGY3AnJIe4Y6mdUV4I4cmWuCFh4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937031442164.1048520266512; Fri, 29 Jan 2021 08:17:11 -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-106-ijt0rs0ZM1KDsPl3qVzyBQ-1; Fri, 29 Jan 2021 11:17:04 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AACD2100C60A; Fri, 29 Jan 2021 16:16:54 +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 8C04A50F1A; Fri, 29 Jan 2021 16:16:54 +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 EF73B1809CAB; Fri, 29 Jan 2021 16:16:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGjAf010302 for ; Fri, 29 Jan 2021 11:16:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6A31F60CD2; Fri, 29 Jan 2021 16:16:45 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id A836E60CE6; Fri, 29 Jan 2021 16:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937030; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Dad0WEqRnbo/3JfZw8BuYm+1Yhj9FlRPYxhW569Khl8=; b=YInWaU19Z64IY0CZCpdlauPpcFa8/WICYOuQiNV7Q2LVj94dcvotPyfFHPIOWMEjtzldWC v8N3HR3oecWsTN3WwNKoosxpJuufMr+nDH36fBL9QCpZbGc5BvKy7UofdY4DaLEzvkVtRZ VRSnCXCfsodzzhc5OHmaKd56SnAbLtI= X-MC-Unique: ijt0rs0ZM1KDsPl3qVzyBQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 08/19] commandhelper: Factor out printArguments Date: Fri, 29 Jan 2021 17:16:18 +0100 Message-Id: <20210129161629.604823-9-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index c44322502f..aa346f1dfd 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -80,6 +80,15 @@ static struct Arguments *parseArguments(int argc, char**= argv) return NULL; } =20 +static void printArguments(FILE *log, int argc, char** argv) +{ + size_t i; + + for (i =3D 1; i < argc; i++) { + fprintf(log, "ARG:%s\n", argv[i]); + } +} + static int envsort(const void *a, const void *b) { const char *const*astrptr =3D a; @@ -105,9 +114,7 @@ int main(int argc, char **argv) { if (!log || !args) goto cleanup; =20 - for (i =3D 1; i < argc; i++) { - fprintf(log, "ARG:%s\n", argv[i]); - } + printArguments(log, argc, argv); =20 for (n =3D 0; environ[n]; n++) { } --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937021; cv=none; d=zohomail.com; s=zohoarc; b=M6ZrBUKWnfkC0AB+AEoaETt3dy+sxPC7R3k31tnGifyYpCn/iOPXoW5m/pLAiyzYYCQrCbOqIC4vq8GXK/5Pv9PK34orMk8HYUq1aeXLdC393dOauytJBho9gnxCtif/sHWyWeI2YqoJ9aFTQhOn04ybs735OSkkkfFvvKnQkgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937021; h=Content-Type:Content-Transfer-Encoding:Cc: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=zIotAChBTX+rdXydwtMS1GNFZXseYm/MIJxA7CTz+qw=; b=EwkXEIfMzA77TqD6f3Q3QYv1rzJ9mS90HB3AGsfCsUpt7BAKeO+3U8+IVSyINuTiwxOD13rOHtFbrFGkfb2GmXT6TV7sfxoQjHlE1rwMU8+IYG7xSGIiP4Eq9tqlDY4rQbRWl1ge90sFFjs8TxUdnP+uNFTOlPG6cyKUkAIdNfM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937021693976.1445541153244; Fri, 29 Jan 2021 08:17:01 -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-327-axRrJ6AwNP6MtxQT-bHK3Q-1; Fri, 29 Jan 2021 11:16:58 -0500 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 951388030A0; Fri, 29 Jan 2021 16:16:50 +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 72CA55D72E; Fri, 29 Jan 2021 16:16:50 +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 3A7B450046; Fri, 29 Jan 2021 16:16:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGGn5Q010322 for ; Fri, 29 Jan 2021 11:16:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id A96BC60CE6; Fri, 29 Jan 2021 16:16:49 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id E908460CE0; Fri, 29 Jan 2021 16:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937020; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zIotAChBTX+rdXydwtMS1GNFZXseYm/MIJxA7CTz+qw=; b=Un3uX8y/bvc7QjEgaL+iSFd1CILqGb2IyNJIMDKhOOrNwvPqMgJJsZ/iu/tQHM/eVxkDBS n1qVmdrjK1JhSPvuvY3/ts2YiRgEsKuMq2Bjju5Klhy6ESzwHbxlO9y5aZJtL72PjF6sUk 5KPH0IGc8F1MkezQ7kdUjnkTnovELYw= X-MC-Unique: axRrJ6AwNP6MtxQT-bHK3Q-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 09/19] commandhelper: Factor out printEnvironment Date: Fri, 29 Jan 2021 17:16:19 +0100 Message-Id: <20210129161629.604823-10-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 57 +++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index aa346f1dfd..14c7302633 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -96,11 +96,44 @@ static int envsort(const void *a, const void *b) return strcmp(*astrptr, *bstrptr); } =20 +static int printEnvironment(FILE *log) +{ + char **newenv; + size_t length; + size_t i; + int ret =3D -1; + + for (length =3D 0; environ[length]; length++) { + } + + if (!(newenv =3D malloc(sizeof(*newenv) * length))) + goto cleanup; + + for (i =3D 0; i < length; i++) { + newenv[i] =3D environ[i]; + } + + qsort(newenv, length, sizeof(newenv[0]), envsort); + + for (i =3D 0; i < length; i++) { + /* Ignore the variables used to instruct the loader into + * behaving differently, as they could throw the tests off. */ + if (!STRPREFIX(newenv[i], "LD_")) + fprintf(log, "ENV:%s\n", newenv[i]); + } + + ret =3D 0; + + cleanup: + if (newenv) + free(newenv); + return ret; +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); - size_t i, n; + size_t i; int open_max; - char **newenv =3D NULL; char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; @@ -116,25 +149,9 @@ int main(int argc, char **argv) { =20 printArguments(log, argc, argv); =20 - for (n =3D 0; environ[n]; n++) { - } - - if (!(newenv =3D malloc(sizeof(*newenv) * n))) + if (printEnvironment(log) !=3D 0) goto cleanup; =20 - for (i =3D 0; i < n; i++) { - newenv[i] =3D environ[i]; - } - - qsort(newenv, n, sizeof(newenv[0]), envsort); - - for (i =3D 0; i < n; i++) { - /* Ignore the variables used to instruct the loader into - * behaving differently, as they could throw the tests off. */ - if (!STRPREFIX(newenv[i], "LD_")) - fprintf(log, "ENV:%s\n", newenv[i]); - } - open_max =3D sysconf(_SC_OPEN_MAX); if (open_max < 0) goto cleanup; @@ -265,8 +282,6 @@ int main(int argc, char **argv) { free(buffers[i]); if (args) free(args); - if (newenv) - free(newenv); if (log) fclose(log); return ret; --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937053; cv=none; d=zohomail.com; s=zohoarc; b=eYXSp3OJRj9IfHkBvfeLWM/oW+H0ulIPIgnq5ww2wMBRD/t0hywdHzR/Q6LOWaxqsyIr+wjshn2mvGkqZIkSqqEk0wyqLMxJfgIEBhLSaCFye6SYsvIgeomWKlIYwvjtlXQQIO8j65l2GEZirrgSR2EabuUuV1ol3Ib1Jhi6ReE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937053; h=Content-Type:Content-Transfer-Encoding:Cc: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=m8uIkHx6VWwmzEczl7wPVxotBYUTSWH/qvfZzwk0ybQ=; b=P3EgF+gXBrn8s5hhi4eSkOSLMa0By7AbciNGLgf+GizLdGuZRRfBK0V2nBfcEGJmj+eJI3/q3zVH2ARHMgtYOfEqfgmNkIHn4kEpk3a3NlceaXAI2v6NgPTEVolkYKDKliypEAK2byQUkcHE1GSDsi6H5aC2cyQffHqQpzK2NGw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937053169216.38735275670297; Fri, 29 Jan 2021 08:17:33 -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-512-gUHMncQQP8qiCPgzTDL6YQ-1; Fri, 29 Jan 2021 11:17:29 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70EB2C73B1; Fri, 29 Jan 2021 16:17:22 +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 31AF977BE7; Fri, 29 Jan 2021 16:17:22 +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 EB7911809CA7; Fri, 29 Jan 2021 16:17:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHKjj010605 for ; Fri, 29 Jan 2021 11:17:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id C5F02779D8; Fri, 29 Jan 2021 16:17:20 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DCCD60CD2; Fri, 29 Jan 2021 16:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937052; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=m8uIkHx6VWwmzEczl7wPVxotBYUTSWH/qvfZzwk0ybQ=; b=eAE+59FIUymCEJU9n0CQYFQpo//kU+Mwwtr7erG/gGZvJ14YqDSdYnvHaD8SluN00rLJcY 99kjR2ZFff119XZyGnyIJoURoZE3vdS5P+XS8hRtkvBXmKIKSSNoP/goOOTlyqyP1/rS/L r/dtydiDaf73tsbWpwbdpHOvBLyBKhw= X-MC-Unique: gUHMncQQP8qiCPgzTDL6YQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 10/19] commandhelper: Factor out printFds Date: Fri, 29 Jan 2021 17:16:20 +0100 Message-Id: <20210129161629.604823-11-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 14c7302633..fa32f6a435 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -130,10 +130,32 @@ static int printEnvironment(FILE *log) return ret; } =20 +static int printFds(FILE *log) +{ + long int open_max =3D sysconf(_SC_OPEN_MAX); + size_t i; + + if (open_max < 0) + return -1; + + for (i =3D 0; i < open_max; i++) { + int ignore; + + if (i =3D=3D fileno(log)) + continue; + + if (fcntl(i, F_GETFD, &ignore) =3D=3D -1 && errno =3D=3D EBADF) + continue; + + fprintf(log, "FD:%zu\n", i); + } + + return 0; +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); size_t i; - int open_max; char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; @@ -152,19 +174,8 @@ int main(int argc, char **argv) { if (printEnvironment(log) !=3D 0) goto cleanup; =20 - open_max =3D sysconf(_SC_OPEN_MAX); - if (open_max < 0) + if (printFds(log) !=3D 0) goto cleanup; - for (i =3D 0; i < open_max; i++) { - int f; - int closed; - if (i =3D=3D fileno(log)) - continue; - closed =3D fcntl(i, F_GETFD, &f) =3D=3D -1 && - errno =3D=3D EBADF; - if (!closed) - fprintf(log, "FD:%zu\n", i); - } =20 while (true) { bool daemonized =3D getpgrp() !=3D getppid(); --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937056; cv=none; d=zohomail.com; s=zohoarc; b=lMtNnYeT84A2aWFbMv5149qw72gvcfllxeRWjIyLFF2RrvrbRrD8pMkxurbZaElNkh7k1bJ2cIjn6T67fU9oZBU4sh0mpRQciRpEuL/Xshk30jn0FkpPViLRg7BK6oPBv0+0qdB/md3wRuGRYS9HuHNGMCJdZUjZDZUKilSlRXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937056; h=Content-Type:Content-Transfer-Encoding:Cc: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=FERoLacJ+OYH6c0/PcnZKG7/HFadbJ1Z1c/3FZDZjwc=; b=Xg1Bd7gx+Rp0iHjZr1u+sxAWlJ6qVsq9Yf7KgedxoYz/gMArivf2YTf+4Ci1BCCc5rVBqDKxNcJPV4JZxXXHtM9LZ4dx1+VSQ2la0nU7zpyus8awmQko3HUxovK2L/2844vfQg/Amp+5z8WtS5snyl5CH9yWhMr/YlzPEFmGMVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937056933995.7263969117656; Fri, 29 Jan 2021 08:17:36 -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-131-saeghY0bMHyLnc_FdLkjlQ-1; Fri, 29 Jan 2021 11:17:32 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A4C280F044; Fri, 29 Jan 2021 16:17:25 +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 EDA6C60CD0; Fri, 29 Jan 2021 16:17: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 B5B9A50043; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHLn9010632 for ; Fri, 29 Jan 2021 11:17:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id D15C260CC4; Fri, 29 Jan 2021 16:17:21 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F6A660871; Fri, 29 Jan 2021 16:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937055; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FERoLacJ+OYH6c0/PcnZKG7/HFadbJ1Z1c/3FZDZjwc=; b=ZvLR6rTm2WM3fqoozsW+oUMSly5bbNcfkW41uFsNEy9MeKYrFH2cxaxoYo8uXcCquFD3IQ CbSx/OoCo787DAVsqHbX4bxapFDaSTG79dQm7Gd0ifoyHkBDoIfTdVqtL1hVoBLGIBpe3p 55BPAjzg9AdHmFYW4IjtK4Rruwt0UiE= X-MC-Unique: saeghY0bMHyLnc_FdLkjlQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 11/19] commandhelper: Factor out printDaemonization Date: Fri, 29 Jan 2021 17:16:21 +0100 Message-Id: <20210129161629.604823-12-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index fa32f6a435..01dd6f9e45 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -153,6 +153,19 @@ static int printFds(FILE *log) return 0; } =20 +static void printDaemonization(FILE *log, struct Arguments *args) +{ + int retries =3D 3; + + if (args->daemonize_check) { + while ((getpgrp() =3D=3D getppid()) && (retries-- > 0)) { + usleep(100 * 1000); + } + } + + fprintf(log, "DAEMON:%s\n", getpgrp() !=3D getppid() ? "yes" : "no"); +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); size_t i; @@ -162,7 +175,6 @@ int main(int argc, char **argv) { struct pollfd fds[3]; char *buffers[3] =3D {NULL, NULL, NULL}; size_t buflen[3] =3D {0, 0, 0}; - size_t daemonize_retries =3D 3; char buf[1024]; ssize_t got; =20 @@ -177,17 +189,7 @@ int main(int argc, char **argv) { if (printFds(log) !=3D 0) goto cleanup; =20 - while (true) { - bool daemonized =3D getpgrp() !=3D getppid(); - - if (args->daemonize_check && !daemonized && daemonize_retries-- > = 0) { - usleep(100*1000); - continue; - } - - fprintf(log, "DAEMON:%s\n", daemonized ? "yes" : "no"); - break; - } + printDaemonization(log, args); =20 if (!(cwd =3D getcwd(NULL, 0))) goto cleanup; --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1611937056; cv=none; d=zohomail.com; s=zohoarc; b=hcNYeTImLsYmYRtjt6kyECFRaC3PTu6iumCHfYE/jpo6c9rVGgvEQtudu0zn9T/zlr2CcCWtyt262JkUBsvER4nhaf0QFtU6BiuKN7eALxeBLVGia3bw6KNqTRAhbF/T4jVj0W67zjoUCxAVjFbD8jGTAm0j0hwD3fXVlqeSdjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937056; h=Content-Type:Content-Transfer-Encoding:Cc: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=Hcp5BUy9Qpjsq+pNqC7E7serFZeXuUJdsPnoGM2cSpU=; b=DHcwub7IsvbLVP7pstW6l66tds7+vxhzm8L7Yy00RFb7S6kYu4YODLRUPDn/CmfubPRf44lCcxrpot+Rpjzvbz/NuL7oI6q1OzKLVHVrY+a9FR/NbRgKnZfptbCt1zBbrKyc8annn6NBRCzN03jTHa9iw+v3gYntbxLe2/JKKcY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1611937056289590.2568813375241; Fri, 29 Jan 2021 08:17:36 -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-20-JbhwnPrjMTGpVDBo8YQelg-1; Fri, 29 Jan 2021 11:17:32 -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 2EEE4190B2A7; Fri, 29 Jan 2021 16:17:25 +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 0177219725; Fri, 29 Jan 2021 16:17:25 +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 BB37050044; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHMEP010649 for ; Fri, 29 Jan 2021 11:17:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id ECED27771F; Fri, 29 Jan 2021 16:17:22 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3506F77BE1; Fri, 29 Jan 2021 16:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937055; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Hcp5BUy9Qpjsq+pNqC7E7serFZeXuUJdsPnoGM2cSpU=; b=ZXMiXoBYezOhXZ7XolQSK0Tm73ob1oxlId0jlzhE7Z3CBuc7kQOFI59nLdVVdPC+LiGP+5 xcBBDfs3ZL557HIxNwnvPRaY36z8ri2zVjPwvsxA/lmg6xmUaOCcB5WMeQcTjNUytQs7Z6 eWIJ0ndnBLxPQNzklic4yI9u7bb7eME= X-MC-Unique: JbhwnPrjMTGpVDBo8YQelg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 12/19] commandhelper: Factor out printCwd Date: Fri, 29 Jan 2021 17:16:22 +0100 Message-Id: <20210129161629.604823-13-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 01dd6f9e45..929de7a05d 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -166,10 +166,34 @@ static void printDaemonization(FILE *log, struct Argu= ments *args) fprintf(log, "DAEMON:%s\n", getpgrp() !=3D getppid() ? "yes" : "no"); } =20 +static int printCwd(FILE *log) +{ + char *cwd =3D NULL; + char *display; + + if (!(cwd =3D getcwd(NULL, 0))) + return -1; + + if ((strlen(cwd) > strlen(".../commanddata")) && + (STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")= )) { + strcpy(cwd, ".../commanddata"); + } + + display =3D cwd; + +# ifdef __APPLE__ + if (strstr(cwd, "/private")) + display =3D cwd + strlen("/private"); +# endif + + fprintf(log, "CWD:%s\n", display); + free(cwd); + return 0; +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); size_t i; - char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; struct pollfd fds[3]; @@ -191,22 +215,8 @@ int main(int argc, char **argv) { =20 printDaemonization(log, args); =20 - if (!(cwd =3D getcwd(NULL, 0))) + if (printCwd(log) !=3D 0) goto cleanup; - if (strlen(cwd) > strlen(".../commanddata") && - STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")) - strcpy(cwd, ".../commanddata"); -# ifdef __APPLE__ - char *noprivateprefix =3D NULL; - if (strstr(cwd, "/private")) - noprivateprefix =3D cwd + strlen("/private"); - else - noprivateprefix =3D cwd; - fprintf(log, "CWD:%s\n", noprivateprefix); -# else - fprintf(log, "CWD:%s\n", cwd); -# endif - free(cwd); =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937060; cv=none; d=zohomail.com; s=zohoarc; b=bic9jk+UfJM44TL4PSKzDXdxoiCcwzvR/Ml+8SP16/AytoRO+W3WUI6XpMPKRzhmUMqQRwhpdHZAzzNZxgAMscZgf1Eq+9mXcVVMqdDuUBvv2B0U/T0Ma0TTIrxKcYMa7RuGogCvgDVDBvcFcz6frJIrZ+OL8Kcxo9XzZaazFoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937060; h=Content-Type:Content-Transfer-Encoding:Cc: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=zwZWe81T+/9T9WV2Kl4DKTCRYWs3sbf/ffjvuSy7l1M=; b=C0QFr++eSPginU13mY/CleA6f6cuG5Y1MuvBjNWTUqlkRV9o91L1ks4sUvc3iqREn1T0X9oOtSgLhUGKDnj5WGhYg0yb3bT+z/2N5Q0pBJAeqPl9MFqYeMrSt+jezNRB1Sbw+vbHlK17JaPqF2dAOYG1YOpVja8+yDjcecC+Gww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937060062858.1704575641133; Fri, 29 Jan 2021 08:17:40 -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-100-F37YWeLwNTWy6uopj_1cOQ-1; Fri, 29 Jan 2021 11:17:36 -0500 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 7254C8144ED; Fri, 29 Jan 2021 16:17:28 +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 4BE9E62693; Fri, 29 Jan 2021 16:17:28 +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 B5B3350049; Fri, 29 Jan 2021 16:17:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHOBt010657 for ; Fri, 29 Jan 2021 11:17:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E74160C5E; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D79B60871; Fri, 29 Jan 2021 16:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937059; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zwZWe81T+/9T9WV2Kl4DKTCRYWs3sbf/ffjvuSy7l1M=; b=AH6ha25CfhIRPqCnL21PtAIe+Hta5tP5jCxyA0Y2qvfBYztlS0C5jQQWDKhCInmAxmitnb tNI+bLk66TzBHJBD9MFc/TsKlokKnj3BLcylZrFZZr3TFOX0x8jLWLHrvE+kmSBAElRWNk VJ9bSPmlyimoQGnzezhfHPxsjdczYrA= X-MC-Unique: F37YWeLwNTWy6uopj_1cOQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 13/19] commandhelper: Factor out printInput Date: Fri, 29 Jan 2021 17:16:23 +0100 Message-Id: <20210129161629.604823-14-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 65 ++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 929de7a05d..d501e33e88 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -191,39 +191,20 @@ static int printCwd(FILE *log) return 0; } =20 -int main(int argc, char **argv) { - struct Arguments *args =3D parseArguments(argc, argv); - size_t i; - FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); - int ret =3D EXIT_FAILURE; +static int printInput(struct Arguments *args) +{ + char buf[1024]; struct pollfd fds[3]; char *buffers[3] =3D {NULL, NULL, NULL}; size_t buflen[3] =3D {0, 0, 0}; - char buf[1024]; + int ret =3D -1; + size_t i; ssize_t got; =20 - if (!log || !args) - goto cleanup; - - printArguments(log, argc, argv); - - if (printEnvironment(log) !=3D 0) - goto cleanup; - - if (printFds(log) !=3D 0) - goto cleanup; - - printDaemonization(log, args); - - if (printCwd(log) !=3D 0) - goto cleanup; - - fprintf(log, "UMASK:%04o\n", umask(0)); - if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; - usleep(100*1000); + usleep(100 * 1000); } =20 fprintf(stdout, "BEGIN STDOUT\n"); @@ -298,11 +279,43 @@ int main(int argc, char **argv) { fprintf(stderr, "END STDERR\n"); fflush(stderr); =20 - ret =3D EXIT_SUCCESS; + ret =3D 0; =20 cleanup: for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) free(buffers[i]); + return ret; +} + +int main(int argc, char **argv) { + struct Arguments *args =3D parseArguments(argc, argv); + FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); + int ret =3D EXIT_FAILURE; + + if (!log || !args) + goto cleanup; + + printArguments(log, argc, argv); + + if (printEnvironment(log) !=3D 0) + goto cleanup; + + if (printFds(log) !=3D 0) + goto cleanup; + + printDaemonization(log, args); + + if (printCwd(log) !=3D 0) + goto cleanup; + + fprintf(log, "UMASK:%04o\n", umask(0)); + + if (printInput(args) !=3D 0) + goto cleanup; + + ret =3D EXIT_SUCCESS; + + cleanup: if (args) free(args); if (log) --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937144; cv=none; d=zohomail.com; s=zohoarc; b=H/f8wG761RgpbNPXkE9nNxOz7z19fLwJGE8GbV7u8lntQqsHzH6unKEtglft6UF2qPy/vAM5rxBYVC6y7OSldFNVcNpkNKqYOMGUMEdf9KCbhKp9L/TFYB4Askbp4WqphdqCtynmjRengAvq/gPWlSyYNLTfto3ChyuoKFjLn0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937144; h=Content-Type:Content-Transfer-Encoding:Cc: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=Tl38d20OfW5zIZOCKs3zzKGiET2pfxC3AmOaMADoszc=; b=nGwsA8ZtW+cEGktXg/CsJW0x+kEGZ1G9gq7+vtB0TEPzf+FtYVjkVOriqiAloWojqUoUhaUft/HHeR/geVPYJgXTeWXUgl0Fc9SRhA3NVlxRdXia8Uv23gXEd9yggkqEuGYP8eAc7hoFQLO4EXCQzKVhqRtBI1i5DDHHbkNE/+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937144449238.42584194994777; Fri, 29 Jan 2021 08:19:04 -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-55-gQmf1Y-OMp22sjXLJhLE6w-1; Fri, 29 Jan 2021 11:17:42 -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 07B9B8735DA; Fri, 29 Jan 2021 16:17:31 +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 D82D860BE2; Fri, 29 Jan 2021 16:17:30 +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 9DA721809CA0; Fri, 29 Jan 2021 16:17:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHPpH010665 for ; Fri, 29 Jan 2021 11:17:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2115D60C5E; Fri, 29 Jan 2021 16:17:25 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64B0560CC4; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937143; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Tl38d20OfW5zIZOCKs3zzKGiET2pfxC3AmOaMADoszc=; b=ZKjbj6BgqiMAvuxxNlZDBOG0j5DFNdWo3LxziyWFpIURixDN5M8RqWTJn6DNhp6VgjnDDR OJjDlnUx7g68ek19OgGKxSvaIUeHL3R1/M1c4FU91xAWvLa3C5K7VqIRQvbtBSBIDFU+5s O6W/XN09bKGVnOMiqn8/xv3Kz7uzfSk= X-MC-Unique: gQmf1Y-OMp22sjXLJhLE6w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 14/19] commandhelper: Make number of fds variable in printInput Date: Fri, 29 Jan 2021 17:16:24 +0100 Message-Id: <20210129161629.604823-15-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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 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) Content-Type: text/plain; charset="utf-8" Fixes a buffer overflow triggered when more than three "--readfd" arguments were given on the command line. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index d501e33e88..72a3e89da1 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -194,13 +194,22 @@ static int printCwd(FILE *log) static int printInput(struct Arguments *args) { char buf[1024]; - struct pollfd fds[3]; - char *buffers[3] =3D {NULL, NULL, NULL}; - size_t buflen[3] =3D {0, 0, 0}; + struct pollfd *fds =3D NULL; + char **buffers =3D NULL; + size_t *buflen =3D NULL; int ret =3D -1; size_t i; ssize_t got; =20 + if (!(fds =3D calloc(args->numreadfds, sizeof(*fds)))) + goto cleanup; + + if (!(buffers =3D calloc(args->numreadfds, sizeof(*buffers)))) + goto cleanup; + + if (!(buflen =3D calloc(args->numreadfds, sizeof(*buflen)))) + goto cleanup; + if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; @@ -282,8 +291,14 @@ static int printInput(struct Arguments *args) ret =3D 0; =20 cleanup: - for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) - free(buffers[i]); + if (buffers) { + for (i =3D 0; i < args->numreadfds; i++) + free(buffers[i]); + } + free(fds); + free(buflen); + free(buffers); + return ret; } =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937064; cv=none; d=zohomail.com; s=zohoarc; b=UJkh0/BUYzg/eqBCPhUtCiF3HbD/FjhlXz+kOWDXQ0YSdSe6wVdXI0JPhOcemI/vZPH1oWUUjvffSEIkt0dcPa/Pf+wpuXemU3225INz2OG+nC74pIsDz2s9OwgjaVS7WZglsovfQgV5xAB+swOkxgUDgytUdy9bHhqXGwwV6xQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937064; h=Content-Type:Content-Transfer-Encoding:Cc: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=QLGcFGhpezr2vpfzrADjTD3B3zg+6WOdgC/6HuXjNvg=; b=mvH2UpzceelxjDlbQfiSAh+bHJsajNoL14QIWh28u7dw3tcilKWJdNb2H2VeKAOxeZ5pa3ZWk02mtmKNSoWjO/GsfZ02IgiAWpxy3slPq9Otv1Lzwpu68cVByN6D3pGqm8t1WHg6WZLuBeeSfNwTYmCwv86U22U56lUh8g4k+50= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937064379623.8279267933302; Fri, 29 Jan 2021 08:17:44 -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-335-G1LwbgnvMbe6ziIzrWeKOA-1; Fri, 29 Jan 2021 11:17:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD751192202E; Fri, 29 Jan 2021 16:17:33 +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 BA24F5D9C0; Fri, 29 Jan 2021 16:17:33 +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 7805E50044; Fri, 29 Jan 2021 16:17:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHQg5010682 for ; Fri, 29 Jan 2021 11:17:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 39B5760C5E; Fri, 29 Jan 2021 16:17:26 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75AC060622; Fri, 29 Jan 2021 16:17:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937063; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QLGcFGhpezr2vpfzrADjTD3B3zg+6WOdgC/6HuXjNvg=; b=WFS09SF6q7xZDGUqe5JgMQ6LBd17xRMs4jchpHPSqsovIb5X6sXJt8VvT8NiNRPUMsOcZ0 DQqTafpc8fJXaxxO6q/LT0p6Xon5wscMWmBOLgLazaewFTNgl3cfFJJ3JrM6IjbS6q+G7J skpiZxHdoJ+AqAiUJyQ3WUtjZBC9DiY= X-MC-Unique: G1LwbgnvMbe6ziIzrWeKOA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 15/19] commandhelper: Make number of fds variable in parseArguments Date: Fri, 29 Jan 2021 17:16:25 +0100 Message-Id: <20210129161629.604823-16-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.14 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) Content-Type: text/plain; charset="utf-8" Fixes a buffer overflow triggered when more than three "--readfd" arguments were given on the command line. Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 72a3e89da1..6d5fe04042 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -36,7 +36,7 @@ extern char **environ; # define VIR_FROM_THIS VIR_FROM_NONE =20 struct Arguments { - int readfds[3]; + int *readfds; int numreadfds; bool daemonize_check; bool close_stdin; @@ -51,6 +51,9 @@ static struct Arguments *parseArguments(int argc, char** = argv) if (!(args =3D calloc(1, sizeof(*args)))) goto cleanup; =20 + if (!(args->readfds =3D calloc(1, sizeof(*args->readfds)))) + goto cleanup; + args->numreadfds =3D 1; args->readfds[0] =3D STDIN_FILENO; =20 @@ -58,6 +61,12 @@ static struct Arguments *parseArguments(int argc, char**= argv) if (STREQ(argv[i - 1], "--readfd")) { char c; =20 + args->readfds =3D realloc(args->readfds, + (args->numreadfds + 1) * + sizeof(*args->readfds)); + if (!args->readfds) + goto cleanup; + if (1 !=3D sscanf(argv[i], "%u%c", &args->readfds[args->numreadfds++], &c)) { printf("Could not parse fd %s\n", argv[i]); @@ -76,7 +85,12 @@ static struct Arguments *parseArguments(int argc, char**= argv) if (ret =3D=3D 0) return args; =20 - free(args); + if (args) { + if (args->readfds) + free(args->readfds); + free(args); + } + return NULL; } =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937063; cv=none; d=zohomail.com; s=zohoarc; b=A8kG7tPCuLk6SYAgqtH+fbOHZ76eRNATfZJgCEhLYM5wFCxGK0EIL1xVTIzm1RxycWdc5bUThlknzg2FZYp+kPgqLMoGk9Lk/QXJ/7ENpEleQ2+2OjXXccE+jKrxZw02pxnJsuUmzMBb00DZju4ELZZZGQAjgvXwsXkZUTAka7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937063; h=Content-Type:Content-Transfer-Encoding:Cc: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=ZxccirO/ZRQ415K4SY0vC9Cr735QVxM1xis9LeZlD5E=; b=N4EAmj9DF8lpOmNF0Wahf+QinY3Zsr+8DyjtP5G6pjn/qQyCffy2kxJAg4fzpLKgZv/YcBhzr6Mq02Ix5O+viqL5WzUka5HiMYblmEto1Im0Y6izf9m3elurcEnCQzf8mx4R5XeD/GsgPFqqe0oG8NLAArO3HfLtgHDHPPedsLg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937063081617.7781156489708; Fri, 29 Jan 2021 08:17:43 -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-470-xn7yn16JM6CqW0Af7HyNHw-1; Fri, 29 Jan 2021 11:17:40 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39196107ACF5; Fri, 29 Jan 2021 16:17:32 +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 16D059CA0; Fri, 29 Jan 2021 16:17:32 +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 D7F8F1809CA2; Fri, 29 Jan 2021 16:17:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHRPi010690 for ; Fri, 29 Jan 2021 11:17:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D64960CD2; Fri, 29 Jan 2021 16:17:27 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DFE260871; Fri, 29 Jan 2021 16:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937062; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZxccirO/ZRQ415K4SY0vC9Cr735QVxM1xis9LeZlD5E=; b=dTs2qWa8rlI5hHlxzsWpsjjrLaiwXFwXSyHcDhsTS8g0dXpw0AkunSLAg+AVwYtaEMPtBq OsyzgtF7ffu5nlD74N5Ik2Ix7/hXpZOsyHS8wLfi4B9M5vq7jqgXDKt6lc5pfwTY8fQuQt /3OPNq2OyCBXngVPj2p9sxUEQD/bl4w= X-MC-Unique: xn7yn16JM6CqW0Af7HyNHw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 16/19] commandhelper: Convert parseArguments to g_auto* Date: Fri, 29 Jan 2021 17:16:26 +0100 Message-Id: <20210129161629.604823-17-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 6d5fe04042..e616f92987 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -35,24 +35,32 @@ extern char **environ; =20 # define VIR_FROM_THIS VIR_FROM_NONE =20 -struct Arguments { +typedef struct Arguments { int *readfds; int numreadfds; bool daemonize_check; bool close_stdin; -}; +} Arguments; + +static void cleanupArguments(struct Arguments* args) { + if (args) + free(args->readfds); + + free(args); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(Arguments, cleanupArguments); =20 static struct Arguments *parseArguments(int argc, char** argv) { - struct Arguments* args =3D NULL; - int ret =3D -1; + g_autoptr(Arguments) args =3D NULL; size_t i; =20 if (!(args =3D calloc(1, sizeof(*args)))) - goto cleanup; + return NULL; =20 if (!(args->readfds =3D calloc(1, sizeof(*args->readfds)))) - goto cleanup; + return NULL; =20 args->numreadfds =3D 1; args->readfds[0] =3D STDIN_FILENO; @@ -65,12 +73,12 @@ static struct Arguments *parseArguments(int argc, char*= * argv) (args->numreadfds + 1) * sizeof(*args->readfds)); if (!args->readfds) - goto cleanup; + return NULL; =20 if (1 !=3D sscanf(argv[i], "%u%c", &args->readfds[args->numreadfds++], &c)) { printf("Could not parse fd %s\n", argv[i]); - goto cleanup; + return NULL; } } else if (STREQ(argv[i], "--check-daemonize")) { args->daemonize_check =3D true; @@ -79,19 +87,7 @@ static struct Arguments *parseArguments(int argc, char**= argv) } } =20 - ret =3D 0; - - cleanup: - if (ret =3D=3D 0) - return args; - - if (args) { - if (args->readfds) - free(args->readfds); - free(args); - } - - return NULL; + return g_steal_pointer(&args); } =20 static void printArguments(FILE *log, int argc, char** argv) --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937066; cv=none; d=zohomail.com; s=zohoarc; b=nd+zDb5B7rF6Wv3K4kpf7vLyNV0T6yt1P61cQNfTSeKZ4efq9G+Lyhks87MUUwgFBJg2m+ytcu90AEh1sypg64laX+lvrI4YxNuKC5A8s7IV+ZhWDPerQhtWL5O18bS7pBK57dWv7oCEzFPVbH82sQCk3vX+kHP+iNguQujLKKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937066; h=Content-Type:Content-Transfer-Encoding:Cc: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=1bmS5XRK5XXsMALcvl53KYd8ru0gJ/NSEnkgV5LTH5o=; b=bchncAqMg6E2UJxVnHl+qiCH0SOegrzNPDBrLMqWdAXLU0lhv1DHwC8jnKrw2D7zBFj03PXuPeChzzvOO+A59KmOc/2XJ16WT9PuujZDXFA/r6j3wmTAIHri49S5v0TcCEpIGmEbhoUQxU5ssKfU9qo9WWBENirO41WGFfu0rHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937066900373.0769221530811; Fri, 29 Jan 2021 08:17:46 -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-542-YGKlft1ANh-aDysCotW5uw-1; Fri, 29 Jan 2021 11:17:43 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5F28101595A; Fri, 29 Jan 2021 16:17:37 +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 6F7F060CD0; Fri, 29 Jan 2021 16:17:37 +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 3B42B1809CA0; Fri, 29 Jan 2021 16:17:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHSw5010707 for ; Fri, 29 Jan 2021 11:17:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7B24D60871; Fri, 29 Jan 2021 16:17:28 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0C616F98B; Fri, 29 Jan 2021 16:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937065; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1bmS5XRK5XXsMALcvl53KYd8ru0gJ/NSEnkgV5LTH5o=; b=dGb5HbN3YKj1S6BKGqWFUuHAxcKiw7F3gyp0fVELAyfH88nDWW5c9013SogFQ9ovAwL6hL INMwGpOeTxx0bg1HNojgDyxB2Bea7deVElzaI+WpuWtJzJ/NIKWEckFDxN+1HqYTGMOmkh 2GwXN8GYR3E8EkBh/Vi9IqTFHapkPkg= X-MC-Unique: YGKlft1ANh-aDysCotW5uw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 17/19] commandhelper: Convert printEnvironment to g_auto* Date: Fri, 29 Jan 2021 17:16:27 +0100 Message-Id: <20210129161629.604823-18-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index e616f92987..26a7de5149 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -108,16 +108,15 @@ static int envsort(const void *a, const void *b) =20 static int printEnvironment(FILE *log) { - char **newenv; + g_autofree char **newenv =3D NULL; size_t length; size_t i; - int ret =3D -1; =20 for (length =3D 0; environ[length]; length++) { } =20 if (!(newenv =3D malloc(sizeof(*newenv) * length))) - goto cleanup; + return -1; =20 for (i =3D 0; i < length; i++) { newenv[i] =3D environ[i]; @@ -132,12 +131,7 @@ static int printEnvironment(FILE *log) fprintf(log, "ENV:%s\n", newenv[i]); } =20 - ret =3D 0; - - cleanup: - if (newenv) - free(newenv); - return ret; + return 0; } =20 static int printFds(FILE *log) --=20 2.26.2 From nobody Sun Apr 28 08:35:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611937069; cv=none; d=zohomail.com; s=zohoarc; b=h9cuhyQNc2X7VXcXG6udpCYPUYPmdbchOmnsVXCJp1cYPipB8hH1qI89ntp7XY0wk/aeNnlH6AAjWWBD71J/73kb+cAoeo9DF4TsvQ7odkG7R9rBbT4de6D46QZ2MEvaDGB3NfM/9qlURIbGzMsQmugP3a54CuRP2Y+iqYw+k/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937069; h=Content-Type:Content-Transfer-Encoding:Cc: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=08bYwxb4fp8bxcBc+MUCWWsLpwQkLek4EmUxtZzXB0U=; b=F4/2EQ8Y8pEXFbAg1zY6eLhZ/mUY36RfW8lQ7RY0QUym62tluGBpG4p545HSmZ8SCpebPebpDGGJ75aIgX0VD/IdqbJnjhGKiJCKgWt5BP2K1cz1pZrHWl6oUO+TEeaOiYfITibSNM/LwBv/m8WmknuBRQinx0+FSKobfSzUM+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937069702919.3796548571842; Fri, 29 Jan 2021 08:17:49 -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-214-69_ETk5xPJqxWfhJvcc79g-1; Fri, 29 Jan 2021 11:17:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79E9FCC656; Fri, 29 Jan 2021 16:17:40 +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 5887E5D9C9; Fri, 29 Jan 2021 16:17:40 +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 1F36850045; Fri, 29 Jan 2021 16:17:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHTHl010724 for ; Fri, 29 Jan 2021 11:17:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id A2FF460CD0; Fri, 29 Jan 2021 16:17:29 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id D416C6F98B; Fri, 29 Jan 2021 16:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937068; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=08bYwxb4fp8bxcBc+MUCWWsLpwQkLek4EmUxtZzXB0U=; b=PCMu7RoU41rBA9eIyGp10LSawIdK1LLk0U+54WNN2mYOAjSGdlEWFU70/VkEkfZOTLo22B IicbbeZd/S9dt3wFzuMgAQ6ToBO7ImrMi6rvq01iXgN8motlOQV4YBkCe3tRJ3K2H4mhLC FrEzu/Hkp5N2pwzYaLAuEjDhr1klgI4= X-MC-Unique: 69_ETk5xPJqxWfhJvcc79g-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 18/19] commandhelper: Convert printCwd to g_auto* Date: Fri, 29 Jan 2021 17:16:28 +0100 Message-Id: <20210129161629.604823-19-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.14 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 26a7de5149..3bd7d2b28d 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -172,7 +172,7 @@ static void printDaemonization(FILE *log, struct Argume= nts *args) =20 static int printCwd(FILE *log) { - char *cwd =3D NULL; + g_autofree char *cwd =3D NULL; char *display; =20 if (!(cwd =3D getcwd(NULL, 0))) @@ -191,7 +191,6 @@ static int printCwd(FILE *log) # endif =20 fprintf(log, "CWD:%s\n", display); - free(cwd); return 0; } =20 --=20 2.26.2 From nobody Sun Apr 28 08:35:09 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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=1611937096; cv=none; d=zohomail.com; s=zohoarc; b=TdGbNWlvnfSx/c++ZfW7Ut/RPyp7A3t5KlfO8HhjT89qWyi6jWK9oj8z5s1fgaFL48vphpJMa1kZ2kuzy/lXgPemhncqYvn4mlwzXLbajVdKoQgCWmB+TLqrIj9wN/koqiTtEtR/jM+jVOxDSQ3ZZVJx0Qna9zGUHPsHw7Jh5ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937096; h=Content-Type:Content-Transfer-Encoding:Cc: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=eUR5qMHdKTpR0kXr63HgBXj+J1nyP5p5lPo+6H0CVhA=; b=K0aIYhXNoeOLLeL8IhtZCsTWD5agZrN3950Um+1SBprlSvjIQevRzeXARySNKBxEDLvljospz8M9c7W1kb8R+jf1AQ06b66VLn8m5JGiurg350H87qeqe5UhmvkpG2ASGcxWNPxTCMasaw2ND4RARtqX8rkqiWHdX1KUdnU/Z6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611937096233714.7390071029553; Fri, 29 Jan 2021 08:18:16 -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-478-WdDe-kkSMMmdKVFradm-0g-1; Fri, 29 Jan 2021 11:17:45 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29E47806688; Fri, 29 Jan 2021 16:17: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 E0B746F940; Fri, 29 Jan 2021 16:17:34 +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 A0CB950046; Fri, 29 Jan 2021 16:17:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHU7h010731 for ; Fri, 29 Jan 2021 11:17:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id B22B260871; Fri, 29 Jan 2021 16:17:30 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3C8D60C5E; Fri, 29 Jan 2021 16:17:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937095; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eUR5qMHdKTpR0kXr63HgBXj+J1nyP5p5lPo+6H0CVhA=; b=XdCnBiiJI0gtNTYquGRhOO6Pv537/gGRe/NMa5FZdsVbTO4Plv+wjogUanhs4pMdiEJTJD ifpoOoM32OWeWYaGxYo2DwttjmNkhZQWIu42WLUvWZv3he7zMFPIZUck3i85CcVtN/y8MT OcU8Xcde2QPlSqKc6fOvCTLzkf08wvQ= X-MC-Unique: WdDe-kkSMMmdKVFradm-0g-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 19/19] commandhelper: Convert main to g_auto* Date: Fri, 29 Jan 2021 17:16:29 +0100 Message-Id: <20210129161629.604823-20-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 3bd7d2b28d..940a979a3f 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -306,39 +306,31 @@ static int printInput(struct Arguments *args) } =20 int main(int argc, char **argv) { - struct Arguments *args =3D parseArguments(argc, argv); - FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); - int ret =3D EXIT_FAILURE; + g_autoptr(Arguments) args =3D parseArguments(argc, argv); + g_autoptr(FILE) log =3D fopen(abs_builddir "/commandhelper.log", "w"); =20 if (!log || !args) - goto cleanup; + return EXIT_FAILURE; =20 printArguments(log, argc, argv); =20 if (printEnvironment(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 if (printFds(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 printDaemonization(log, args); =20 if (printCwd(log) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 if (printInput(args) !=3D 0) - goto cleanup; + return EXIT_FAILURE; =20 - ret =3D EXIT_SUCCESS; - - cleanup: - if (args) - free(args); - if (log) - fclose(log); - return ret; + return EXIT_SUCCESS; } =20 #else --=20 2.26.2