Date: Mon, 29 Oct 2018 21:08:35 +0000 (UTC) From: Alex Richardson <arichardson@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339880 - head/lib/libpmc/pmu-events Message-ID: <201810292108.w9TL8ZYw042161@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/stddef.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -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 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810292108.w9TL8ZYw042161>