From: Michael Tremer Date: Tue, 21 Oct 2025 15:52:26 +0000 (+0000) Subject: file: Return the error code if we could not read the file X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a77a0e1b164b04252af3702fd8300daeb063996e;p=telemetry.git file: Return the error code if we could not read the file Signed-off-by: Michael Tremer --- diff --git a/src/daemon/file.c b/src/daemon/file.c index 4780e73..514ba02 100644 --- a/src/daemon/file.c +++ b/src/daemon/file.c @@ -179,11 +179,15 @@ int td_file_walk(td_file* self, // Fetch the next line r = getline(&line, &length, self->f); if (r < 0) { - // Reset r if have reached the end of the file + // Break if we have reached the end of the line if (feof(self->f)) - r = 0; + break; + + // Handle errors + if (ferror(self->f)) + r = -errno; - break; + goto ERROR; } // Remove the trailing newline @@ -198,6 +202,9 @@ int td_file_walk(td_file* self, goto ERROR; } + // Success + r = 0; + ERROR: if (line) free(line);