svn commit: r359471 - stable/12/lib/libpmc/pmu-events

Ed Maste emaste at FreeBSD.org
Mon Mar 30 22:04:25 UTC 2020


Author: emaste
Date: Mon Mar 30 22:02:27 2020
New Revision: 359471
URL: https://svnweb.freebsd.org/changeset/base/359471

Log:
  MFC r339880 (arichardson): 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.

Modified:
  stable/12/lib/libpmc/pmu-events/jevents.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libpmc/pmu-events/jevents.c
==============================================================================
--- stable/12/lib/libpmc/pmu-events/jevents.c	Mon Mar 30 22:01:36 2020	(r359470)
+++ stable/12/lib/libpmc/pmu-events/jevents.c	Mon Mar 30 22:02:27 2020	(r359471)
@@ -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;
@@ -861,8 +859,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;
 }
@@ -1123,8 +1124,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 */


More information about the svn-src-all mailing list