From nobody Thu Oct 06 13:57:05 2022 X-Original-To: dev-commits-src-all@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 4MjtKZ23l4z4dg0X; Thu, 6 Oct 2022 13:57:06 +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 4MjtKZ1BQjz3GcT; Thu, 6 Oct 2022 13:57:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665064626; 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=AZzfG+fd8Q7O+a0HSUNcOSFyynwvxJ7gl4wgPy1ii6Y=; b=Gh40JVik81z7rGQ/+aZisKgfdxdirpJbdGQHJ0XYOs0HS6szQ7Lvb7Nd5CEMohZ99mAILF o4EZeXlak2wdE7CxS54SVre9aQepyLaxtFNpHZj0YSKv64+xgOyBxOlA6vZVBFC8U0Q3yG OMDYHsLOY0a3d8dgRC2xOHK7Lt1+H+MvK73A/Igbbbli/KirOpQoShJsYGTCcRJqgaKanI iZ0Kz/5sWgB6DeyvkwkORWg7m3E3dO/p8tz/j8OL3LyTisZfG1d0Hg2s4/Ar6CXdcWp1BO Dvkco6Mj0mwEuJJNjoNXVkBLpEQRHhskGVJYZ+ws6x+WvVz36le8Fp79pnUqOg== 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 4MjtKZ04ghzGr2; Thu, 6 Oct 2022 13:57:06 +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 296Dv5T4042679; Thu, 6 Oct 2022 13:57:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 296Dv5CS042678; Thu, 6 Oct 2022 13:57:05 GMT (envelope-from git) Date: Thu, 6 Oct 2022 13:57:05 GMT Message-Id: <202210061357.296Dv5CS042678@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: 685159977f56 - stable/13 - ipfilter/ippool: Return error code when listing a pool fails List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 685159977f5684dad17f85b1eff2d75eb2fcc160 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665064626; 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=AZzfG+fd8Q7O+a0HSUNcOSFyynwvxJ7gl4wgPy1ii6Y=; b=rQOWt/w7rihDrYW5ZB2OkqTwjt419FfSmlnnw/b9vNvmUNID7/oLzY9WlKQYcUHAaStgFM 8TAZj1/trGyBB9DGZlvzG2u89eN8Tqpdxhu9qcvgQ8+DcmnFZQxntc9P05nMXqJPtl/P69 R3ztHFNuYJYU/R7jMalfsFo3fLlbAaRK1eEoFMNrVEpHHtYPKo3ugMEkxi53g89i/5rtgo 4Nvyjp4MnrvFBwaE03OkcjgBj6/dkwaRzF66wKvjwkwHKdl5XXupCziQk36jkdMHbdLiou GyCEi89bL6dbZwZjSYmPj0fADM83bmb7NwQgiqS20MsosjLLMBUh3P8ZPNucjA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665064626; a=rsa-sha256; cv=none; b=P1Cv5/wj4T/38+rjI7zGoeJYUldiBVNg23hwGlnbzpj18DC2SuLqICoojkXSpUHPC9fWA8 KirrfWuZvwVnyaq0UVDXWZVOovf7rozGYCl8+UVOw5nLDCTPY+Ngv6W/CaMpiTT0aXaX+K tXMGj+IpK8ESwKWgQ7kXJ9nGtSHk5YL+MUszKMy93GYz21yLAgiJ7fatFEJGVJaywtwLCd Ct/mbl95fEaK18u42eIiI9YXOMvns8a5MymYGl7LlS2vWweNf+xzAm2dt77DYU9PxGf06E LiBqMosVTbmjlzpT2Ptzg4lniE3F5ev9r9jkI6SBaiDqTK3BF1dU9J03A9lGDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=685159977f5684dad17f85b1eff2d75eb2fcc160 commit 685159977f5684dad17f85b1eff2d75eb2fcc160 Author: Cy Schubert AuthorDate: 2022-09-22 13:00:09 +0000 Commit: Cy Schubert CommitDate: 2022-10-06 13:55:57 +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. (cherry picked from commit 5568c8b2c58a65a07b42af0e09c3fc619f13316c) --- 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); }