From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 00E845A026E for ; Thu, 16 Feb 2023 06:43:23 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4K6SwWz4x8D; Thu, 16 Feb 2023 16:43:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526193; bh=oL/ZEWC59w67GNwxFSbkkDzVn1/EP++WOHhYfDoaoJQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Vjx8KtAAHknWvP7C8cayGFQ8Yf4KBcPV/d6eRIaaLXL7dZz1NAN6vYPmeNABU3rQK aqQSEW5/uB9LBndcH9MF11sSgBq+QG0XiOUsxGKnUHGAgIrmbOm+iC69W7Q09/8dqr 5Ch0bAXjLrFjd3qwqtclQ7UAla7VTQnO1Q/GtBbo= Date: Thu, 16 Feb 2023 16:37:22 +1100 From: David Gibson To: Laine Stump Subject: Re: [PATCH v4 5/9] make conf_pasta_ns() exit immediately after logging error Message-ID: References: <20230215082437.110151-1-laine@redhat.com> <20230215082437.110151-6-laine@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0Kz8diwj8Bkz/GeY" Content-Disposition: inline In-Reply-To: <20230215082437.110151-6-laine@redhat.com> Message-ID-Hash: UY5EVZ67USIMMUCCNOYTDDAJEKIHR26C X-Message-ID-Hash: UY5EVZ67USIMMUCCNOYTDDAJEKIHR26C X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --0Kz8diwj8Bkz/GeY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 15, 2023 at 03:24:33AM -0500, Laine Stump wrote: > As with conf_ports, this allows us to make the function return void. >=20 > Signed-off-by: Laine Stump Reviewed-by: David Gibson > --- > conf.c | 35 +++++++++++------------------------ > 1 file changed, 11 insertions(+), 24 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 0d4ff79..c7ed64c 100644 > --- a/conf.c > +++ b/conf.c > @@ -497,21 +497,15 @@ static int conf_netns_opt(char *netns, const char *= arg) > * @optind: Index of first non-option argument > * @argc: Number of arguments > * @argv: Command line arguments > - * > - * Return: 0 on success, negative error code otherwise > */ > -static int conf_pasta_ns(int *netns_only, char *userns, char *netns, > - int optind, int argc, char *argv[]) > +static void conf_pasta_ns(int *netns_only, char *userns, char *netns, > + int optind, int argc, char *argv[]) > { > - if (*netns_only && *userns) { > - err("Both --userns and --netns-only given"); > - return -EINVAL; > - } > + if (*netns_only && *userns) > + die("Both --userns and --netns-only given"); > =20 > - if (*netns && optind !=3D argc) { > - err("Both --netns and PID or command given"); > - return -EINVAL; > - } > + if (*netns && optind !=3D argc) > + die("Both --netns and PID or command given"); > =20 > if (optind + 1 =3D=3D argc) { > char *endptr; > @@ -520,10 +514,8 @@ static int conf_pasta_ns(int *netns_only, char *user= ns, char *netns, > pidval =3D strtol(argv[optind], &endptr, 10); > if (!*endptr) { > /* Looks like a pid */ > - if (pidval < 0 || pidval > INT_MAX) { > - err("Invalid PID %s", argv[optind]); > - return -EINVAL; > - } > + if (pidval < 0 || pidval > INT_MAX) > + die("Invalid PID %s", argv[optind]); > =20 > snprintf(netns, PATH_MAX, "/proc/%ld/ns/net", pidval); > if (!*userns) > @@ -535,8 +527,6 @@ static int conf_pasta_ns(int *netns_only, char *usern= s, char *netns, > /* Attaching to a netns/PID, with no userns given */ > if (*netns && !*userns) > *netns_only =3D 1; > - > - return 0; > } > =20 > /** conf_ip4_prefix() - Parse an IPv4 prefix length or netmask > @@ -1560,13 +1550,10 @@ void conf(struct ctx *c, int argc, char **argv) > } > } while (name !=3D -1); > =20 > - if (c->mode =3D=3D MODE_PASTA) { > - if (conf_pasta_ns(&netns_only, userns, netns, > - optind, argc, argv) < 0) > - usage(argv[0]); > - } else if (optind !=3D argc) { > + if (c->mode =3D=3D MODE_PASTA) > + conf_pasta_ns(&netns_only, userns, netns, optind, argc, argv); > + else if (optind !=3D argc) > usage(argv[0]); > - } > =20 > isolate_user(uid, gid, !netns_only, userns, c->mode); > =20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --0Kz8diwj8Bkz/GeY Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtwQsACgkQzQJF27ox 2Gc3Vg/9FulftvhvsaGzr1GBSVFjuSQEU7f6sl/lG3YeJNpD+ROAfMOQXpdXm7mm 7c0utpsaebQIg60DZiBg2NZYVMcxK/+He8YIG36omsUz3yPacE9z+1pCAm4IzShf qFc6kYYoabsaHeuwEWyNdeWAiBaHf+u6nbco2odqQprHDqu3jSa9R6mJ3ufbMYLW xDCgRs1ilZeB2OrzN62Bh4FZLNPOTbqSL3c5M6o7cPIz/xG50u26LzTAiAhZpZJv 8PUjdTa/ot9TsgpMTms5PLA7cmx3++HLHyqCufEJvJm4K3+elYE7Fy8n+Bl50ble 1NX9CivY80i4GoYOBlncfK+zqISyy/4OG8VHfOuyZmbJRTcBB3IP1snkAI+w6ns4 Q8jVyOVL83gUWv0MPiPc3mRefw5lGHqe3gnzaSUSKeRhZwpFq4q5ujbffSHI2rUi ZYgLNIOodesVa2qjh88U3UJu0kKxCW8FhDQ8BUnHlvxGqHeIwxzw+H7Tdzgt3CsO APQJKhGcNOpdKwZTPM71M/LLyLNpqocgHUwQPwbdZhp0HQLu6YVCYBu33QI81r7r Klpn/3buyKUq9r7hjoECJpDnU45fcqO+otlVN/ao/+SRW3ESw5qEPCaoC3XikHBX wWP+RC7fYQQIf5eF4AysPoqmecp5unipv71Krm1LS0lpcqCuKP4= =QQMG -----END PGP SIGNATURE----- --0Kz8diwj8Bkz/GeY--