From 7eb2e42625a4fa48c1ee13a37f940d3f3ac50620 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 9 Oct 2012 21:52:19 +0100 Subject: [PATCH] build-sys: be conservative about posix_fadvice Check that function availability before use. Signed-off-by: Sami Kerola --- configure.ac | 1 + src/getdata.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 14a753c..e636409 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,7 @@ AC_CHECK_FUNCS([\ inet_ntoa \ memset \ nl_langinfo \ + posix_fadvise \ strdup \ strerror \ strrchr \ diff --git a/src/getdata.c b/src/getdata.c index 0c69fae..0f39af3 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -80,20 +80,22 @@ int parse_leases(void) if (dhcpd_leases == NULL) { err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file); } -#ifdef POSIX_FADV_WILLNEED +#ifdef HAVE_POSIX_FADVISE +# ifdef POSIX_FADV_WILLNEED posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED); if (errno) { err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file); } -#endif /* POSIX_FADV_WILLNEED */ -#ifdef POSIX_FADV_SEQUENTIAL +# endif /* POSIX_FADV_WILLNEED */ +# ifdef POSIX_FADV_SEQUENTIAL posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL); if (errno) { err(EXIT_FAILURE, "parse_leases: fadvise %s", config.dhcpdlease_file); } -#endif /* POSIX_FADV_SEQUENTIAL */ +# endif /* POSIX_FADV_SEQUENTIAL */ +#endif /* HAVE_POSIX_FADVISE */ /* I found out that there's one lease address per 300 bytes in * dhcpd.leases file. Malloc is little bit pessimistic and uses 250.