From owner-svn-src-head@freebsd.org Mon Oct 29 21:08:39 2018 Return-Path: Delivered-To: svn-src-head@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 F2B0710EA253; Mon, 29 Oct 2018 21:08:38 +0000 (UTC) (envelope-from arichardson@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 A4FEB83306; Mon, 29 Oct 2018 21:08:38 +0000 (UTC) (envelope-from arichardson@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 5163E13AEC; Mon, 29 Oct 2018 21:08:35 +0000 (UTC) (envelope-from arichardson@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9TL8ZKJ042162; Mon, 29 Oct 2018 21:08:35 GMT (envelope-from arichardson@FreeBSD.org) Received: (from arichardson@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9TL8ZYw042161; Mon, 29 Oct 2018 21:08:35 GMT (envelope-from arichardson@FreeBSD.org) Message-Id: <201810292108.w9TL8ZYw042161@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arichardson set sender to arichardson@FreeBSD.org using -f From: Alex Richardson Date: Mon, 29 Oct 2018 21:08:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339880 - head/lib/libpmc/pmu-events X-SVN-Group: head X-SVN-Commit-Author: arichardson X-SVN-Commit-Paths: head/lib/libpmc/pmu-events X-SVN-Commit-Revision: 339880 X-SVN-Commit-Repository: base 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.29 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: Mon, 29 Oct 2018 21:08:39 -0000 Author: arichardson Date: Mon Oct 29 21:08:34 2018 New Revision: 339880 URL: https://svnweb.freebsd.org/changeset/base/339880 Log: Fix get_maxfds() in jevents If RLIM_INFINITY == -1ULL (such as on macOS) the min() call will result in a value of less than 1 being returned. This causes nftw() to fail with EINVAL. While touching this file also fix includes to work on Linux/macOS and don't declare snprintf since it may have different attributes in the system headers there. Reviewed By: mmacy Approved By: brooks (mentor) Differential Revision: https://reviews.freebsd.org/D17682 Modified: head/lib/libpmc/pmu-events/jevents.c Modified: head/lib/libpmc/pmu-events/jevents.c ============================================================================== --- head/lib/libpmc/pmu-events/jevents.c Mon Oct 29 21:08:28 2018 (r339879) +++ head/lib/libpmc/pmu-events/jevents.c Mon Oct 29 21:08:34 2018 (r339880) @@ -34,7 +34,7 @@ */ -#include +#include #include #include #include @@ -54,8 +54,6 @@ #include "json.h" #include "jevents.h" -int snprintf(char * __restrict, size_t, const char * __restrict, - ...) __printflike(3, 4); _Noreturn void _Exit(int); int verbose; @@ -859,8 +857,11 @@ static int get_maxfds(void) { struct rlimit rlim; - if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) - return min((int)rlim.rlim_max / 2, 512); + if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { + if (rlim.rlim_max == RLIM_INFINITY) + return 512; + return min((unsigned)rlim.rlim_max / 2, 512); + } return 512; } @@ -1121,8 +1122,8 @@ int main(int argc, char *argv[]) mapfile = NULL; rc = nftw(ldirname, preprocess_arch_std_files, maxfds, 0); if (rc && verbose) { - pr_info("%s: Error preprocessing arch standard files %s\n", - prog, ldirname); + pr_info("%s: Error preprocessing arch standard files %s: %s\n", + prog, ldirname, strerror(errno)); goto empty_map; } else if (rc < 0) { /* Make build fail */