ctdb: Report errors from getline()
[samba.git] / ctdb / protocol / protocol_util.c
index 797efc895934fabf9ba8562d98b5230fc047ce2d..5e48c1513bc13394e938c476405aee4abf65c694 100644 (file)
@@ -751,7 +751,6 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
        FILE *f = NULL;
        int ret = 0;
        size_t len = 0;
-       ssize_t nread;
 
        if (conn_list == NULL) {
                return EINVAL;
@@ -769,7 +768,16 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
                return errno;
        }
 
-       while ((nread = getline(&line, &len, f)) != -1) {
+       for (;;) {
+               ssize_t nread = getline(&line, &len, f);
+               if (nread == -1) {
+                       if (!feof(f)) {
+                               /* real error */
+                               ret = errno;
+                       }
+                       break;
+               }
+
                if ((nread > 0) && (line[nread-1] == '\n')) {
                        line[nread-1] = '\0';
                }