From 82224fca78c4de1f9ae8524eb14dd0478641779c Mon Sep 17 00:00:00 2001 From: Jo Sutton Date: Wed, 24 Apr 2024 14:26:20 +1200 Subject: [PATCH] ctdb: Report errors from getline() Signed-off-by: Jo Sutton Reviewed-by: Martin Schwenke --- ctdb/protocol/protocol_util.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 797efc89593..5e48c1513bc 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -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'; } -- 2.34.1