Fix bug in handling errno from lseek()

This commit is contained in:
Andrew Bettison 2013-08-26 17:38:37 +09:30
parent 9c49abd431
commit 1b26917f58

View File

@ -885,14 +885,16 @@ overlay_broadcast_ensemble(struct network_destination *destination,
/* This lseek() is unneccessary because the dummy file is opened in O_APPEND mode. It's /* This lseek() is unneccessary because the dummy file is opened in O_APPEND mode. It's
only purpose is to find out the offset to print in the DEBUG statement. It is vulnerable only purpose is to find out the offset to print in the DEBUG statement. It is vulnerable
to a race condition with other processes appending to the same file. */ to a race condition with other processes appending to the same file. */
off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END); if (config.debug.overlayinterfaces) {
/* Don't complain if the seek fails because we are writing to a pipe or device that does off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END);
not support seeking. */ if (fsize == -1) {
if (errno!=ESPIPE) { /* Don't complain if the seek fails because we are writing to a pipe or device that does
if (fsize == -1) not support seeking. */
return WHY_perror("lseek"); if (errno != ESPIPE)
if (config.debug.overlayinterfaces) return WHY_perror("lseek");
DEBUGF("Write to interface %s at offset=%zu", interface->name, fsize); DEBUGF("Write to interface %s at unknown offset", interface->name);
} else
DEBUGF("Write to interface %s at offset=%llu", interface->name, (long long)fsize);
} }
ssize_t nwrite = write(interface->alarm.poll.fd, &packet, sizeof(packet)); ssize_t nwrite = write(interface->alarm.poll.fd, &packet, sizeof(packet));
if (nwrite == -1) if (nwrite == -1)