From 1b26917f58954a824e3a08b79131a61e90e12028 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 26 Aug 2013 17:38:37 +0930 Subject: [PATCH] Fix bug in handling errno from lseek() --- overlay_interface.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/overlay_interface.c b/overlay_interface.c index 5816c750..fec1288c 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -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 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. */ - off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END); - /* Don't complain if the seek fails because we are writing to a pipe or device that does - not support seeking. */ - if (errno!=ESPIPE) { - if (fsize == -1) - return WHY_perror("lseek"); - if (config.debug.overlayinterfaces) - DEBUGF("Write to interface %s at offset=%zu", interface->name, fsize); + if (config.debug.overlayinterfaces) { + off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END); + if (fsize == -1) { + /* Don't complain if the seek fails because we are writing to a pipe or device that does + not support seeking. */ + if (errno != ESPIPE) + return WHY_perror("lseek"); + 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)); if (nwrite == -1)