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 51B4D5A0082 for ; Wed, 8 Feb 2023 18:48:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675878523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fsTBgTKkxXv735AkQ+vOJhCtf4oIKUvtwLicVMEr3Uk=; b=I+c/8hO3zj9jofyBxUTpvwroSHS4EXTjRUbo7dFSwGtHt/iQxfhkfqPHOxa7nZfYpVTUrz Q4YUk5thujfgKhGpAoTmGyYJG1MktPiO+HIbVU0g9uROeWlW093aY4KUFAq6nHl3UJdH26 xMoBfTBLT+4JTtmew/2FVCATo3uWYOM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-208-AbCknXeQMLOEmTY6M6S57A-1; Wed, 08 Feb 2023 12:48:40 -0500 X-MC-Unique: AbCknXeQMLOEmTY6M6S57A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E00AB3815EE4; Wed, 8 Feb 2023 17:48:39 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.17.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67212166B29; Wed, 8 Feb 2023 17:48:39 +0000 (UTC) From: Laine Stump To: passt-dev@passt.top, laine@laine.org Subject: [PATCH v2 5/9] make conf_pasta_ns() exit immediately after logging error Date: Wed, 8 Feb 2023 12:48:34 -0500 Message-Id: <20230208174838.1680517-6-laine@redhat.com> In-Reply-To: <20230208174838.1680517-1-laine@redhat.com> References: <20230208174838.1680517-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: BHIOKWDQQWT3Z5G42VXEO62NFMFKBKQG X-Message-ID-Hash: BHIOKWDQQWT3Z5G42VXEO62NFMFKBKQG X-MailFrom: laine@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 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: 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); } } /* 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); -- 2.39.1