From nobody Thu Sep 22 22:39:26 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MYVZl2V9tz4cV2p; Thu, 22 Sep 2022 22:39:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MYVZk75Wgz3yls; Thu, 22 Sep 2022 22:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663886367; 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; bh=ZDpOfpkLva6rX5vbQsymwDeooR82DNAvy981xZGyXO0=; b=Mm8tT4ErlinIbA+VIUHV6zYOkJDFqLKOwLsTZslXX4ct/7niOSJ7Q9+tkqDmeV5LhTo8IS qvKFb6cKkB9nLXlaRSL3Mv3BfPy2Yh2gLp08Svv/nJgKIkVYc6tAd7EGcet2JNDuD5VHdL 27+P4yPlLeiM63qjzNmrYKkTRDtN1ueZ+7UXt5GMEN4mw/gTOAS6uT9tiT4Yp7IKiDIHj1 X/abOon+/dFTYUr/FshrgbBBxH3iYYdYH+dR+FHgQOH9pJ7W2ojgjXykqLEB1IYafk2xCA 2DPL38Y0g5UVpn+CooYBOMpF1xGo4nmY01YRtAQt6kF0J98GSa2BnaUqCR2OWQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MYVZk68FqzYL1; Thu, 22 Sep 2022 22:39:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28MMdQhA021733; Thu, 22 Sep 2022 22:39:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28MMdQIp021732; Thu, 22 Sep 2022 22:39:26 GMT (envelope-from git) Date: Thu, 22 Sep 2022 22:39:26 GMT Message-Id: <202209222239.28MMdQIp021732@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: 5568c8b2c58a - main - ipfilter/ippool: Return error code when listing a pool fails List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5568c8b2c58a65a07b42af0e09c3fc619f13316c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663886367; 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; bh=ZDpOfpkLva6rX5vbQsymwDeooR82DNAvy981xZGyXO0=; b=qLCKFrkY6e+jkD9IT1mWlnvDNCqQpOIKq9j3ZzfULvvpQYPe13ua0aqC49nksNxEwu3ayA yCkk1DiDXqgkbvSFJlMfscOqFGofGnia3EPIMh9Lc9mcTa4TpoWs3t+pua51PWFDerV5JN E2vTFEoB0JnQuBgcj9IM4TzPaslgVE3o7YKeaqsE/54cayTBgR7e8YsPWaEz+4HeXK4tKb 2EXp57Tl+uU1e3MwJgrvpu6QEBNLuIZ9gQqkTiofljKsTF+9d+MTu9oDyaxnpn23p3RzKw +KlHm2NfMwkPrtLRML5lzjKfhCyhBkS953otnyjmANtLntC6SEUVwwU1QNL83A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663886367; a=rsa-sha256; cv=none; b=cl73bfdp62snGuSu7zIfvhqLXO5SkyIKDT3ThUcsjTtoNXx18gQbVKjN2pTIq6jclCeJof OYMxo4hrL9ybEt0HfjqYPhaTO/nZ+qL5XcvKNpJSqFo8/nyfHLGynwB/8lh/8jH7aaqEhh 9ckxSLQB4L8ZB+itiT6Rsz0+qWIhhaDY9jgxvEWrieUay6Y6fDIxvb/yFt0txNprNX6mGG znYO3pqt10mS3rjkSNBog9fMu5u771LbGsObcCOqWKEq5uxRJzfmKuwxkw0TN30Umw9JzF 3rf64djqOroIbEQktIVp1hv8Caie5WspqWZbBqsJZcHLD2LARAgQlRAaMgy0Eg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=5568c8b2c58a65a07b42af0e09c3fc619f13316c commit 5568c8b2c58a65a07b42af0e09c3fc619f13316c Author: Cy Schubert AuthorDate: 2022-09-22 13:00:09 +0000 Commit: Cy Schubert CommitDate: 2022-09-22 22:38:11 +0000 ipfilter/ippool: Return error code when listing a pool fails When an internal or other error occurs during the listing of a pool, return an error code when extiting ippool(8). Printing an error to stderr without returning an error code is useless in shell scripts. MFC after: 2 weeks --- sbin/ipf/ippool/ippool.c | 63 ++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/sbin/ipf/ippool/ippool.c b/sbin/ipf/ippool/ippool.c index 384146d729c9..53e1f19c6f90 100644 --- a/sbin/ipf/ippool/ippool.c +++ b/sbin/ipf/ippool/ippool.c @@ -47,15 +47,15 @@ int poolnodecommand(int, int, char *[]); int loadpoolfile(int, char *[], char *); int poollist(int, char *[]); void poollist_dead(int, char *, int, char *, char *); -void poollist_live(int, char *, int, int); +int poollist_live(int, char *, int, int); int poolflush(int, char *[]); int poolstats(int, char *[]); int gettype(char *, u_int *); int getrole(char *); int setnodeaddr(int, int, void *ptr, char *arg); -void showpools_live(int, int, ipf_pool_stat_t *, char *); -void showhashs_live(int, int, iphtstat_t *, char *); -void showdstls_live(int, int, ipf_dstl_stat_t *, char *); +int showpools_live(int, int, ipf_pool_stat_t *, char *); +int showhashs_live(int, int, iphtstat_t *, char *); +int showdstls_live(int, int, ipf_dstl_stat_t *, char *); int opts = 0; int fd = -1; @@ -743,9 +743,10 @@ poollist(int argc, char *argv[]) } op.iplo_unit = role; - if (live_kernel) - poollist_live(role, poolname, type, fd); - else + if (live_kernel) { + if (poollist_live(role, poolname, type, fd) != 0) + return (1); + } else poollist_dead(role, poolname, type, kernel, core); return (0); } @@ -820,7 +821,7 @@ poollist_dead(int role, char *poolname, int type, char *kernel, char *core) } -void +int poollist_live(int role, char *poolname, int type, int fd) { ipf_pool_stat_t plstat; @@ -840,10 +841,11 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showpools_live(fd, role, &plstat, poolname); + if (showpools_live(fd, role, &plstat, poolname)) + return (1); } else { for (role = -1; role <= IPL_LOGMAX; role++) { op.iplo_unit = role; @@ -851,10 +853,11 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showpools_live(fd, role, &plstat, poolname); + if (showpools_live(fd, role, &plstat, poolname)) + return (1); } role = IPL_LOGALL; @@ -876,9 +879,10 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showhashs_live(fd, role, &htstat, poolname); + if (showhashs_live(fd, role, &htstat, poolname)) + return (1); } else { for (role = 0; role <= IPL_LOGMAX; role++) { @@ -886,10 +890,11 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showhashs_live(fd, role, &htstat, poolname); + if (showhashs_live(fd, role, &htstat, poolname)) + return(1); } role = IPL_LOGALL; } @@ -910,9 +915,10 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showdstls_live(fd, role, &dlstat, poolname); + if (showdstls_live(fd, role, &dlstat, poolname)) + return (1); } else { for (role = 0; role <= IPL_LOGMAX; role++) { @@ -920,18 +926,20 @@ poollist_live(int role, char *poolname, int type, int fd) c = ioctl(fd, SIOCLOOKUPSTAT, &op); if (c == -1) { ipferror(fd, "ioctl(SIOCLOOKUPSTAT)"); - return; + return (1); } - showdstls_live(fd, role, &dlstat, poolname); + if (showdstls_live(fd, role, &dlstat, poolname)) + return (1); } role = IPL_LOGALL; } } + return (0); } -void +int showpools_live(int fd, int role, ipf_pool_stat_t *plstp, char *poolname) { ipflookupiter_t iter; @@ -956,7 +964,7 @@ showpools_live(int fd, int role, ipf_pool_stat_t *plstp, char *poolname) while (plstp->ipls_list[role + 1] != NULL) { if (ioctl(fd, SIOCLOOKUPITER, &obj)) { ipferror(fd, "ioctl(SIOCLOOKUPITER)"); - break; + return (1); } if (((pool.ipo_flags & IPOOL_DELETE) == 0) || ((opts & OPT_DEBUG) != 0)) @@ -964,10 +972,11 @@ showpools_live(int fd, int role, ipf_pool_stat_t *plstp, char *poolname) plstp->ipls_list[role + 1] = pool.ipo_next; } + return (0); } -void +int showhashs_live(int fd, int role, iphtstat_t *htstp, char *poolname) { ipflookupiter_t iter; @@ -990,17 +999,18 @@ showhashs_live(int fd, int role, iphtstat_t *htstp, char *poolname) while (htstp->iphs_tables != NULL) { if (ioctl(fd, SIOCLOOKUPITER, &obj)) { ipferror(fd, "ioctl(SIOCLOOKUPITER)"); - break; + return (1); } printhash_live(&table, fd, poolname, opts, pool_fields); htstp->iphs_tables = table.iph_next; } + return (0); } -void +int showdstls_live(int fd, int role, ipf_dstl_stat_t *dlstp, char *poolname) { ipflookupiter_t iter; @@ -1023,13 +1033,14 @@ showdstls_live(int fd, int role, ipf_dstl_stat_t *dlstp, char *poolname) while (dlstp->ipls_list[role] != NULL) { if (ioctl(fd, SIOCLOOKUPITER, &obj)) { ipferror(fd, "ioctl(SIOCLOOKUPITER)"); - break; + return (1); } printdstl_live(&table, fd, poolname, opts, pool_fields); dlstp->ipls_list[role] = table.ipld_next; } + return (0); }