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
This commit is contained in:
Alex Richardson 2018-10-29 21:08:34 +00:00
parent 3ab5b6bd97
commit 2fa224b17d

View File

@ -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 */