From owner-svn-src-stable-10@freebsd.org Tue Jul 3 14:57:12 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5680E10276B8; Tue, 3 Jul 2018 14:57:12 +0000 (UTC) (envelope-from robak@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 06E6385233; Tue, 3 Jul 2018 14:57:12 +0000 (UTC) (envelope-from robak@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DC1A21D92E; Tue, 3 Jul 2018 14:57:11 +0000 (UTC) (envelope-from robak@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w63EvBdN011770; Tue, 3 Jul 2018 14:57:11 GMT (envelope-from robak@FreeBSD.org) Received: (from robak@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w63EvBqG011767; Tue, 3 Jul 2018 14:57:11 GMT (envelope-from robak@FreeBSD.org) Message-Id: <201807031457.w63EvBqG011767@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: robak set sender to robak@FreeBSD.org using -f From: Bartek Rutkowski Date: Tue, 3 Jul 2018 14:57:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335891 - in stable/10/lib/libutil: . tests X-SVN-Group: stable-10 X-SVN-Commit-Author: robak X-SVN-Commit-Paths: in stable/10/lib/libutil: . tests X-SVN-Commit-Revision: 335891 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 14:57:12 -0000 Author: robak (ports committer) Date: Tue Jul 3 14:57:11 2018 New Revision: 335891 URL: https://svnweb.freebsd.org/changeset/base/335891 Log: MFC r327317: humanize_number(3): fix math edge case in rounding large numbers Fix for remainder overflow, when in rare cases adding remainder to divider exceeded 1 and turned the total to 1000 in final formatting, taking up the space for the unit character. The fix continues the division of the original number if the above case happens -- added the appropriate check to the for loop performing the division. This lowers the value shown, to make it fit into the buffer space provided (1.0M for 4+1 character buffer, as used by ls). Add test case for the reported bug and extend test program to support providing buffer length (ls -lh uses 5, tests hard-coded 4). PR: 224498 Modified: stable/10/lib/libutil/humanize_number.3 stable/10/lib/libutil/humanize_number.c stable/10/lib/libutil/tests/humanize_number_test.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libutil/humanize_number.3 ============================================================================== --- stable/10/lib/libutil/humanize_number.3 Tue Jul 3 14:40:19 2018 (r335890) +++ stable/10/lib/libutil/humanize_number.3 Tue Jul 3 14:57:11 2018 (r335891) @@ -200,3 +200,9 @@ The .Dv HN_IEC_PREFIXES flag was introduced in .Fx 9.0 . +.Sh CAVEATS +For numbers greater than 999 using buffer length of 4 and less can cause +rounding errors. +When using +.Dv HN_IEC_PREFIXES +the same error occurs for buffer length of 5 or less. Modified: stable/10/lib/libutil/humanize_number.c ============================================================================== --- stable/10/lib/libutil/humanize_number.c Tue Jul 3 14:40:19 2018 (r335890) +++ stable/10/lib/libutil/humanize_number.c Tue Jul 3 14:57:11 2018 (r335891) @@ -143,7 +143,8 @@ humanize_number(char *buf, size_t len, int64_t quotien */ for (i = 0; (quotient >= max || (quotient == max - 1 && - remainder >= divisordeccut)) && i < maxscale; i++) { + (remainder >= divisordeccut || remainder >= + divisor / 2))) && i < maxscale; i++) { remainder = quotient % divisor; quotient /= divisor; } Modified: stable/10/lib/libutil/tests/humanize_number_test.c ============================================================================== --- stable/10/lib/libutil/tests/humanize_number_test.c Tue Jul 3 14:40:19 2018 (r335890) +++ stable/10/lib/libutil/tests/humanize_number_test.c Tue Jul 3 14:57:11 2018 (r335891) @@ -49,333 +49,337 @@ static struct { int64_t num; int flags; int scale; + size_t buflen; } test_args[] = { /* tests 0-13 test 1000 suffixes */ - { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, /* tests 14-27 test 1024 suffixes */ - { 2, "0 ", (int64_t)0L, 0, HN_AUTOSCALE }, - { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, - { 3, "1 G", (int64_t)512*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 2, "1 ", (int64_t)1L, 0, HN_AUTOSCALE }, - { 3, "2 K", (int64_t)1536L, 0, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1536*1024L, 0, HN_AUTOSCALE }, - { 3, "2 G", (int64_t)1536*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 2, "0 ", (int64_t)0L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 2, "1 ", (int64_t)1L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 K", (int64_t)1536L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1536*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, /* tests 28-37 test rounding */ - { 3, "0 M", (int64_t)500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)1000*1000L + 500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1000*1000L + 500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "0 K", (int64_t)512L-1, 0, HN_AUTOSCALE }, - { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, - { 3, "0 M", (int64_t)512*1024L-1, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)1024*1024L + 512*1024L-1, 0, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1024*1024L + 512*1024L, 0, HN_AUTOSCALE }, + { 3, "0 M", (int64_t)500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)1000*1000L + 500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1000*1000L + 500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "0 K", (int64_t)512L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE, 4 }, + { 3, "0 M", (int64_t)512*1024L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)1024*1024L + 512*1024L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1024*1024L + 512*1024L, 0, HN_AUTOSCALE, 4 }, /* tests 38-61 test specific scale factors with 1000 divisor */ - { 3, "0 k", (int64_t)0L, HN_DIVISOR_1000, 1 }, - { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, 1 }, - { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, 2 }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, 2 }, - { 3, "0 G", (int64_t)500*1000L, HN_DIVISOR_1000, 3 }, - { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 3 }, - { 3, "0 T", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "0 P", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "0 E", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "0 k", (int64_t)1L, HN_DIVISOR_1000, 1 }, - { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, 1 }, - { 3, "0 M", (int64_t)1500L, HN_DIVISOR_1000, 2 }, - { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, 2 }, - { 3, "0 G", (int64_t)1500*1000L, HN_DIVISOR_1000, 3 }, - { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 3 }, - { 3, "0 T", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "0 P", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "0 E", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 3, "0 k", (int64_t)0L, HN_DIVISOR_1000, 1, 4 }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, 1, 4 }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, 2, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, 2, 4 }, + { 3, "0 G", (int64_t)500*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "0 T", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "0 P", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "0 E", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "0 k", (int64_t)1L, HN_DIVISOR_1000, 1, 4 }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, 1, 4 }, + { 3, "0 M", (int64_t)1500L, HN_DIVISOR_1000, 2, 4 }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, 2, 4 }, + { 3, "0 G", (int64_t)1500*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "0 T", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "0 P", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "0 E", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, /* tests 62-85 test specific scale factors with 1024 divisor */ - { 3, "0 K", (int64_t)0L, 0, 1 }, - { 3, "1 K", (int64_t)512L, 0, 1 }, - { 3, "0 M", (int64_t)512L, 0, 2 }, - { 3, "1 M", (int64_t)512*1024L, 0, 2 }, - { 3, "0 G", (int64_t)512*1024L, 0, 3 }, - { 3, "1 G", (int64_t)512*1024*1024L, 0, 3 }, - { 3, "0 T", (int64_t)512*1024*1024L, 0, 4 }, - { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, 4 }, - { 3, "0 P", (int64_t)512*1024*1024*1024L, 0, 5 }, - { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, 5 }, - { 3, "0 E", (int64_t)512*1024*1024*1024*1024L, 0, 6 }, - { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 K", (int64_t)1L, 0, 1 }, - { 3, "2 K", (int64_t)1536L, 0, 1 }, - { 3, "0 M", (int64_t)1536L, 0, 2 }, - { 3, "2 M", (int64_t)1536*1024L, 0, 2 }, - { 3, "0 G", (int64_t)1536*1024L, 0, 3 }, - { 3, "2 G", (int64_t)1536*1024*1024L, 0, 3 }, - { 3, "0 T", (int64_t)1536*1024*1024L, 0, 4 }, - { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, 4 }, - { 3, "0 P", (int64_t)1536*1024*1024*1024L, 0, 5 }, - { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, 5 }, - { 3, "0 E", (int64_t)1536*1024*1024*1024*1024L, 0, 6 }, - { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 K", (int64_t)0L, 0, 1, 4 }, + { 3, "1 K", (int64_t)512L, 0, 1, 4 }, + { 3, "0 M", (int64_t)512L, 0, 2, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, 2, 4 }, + { 3, "0 G", (int64_t)512*1024L, 0, 3, 4 }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, 3, 4 }, + { 3, "0 T", (int64_t)512*1024*1024L, 0, 4, 4 }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, 4, 4 }, + { 3, "0 P", (int64_t)512*1024*1024*1024L, 0, 5, 4 }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, 5, 4 }, + { 3, "0 E", (int64_t)512*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "0 K", (int64_t)1L, 0, 1, 4 }, + { 3, "2 K", (int64_t)1536L, 0, 1, 4 }, + { 3, "0 M", (int64_t)1536L, 0, 2, 4 }, + { 3, "2 M", (int64_t)1536*1024L, 0, 2, 4 }, + { 3, "0 G", (int64_t)1536*1024L, 0, 3, 4 }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, 3, 4 }, + { 3, "0 T", (int64_t)1536*1024*1024L, 0, 4, 4 }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, 4, 4 }, + { 3, "0 P", (int64_t)1536*1024*1024*1024L, 0, 5, 4 }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, 5, 4 }, + { 3, "0 E", (int64_t)1536*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, 6, 4 }, /* tests 86-99 test invalid specific scale values of < 0 or >= 7 with and without HN_DIVISOR_1000 set */ /* all should return errors with new code; with old, the latter 3 are instead processed as if having AUTOSCALE and/or GETSCALE set */ - { -1, "", (int64_t)1L, 0, 7 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, 7 }, - { -1, "", (int64_t)1L, 0, 1000 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, 1000 }, - { -1, "", (int64_t)0L, 0, 1000*1000 }, - { -1, "", (int64_t)0L, HN_DIVISOR_1000, 1000*1000 }, - { -1, "", (int64_t)0L, 0, INT_MAX }, - { -1, "", (int64_t)0L, HN_DIVISOR_1000, INT_MAX }, + { -1, "", (int64_t)1L, 0, 7, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 7, 4 }, + { -1, "", (int64_t)1L, 0, 1000, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 1000, 4 }, + { -1, "", (int64_t)0L, 0, 1000*1000, 4 }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, 1000*1000, 4 }, + { -1, "", (int64_t)0L, 0, INT_MAX, 4 }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, INT_MAX, 4 }, /* Negative scale values are not handled well by the existing library routine - should report as error */ /* all should return errors with new code, fail assertion with old */ - { -1, "", (int64_t)1L, 0, -1 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1 }, - { -1, "", (int64_t)1L, 0, -1000 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1000 }, + { -1, "", (int64_t)1L, 0, -1, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1, 4 }, + { -1, "", (int64_t)1L, 0, -1000, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1000, 4 }, /* __INT_MIN doesn't print properly, skipped. */ - { -1, "", (int64_t)1L, 0, -__INT_MAX }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -__INT_MAX }, + { -1, "", (int64_t)1L, 0, -__INT_MAX, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -__INT_MAX, 4 }, /* tests for scale == 0, without autoscale */ /* tests 100-114 test scale 0 with 1000 divisor - print first N digits */ - { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, 0 }, - { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, 0 }, - { 3, "10 ", (int64_t)10L, HN_DIVISOR_1000, 0 }, - { 3, "0 M", (int64_t)150L, HN_DIVISOR_1000, HN_NOSPACE }, - { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, HN_NOSPACE }, - { 3, "0 M", (int64_t)999L, HN_DIVISOR_1000, HN_NOSPACE }, - { 4, "150", (int64_t)150L, HN_DIVISOR_1000, 0 }, - { 4, "500", (int64_t)500L, HN_DIVISOR_1000, 0 }, - { 4, "999", (int64_t)999L, HN_DIVISOR_1000, 0 }, - { 5, "100", (int64_t)1000L, HN_DIVISOR_1000, 0 }, - { 5, "150", (int64_t)1500L, HN_DIVISOR_1000, 0 }, - { 7, "500", (int64_t)500*1000L, HN_DIVISOR_1000, 0 }, - { 8, "150", (int64_t)1500*1000L, HN_DIVISOR_1000, 0 }, - { 10, "500", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 0 }, - { 11, "150", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 0 }, + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, 0, 4 }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, 0, 4 }, + { 3, "10 ", (int64_t)10L, HN_DIVISOR_1000, 0, 4 }, + { 3, "0 M", (int64_t)150L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 3, "0 M", (int64_t)999L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 4, "150", (int64_t)150L, HN_DIVISOR_1000, 0, 4 }, + { 4, "500", (int64_t)500L, HN_DIVISOR_1000, 0, 4 }, + { 4, "999", (int64_t)999L, HN_DIVISOR_1000, 0, 4 }, + { 5, "100", (int64_t)1000L, HN_DIVISOR_1000, 0, 4 }, + { 5, "150", (int64_t)1500L, HN_DIVISOR_1000, 0, 4 }, + { 7, "500", (int64_t)500*1000L, HN_DIVISOR_1000, 0, 4 }, + { 8, "150", (int64_t)1500*1000L, HN_DIVISOR_1000, 0, 4 }, + { 10, "500", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 0, 4 }, + { 11, "150", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 0, 4 }, /* tests 115-126 test scale 0 with 1024 divisor - print first N digits */ - { 2, "0 ", (int64_t)0L, 0, 0 }, - { 2, "1 ", (int64_t)1L, 0, 0 }, - { 3, "10 ", (int64_t)10L, 0, 0 }, - { 4, "150", (int64_t)150L, 0, 0 }, - { 4, "500", (int64_t)500L, 0, 0 }, - { 4, "999", (int64_t)999L, 0, 0 }, - { 5, "100", (int64_t)1000L, 0, 0 }, - { 5, "150", (int64_t)1500L, 0, 0 }, - { 7, "500", (int64_t)500*1000L, 0, 0 }, - { 8, "150", (int64_t)1500*1000L, 0, 0 }, - { 10, "500", (int64_t)500*1000*1000L, 0, 0 }, - { 11, "150", (int64_t)1500*1000*1000L, 0, 0 }, + { 2, "0 ", (int64_t)0L, 0, 0, 4 }, + { 2, "1 ", (int64_t)1L, 0, 0, 4 }, + { 3, "10 ", (int64_t)10L, 0, 0, 4 }, + { 4, "150", (int64_t)150L, 0, 0, 4 }, + { 4, "500", (int64_t)500L, 0, 0, 4 }, + { 4, "999", (int64_t)999L, 0, 0, 4 }, + { 5, "100", (int64_t)1000L, 0, 0, 4 }, + { 5, "150", (int64_t)1500L, 0, 0, 4 }, + { 7, "500", (int64_t)500*1000L, 0, 0, 4 }, + { 8, "150", (int64_t)1500*1000L, 0, 0, 4 }, + { 10, "500", (int64_t)500*1000*1000L, 0, 0, 4 }, + { 11, "150", (int64_t)1500*1000*1000L, 0, 0, 4 }, + /* Test case for rounding of edge numbers around 999.5+, see PR224498. + * Require buflen >= 5 */ + { 4, "1.0M", (int64_t)1023500, HN_DECIMAL|HN_B|HN_NOSPACE, HN_AUTOSCALE, 5 }, + /* Test boundary cases for very large positive/negative number formatting */ /* Explicit scale, divisor 1024 */ - /* XXX = requires length 5 (buflen 6) for some cases*/ - /* KLUDGE - test loop below will bump length 5 up to 5 */ - { 3, "8 E", INT64_MAX, 0, 6 }, - { 4, "-8 E", -INT64_MAX, 0, 6 }, - { 3, "0 E", (int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", (int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, - { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, - { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, - { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, + /* Requires buflen >= 6 */ + { 3, "8 E", INT64_MAX, 0, 6, 6 }, + { 4, "-8 E", -INT64_MAX, 0, 6, 6 }, + { 3, "0 E", (int64_t)92*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", (int64_t)81*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 5, 6 }, /* Explicit scale, divisor 1000 */ - { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, 6 }, - { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, 6, 6 }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, /* Autoscale, divisor 1024 */ - { 3, "8 E", INT64_MAX, 0, HN_AUTOSCALE }, - { 4, "-8 E", -INT64_MAX, 0, HN_AUTOSCALE }, - { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "8 E", INT64_MAX, 0, HN_AUTOSCALE, 6 }, + { 4, "-8 E", -INT64_MAX, 0, HN_AUTOSCALE, 6 }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, /* Autoscale, divisor 1000 */ - { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, /* 0 scale, divisor 1024 */ - { 12, "skdj", INT64_MAX, 0, 0 }, - { 21, "-9223", -INT64_MAX, 0, 0 }, - { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, - { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, - { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, - { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, - { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, - { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, + { 12, "skdj", INT64_MAX, 0, 0, 6 }, + { 21, "-9223", -INT64_MAX, 0, 0, 6 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 0, 6 }, /* 0 scale, divisor 1000 */ /* XXX - why does this fail? */ - { -1, "", INT64_MAX, HN_DIVISOR_1000, 0 }, - { 21, "-9223", -INT64_MAX, HN_DIVISOR_1000, 0 }, - { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { -1, "", INT64_MAX, HN_DIVISOR_1000, 0, 6 }, + { 21, "-9223", -INT64_MAX, HN_DIVISOR_1000, 0, 6 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, /* Expected to pass */ - { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, /* Need to implement tests for GETSCALE */ -/* { ?, "", (int64_t)0L, HN_DIVISOR_1000, HN_GETSCALE }, +/* { ?, "", (int64_t)0L, HN_DIVISOR_1000, HN_GETSCALE, 6 }, ... */ /* Tests for HN_DECIMAL */ /* Positive, Autoscale */ - { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "994 k", (int64_t)994*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "995 k", (int64_t)995*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "994 M", (int64_t)994*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "995 M", (int64_t)995*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "994 k", (int64_t)994*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "995 k", (int64_t)995*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "994 M", (int64_t)994*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "995 M", (int64_t)995*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 5, "500 K", (int64_t)500*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "994 K", (int64_t)994*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "995 K", (int64_t)995*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "999 K", (int64_t)999*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1000*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1018*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1019*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.5 M", (int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.9 M", (int64_t)1996*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)1997*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2047*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2048*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2099*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.1 M", (int64_t)2100*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "9.9 M", (int64_t)10188*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "500 K", (int64_t)500*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "994 K", (int64_t)994*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "995 K", (int64_t)995*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "999 K", (int64_t)999*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1000*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1018*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1019*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.5 M", (int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.9 M", (int64_t)1996*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)1997*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2047*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2048*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2099*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.1 M", (int64_t)2100*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "9.9 M", (int64_t)10188*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* XXX - shouldn't the following two be "10. M"? */ - { 4, "10 M", (int64_t)10189*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 4, "10 M", (int64_t)10240*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "500 M", (int64_t)500*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "994 M", (int64_t)994*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "995 M", (int64_t)995*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "999 M", (int64_t)999*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 G", (int64_t)1000*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 G", (int64_t)1023*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 4, "10 M", (int64_t)10189*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 4, "10 M", (int64_t)10240*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "500 M", (int64_t)500*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "994 M", (int64_t)994*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "995 M", (int64_t)995*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "999 M", (int64_t)999*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 G", (int64_t)1000*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 G", (int64_t)1023*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Negative, Autoscale - should pass */ - { 6, "-1.5 ", -(int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-1.9 ", -(int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-9.9 ", -(int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-1.5 ", -(int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-1.9 ", -(int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-9.9 ", -(int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 6, "-1.5 ", -(int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-1.9 ", -(int64_t)1949*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-9.7 ", -(int64_t)9949*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-1.5 ", -(int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-1.9 ", -(int64_t)1949*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-9.7 ", -(int64_t)9949*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Positive/negative, at maximum scale */ - { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, /* Negatives work with latest rev only: */ - { 6, "-9.2 ", -INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-8.9 ", -(int64_t)8949*1000*1000*1000*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-9.2 ", -INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-8.9 ", -(int64_t)8949*1000*1000*1000*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 5, "8.0 E", INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "7.9 E", INT64_MAX-(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-8.0 ", -INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-7.9 ", -INT64_MAX+(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "8.0 E", INT64_MAX, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "7.9 E", INT64_MAX-(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-8.0 ", -INT64_MAX, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-7.9 ", -INT64_MAX+(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Positive, Fixed scales */ - { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "0.5 M", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "949 k", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "0.9 M", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "950 k", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "1.0 M", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "1.0 M", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "0.5 G", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, - { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.0 G", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "0.5 M", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "949 k", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "0.9 M", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "950 k", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "1.0 M", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "1.0 M", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "0.5 G", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3, 6 }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.0 G", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3, 6 }, /* Positive/negative, at maximum scale */ - { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 5, "1.0 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, 6 }, + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 6 }, + { 5, "1.0 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, 6, 6 }, /* HN_DECIMAL + binary + fixed scale cases not completed */ - { 5, "512 K", (int64_t)512*1024L, HN_DECIMAL, 1 }, - { 5, "0.5 M", (int64_t)512*1024L, HN_DECIMAL, 2 }, + { 5, "512 K", (int64_t)512*1024L, HN_DECIMAL, 1, 6 }, + { 5, "0.5 M", (int64_t)512*1024L, HN_DECIMAL, 2, 6 }, /* Negative, Fixed scales */ /* Not yet added, but should work with latest rev */ @@ -439,9 +443,9 @@ static struct { } flags[] = { { HN_AUTOSCALE, "HN_AUTOSCALE" }, { HN_GETSCALE, "HN_GETSCALE" }, - { HN_DIVISOR_1000, "HN_DIVISOR_1000"}, - { HN_B, "HN_B"}, - { HN_DECIMAL, "HN_DECIMAL"}, + { HN_DIVISOR_1000, "HN_DIVISOR_1000" }, + { HN_B, "HN_B" }, + { HN_DECIMAL, "HN_DECIMAL" }, }; static const char *separator = "|"; @@ -496,13 +500,14 @@ main(int argc, char * const argv[]) { char *buf; char *flag_str, *scale_str; - size_t buflen, errcnt, i, skipped, tested; + size_t blen, buflen, errcnt, i, skipped, tested; int r; int includeNegScale; int includeExabyteTests; int verbose; - buflen = 4; + buf = NULL; + buflen = 0; includeNegScale = 0; includeExabyteTests = 0; verbose = 0; @@ -510,7 +515,6 @@ main(int argc, char * const argv[]) read_options(argc, argv, &buflen, &includeNegScale, &includeExabyteTests, &verbose); - buf = malloc(buflen); errcnt = 0; tested = 0; skipped = 0; @@ -520,16 +524,8 @@ main(int argc, char * const argv[]) printf("1..%zu\n", nitems(test_args)); for (i = 0; i < nitems(test_args); i++) { - /* KLUDGE */ - if (test_args[i].num == INT64_MAX && buflen == 4) { - /* Start final tests which require buffer of 6 */ - free(buf); - buflen = 6; - buf = malloc(buflen); - if (verbose) - printf("Buffer length increased to %zu\n", - buflen); - } + blen = (buflen > 0) ? buflen : test_args[i].buflen; + buf = realloc(buf, blen); if (test_args[i].scale < 0 && ! includeNegScale) { skipped++; @@ -542,7 +538,7 @@ main(int argc, char * const argv[]) continue; } - r = humanize_number(buf, buflen, test_args[i].num, "", + r = humanize_number(buf, blen, test_args[i].num, "", test_args[i].scale, test_args[i].flags); flag_str = str_flags(test_args[i].flags, "[no flags]"); scale_str = str_scale(test_args[i].scale); @@ -553,7 +549,7 @@ main(int argc, char * const argv[]) "buflen: %zu, got: %d + \"%s\", " "expected %d + \"%s\"; num = %jd, " "scale = %s, flags= %s.\n", - i, buflen, r, buf, test_args[i].retval, + i, blen, r, buf, test_args[i].retval, test_args[i].res, (intmax_t)test_args[i].num, scale_str, flag_str); @@ -565,10 +561,10 @@ main(int argc, char * const argv[]) if (verbose) printf("result mismatch on index %zu, got: " "\"%s\", expected \"%s\"; num = %jd, " - "scale = %s, flags= %s.\n", + "buflen: %zu, scale = %s, flags= %s.\n", i, buf, test_args[i].res, (intmax_t)test_args[i].num, - scale_str, flag_str); + blen, scale_str, flag_str); else printf("not ok %zu # buf \"%s\" != \"%s\"\n", i + 1, buf, test_args[i].res); @@ -577,15 +573,15 @@ main(int argc, char * const argv[]) if (verbose) printf("successful result on index %zu, " "returned %d, got: \"%s\"; num = %jd, " - "scale = %s, flags= %s.\n", - i, r, buf, - (intmax_t)test_args[i].num, - scale_str, flag_str); + "buflen = %zd, scale = %s, flags= %s.\n", + i, r, buf, (intmax_t)test_args[i].num, + blen, scale_str, flag_str); else printf("ok %zu\n", i + 1); } tested++; } + free(buf); if (verbose) printf("total errors: %zu/%zu tests, %zu skipped\n", errcnt, From owner-svn-src-stable-10@freebsd.org Tue Jul 3 22:11:17 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9B331102D3A5; Tue, 3 Jul 2018 22:11:17 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BF0F73684; Tue, 3 Jul 2018 22:11:17 +0000 (UTC) (envelope-from dteske@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2E49022057; Tue, 3 Jul 2018 22:11:17 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w63MBH6l033493; Tue, 3 Jul 2018 22:11:17 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w63MBH6x033492; Tue, 3 Jul 2018 22:11:17 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201807032211.w63MBH6x033492@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Tue, 3 Jul 2018 22:11:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335914 - stable/10/usr.sbin/bsdinstall/distfetch X-SVN-Group: stable-10 X-SVN-Commit-Author: dteske X-SVN-Commit-Paths: stable/10/usr.sbin/bsdinstall/distfetch X-SVN-Commit-Revision: 335914 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 22:11:17 -0000 Author: dteske Date: Tue Jul 3 22:11:16 2018 New Revision: 335914 URL: https://svnweb.freebsd.org/changeset/base/335914 Log: MFC SVN r290340: Fix typo in error message Submitted by: git_johnko.ca (John Ko) Sponsored by: Smule, Inc. Differential Revision: https://reviews.freebsd.org/D3997 Modified: stable/10/usr.sbin/bsdinstall/distfetch/distfetch.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/bsdinstall/distfetch/distfetch.c ============================================================================== --- stable/10/usr.sbin/bsdinstall/distfetch/distfetch.c Tue Jul 3 22:03:28 2018 (r335913) +++ stable/10/usr.sbin/bsdinstall/distfetch/distfetch.c Tue Jul 3 22:11:16 2018 (r335914) @@ -78,7 +78,7 @@ main(void) if (chdir(getenv("BSDINSTALL_DISTDIR")) != 0) { snprintf(error, sizeof(error), - "Could could change to directory %s: %s\n", + "Could not change to directory %s: %s\n", getenv("BSDINSTALL_DISTDIR"), strerror(errno)); dialog_msgbox("Error", error, 0, 0, TRUE); end_dialog(); From owner-svn-src-stable-10@freebsd.org Wed Jul 4 03:24:12 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 462DB102710F; Wed, 4 Jul 2018 03:24:12 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DFCDC81CA0; Wed, 4 Jul 2018 03:24:11 +0000 (UTC) (envelope-from dteske@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C101B2546C; Wed, 4 Jul 2018 03:24:11 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w643OBSq096825; Wed, 4 Jul 2018 03:24:11 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w643OBd7096824; Wed, 4 Jul 2018 03:24:11 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201807040324.w643OBd7096824@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Wed, 4 Jul 2018 03:24:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335927 - stable/10 X-SVN-Group: stable-10 X-SVN-Commit-Author: dteske X-SVN-Commit-Paths: stable/10 X-SVN-Commit-Revision: 335927 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 03:24:12 -0000 Author: dteske Date: Wed Jul 4 03:24:11 2018 New Revision: 335927 URL: https://svnweb.freebsd.org/changeset/base/335927 Log: MFC SVN r335750: Fix typo in top-level Makefile Submitted by: Ben Widawsky Sponsored by: Smule, Inc. Differential Revision: https://reviews.freebsd.org/P186 Modified: stable/10/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/Makefile ============================================================================== --- stable/10/Makefile Wed Jul 4 03:22:44 2018 (r335926) +++ stable/10/Makefile Wed Jul 4 03:24:11 2018 (r335927) @@ -144,7 +144,7 @@ _MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAK # We often need to use the tree's version of make to build it. # Choices add to complexity though. # We cannot blindly use a make which may not be the one we want -# so be exlicit - until all choice is removed. +# so be explicit - until all choice is removed. .if !defined(WITHOUT_BMAKE) WANT_MAKE= bmake .else From owner-svn-src-stable-10@freebsd.org Wed Jul 4 14:10:37 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4829F103A97D; Wed, 4 Jul 2018 14:10:37 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EE0AF7D434; Wed, 4 Jul 2018 14:10:36 +0000 (UTC) (envelope-from ian@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B56F942E6; Wed, 4 Jul 2018 14:10:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w64EAaZ6024274; Wed, 4 Jul 2018 14:10:36 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64EAar3024273; Wed, 4 Jul 2018 14:10:36 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201807041410.w64EAar3024273@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 4 Jul 2018 14:10:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335950 - stable/10/etc X-SVN-Group: stable-10 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/10/etc X-SVN-Commit-Revision: 335950 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 14:10:37 -0000 Author: ian Date: Wed Jul 4 14:10:36 2018 New Revision: 335950 URL: https://svnweb.freebsd.org/changeset/base/335950 Log: MFC r335595-r335596 r335595: Modernize usage of "restrict" keyword in ntp.conf It is no longer necessary to specify a -4/-6 flag on any ntp.conf keyword. The address type is inferred from the address itself as necessary. "restrict default" statements always apply to both address families regardless of any -4/-6 flag that may be present. So this change just tidies up our default config by removing the redundant restrict -6 statement and comment, and by removing the -6 flag from the restrict keyword that allows access from localhost. This change was inspired by the patches provided in PRs 201803 and 210245, and included some contrib/ntp code inspection to verify that the -4/-6 keywords are basically no-ops in all contexts now. PR: 201803 210245 Differential Revision: https://reviews.freebsd.org/D15974 r335596: Fix a comment; the ntp leaplist file is updated periodically, but not weekly (it's only updated when a check shows it's within 30 days of expiring). PR: 207138 Modified: stable/10/etc/ntp.conf Directory Properties: stable/10/ (props changed) Modified: stable/10/etc/ntp.conf ============================================================================== --- stable/10/etc/ntp.conf Wed Jul 4 14:04:23 2018 (r335949) +++ stable/10/etc/ntp.conf Wed Jul 4 14:10:36 2018 (r335950) @@ -62,15 +62,13 @@ pool 0.freebsd.pool.ntp.org iburst # See http://support.ntp.org/bin/view/Support/AccessRestrictions # for more information. # -restrict default limited kod nomodify notrap noquery nopeer -restrict -6 default limited kod nomodify notrap noquery nopeer -restrict source limited kod nomodify notrap noquery +restrict default limited kod nomodify notrap noquery nopeer +restrict source limited kod nomodify notrap noquery # # Alternatively, the following rules would block all unauthorized access. # #restrict default ignore -#restrict -6 default ignore # # In this case, all remote NTP time servers also need to be explicitly # allowed or they would not be able to exchange time information with @@ -85,7 +83,7 @@ restrict source limited kod nomodify notrap noquer # # The following settings allow unrestricted access from the localhost restrict 127.0.0.1 -restrict -6 ::1 +restrict ::1 # # If a server loses sync with all upstream servers, NTP clients @@ -101,6 +99,6 @@ restrict -6 ::1 # See http://support.ntp.org/bin/view/Support/ConfiguringNTP#Section_6.14. # for documentation regarding leapfile. Updates to the file can be obtained # from ftp://time.nist.gov/pub/ or ftp://tycho.usno.navy.mil/pub/ntp/. -# Use either leapfile in /etc/ntp or weekly updated leapfile in /var/db. +# Use either leapfile in /etc/ntp or periodically updated leapfile in /var/db. #leapfile "/etc/ntp/leap-seconds" leapfile "/var/db/ntpd.leap-seconds.list" From owner-svn-src-stable-10@freebsd.org Wed Jul 4 14:12:12 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2D886103AC4B; Wed, 4 Jul 2018 14:12:12 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 45DE37D94D; Wed, 4 Jul 2018 14:12:10 +0000 (UTC) (envelope-from ian@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C438A4358; Wed, 4 Jul 2018 14:12:09 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w64EC9lk026062; Wed, 4 Jul 2018 14:12:09 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64EC9jU026061; Wed, 4 Jul 2018 14:12:09 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201807041412.w64EC9jU026061@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 4 Jul 2018 14:12:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335952 - stable/10/etc/rc.d X-SVN-Group: stable-10 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/10/etc/rc.d X-SVN-Commit-Revision: 335952 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 14:12:12 -0000 Author: ian Date: Wed Jul 4 14:12:09 2018 New Revision: 335952 URL: https://svnweb.freebsd.org/changeset/base/335952 Log: MFC r335575, r335786 r335575: Use 'mv -f' in rc.d/ntpd to avoid spuriously halting the boot. The final 'mv' to install a fetched leap-list file can fail (due to a readonly fs, or schg flags, for example), and that leads to mv(1) prompting the user, stopping the boot process. Instead, use mv -f to supress the prompting, and if verbose mode is on, emit a warning that the existing file cannot be replaced. PR: 219255 r335786: Rename variable ntp_tmp_leapfile to have a leading underbar, to distinguish it from variables with similar names which are set in rc.conf. This will make more sense as the script grows more similar-name local variables in some upcoming changes. Modified: stable/10/etc/rc.d/ntpd Directory Properties: stable/10/ (props changed) Modified: stable/10/etc/rc.d/ntpd ============================================================================== --- stable/10/etc/rc.d/ntpd Wed Jul 4 14:11:49 2018 (r335951) +++ stable/10/etc/rc.d/ntpd Wed Jul 4 14:12:09 2018 (r335952) @@ -18,7 +18,7 @@ extra_commands="fetch" fetch_cmd="ntpd_fetch_leapfile" start_precmd="ntpd_precmd" -ntp_tmp_leapfile="/var/run/ntpd.leap-seconds.list" +_ntp_tmp_leapfile="/var/run/ntpd.leap-seconds.list" load_rc_config $name @@ -54,7 +54,7 @@ ntpd_precmd() ( cd /dev ; /bin/pax -rw -pe clockctl "${ntpd_chrootdir}/dev" ) fi ln -fs "${ntpd_chrootdir}/var/db/ntp.drift" /var/db/ntp.drift - ln -fs "${ntpd_chrootdir}${ntp_tmp_leapfile}" ${ntp_tmp_leapfile} + ln -fs "${ntpd_chrootdir}${_ntp_tmp_leapfile}" ${_ntp_tmp_leapfile} # Change run_rc_commands()'s internal copy of $ntpd_flags # @@ -123,15 +123,16 @@ ntpd_fetch_leapfile() { $verbose Within ntp leapfile expiry limit, initiating fetch for url in $ntp_leapfile_sources ; do $verbose fetching $url - fetch $ntp_leapfile_fetch_opts -o $ntp_tmp_leapfile $url && break + fetch $ntp_leapfile_fetch_opts -o $_ntp_tmp_leapfile $url && break done - ntp_ver_no_tmp=$(get_ntp_leapfile_ver $ntp_tmp_leapfile) - ntp_expiry_tmp=$(get_ntp_leapfile_expiry $ntp_tmp_leapfile) + ntp_ver_no_tmp=$(get_ntp_leapfile_ver $_ntp_tmp_leapfile) + ntp_expiry_tmp=$(get_ntp_leapfile_expiry $_ntp_tmp_leapfile) if [ "$ntp_expiry_tmp" -gt "$ntp_expiry_db" -o \ "$ntp_expiry_tmp" -eq "$ntp_expiry_db" -a \ "$ntp_ver_no_tmp" -gt "$ntp_ver_no_db" ]; then $verbose using $url as $ntp_db_leapfile - mv $ntp_tmp_leapfile $ntp_db_leapfile + mv -f $_ntp_tmp_leapfile $ntp_db_leapfile || + $verbose "warning: cannot replace $ntp_db_leapfile (read-only fs?)" else $verbose using existing $ntp_db_leapfile fi From owner-svn-src-stable-10@freebsd.org Wed Jul 4 18:03:20 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C8099102AC22; Wed, 4 Jul 2018 18:03:20 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 793C48B2DD; Wed, 4 Jul 2018 18:03:20 +0000 (UTC) (envelope-from emaste@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5A02569FC; Wed, 4 Jul 2018 18:03:20 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w64I3Kr0049630; Wed, 4 Jul 2018 18:03:20 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64I3KvR049629; Wed, 4 Jul 2018 18:03:20 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201807041803.w64I3KvR049629@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Wed, 4 Jul 2018 18:03:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r335965 - stable/10/lib/libutil/tests X-SVN-Group: stable-10 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/10/lib/libutil/tests X-SVN-Commit-Revision: 335965 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 18:03:21 -0000 Author: emaste Date: Wed Jul 4 18:03:19 2018 New Revision: 335965 URL: https://svnweb.freebsd.org/changeset/base/335965 Log: MFC r306098 (br): Use kqueue(2) instead of select(2). This helps to ensure we will not lose SIGINT sent by parent to child. PR: 212562, 228492 Modified: stable/10/lib/libutil/tests/pidfile_test.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libutil/tests/pidfile_test.c ============================================================================== --- stable/10/lib/libutil/tests/pidfile_test.c Wed Jul 4 18:01:53 2018 (r335964) +++ stable/10/lib/libutil/tests/pidfile_test.c Wed Jul 4 18:03:19 2018 (r335965) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -43,8 +44,8 @@ __FBSDID("$FreeBSD$"); #include /* - * We need a signal handler so kill(2) will interrupt our child's - * select(2) instead of killing it. + * We need a signal handler so kill(2) will interrupt the child + * instead of killing it. */ static void signal_handler(int sig) @@ -129,7 +130,9 @@ common_test_pidfile_child(const char *fn, int parent_o struct pidfh *pf = NULL; pid_t other = 0, pid = 0; int fd[2], serrno, status; + struct kevent event, ke; char ch; + int kq; unlink(fn); if (pipe(fd) != 0) @@ -166,10 +169,20 @@ common_test_pidfile_child(const char *fn, int parent_o if (pf == NULL) _exit(1); if (pidfile_write(pf) != 0) - _exit(1); + _exit(2); + kq = kqueue(); + if (kq == -1) + _exit(3); + EV_SET(&ke, SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); + /* Attach event to the kqueue. */ + if (kevent(kq, &ke, 1, NULL, 0, NULL) != 0) + _exit(4); + /* Inform the parent we are ready to receive SIGINT */ if (write(fd[1], "*", 1) != 1) - _exit(1); - select(0, 0, 0, 0, 0); + _exit(5); + /* Wait for SIGINT received */ + if (kevent(kq, NULL, 0, &event, 1, NULL) != 1) + _exit(6); _exit(0); } // parent From owner-svn-src-stable-10@freebsd.org Fri Jul 6 19:10:10 2018 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 548741046742; Fri, 6 Jul 2018 19:10:10 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0490F91A5B; Fri, 6 Jul 2018 19:10:10 +0000 (UTC) (envelope-from jamie@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D5BAC4D43; Fri, 6 Jul 2018 19:10:09 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w66JA9w4060714; Fri, 6 Jul 2018 19:10:09 GMT (envelope-from jamie@FreeBSD.org) Received: (from jamie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w66JA7Qb060702; Fri, 6 Jul 2018 19:10:07 GMT (envelope-from jamie@FreeBSD.org) Message-Id: <201807061910.w66JA7Qb060702@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jamie set sender to jamie@FreeBSD.org using -f From: Jamie Gritton Date: Fri, 6 Jul 2018 19:10:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r336039 - in stable/10: lib/libugidfw sbin/ipfw usr.bin/cpuset usr.bin/sockstat X-SVN-Group: stable-10 X-SVN-Commit-Author: jamie X-SVN-Commit-Paths: in stable/10: lib/libugidfw sbin/ipfw usr.bin/cpuset usr.bin/sockstat X-SVN-Commit-Revision: 336039 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jul 2018 19:10:10 -0000 Author: jamie Date: Fri Jul 6 19:10:07 2018 New Revision: 336039 URL: https://svnweb.freebsd.org/changeset/base/336039 Log: MFC r335921: Allow jail names (not just IDs) to be specified for: cpuset(1), ipfw(8), sockstat(1), ugidfw(8) These are the last of the jail-aware userland utilities that didn't work with names. PR: 229266 Differential Revision: D16047 Modified: stable/10/lib/libugidfw/ugidfw.c stable/10/sbin/ipfw/Makefile stable/10/sbin/ipfw/ipfw.8 stable/10/sbin/ipfw/ipfw2.c stable/10/usr.bin/cpuset/Makefile stable/10/usr.bin/cpuset/cpuset.1 stable/10/usr.bin/cpuset/cpuset.c stable/10/usr.bin/sockstat/Makefile stable/10/usr.bin/sockstat/sockstat.1 stable/10/usr.bin/sockstat/sockstat.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libugidfw/ugidfw.c ============================================================================== --- stable/10/lib/libugidfw/ugidfw.c Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/lib/libugidfw/ugidfw.c Fri Jul 6 19:10:07 2018 (r336039) @@ -32,9 +32,11 @@ */ #include #include +#include #include #include #include +#include #include #include @@ -599,16 +601,45 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max } int +bsde_get_jailid(const char *name, size_t buflen, char *errstr) +{ + char *ep; + int jid; + struct iovec jiov[4]; + + /* Copy jail_getid(3) instead of messing with library dependancies */ + jid = strtoul(name, &ep, 10); + if (*name && !*ep) + return jid; + jiov[0].iov_base = __DECONST(char *, "name"); + jiov[0].iov_len = sizeof("name"); + jiov[1].iov_len = strlen(name) + 1; + jiov[1].iov_base = alloca(jiov[1].iov_len); + strcpy(jiov[1].iov_base, name); + if (errstr && buflen) { + jiov[2].iov_base = __DECONST(char *, "errmsg"); + jiov[2].iov_len = sizeof("errmsg"); + jiov[3].iov_base = errstr; + jiov[3].iov_len = buflen; + errstr[0] = 0; + jid = jail_get(jiov, 4, 0); + if (jid < 0 && !errstr[0]) + snprintf(errstr, buflen, "jail_get: %s", + strerror(errno)); + } else + jid = jail_get(jiov, 2, 0); + return jid; +} + +static int bsde_parse_subject(int argc, char *argv[], struct mac_bsdextended_subject *subject, size_t buflen, char *errstr) { int not_seen, flags; int current, neg, nextnot; - char *endp; uid_t uid_min, uid_max; gid_t gid_min, gid_max; int jid; - long value; current = 0; flags = 0; @@ -667,13 +698,9 @@ bsde_parse_subject(int argc, char *argv[], snprintf(errstr, buflen, "one jail only"); return (-1); } - value = strtol(argv[current+1], &endp, 10); - if (*endp != '\0') { - snprintf(errstr, buflen, "invalid jid: '%s'", - argv[current+1]); + jid = bsde_get_jailid(argv[current+1], buflen, errstr); + if (jid < 0) return (-1); - } - jid = value; flags |= MBS_PRISON_DEFINED; if (nextnot) { neg ^= MBS_PRISON_DEFINED; Modified: stable/10/sbin/ipfw/Makefile ============================================================================== --- stable/10/sbin/ipfw/Makefile Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/sbin/ipfw/Makefile Fri Jul 6 19:10:07 2018 (r336039) @@ -11,8 +11,8 @@ SRCS+= altq.c CFLAGS+=-DPF .endif -DPADD= ${LIBUTIL} -LDADD= -lutil +DPADD= ${LIBJAIL} ${LIBUTIL} +LDADD= -ljail -lutil MAN= ipfw.8 .include Modified: stable/10/sbin/ipfw/ipfw.8 ============================================================================== --- stable/10/sbin/ipfw/ipfw.8 Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/sbin/ipfw/ipfw.8 Fri Jul 6 19:10:07 2018 (r336039) @@ -1,7 +1,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 12, 2018 +.Dd July 3, 2018 .Dt IPFW 8 .Os .Sh NAME @@ -1377,10 +1377,10 @@ Matches all TCP or UDP packets sent by or received for A .Ar group may be specified by name or number. -.It Cm jail Ar prisonID +.It Cm jail Ar jail Matches all TCP or UDP packets sent by or received for the -jail whos prison ID is -.Ar prisonID . +jail whose ID or name is +.Ar jail . .It Cm icmptypes Ar types Matches ICMP packets whose ICMP type is in the list .Ar types . Modified: stable/10/sbin/ipfw/ipfw2.c ============================================================================== --- stable/10/sbin/ipfw/ipfw2.c Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/sbin/ipfw/ipfw2.c Fri Jul 6 19:10:07 2018 (r336039) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -3653,13 +3654,12 @@ read_options: case TOK_JAIL: NEED1("jail requires argument"); { - char *end; int jid; cmd->opcode = O_JAIL; - jid = (int)strtol(*av, &end, 0); - if (jid < 0 || *end != '\0') - errx(EX_DATAERR, "jail requires prison ID"); + jid = jail_getid(*av); + if (jid < 0) + errx(EX_DATAERR, "%s", jail_errmsg); cmd32->d[0] = (uint32_t)jid; cmd->len |= F_INSN_SIZE(ipfw_insn_u32); av++; Modified: stable/10/usr.bin/cpuset/Makefile ============================================================================== --- stable/10/usr.bin/cpuset/Makefile Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/cpuset/Makefile Fri Jul 6 19:10:07 2018 (r336039) @@ -2,4 +2,7 @@ PROG= cpuset +DPADD= ${LIBJAIL} +LDADD= -ljail + .include Modified: stable/10/usr.bin/cpuset/cpuset.1 ============================================================================== --- stable/10/usr.bin/cpuset/cpuset.1 Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/cpuset/cpuset.1 Fri Jul 6 19:10:07 2018 (r336039) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 14, 2011 +.Dd July 3, 2018 .Dt CPUSET 1 .Os .Sh NAME @@ -48,10 +48,10 @@ .Nm .Op Fl cr .Op Fl l Ar cpu-list -.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq +.Op Fl j Ar jail | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq .Nm .Op Fl cgir -.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq +.Op Fl j Ar jail | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq .Sh DESCRIPTION The .Nm @@ -62,7 +62,7 @@ about processor binding, sets, and available processor .Nm requires a target to modify or query. The target may be specified as a command, process id, thread id, a -cpuset id, an irq or a jail id. +cpuset id, an irq or a jail. Using .Fl g the target's set id or mask may be queried. @@ -118,8 +118,8 @@ the id of the target. When used with the .Fl g option print the id rather than the valid mask of the target. -.It Fl j Ar jailid -Specifies a jail id as the target of the operation. +.It Fl j Ar jail +Specifies a jail id or name as the target of the operation. .It Fl l Ar cpu-list Specifies a list of CPUs to apply to a target. Specification may include Modified: stable/10/usr.bin/cpuset/cpuset.c ============================================================================== --- stable/10/usr.bin/cpuset/cpuset.c Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/cpuset/cpuset.c Fri Jul 6 19:10:07 2018 (r336039) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -226,7 +227,9 @@ main(int argc, char *argv[]) case 'j': jflag = 1; which = CPU_WHICH_JAIL; - id = atoi(optarg); + id = jail_getid(optarg); + if (id < 0) + errx(EXIT_FAILURE, "%s", jail_errmsg); break; case 'l': lflag = 1; Modified: stable/10/usr.bin/sockstat/Makefile ============================================================================== --- stable/10/usr.bin/sockstat/Makefile Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/sockstat/Makefile Fri Jul 6 19:10:07 2018 (r336039) @@ -2,4 +2,7 @@ PROG= sockstat +DPADD= ${LIBJAIL} +LDADD= -ljail + .include Modified: stable/10/usr.bin/sockstat/sockstat.1 ============================================================================== --- stable/10/usr.bin/sockstat/sockstat.1 Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/sockstat/sockstat.1 Fri Jul 6 19:10:07 2018 (r336039) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 27, 2015 +.Dd July 3, 2018 .Dt SOCKSTAT 1 .Os .Sh NAME @@ -58,8 +58,8 @@ Show (IPv6) sockets. .It Fl c Show connected sockets. -.It Fl j Ar jid -Show only sockets belonging to the specified jail ID. +.It Fl j Ar jail +Show only sockets belonging to the specified jail ID or name. .It Fl L Only show Internet sockets if the local and foreign addresses are not in the loopback network prefix Modified: stable/10/usr.bin/sockstat/sockstat.c ============================================================================== --- stable/10/usr.bin/sockstat/sockstat.c Fri Jul 6 18:50:22 2018 (r336038) +++ stable/10/usr.bin/sockstat/sockstat.c Fri Jul 6 19:10:07 2018 (r336039) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1157,7 +1158,9 @@ main(int argc, char *argv[]) opt_c = 1; break; case 'j': - opt_j = atoi(optarg); + opt_j = jail_getid(optarg); + if (opt_j < 0) + errx(1, "%s", jail_errmsg); break; case 'L': opt_L = 1;