# HG changeset patch # User Matt Johnston # Date 1156076173 0 # Node ID 9e2ad10239785f893fa21142b45d556009b0c8d3 # Parent 01e4180895ba1330057d3fb688d8d5303c9b4350 Handle failure reading a file (such as a key file) diff -r 01e4180895ba -r 9e2ad1023978 dbutil.c --- a/dbutil.c Mon Aug 07 13:41:23 2006 +0000 +++ b/dbutil.c Sun Aug 20 12:16:13 2006 +0000 @@ -527,26 +527,36 @@ * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ int buf_readfile(buffer* buf, const char* filename) { - int fd; + int fd = -1; int len; int maxlen; + ret = DROPBEAR_FAILURE; fd = open(filename, O_RDONLY); if (fd < 0) { - close(fd); - return DROPBEAR_FAILURE; + goto out; } do { maxlen = buf->size - buf->pos; - len = read(fd, buf_getwriteptr(buf, maxlen), - maxlen); + len = read(fd, buf_getwriteptr(buf, maxlen), maxlen); + if (len < 0) { + if (errno == EINTR || errno == EAGAIN) { + continue; + } + goto out; + } buf_incrwritepos(buf, len); } while (len < maxlen && len > 0); - close(fd); - return DROPBEAR_SUCCESS; + ret = DROPBEAR_SUCCESS; + +out: + if (fd >= 0) { + m_close(fd); + } + return ret; } /* get a line from the file into buffer in the style expected for an