ctdb: Report errors from getline()
authorJo Sutton <josutton@catalyst.net.nz>
Wed, 24 Apr 2024 02:26:20 +0000 (14:26 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 24 Apr 2024 05:16:29 +0000 (05:16 +0000)
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Martin Schwenke <martin@meltin.net>
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';
                }