From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 37D795A005E for ; Thu, 9 Feb 2023 18:45:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675964754; h=from:from: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; bh=m39VYzntlZCto8OL1ubRiVCk6yA1Aw8CjiHthjXGNsg=; b=JC3ilAqtdpqcYsK1tf3lHkPgzhA5/UWY+LWxTDojxvA55SX9cMCPKpV4kz4QYydx+kmdAZ BDTYTV+EFJ3TrhJ8sW+bNmPEsiYVcSZchDMfaLFQOlXQ9gqYnAghlmYtHfT9kzzCZ62Xxs Ra5ar+0YPSkmyZarZ+M7KSA1bdZYKJY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-380-Av_b3LgmMCWu_pDnhtBo4w-1; Thu, 09 Feb 2023 12:45:49 -0500 X-MC-Unique: Av_b3LgmMCWu_pDnhtBo4w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 947ED80280C; Thu, 9 Feb 2023 17:45:47 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B7721410F36; Thu, 9 Feb 2023 17:45:47 +0000 (UTC) Date: Thu, 9 Feb 2023 18:45:44 +0100 From: Stefano Brivio To: Laine Stump Subject: Re: [PATCH v2 5/9] make conf_pasta_ns() exit immediately after logging error Message-ID: <20230209184544.67ffe433@elisabeth> In-Reply-To: <20230208174838.1680517-6-laine@redhat.com> References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-6-laine@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: DLVTOHIAV4U5UAQSRZNZM2ERQ3M3BPPP X-Message-ID-Hash: DLVTOHIAV4U5UAQSRZNZM2ERQ3M3BPPP X-MailFrom: sbrivio@redhat.com 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, laine@laine.org 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: On Wed, 8 Feb 2023 12:48:34 -0500 Laine Stump wrote: > As with conf_ports, this allows us to make the function return void. > > Signed-off-by: Laine Stump > --- > conf.c | 37 ++++++++++++------------------------- > 1 file changed, 12 insertions(+), 25 deletions(-) > > diff --git a/conf.c b/conf.c > index 799b9ff..1e9c6f6 100644 > --- a/conf.c > +++ b/conf.c > @@ -500,21 +500,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) > + errexit("Both --userns and --netns-only given"); > > - if (*netns && optind != argc) { > - err("Both --netns and PID or command given"); > - return -EINVAL; > - } > + if (*netns && optind != argc) > + errexit("Both --netns and PID or command given"); > > if (optind + 1 == argc) { > char *endptr; > @@ -523,23 +517,19 @@ static int conf_pasta_ns(int *netns_only, char *userns, char *netns, > pidval = 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) > + errexit("Invalid PID %s", argv[optind]); > > snprintf(netns, PATH_MAX, "/proc/%ld/ns/net", pidval); > if (!*userns) > snprintf(userns, PATH_MAX, "/proc/%ld/ns/user", > - pidval); > + pidval); Stray change. > } > } > > /* Attaching to a netns/PID, with no userns given */ > if (*netns && !*userns) > *netns_only = 1; > - > - return 0; > } > > /** conf_ip4_prefix() - Parse an IPv4 prefix length or netmask > @@ -1562,13 +1552,10 @@ void conf(struct ctx *c, int argc, char **argv) > } > } while (name != -1); > > - if (c->mode == MODE_PASTA) { > - if (conf_pasta_ns(&netns_only, userns, netns, > - optind, argc, argv) < 0) > - usage(argv[0]); > - } else if (optind != argc) { > + if (c->mode == MODE_PASTA) > + conf_pasta_ns(&netns_only, userns, netns, optind, argc, argv); > + else if (optind != argc) > usage(argv[0]); > - } > > isolate_user(uid, gid, !netns_only, userns, c->mode); > -- Stefano