getdata: posix_fadvise() error checking

Helmut reported run of 'make check' failing in debian pbuilder
environment.  The posix_fadvise() functions were failing with a message
such as

 dhcpd-pools: parse_config: fadvise ../tests/confs/complete: Cannot allocate memory

which to me is likely error in how an error is determined.  Relying on
errno value not being mangled by libc is unreliable.  Attempt to fix this
is simple, check return values of these function calls and ignore the
errno.

Reported-by: Helmut Grohne <h.grohne@cygnusnetworks.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2013-04-21 14:05:59 +01:00
parent 90c1a4e4c5
commit 5966360f12

View file

@ -74,15 +74,13 @@ int parse_leases(void)
}
#ifdef HAVE_POSIX_FADVISE
# ifdef POSIX_FADV_WILLNEED
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED);
if (errno) {
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
}
# endif /* POSIX_FADV_WILLNEED */
# ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL);
if (errno) {
if (posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_leases: fadvise %s",
config.dhcpdlease_file);
}
@ -228,14 +226,12 @@ void parse_config(int is_include, const char *restrict config_file,
err(EXIT_FAILURE, "parse_config: %s", config_file);
}
#ifdef POSIX_FADV_WILLNEED
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_WILLNEED);
if (errno) {
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_WILLNEED) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
#endif /* POSIX_FADV_WILLNEED */
#ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL);
if (errno) {
if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) {
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
}
#endif /* POSIX_FADV_SEQUENTIAL */