From owner-svn-src-head@freebsd.org Sun Nov 29 12:33:57 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8610FA3CBCA; Sun, 29 Nov 2015 12:33:57 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47AD71A80; Sun, 29 Nov 2015 12:33:57 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tATCXuFW078754; Sun, 29 Nov 2015 12:33:56 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tATCXuPv078753; Sun, 29 Nov 2015 12:33:56 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201511291233.tATCXuPv078753@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sun, 29 Nov 2015 12:33:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291451 - head/usr.bin/rctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Nov 2015 12:33:57 -0000 Author: trasz Date: Sun Nov 29 12:33:56 2015 New Revision: 291451 URL: https://svnweb.freebsd.org/changeset/base/291451 Log: Simplify rule retrieval and improve error handling. MFC after: 1 month Sponsored by: The FreeBSD Foundation Modified: head/usr.bin/rctl/rctl.c Modified: head/usr.bin/rctl/rctl.c ============================================================================== --- head/usr.bin/rctl/rctl.c Sun Nov 29 12:23:08 2015 (r291450) +++ head/usr.bin/rctl/rctl.c Sun Nov 29 12:33:56 2015 (r291451) @@ -387,20 +387,24 @@ show_limits(const char *filter, int hfla char *outbuf = NULL; size_t outbuflen = RCTL_DEFAULT_BUFSIZE / 4; - do { + for (;;) { outbuflen *= 4; outbuf = realloc(outbuf, outbuflen); if (outbuf == NULL) err(1, "realloc"); + error = rctl_get_limits(filter, strlen(filter) + 1, + outbuf, outbuflen); + if (error == 0) + break; + if (errno == ERANGE) + continue; + if (errno == ENOSYS) + enosys(); + warn("rctl_get_limits"); + free(outbuf); - error = rctl_get_limits(filter, strlen(filter) + 1, outbuf, - outbuflen); - if (error && errno != ERANGE) { - if (errno == ENOSYS) - enosys(); - warn("rctl_get_limits"); - } - } while (error && errno == ERANGE); + return (error); + } print_rules(outbuf, hflag, nflag); free(outbuf); @@ -466,20 +470,24 @@ show_usage(const char *filter, int hflag char *copy, *outbuf = NULL, *tmp; size_t outbuflen = RCTL_DEFAULT_BUFSIZE / 4; - do { + for (;;) { outbuflen *= 4; outbuf = realloc(outbuf, outbuflen); if (outbuf == NULL) err(1, "realloc"); + error = rctl_get_racct(filter, strlen(filter) + 1, + outbuf, outbuflen); + if (error == 0) + break; + if (errno == ERANGE) + continue; + if (errno == ENOSYS) + enosys(); + warn("rctl_get_racct"); + free(outbuf); - error = rctl_get_racct(filter, strlen(filter) + 1, outbuf, - outbuflen); - if (error && errno != ERANGE) { - if (errno == ENOSYS) - enosys(); - warn("rctl_get_racct"); - } - } while (error && errno == ERANGE); + return (error); + } copy = outbuf; while ((tmp = strsep(©, ",")) != NULL) { @@ -512,19 +520,23 @@ show_rules(const char *filter, int hflag else filterlen = 0; - do { + for (;;) { outbuflen *= 4; outbuf = realloc(outbuf, outbuflen); if (outbuf == NULL) err(1, "realloc"); - error = rctl_get_rules(filter, filterlen, outbuf, outbuflen); - if (error && errno != ERANGE) { - if (errno == ENOSYS) - enosys(); - warn("rctl_get_rules"); - } - } while (error && errno == ERANGE); + if (error == 0) + break; + if (errno == ERANGE) + continue; + if (errno == ENOSYS) + enosys(); + warn("rctl_get_rules"); + free(outbuf); + + return (error); + } print_rules(outbuf, hflag, nflag); free(outbuf);