From nobody Sat May 4 15:49:30 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=1612178925; cv=none; d=zohomail.com; s=zohoarc; b=Vxoae02aG9mpurjgwvTJtpUpiw0bi6hK1P3z6RqxF02ABAK7IwimdZAuKdw9JBAFlKLYA/Iqo/JmBbSkSQOLm57KLc+dy6at2Vup+2vy/T4WE7ohqBQKDRZQPCU/24pQrJzvn/q5eZ/vixwmbsT4D1EymSZY4dqctwqittpUQ+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178925; 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=wieBaxGJkTsJ1MHBymfPOKSt29YUPOdPg5RcE5gp2y0=; b=T191e5VzDp5683y7wzzd32R4YtVa431/CdaRHlFYlcmCOkXzSWLBNsDointojJpFCCbkQrn8xm+4F/woQ2/NnC/0bKEgJmeWfnefHaUzsZCnd+ol5p8Ac6VwnqDdd+ncV4mDAns4fgPKHP9Y0BDNuo3UTVrB1TYYXS9pW6LieQI= 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 16121789259551010.1893021535005; Mon, 1 Feb 2021 03:28:45 -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-170--YsVlBHUPKq6uqtVN50aIw-1; Mon, 01 Feb 2021 06:28:43 -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 DC9E4107ACF6; Mon, 1 Feb 2021 11:28: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 BA9C660C64; Mon, 1 Feb 2021 11:28: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 82DF31809CA5; Mon, 1 Feb 2021 11:28:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSAsI003238 for ; Mon, 1 Feb 2021 06:28:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE3E46A90A; Mon, 1 Feb 2021 11:28:10 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAEDE2C313; Mon, 1 Feb 2021 11:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178925; 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=wieBaxGJkTsJ1MHBymfPOKSt29YUPOdPg5RcE5gp2y0=; b=fV0g6/uHsXygL1jKgMNzpFnLKA9AyS1iFaZiefMkp/k7Vyap0t23NvOuzVFdQkttGFhIDl kr+ES3gJhXllPKUGPtOhAL1K8TI3XlLsVNrnR5PtVyTT10zbIp413BUHf5plLM38sRGIsb dZ/72ihNKJAnbbRBuwWjCPP/NUKNKBk= X-MC-Unique: -YsVlBHUPKq6uqtVN50aIw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/20] commandhelper: Remove origenv variable Date: Mon, 1 Feb 2021 12:27:45 +0100 Message-Id: <20210201112804.144366-2-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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" 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 Sat May 4 15:49:30 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=1612179012; cv=none; d=zohomail.com; s=zohoarc; b=jvd36QzqivJwEOcgpLNF+Wyea0GCX+kvoQliBKYlYQUB1AoYT3GJPz+UcPYxYfpM73HNuKsS0jAoOMiseKrJ/FHDx/Df6bGhIZ2fkJY4Rs9Bp0Fzv6XLMcw6Diod6iS+tGax6uo9op7BZ1HPQ+UcsOBea3XrlLxti5P6T2aCc24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179012; 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=u4qAZzuDouZl+gOMYX7Rt6s1o0IDup484vWy8CW96S4=; b=DWZix1c/voauvljXyaCueINXw4PePng2pn0PfjnW67jUvRmKzg2B4dlwZO4rAyyI31nK494PY/fgvA1u2a07EQub1+0qlZ4YJDSVa1mvZcmHtVmi9jEjWFq72O22Pco/345ql3xQ2MnIT554fgpptHIQefv3+D/yKa4jcb8cJGI= 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 1612179012969715.6269838500051; Mon, 1 Feb 2021 03:30:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-gtcVV4EXPN6OmNWUoX01Mg-1; Mon, 01 Feb 2021 06:28:24 -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 0FAA51006C80; Mon, 1 Feb 2021 11:28:18 +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 102622C169; Mon, 1 Feb 2021 11:28:16 +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 C9CB5180954D; Mon, 1 Feb 2021 11:28:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSCTr003249 for ; Mon, 1 Feb 2021 06:28:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 23D031840B; Mon, 1 Feb 2021 11:28:12 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D5F7669F2; Mon, 1 Feb 2021 11:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179011; 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=u4qAZzuDouZl+gOMYX7Rt6s1o0IDup484vWy8CW96S4=; b=AYelCzroMsvlf92yh0dYXjBIeF0EfMtoObyUoc29IYsxXQPEU8KvqRriVTfFbiAFAyOy4J 3hpTtR1k72Ml7HC8hqJ9Gc9DUfc2q0xNhQMcOuMz3M/EVK0o8+x6S48n4jMrHPMgMSb/N9 mtI4PmkR2TRJjSvQ3368PfcVpmLGoI8= X-MC-Unique: gtcVV4EXPN6OmNWUoX01Mg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/20] commandhelper: Remove numpollfds variable Date: Mon, 1 Feb 2021 12:27:46 +0100 Message-Id: <20210201112804.144366-3-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 | 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 Sat May 4 15:49:30 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=1612179005; cv=none; d=zohomail.com; s=zohoarc; b=gFu3p2ymai+1vI/Tv/IUSCiSuehom2uH7fSj5aZE5gklfCjKL7MWWYdloTsFBybXqE+FvF56XOuusZLUeEsKoqDeHSPTfjn2VU/eARKxya0ed3T782O4R+eGU7k1h1m1tBFWEuPjsv0cm1o/yrDnAbN8nYTSd8WMilUzgxno/lI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179005; 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=DtXBUQX78KIbc27ojQphowYybabC1Tb1xbEck6yD7+A=; b=oHMY+7fnJPbS8ZqSybPGxAbUP2enrPjKwiRhhT0/FTvHW/QvNkCkGUS9iEmSNKQZXDHUt3dgOn/3zE8vYqe2xmzW2I+ecJD0bm132bQ1qzA/b8lPlJREeNsCnu1M6omFSXfPO+pGsR61djOi4nVKtFiyp7+5R5Cbr0OFAr74zhk= 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 1612179005601712.9082274282952; Mon, 1 Feb 2021 03:30:05 -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-595-FwdKH4eKOIq5iLy6-Oxo1A-1; Mon, 01 Feb 2021 06:28:52 -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 15CC780400F; Mon, 1 Feb 2021 11:28:41 +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 E8BD45DA2E; Mon, 1 Feb 2021 11:28: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 6130750038; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSD0I003258 for ; Mon, 1 Feb 2021 06:28:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 475862C313; Mon, 1 Feb 2021 11:28:13 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B3DD1840B; Mon, 1 Feb 2021 11:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179004; 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=DtXBUQX78KIbc27ojQphowYybabC1Tb1xbEck6yD7+A=; b=HsDfonTftiVeRAchVMU/6gtizOTpklsCfMeXMqQHC1+T4rnGRec2PVvNDglNjzaVtcK0Zo qb9OsJ0sFiT4fASBxVKNgfL3mXzTF6MRzGLbtXVNO13WRPlJRofZBqHcwZyHkkKY5c6PLs KQXMkZvSObQ2gUNtjeN1PLEqcJtzWgk= X-MC-Unique: FwdKH4eKOIq5iLy6-Oxo1A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/20] commandhelper: Simplify envsort Date: Mon, 1 Feb 2021 12:27:47 +0100 Message-Id: <20210201112804.144366-4-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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" This saves two invocations of each `strndup` and `free`. Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 2b937979c0..22835302b8 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -37,24 +37,19 @@ extern char **environ; =20 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; + const char *astr =3D *(const char**)a; + const char *bstr =3D *(const char**)b; + + while (true) { + char achar =3D (*astr =3D=3D '=3D') ? '\0' : *astr; + char bchar =3D (*bstr =3D=3D '=3D') ? '\0' : *bstr; + + if ((achar =3D=3D '\0') || (achar !=3D bchar)) + return achar - bchar; + + astr++; + bstr++; + } } =20 int main(int argc, char **argv) { --=20 2.26.2 From nobody Sat May 4 15:49:30 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=1612179007; cv=none; d=zohomail.com; s=zohoarc; b=Lp92Cwy1i9VqbyGdPdxAQyg6jzluWuevDLftaFL6rShpSK4nWCPJLcx5YjsW64kZkbGaATq4pAcmz/7dFKpi7olzZLTF0Pk5tmtL7b1jgJOOdgsZ/BfXRQZIRZaFXWjhC3effFmeWcAPAu48ZVR/WJD7RrIQeHM+phPhBEulOwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179007; 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=88eVKKCqZ7mTe6AT5UBvvxRTS437VV2Nbrc/uG5faVo=; b=IRRa1T8dhQavEpZ2Ihl9cQuOjbuwRCTd9e/1G4AAxt/gEpDfjmebOWCYZprWCr+8ySFllUyliqzWjhtcPp6XpvR376zLB9p/JwaUHVznSlCNX+eyqc7yvAxPuLPeucZ5dzgUT9icEMbm5nzJ28ks+B5CmoBDph9YgDNmTK/dG84= 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 1612179007161883.7470610119699; Mon, 1 Feb 2021 03:30: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-191-ScXBqazJMaWcQ8YpV_04Yg-1; Mon, 01 Feb 2021 06:28:51 -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 74FAAAFA8C; Mon, 1 Feb 2021 11:28: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 4BA3FE140; Mon, 1 Feb 2021 11:28: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 14E611809CA4; Mon, 1 Feb 2021 11:28:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSEZc003268 for ; Mon, 1 Feb 2021 06:28:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7E1B56A908; Mon, 1 Feb 2021 11:28:14 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A5CE69324; Mon, 1 Feb 2021 11:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179006; 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=88eVKKCqZ7mTe6AT5UBvvxRTS437VV2Nbrc/uG5faVo=; b=cT3KtfcRb1xtcMrnenHCdZ/RiHqYC8cd6j/ZXmjIX0WoqZ3V1YYkAFuJkbpx+2maZMYQdJ wiwcAqKI9fgA6zAvZ/6zU8zv+b3L6Wiw8YYKLvmlEug6UiZVOr+CxYMmEhmGgVrNju4Pjv 88fVv4Pam5iGJmk6VoxHRyz4OvNPvQY= X-MC-Unique: ScXBqazJMaWcQ8YpV_04Yg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/20] commandhelper: Consolidate error paths Date: Mon, 1 Feb 2021 12:27:48 +0100 Message-Id: <20210201112804.144366-5-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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" 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 22835302b8..1ee697498c 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -71,7 +71,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]); @@ -89,7 +89,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]; @@ -232,8 +232,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 Sat May 4 15:49:30 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=1612178926; cv=none; d=zohomail.com; s=zohoarc; b=G/gvak82MN55OrGUKOcmDd0RFS0wOkjf4gN+T3Mc2jWd+J+KMbv5as4BgiTLoRP7Q02K5gDBwXwXp5nHyHyk2pr/0NYu1YU1o5bmBV+lKSRts85TAn8x+FNqCpNyo4azJv7NhPiXcFpF0HdpSj2g8gsB4Cso8pzaOxt5GGd6bPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178926; 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=UMj0seWMlwXOXQM5n/NjU7LBAnwuSd9xSFAvP3KscbU=; b=PBuU729zmi2EwSsewy6mTCJr2MNeg/A4MXxfAUTg+22In/f9ow5ZN23yHPRlq5uiL2ZNQLRQBvUivyjvpzrhTUEqpkmPRoQwDjOvZEwIrlsV45mqyw14knoOFQMpsNPORJ+XEQJFC6cHOD34/7axULhJ0YQ4l2QCn86/2WCIzoE= 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 1612178926349266.88291220756014; Mon, 1 Feb 2021 03:28: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-198-APeDQ2MRPSa6-4Ui-dpabw-1; Mon, 01 Feb 2021 06:28:43 -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 F1B4CAFA83; Mon, 1 Feb 2021 11:28: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 CC66E5DA2E; Mon, 1 Feb 2021 11:28: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 9892A18095C9; Mon, 1 Feb 2021 11:28:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSFIa003279 for ; Mon, 1 Feb 2021 06:28:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id B59246A90C; Mon, 1 Feb 2021 11:28:15 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0F04669F2; Mon, 1 Feb 2021 11:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178925; 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=UMj0seWMlwXOXQM5n/NjU7LBAnwuSd9xSFAvP3KscbU=; b=D8POGPiOLa5BkwYweAKC06+FB3A6mxwpQCC7mbSK5UafAjYFR5CobHbvNo5cR7tk8hUTYL 8I2PaZJFyvIZ1GxiTKXeRLJKmsUMZT54LiXlq/93/+dgQ7+8RKuxSFoi6kclAgMAFaXcUY szArPr5MzWDBpZVWK2tWgnpk+y9zIt8= X-MC-Unique: APeDQ2MRPSa6-4Ui-dpabw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/20] commandhelper: Consolidate argument parsing Date: Mon, 1 Feb 2021 12:27:49 +0100 Message-Id: <20210201112804.144366-6-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 1ee697498c..62e1b98c60 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -66,6 +66,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; @@ -82,6 +83,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 @@ -149,7 +152,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 Sat May 4 15:49:30 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=1612179012; cv=none; d=zohomail.com; s=zohoarc; b=J8ywzTv6RKVYuKb5Zkoaxhdf0wTho9Uiwp888kca0AZOJT0FulHrfeUmiupZYckr+HFXVUbSBuvqbgoctaQGguqhVFXfMyc2oLionLg2gDW2kBJMv+iJcIGNjxhxRgMPyPjyUB//YzBaN+BpLSxk1la8bC39QDo0C2yQNqYYV1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179012; 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=RyxbpFUSfp63bnDgcgXTHrcoLgVlwkmJYiakI9WTBZE=; b=GXjX6/fB0kecZOeHdj4Ihjkonnp6RM6OyKbxuT0HWEAbN2TW0QRiecPbu/JADaSh4F1eGVbldfhy18sp6Bf8yNDacQTj6IJNEbnpXsDr/RvySTrLM4EkYthiAiIDsZHBvS51JCS7NNszihMcaFmF78nz/bgxNgUuH45/KkJCQo8= 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 1612179012966499.87963393648045; Mon, 1 Feb 2021 03:30:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-ZpoKIllWP_iIJJE4Ky6Ajg-1; Mon, 01 Feb 2021 06:28:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BAB2107ACFB; Mon, 1 Feb 2021 11:28:46 +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 0CA965C1A3; Mon, 1 Feb 2021 11:28:46 +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 C9F9650041; Mon, 1 Feb 2021 11:28:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSGPa003293 for ; Mon, 1 Feb 2021 06:28:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id ECC9B6A908; Mon, 1 Feb 2021 11:28:16 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 136082C313; Mon, 1 Feb 2021 11:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179011; 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=RyxbpFUSfp63bnDgcgXTHrcoLgVlwkmJYiakI9WTBZE=; b=Q93Zr5oSZv+vk5AwAFNLQ3NBtpzv6UeRbf/Jhcqd4MqHXEEqBMDKzlgHZvY1bSJdea3Xg+ LJodn3RSg1dYdpXPU4641FrKEUDU1V6Y/L6sxFErY0fEHuKyqLmDJtE1rn280kpTsMGvzV bdG48DRQb9Nu3fSwFTEQECtHHaslIS8= X-MC-Unique: ZpoKIllWP_iIJJE4Ky6Ajg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/20] commandhelper: Split argument parsing and printing Date: Mon, 1 Feb 2021 12:27:50 +0100 Message-Id: <20210201112804.144366-7-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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.16 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 62e1b98c60..24373d6c07 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -75,8 +75,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]); @@ -88,6 +86,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 Sat May 4 15:49:30 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=1612178932; cv=none; d=zohomail.com; s=zohoarc; b=J9EC/ofK61hNpYi6KLWIfyN1f1Y6cFcSvS0GnEKkBGGlypUSZYsH544WXDznPBpPohIh0RGNeTxKISMPuBKh4Uc06Ds4xcY7cHvtQH1xnJyE5eAAMTj+GNIGKHTcuO3vb5oJRkzYoTxDtLRyN7v3MGS6YYtkDsWyQ7kuMnSHbcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178932; 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=pjLtvqA9/XOl7EeXDRWQ+nnFOG4PrAijXxvl10Jgp1w=; b=NbuSy9+f7p4zFV44ZNCY351Q/uSQnby1WI+wJfiGZuzf49WZJE2G+xZbIcrRI4Xp+430Nh7+3hmjA5CKMtHkXhIpa/NIPBQPf2M50Nj7FSPGp4fn62L5uYqTTcOAD+vm74SFTxwPtYbwTXYGrCUy+R3BxUKly6scEkkmFh8dQ9c= 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 1612178932197462.11912016236283; Mon, 1 Feb 2021 03:28: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-454-iCcHPQqAO0Wvamyp0ZQH9w-1; Mon, 01 Feb 2021 06:28:48 -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 C8151AFA88; Mon, 1 Feb 2021 11:28: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 A4D152C313; Mon, 1 Feb 2021 11:28: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 728534BB7B; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSIq6003304 for ; Mon, 1 Feb 2021 06:28:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 44DAC6A908; Mon, 1 Feb 2021 11:28:18 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 574491840B; Mon, 1 Feb 2021 11:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178931; 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=pjLtvqA9/XOl7EeXDRWQ+nnFOG4PrAijXxvl10Jgp1w=; b=AQgPd2nQTiRFqRewwRxUEyYusHD6GTX0/1M/g156arZr3qO5LOOxXpv3xne65bGbcYc3Ov FPBxAvNITro8b2C0gf1v5Tl3QD9foRKGHNWu2uVeU4iLO+NWMAhHPLfZLMi/kOWjk3isrk wvnYu34xEr/H+YV6Gc7gSSfhegjFtSE= X-MC-Unique: iCcHPQqAO0Wvamyp0ZQH9w-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/20] commandhelper: Factor out parseArguments Date: Mon, 1 Feb 2021 12:27:51 +0100 Message-Id: <20210201112804.144366-8-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 24373d6c07..f7e406ec83 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 *astr =3D *(const char**)a; @@ -53,39 +98,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]); } @@ -126,7 +155,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; } @@ -154,7 +183,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); @@ -165,8 +194,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; } @@ -174,12 +203,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__ @@ -210,7 +239,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; @@ -220,7 +249,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]) @@ -237,6 +266,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 Sat May 4 15:49:30 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=1612179070; cv=none; d=zohomail.com; s=zohoarc; b=VSSUwEyReSMsEntZ2gukimanfSNGL6/a4/ynK4ck9iX9RZUWmdvemRjEL8N1tXLzfOBKW1SBBsO04MptTv06zQz+/+hcUTr3ABPDr2u87yHYxd/3gdgK294CtbK0Lmj0zNhThS5aXx7R34UQsPrkQVkgEtgmFzvxvuH8sfpHqbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179070; 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=FWB2ddhe3Qoxh1fdSBNfkHlDr5puDLQEcK0lqVP7Ds8=; b=OQz7oP+jDMeOuelaqdVWJnc9mJ2mb6ae5Nes37LUjleXVOXOZ0Ty5/aafBW54VcuMtWdE2B5x9uFoMa4ne8E5F9ca6YNt17wo+J1Gm4zXneWQjQ548gwPXL32GqCp5g8WvUvlaAAiGGmrGLYep9/k9EpfCqkCCN+NWatNoz9TKY= 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 1612179070287474.19474744432057; Mon, 1 Feb 2021 03:31:10 -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-416-0kh0m3BJMRqEhpKEsPyC6A-1; Mon, 01 Feb 2021 06:28:54 -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 215C6107ACE8; Mon, 1 Feb 2021 11:28:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF67F6A912; Mon, 1 Feb 2021 11:28: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 B176E1809CAF; Mon, 1 Feb 2021 11:28:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSJIV003313 for ; Mon, 1 Feb 2021 06:28:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8B1A369324; Mon, 1 Feb 2021 11:28:19 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 981821840B; Mon, 1 Feb 2021 11:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179069; 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=FWB2ddhe3Qoxh1fdSBNfkHlDr5puDLQEcK0lqVP7Ds8=; b=iTFC9tz6zk1l9DniIL4j8dS9i7eHSQRJyF/vHLvj8jLD3levGQWuq6EZJPDxl9yA28Qf1+ PKW3XseoeXWBp21ztTq7Hn1JoAVDxKxaqYGeB+wzF8FeDK3koMOuWr7LtLWlnANYksJC2D VsDZmzwzepUL8JL5QVRir1O6wPF0QTE= X-MC-Unique: 0kh0m3BJMRqEhpKEsPyC6A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/20] commandhelper: Factor out printArguments Date: Mon, 1 Feb 2021 12:27:52 +0100 Message-Id: <20210201112804.144366-9-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index f7e406ec83..ec54f55eb6 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 *astr =3D *(const char**)a; @@ -115,9 +124,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 Sat May 4 15:49:30 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=1612178913; cv=none; d=zohomail.com; s=zohoarc; b=P7pPnKRGtAVQSVJzr+Vs/9c/LfWHzsMmkDXnZ/WSOsB02ymaRmNbDWJ1u6Mk3ciDoQEYrF0EZ8CZYviZVn8I8huHN1C/bOMiCmAq01sOnfpHocjT2BslCAI6Lo0LvgI+YYsHNnu34TYYBwKU4CZh4GVDPjYxj8XW/z3Nx8rs78E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178913; 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=86gxxcaHZBOLaT8weLMOEFGl6ynbW0kiAFiml8T32fs=; b=S7fObbj1pJXJxsL02Umc++tnfH12sTI3MgEwjjv8gmE+6M1EIBw1lykwTwWolDoR0zTPPpSmwX/P06X6XbnAITRPm/7hI741HNGZt0e8ieTlEk2RZZrqdZEU7qcDRQXiglYerQ9Y8SXivmdQmuldrbMNYmFUMyTpWR9HyaoQO+U= 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 1612178913560767.41886270464; Mon, 1 Feb 2021 03:28: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-542-bY1EFU-pN4KieUKQ-fqCgA-1; Mon, 01 Feb 2021 06:28:30 -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 46466107ACF8; Mon, 1 Feb 2021 11:28:25 +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 2330B6F988; Mon, 1 Feb 2021 11:28: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 D7C141809CA1; Mon, 1 Feb 2021 11:28:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSNDw003337 for ; Mon, 1 Feb 2021 06:28:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 435036A90C; Mon, 1 Feb 2021 11:28:23 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55165669F2; Mon, 1 Feb 2021 11:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178912; 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=86gxxcaHZBOLaT8weLMOEFGl6ynbW0kiAFiml8T32fs=; b=AA3NLZ/Iu4aoPHLwqDFaYjEDxU/XzLCzz+Gw/Lw2pUvMvKF+fPEO5Ham2X5nr5bRpd4SOa L75LY9oH0+VXd6Z7eZgNA8sj8CVYBlZAmwkjduzCd2WBUFNTYx9lJ1c/sSoH5TIGsd8vrk YJrfTIgx+0LFYiItZexrMXW5fkj/nDg= X-MC-Unique: bY1EFU-pN4KieUKQ-fqCgA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/20] commandhelper: Factor out printEnvironment Date: Mon, 1 Feb 2021 12:27:53 +0100 Message-Id: <20210201112804.144366-10-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 | 57 +++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index ec54f55eb6..842cc72942 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -106,11 +106,44 @@ static int envsort(const void *a, const void *b) } } =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; @@ -126,25 +159,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; @@ -275,8 +292,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 Sat May 4 15:49:30 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=1612178947; cv=none; d=zohomail.com; s=zohoarc; b=eHLDsdS2tqdHD7RwOr00Hi5Y/3T2KynC64/lBm3t/VTvsOLBnCrvRtKW1XFJk7NuN1+vYl2GjWGz0ukMVtVuZWt94nXJaOikoGBwvJDu/rkUO4+FHcTvyAS26YUJ325ABMpSZX1oGvGu6sqLxRr1w+CN3Pk/b+PZbZ+K2p/2uuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178947; 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=Bcj6X3hYSuL5gF3VbULXOrEp3y4PVEqRLn+ewSrQW1o=; b=Joi+Yig1G68meSyF48v6xSPhWu3tVGzFAEfY+A1aM7L1yCB+Y9NPx0yrghgK4W4yVxaCK88KV6umchU0zm+LJfTe8bqULpPvg6YKLG6QZCeKMsf6OaN7ZNGqPNdiY2uDLYppXKVCD9gsN2VZcAAIH0M+DqVyJbMg0ubWJz3rOtY= 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 1612178947449653.4988089966357; Mon, 1 Feb 2021 03:29: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-269-SYJpuuLAP-yt1NHu_wuoxQ-1; Mon, 01 Feb 2021 06:28:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E55238049C4; Mon, 1 Feb 2021 11:28: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 C27D15F707; Mon, 1 Feb 2021 11:28: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 8A0851809CB5; Mon, 1 Feb 2021 11:28:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSUmX003362 for ; Mon, 1 Feb 2021 06:28:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1342269324; Mon, 1 Feb 2021 11:28:30 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C9506A90C; Mon, 1 Feb 2021 11:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178946; 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=Bcj6X3hYSuL5gF3VbULXOrEp3y4PVEqRLn+ewSrQW1o=; b=iLGx6VZTnBwNlzPBNXneZ1m+IMFXLAcYlgqDELNhawR9KYlFk7DaJgrgZEK5Jm7/0yGexp wb9hjGT5XoKZGYVPJlkjuL8DTQvUSL92fa4FJd9/D0JsFEo6VXbHwdRCjrFwHqfU+XJ71M Fnh1BU223MGallgiEc5X01fdb+49fZc= X-MC-Unique: SYJpuuLAP-yt1NHu_wuoxQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/20] commandhelper: Factor out printFds Date: Mon, 1 Feb 2021 12:27:54 +0100 Message-Id: <20210201112804.144366-11-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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.16 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 842cc72942..fd45c4fdf7 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -140,10 +140,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; @@ -162,19 +184,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 Sat May 4 15:49:30 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=1612178926; cv=none; d=zohomail.com; s=zohoarc; b=O/H1XBh2jKJRHWB7ZMNVvARFi4tn/VZPibsyGYJ6x6kKl2Wu48PN55EuSWg7uPkGr8JzHKHTLgSTx/azFYGYs5mTbysW00l20BH7+Z4g6JJxtXNEe9UAya02oY/5i6PfwrNd+0wtu1zJ3clKfn/vKEsuu1fKPO9Id85z1S0l89s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178926; 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=lrUgAj8ml9atkGOXJYAkUVW2723oDw8sPHuriz33Lnc=; b=dzdESxwo2c4lVoufZkCGAM524EScbOcq8F6/fgaPnN8dKJ/ouFilnVsjMh3M7KHDzY+OyQzMPp4snF0ffAwGoO4D9n7X7G0bFXqHHvRsZPQUTRS/cSnMJ4S5SEvQx1x2jQesno3GRBtZmgbySa/s+wsB5hKyOx0VT/Kcig8NfZ8= 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 1612178926200204.74086140779673; Mon, 1 Feb 2021 03:28: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-176-gFue9FReMzmVwEhKgnV_yQ-1; Mon, 01 Feb 2021 06:28: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 DD482107ACF7; Mon, 1 Feb 2021 11:28: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 BAF85614FC; Mon, 1 Feb 2021 11:28: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 805AA1809CA4; Mon, 1 Feb 2021 11:28:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSViC003367 for ; Mon, 1 Feb 2021 06:28:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 47D4C6A90A; Mon, 1 Feb 2021 11:28:31 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 661041840B; Mon, 1 Feb 2021 11:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178925; 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=lrUgAj8ml9atkGOXJYAkUVW2723oDw8sPHuriz33Lnc=; b=HSpv3yzkpf/gAFEzPtJtkVgXt4Kjxj6BPIBM9MrclDbHXLCngjAmYW2ytP4wTVVV7izk/r vxIGHVD8M+dxxtbu84pwhH2ITj4iyBgUYOnrLfzufSswV3LlGQcG/vlF3dwRWeq7rS0f1x iWrZMUdYJ6KrGwcOcdnBkfo2f/SGMGM= X-MC-Unique: gFue9FReMzmVwEhKgnV_yQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/20] commandhelper: Factor out printDaemonization Date: Mon, 1 Feb 2021 12:27:55 +0100 Message-Id: <20210201112804.144366-12-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 fd45c4fdf7..cceeb1a119 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -163,6 +163,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; @@ -172,7 +185,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 @@ -187,17 +199,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 Sat May 4 15:49:30 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=1612179130; cv=none; d=zohomail.com; s=zohoarc; b=ffdB5Jf5nWT8ZRUxs7guESwyRKusv6kn76Ox1Upq8qv1Waol6IWwNy2lTEcYXqJsA/j7S3gHkaLgBnebkxM5qDBgtcUr331fiSScX9K45hT1QDbPaUaUVRFz7QTDojyC+IDSVTPQdCTFFXetKa3mIAjdPCxAdFqEIqZaTdHOeS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179130; 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=Dar8zKAEdn2CDf5Sw+6co0uKNgb51m/uIgx0ssR9ttM=; b=FrcJyqdouRLWii3tKQcWl9ooZxies1oT8zi3eMVIkzlYp9Tbn+xgktzUJnMKz4Vx5GD6R4GUsVZYWJpd0MfTHi5tscTnD9NwE9C41ObC++gp3arTBPPQTzkR5D08Ro+0oCgPAYC/DvqpOIaAs8q1hHE1YXyvHq+1NmynD1xYo4k= 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 1612179130220934.9442856993293; Mon, 1 Feb 2021 03:32:10 -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-67-vhTyMzVsMGqmCuDX_8htlg-1; Mon, 01 Feb 2021 06:28: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 C043C107ACF9; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F7905DA2E; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6B4EF180954D; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSZ8Y003386 for ; Mon, 1 Feb 2021 06:28:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id A88102C313; Mon, 1 Feb 2021 11:28:35 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ADF26A90A; Mon, 1 Feb 2021 11:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179129; 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=Dar8zKAEdn2CDf5Sw+6co0uKNgb51m/uIgx0ssR9ttM=; b=f08I/uVUt17lYZWkPhCsjttxT/cF2Y80wbvVP6yBxlnKdbujtxubrFRqwSF6HM4hpEjS9C VdLmgy6dsWg4M27mDhzspawwlvWNBNi2fQI2cRa/FIQplqB3zGNyVpPgPCYDnZFrv3866Z HYYMXyal91+7bGiOOa7Vh8TmU9WGI2A= X-MC-Unique: vhTyMzVsMGqmCuDX_8htlg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/20] commandhelper: Factor out printCwd Date: Mon, 1 Feb 2021 12:27:56 +0100 Message-Id: <20210201112804.144366-13-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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 | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index cceeb1a119..ce3f64fc9d 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -176,10 +176,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]; @@ -201,22 +225,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 Sat May 4 15:49:30 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=1612179089; cv=none; d=zohomail.com; s=zohoarc; b=QM/5jY3zDJqjpvbC3GCUt5Ntf8lOBKsGVgKoSPV5TMIbW2xNxDGgqgMNUr+cR/TP84D5lMeiqMjrsHURi5TlbwD+cMrRIoP7dojoaTFgT4OUiktYzCUbbX2IooycdfhjacKE9ylrCVUc63xkQbVfZLdyMEg/djXMZRFfcvYHfyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179089; 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=lwOLJ+BicH9M9sA5HkCFndeDimYLiefVhAbUvyh6hE0=; b=c0+Y3Xv3Fdg4wXYfu0K7ILSu2X8BhPtLXbPxfkp5rlVinUvCv1ZMzdybKYEE0xyeJ+dVS71JnO8Q+IJ144NU/8no/38sb3YjQokLs7QpxPvWgUH6zNH4d8OnB8A5sGZ+K4RKTTA/NfxzV3YQLCL6ziYlgdhY0cElNXLbBmswt9k= 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 1612179089864575.2723878830753; Mon, 1 Feb 2021 03:31:29 -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-311-FIh8wtrfNlCfFi5AG5ftbQ-1; Mon, 01 Feb 2021 06:29:00 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90D418030C2; Mon, 1 Feb 2021 11:28:54 +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 6C6B271C97; Mon, 1 Feb 2021 11:28: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 2E15385FD; Mon, 1 Feb 2021 11:28:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSakZ003395 for ; Mon, 1 Feb 2021 06:28:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id E8B162C313; Mon, 1 Feb 2021 11:28:36 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EC2F6A90A; Mon, 1 Feb 2021 11:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179086; 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=lwOLJ+BicH9M9sA5HkCFndeDimYLiefVhAbUvyh6hE0=; b=bHzRU123xcDiddBTpXMl/MLt5MMznsJ3U0uOmREsVnV9MO1S1pBtUmuBI7H2h/1YHCD1Y/ qq2uFA/VHuZF/IWiE2lXunw28fX98FA1Cx4gQGp9APtxN3Wf4jSzYEB2vL1we7/x+HAQLG iOID6dBSvOE8KeQgnP4GLDkOfYb8s84= X-MC-Unique: FIh8wtrfNlCfFi5AG5ftbQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/20] commandhelper: Factor out printInput Date: Mon, 1 Feb 2021 12:27:57 +0100 Message-Id: <20210201112804.144366-14-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , 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.16 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 ce3f64fc9d..8a9a3c96a0 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -201,39 +201,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"); @@ -308,11 +289,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 Sat May 4 15:49:30 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=1612178938; cv=none; d=zohomail.com; s=zohoarc; b=f//Qx/P/E2SvnyeDS+oiQ+MqCCU+rc9UisIW3guP+aCWQ7UCHFQHH3rrdNPY43mN3QvqLlB3RqIf9aHcnn5WGfF7ZccafSRJdmV/x+Qfgmf/FE7NjLtSYtcbdXvSq9wHQfvTcbWPOWa4ah9+o6gEue+/1TQie3UyVFWOqJ5nE9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178938; 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=MUPYUKjSEWAR9+4O7kJ1LjpuzDLsx9fVbu3PMEPsBm4=; b=ZPPSl7FSdqD6V2FBF3YNachE1DgzAD3OC4/NmVC5HhlH6JCu6nomFyoKGvpEIY/9+NzBDsXCln6Tpnij1LBshZV8SSONcGfLOxnCeB2voXG2x5SVU1xEA6DBYf2vk1y3YA3U8AXV85yFMl3JlLSkW3xKygI5zk34Y7RCHiOOqgI= 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 161217893828131.51718373662493; Mon, 1 Feb 2021 03:28:58 -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-201-5PCV2aeQMei-0BR0pg-2GA-1; Mon, 01 Feb 2021 06:28:55 -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 87C9380401F; Mon, 1 Feb 2021 11:28:46 +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 6238C7216F; Mon, 1 Feb 2021 11:28:46 +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 F035B1809CAC; Mon, 1 Feb 2021 11:28:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BScBg003405 for ; Mon, 1 Feb 2021 06:28:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 009B52C313; Mon, 1 Feb 2021 11:28:38 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 479941840B; Mon, 1 Feb 2021 11:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178937; 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=MUPYUKjSEWAR9+4O7kJ1LjpuzDLsx9fVbu3PMEPsBm4=; b=D3hdVglhEQkG53CmjNEgaJZaruhSVk6lOZp4DdylpT3hEU2/BcvgSVD3j5UDGgTP7ta5Ll Yz2MJlwGnkPHbJdqHRcODShNrxAvovS0m9fuB9xcHsnpd/DgIo0xIvR3uXcxXzVr17oNQ6 Jglnpgv0cREqhEEPUNjEe/0n1AB3LRA= X-MC-Unique: 5PCV2aeQMei-0BR0pg-2GA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 14/20] commandhelper: Make number of fds variable in printInput Date: Mon, 1 Feb 2021 12:27:58 +0100 Message-Id: <20210201112804.144366-15-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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" Fixes a buffer overflow triggered when more than three "--readfd" arguments were given on the command line. Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 8a9a3c96a0..ac64505461 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -204,13 +204,23 @@ 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; + + /* plus one NULL terminator */ + if (!(buffers =3D calloc(args->numreadfds + 1, 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; @@ -292,8 +302,15 @@ 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) { + char **ptr; + for (ptr =3D buffers; *ptr; ptr++) + free(*ptr); + } + free(fds); + free(buflen); + free(buffers); + return ret; } =20 --=20 2.26.2 From nobody Sat May 4 15:49:30 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=1612179183; cv=none; d=zohomail.com; s=zohoarc; b=bpeB/hzSbajQzXBoImiLFGg2ho8cdo+amu6vqCR4IiyBgR0N5vW7MxjGvG0RnGP4tqwAUiGMa9NKPZ1Wz4tTKgC1X8eXEUcUYO3wBtB0hRxS3elhKmaLpzXrHka268dZcMnUKorBKFqk8lkdlnq9M6zokJ6zHII+xAe5U/sD6+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179183; 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=RJ/Rz4e7KmgpgOkm6KdCIgoQTrGDLa+zFurkibsc/fE=; b=BzUHYX97AjItMAD9t+Xxrh9y2m46fjqQaoma2r/uty/pD1bp5jCEN/kqpSFepPN6lTwVIGh4MVeIxJ5PeVihHFZ0kXqoAFbKpblAryhOUZmRW4CQLr1mgXP2Zy+5cDTSZBtwnn2aNivx4Gc9o8BlwMMlZNCPulbmpVHYCuZhlrQ= 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 1612179183634544.1179686767732; Mon, 1 Feb 2021 03:33: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-155-Kv2MyhkcOj2atsVKwHEqqA-1; Mon, 01 Feb 2021 06:28:56 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4665E8030A5; Mon, 1 Feb 2021 11:28:50 +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 263B65FC19; Mon, 1 Feb 2021 11:28: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 E5F6B1809CB2; Mon, 1 Feb 2021 11:28:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSdjw003411 for ; Mon, 1 Feb 2021 06:28:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1A77D2C313; Mon, 1 Feb 2021 11:28:39 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5485E1840B; Mon, 1 Feb 2021 11:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179182; 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=RJ/Rz4e7KmgpgOkm6KdCIgoQTrGDLa+zFurkibsc/fE=; b=IpObHALt7gBQ40RHkrj6TJqG09MZOfqfh+s0PLpC4AX7uRm+BgkHEQ0SlR7nq29S4tHRwy QYmt2qJDUeTLxytvPUtG9xCOVuFA5hoY3z7qIfv0oX1nhQUvob30YSlo1paboaJIlQPjuc 6fQsPnAIpWRw+fzx4g6tco8KvigJM0I= X-MC-Unique: Kv2MyhkcOj2atsVKwHEqqA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/20] commandhelper: Make number of fds variable in parseArguments Date: Mon, 1 Feb 2021 12:27:59 +0100 Message-Id: <20210201112804.144366-16-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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 --- tests/commandhelper.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index ac64505461..9f0b7f25ac 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 @@ -343,8 +357,11 @@ int main(int argc, char **argv) { ret =3D EXIT_SUCCESS; =20 cleanup: - if (args) + if (args) { + if (args->readfds) + free(args->readfds); free(args); + } if (log) fclose(log); return ret; --=20 2.26.2 From nobody Sat May 4 15:49:30 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=1612178937; cv=none; d=zohomail.com; s=zohoarc; b=jym2qqHEgF61GnGI/WKvZWKO6Um7S7x0InHt2av27vdZt3s8erPScm8xkKGQkKV57t07UlKd0q6ip6nKJbhDCOe3NvIZcW1ZQ9Ngj2I1zLpgPNuRxP4pkPfbZJ5wtbNMl4CymVkScNdUyxP/roHx/y39wulE66OYAb2wNa1Zq7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178937; 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=+vef3nWgGH9xeYLxJ/O6ToQTCOqy1RYfQAVAo9U6uWk=; b=nscRIApOriI865++mmmDwD8aMRWE9xtzne146KmB80zvy74vYSdAF5RPBdWhZdjFQc9/C3b+OsOeV6PrCX0JAz/W4oPDBxGMR5uFxGBwj/qL/B0dv5qXsBOMU/Ah1HyLEEm2NA2r3HKcY2ZnSN7rfS0ufPYS71L6pr0J0CeFzK4= 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 1612178937610384.87657826273494; Mon, 1 Feb 2021 03:28: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-326-jNahLOkfOcyzfhD6HliKdw-1; Mon, 01 Feb 2021 06:28:53 -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 829591006C92; Mon, 1 Feb 2021 11:28: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 5ECF960C64; Mon, 1 Feb 2021 11:28: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 27B265003C; Mon, 1 Feb 2021 11:28:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSeo4003428 for ; Mon, 1 Feb 2021 06:28:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D82169324; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 723741840B; Mon, 1 Feb 2021 11:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178934; 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=+vef3nWgGH9xeYLxJ/O6ToQTCOqy1RYfQAVAo9U6uWk=; b=Ji4Ti+H1wLn3ttM2UepVhxmUbUpxuiJWHlkYuI7A27ebvKqYDhJPFfPPhWUR8uBaDyZzZw ebx6TR5PT0EHZ2YfCBPVIuVNP+Ji7p974Yxzg0jqjAPoHFBICODn0r2ThGw1qWh7Q8PZgm RpMTAWHlCcXNXLuouSVlOKdCivkbb+I= X-MC-Unique: jNahLOkfOcyzfhD6HliKdw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 16/20] commandhelper: Use automatic memory management in parseArguments Date: Mon, 1 Feb 2021 12:28:00 +0100 Message-Id: <20210201112804.144366-17-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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" Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 9f0b7f25ac..19dfc09151 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -24,7 +24,9 @@ #include #include =20 -#define VIR_NO_GLIB_STDIO /* This file intentionally does not link to libv= irt/glib */ +/* This file intentionally does not link to libvirt/glib */ +#define VIR_NO_GLIB_STDIO +#define cleanup(T, F) __attribute__((cleanup(F))) T #include "testutils.h" =20 #ifndef WIN32 @@ -42,17 +44,27 @@ struct Arguments { bool close_stdin; }; =20 +static void cleanupArguments(struct Arguments **ptr) +{ + struct Arguments *args =3D *ptr; + + if (args) + free(args->readfds); + + free(args); +} + static struct Arguments *parseArguments(int argc, char** argv) { - struct Arguments* args =3D NULL; - int ret =3D -1; + cleanup(struct Arguments *, cleanupArguments) args =3D NULL; + struct Arguments *ret; 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 +77,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 +91,9 @@ 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; + ret =3D args; + args =3D NULL; + return ret; } =20 static void printArguments(FILE *log, int argc, char** argv) --=20 2.26.2 From nobody Sat May 4 15:49:30 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=1612178937; cv=none; d=zohomail.com; s=zohoarc; b=QHGyhUJYEg5yFpB5HsuXYudNJkcibTn1XbknRdp0MPergZlKHMM3/ZY5uU4LgQqGZ+G6vtvrG96VoFFwUUjT6fA4iUu4WfUoI+NjdgfkutOYbkUrUtCmv7zmYgJQ2bYZy8M5K79NiKLByA02wQGtmZWuxUAEZJeg8uIJVIp9nG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178937; 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=Nke8viukJD9iULU4OVQ2QI5FmKwFxXFpn+S3JvNNfy8=; b=ktl5c1sMHBboIYx4RDuj6+rVaRhXBquXv2czeawx6FSSwLeq/xG43Pk/b3FYshPP1euCqbRvL64KGsuK1fL1n5ZxFv8M3RVx1zEgAv+fjP5epA/zq0hOJKDmvBbndymLT6vHFxblwmusj/70k5Iwse1X6K/HX323V4/0VpnCDXU= 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 1612178937954801.3436300450339; Mon, 1 Feb 2021 03:28: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-294-VRRLDzoTNAykrrSPxxRzGg-1; Mon, 01 Feb 2021 06:28:53 -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 64C92AFA8A; Mon, 1 Feb 2021 11:28:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 444A67216F; Mon, 1 Feb 2021 11:28: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 0ED9D50044; Mon, 1 Feb 2021 11:28:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSfQw003435 for ; Mon, 1 Feb 2021 06:28:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 39E8969324; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8098D1840B; Mon, 1 Feb 2021 11:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178936; 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=Nke8viukJD9iULU4OVQ2QI5FmKwFxXFpn+S3JvNNfy8=; b=O8V/W9wzbVzxcdU/kkenz7ix+2JLLqZn9WQC3eiBAWAwH/tdfvfVtiiOSjHX0tMyO27TTj V8nyxZeagBarC90CHT9qrZ+jAfFlX8CMMBOpZ1DTJStRGAS1ql4rx7Uf4XLH3bXHEPeNj6 Ug5sBZOPp+qdbd81M3s0/N02jhQivJY= X-MC-Unique: VRRLDzoTNAykrrSPxxRzGg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 17/20] commandhelper: Use automatic memory management in printEnvironment Date: Mon, 1 Feb 2021 12:28:01 +0100 Message-Id: <20210201112804.144366-18-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 --- tests/commandhelper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 19dfc09151..854f3c09bf 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -54,6 +54,12 @@ static void cleanupArguments(struct Arguments **ptr) free(args); } =20 +static void cleanupGeneric(void *ptr) +{ + void **ptrptr =3D ptr; + free (*ptrptr); +} + static struct Arguments *parseArguments(int argc, char** argv) { cleanup(struct Arguments *, cleanupArguments) args =3D NULL; @@ -124,16 +130,15 @@ static int envsort(const void *a, const void *b) =20 static int printEnvironment(FILE *log) { - char **newenv; + cleanup(char **, cleanupGeneric) 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]; @@ -148,12 +153,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 Sat May 4 15:49:30 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=1612178948; cv=none; d=zohomail.com; s=zohoarc; b=EvtUXGB9UsNjwUZUXP9zT4HU0u846o02N0U1swzVce4MWIGaI7mWlSme/hHQ33/FaOB6jpCTWgTfnssEIGDn2TiFHfSc/iAIrw+HVowk/XW7Cf8p2YtUiFKUK1POg29y1+kxl1QluhgQiPEp9zpBQ2GBRfkC0/VjY9tQajrATPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178948; 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=8v8Vp+bAWHl1PwnzO7075WfU9+0D8+ANTJ430fZIv0I=; b=JUDQecPU2SY7PpHhAHk65KDy9HqdHvxnv9KUUUyKVV46MjNpJsiodfVtOn6MjVb+NyTFyojVtCKfO4vp5YLOdBUIbi2N/rwGz21FNhykAiT92FKNCMNXAWQSOCAtvgEuV3wT7CYDRkV/bKONexJrCmOhCDjHjXQ5y1stkhsWw2E= 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 1612178948472163.5889329286931; Mon, 1 Feb 2021 03:29:08 -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-260-QZceTZFjOBqjIf53LRmKww-1; Mon, 01 Feb 2021 06:29:02 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65822AFA8D; Mon, 1 Feb 2021 11:28:57 +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 445CC71C8E; Mon, 1 Feb 2021 11:28:57 +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 0D9601809CA3; Mon, 1 Feb 2021 11:28:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSlAa003465 for ; Mon, 1 Feb 2021 06:28:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id EF5656A90A; Mon, 1 Feb 2021 11:28:47 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 419C11840B; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178947; 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=8v8Vp+bAWHl1PwnzO7075WfU9+0D8+ANTJ430fZIv0I=; b=GYKbJ3ikiGYMNr3U8V8c8ZeLrqnG1YbLIUoGajkGIY5ii3QDTBUY7SgNm6nJ09vRQTRxAy mpDwwlKzD08dThcbKGL3lphH+E1F8kD0PId5g+KcwJYuwOcyqxWLMNUqiDQYNUfqFPXDVX XaFKMaE70TByE2WP4iRXWzJ1h9zsFE4= X-MC-Unique: QZceTZFjOBqjIf53LRmKww-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 18/20] commandhelper: Use automatic memory management in printCwd Date: Mon, 1 Feb 2021 12:28:02 +0100 Message-Id: <20210201112804.144366-19-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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 --- tests/commandhelper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 854f3c09bf..5f0c1f5a51 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -194,7 +194,7 @@ static void printDaemonization(FILE *log, struct Argume= nts *args) =20 static int printCwd(FILE *log) { - char *cwd =3D NULL; + cleanup(char *, cleanupGeneric) cwd =3D NULL; char *display; =20 if (!(cwd =3D getcwd(NULL, 0))) @@ -213,7 +213,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 Sat May 4 15:49:30 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=1612179123; cv=none; d=zohomail.com; s=zohoarc; b=QhQHP71xuoL+rubl5KSUsBbghPxxG5GNKQWb8F+PPnlML20o1v/gn23VMik84kxwZQecFmqWFWvpiNwHFYAfFUyJDCx2FjISbJz+4YORgMuyCS9QOG0jKj+DCnHJJsfC1T8kYZuj+nhVUi1fYUvD08aMq0O9z3sjYdkX8xt7LrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179123; 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=vvZpdQSzSM9xlzklINdj5X+7tQHqICZJ7gNEbYVJBco=; b=cFgHdj0DGYkgEnRdMlQMEMChA5yWhn3JGBHSfA0F4D+4bpTZZ3CA+dSUlKd9Luj/UlYhBTEe0F/QEJANi5PPGLiO0HaQOgOXXc/8lMMsY76+Pzs/yCV2z51rKPpDAIXlHUT54uMBUtEztrlKPKpcneP/miGJ0OJqx/kAFhnUIw0= 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 1612179123594184.24417396447484; Mon, 1 Feb 2021 03:32: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-453-9cBeeQVyNUCChwo3rqJXrg-1; Mon, 01 Feb 2021 06:29:01 -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 592D0107ACF5; Mon, 1 Feb 2021 11:28:55 +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 2FEAEE156; Mon, 1 Feb 2021 11:28:55 +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 E738F50047; Mon, 1 Feb 2021 11:28:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSrd9003494 for ; Mon, 1 Feb 2021 06:28:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3E26E6A915; Mon, 1 Feb 2021 11:28:53 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FA436A913; Mon, 1 Feb 2021 11:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179122; 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=vvZpdQSzSM9xlzklINdj5X+7tQHqICZJ7gNEbYVJBco=; b=GQI/djY7Bdw7iKCdqOvzHGIaq0ftUan+E6n0rpw5hDQv3qmd2U4iP+FtGfvromqhhQm/j9 wwbFxFYT0T+9nBaJYLbxzcrPtMembD9XioSgyCExephLx8kWWaa0IWQ3DMEBjXbhwvok49 IShSdsulLJOdjLqlLlcXYBQH9coQbYE= X-MC-Unique: 9cBeeQVyNUCChwo3rqJXrg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 19/20] commandhelper: Use automatic memory management in printInput Date: Mon, 1 Feb 2021 12:28:03 +0100 Message-Id: <20210201112804.144366-20-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 --- tests/commandhelper.c | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 5f0c1f5a51..df9be7d424 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -54,6 +54,19 @@ static void cleanupArguments(struct Arguments **ptr) free(args); } =20 +static void cleanupStringList(char ***ptr) +{ + char **strings =3D *ptr; + + if (strings) { + char **str; + for (str =3D strings; *str; str++) + free(*str); + } + + free(strings); +} + static void cleanupGeneric(void *ptr) { void **ptrptr =3D ptr; @@ -219,26 +232,25 @@ static int printCwd(FILE *log) static int printInput(struct Arguments *args) { char buf[1024]; - struct pollfd *fds =3D NULL; - char **buffers =3D NULL; - size_t *buflen =3D NULL; - int ret =3D -1; + cleanup(struct pollfd *, cleanupGeneric) fds =3D NULL; + cleanup(char **, cleanupStringList) buffers =3D NULL; + cleanup(size_t *, cleanupGeneric) buflen =3D NULL; size_t i; ssize_t got; =20 if (!(fds =3D calloc(args->numreadfds, sizeof(*fds)))) - goto cleanup; + return -1; =20 /* plus one NULL terminator */ if (!(buffers =3D calloc(args->numreadfds + 1, sizeof(*buffers)))) - goto cleanup; + return -1; =20 if (!(buflen =3D calloc(args->numreadfds, sizeof(*buflen)))) - goto cleanup; + return -1; =20 if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) - goto cleanup; + return -1; usleep(100 * 1000); } =20 @@ -258,7 +270,7 @@ static int printInput(struct Arguments *args) =20 if (poll(fds, args->numreadfds, -1) < 0) { printf("poll failed: %s\n", strerror(errno)); - goto cleanup; + return -1; } =20 for (i =3D 0; i < args->numreadfds; i++) { @@ -277,7 +289,7 @@ static int printInput(struct Arguments *args) =20 got =3D read(fds[i].fd, buf, sizeof(buf)); if (got < 0) - goto cleanup; + return -1; if (got =3D=3D 0) { /* do not want to hear from this fd anymore */ fds[i].events =3D 0; @@ -285,7 +297,7 @@ static int printInput(struct Arguments *args) buffers[i] =3D realloc(buffers[i], buflen[i] + got); if (!buf[i]) { fprintf(stdout, "Out of memory!\n"); - goto cleanup; + return -1; } memcpy(buffers[i] + buflen[i], buf, got); buflen[i] +=3D got; @@ -304,9 +316,9 @@ static int printInput(struct Arguments *args) =20 for (i =3D 0; i < args->numreadfds; i++) { if (fwrite(buffers[i], 1, buflen[i], stdout) !=3D buflen[i]) - goto cleanup; + return -1; if (fwrite(buffers[i], 1, buflen[i], stderr) !=3D buflen[i]) - goto cleanup; + return -1; } =20 fprintf(stdout, "END STDOUT\n"); @@ -314,19 +326,7 @@ static int printInput(struct Arguments *args) fprintf(stderr, "END STDERR\n"); fflush(stderr); =20 - ret =3D 0; - - cleanup: - if (buffers) { - char **ptr; - for (ptr =3D buffers; *ptr; ptr++) - free(*ptr); - } - free(fds); - free(buflen); - free(buffers); - - return ret; + return 0; } =20 int main(int argc, char **argv) { --=20 2.26.2 From nobody Sat May 4 15:49:30 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=1612178949; cv=none; d=zohomail.com; s=zohoarc; b=EPhtvUK+Y7cBHjumKCVQwooUBoGrT6+8BTu51fw+enGQzYjsv2VFhYy3GNQoN3mNCdqNJVVFaBWz1LLSnJzy76PlcQTA70sR/TTnZM6DScgFlTPbaNdtCucJqmtwLunkwwKAsHco6BVlpk/eiPrhCQu97095S2XTug1enycHaZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612178949; 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=iDxHKgNS8NCtteGCWekT5cv4VWhHRJUDklcV/hvw++k=; b=LzTKPxEIuKmBPJ7g9gmlS2e0zc3nkTJQtfZscWes5vHkwCp8juKrR4CNpfHrMEkG5so/V0bHRLlM4ghHJuc+d1wLpNh7vTTw8Yk52n8me+DED+sRRfI76cDk3dkiIc7ENH0cxJxS1kAFDdqb034cr/s2hII+rK6x4v1XSbzDa6w= 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 1612178949265928.7931947880229; Mon, 1 Feb 2021 03:29:09 -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-206-VWKfDrCVP4awMKZRSnniPQ-1; Mon, 01 Feb 2021 06:29:06 -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 EAA81AFA80; Mon, 1 Feb 2021 11:29:00 +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 C903B72167; Mon, 1 Feb 2021 11:29:00 +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 9229B85F3; Mon, 1 Feb 2021 11:29:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSxKn003541 for ; Mon, 1 Feb 2021 06:28:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 705436A912; Mon, 1 Feb 2021 11:28:59 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id B10A26A90C; Mon, 1 Feb 2021 11:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612178948; 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=iDxHKgNS8NCtteGCWekT5cv4VWhHRJUDklcV/hvw++k=; b=OZlp1uW+7AYokk01fUrhOhniMoVoK0or/yrT0HjCVcERkSIHZ2SwL713usIszsphyO+Nf5 6krHzcJV6i7qh8V8bHTz0cE0oizufKeOhQycPz2m9HzgdqW7XAIgx0/zNrJorBGq3jJt5V 9HbmHLILHMSk4FiR4aOFSizjvADQK5U= X-MC-Unique: VWKfDrCVP4awMKZRSnniPQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 20/20] commandhelper: Use automatic memory management in main Date: Mon, 1 Feb 2021 12:28:04 +0100 Message-Id: <20210201112804.144366-21-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 --- tests/commandhelper.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index df9be7d424..bf6a5baa40 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -67,6 +67,12 @@ static void cleanupStringList(char ***ptr) free(strings); } =20 +static void cleanupFile(FILE **ptr) +{ + FILE *file =3D *ptr; + fclose(file); +} + static void cleanupGeneric(void *ptr) { void **ptrptr =3D ptr; @@ -330,42 +336,34 @@ 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; + cleanup(struct Arguments *, cleanupArguments) args =3D NULL; + cleanup(FILE *, cleanupFile) log =3D NULL; =20 - if (!log || !args) - goto cleanup; + if (!(log =3D fopen(abs_builddir "/commandhelper.log", "w"))) + return EXIT_FAILURE; + + if (!(args =3D parseArguments(argc, argv))) + 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; - - ret =3D EXIT_SUCCESS; + return EXIT_FAILURE; =20 - cleanup: - if (args) { - if (args->readfds) - free(args->readfds); - free(args); - } - if (log) - fclose(log); - return ret; + return EXIT_SUCCESS; } =20 #else --=20 2.26.2