From e205d79b4dc22178644fa6f3d0a4eae86df36e73 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 17 Dec 2014 20:45:17 -0500 Subject: [PATCH] Misleading error handling: utils_create_pid_file() should return 0 on success MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit fprintf returns a positive value on success, which is used as return value for utils_create_pid_file(), which is odd. This is in preparation for main() refactoring. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/common/utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/utils.c b/src/common/utils.c index e7dccb7b7..3428d312d 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -477,10 +477,14 @@ int utils_create_pid_file(pid_t pid, const char *filepath) ret = fprintf(fp, "%d\n", pid); if (ret < 0) { PERROR("fprintf pid file"); + goto error; } - fclose(fp); + if (fclose(fp)) { + PERROR("fclose"); + } DBG("Pid %d written in file %s", pid, filepath); + ret = 0; error: return ret; } -- 2.34.1