From: octo Date: Sat, 10 Jun 2006 12:59:43 +0000 (+0000) Subject: apcups branch: Fixed the behavior of `sread'. X-Git-Tag: svn-trunk~3^2~2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ed56e29953fc60756ebfee89423fc72347a41dba;p=collectd.git apcups branch: Fixed the behavior of `sread'. If `sread' receives an EOF it will now close the file descriptor and return an error. Prior to this revision it would try to read again and possibly fail then.. Alternatively it might have crashed, who knows..? ;) --- diff --git a/src/common.c b/src/common.c index 98e67044..5487b326 100644 --- a/src/common.c +++ b/src/common.c @@ -144,6 +144,15 @@ ssize_t sread (int fd, void *buf, size_t count) if (status < 0) return (status); + if (status == 0) + { + DBG ("Received EOF from fd %i. " + "Closing fd and returning error.", + fd); + close (fd); + return (-1); + } + assert (nleft >= status); nleft = nleft - status; diff --git a/src/common.h b/src/common.h index f6a8e19a..2be2ff50 100644 --- a/src/common.h +++ b/src/common.h @@ -43,7 +43,8 @@ void *smalloc(size_t size); * * DESCRIPTION * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous - * to `read(2)'. + * to `read(2)'. If EOF is received the file descriptor is closed and an + * error is returned. * * PARAMETERS * `fd' File descriptor to write to.