From: Mathieu Desnoyers Date: Thu, 18 Dec 2014 01:45:17 +0000 (-0500) Subject: Misleading error handling: utils_create_pid_file() should return 0 on success X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e205d79b4dc22178644fa6f3d0a4eae86df36e73;p=lttng-tools.git Misleading error handling: utils_create_pid_file() should return 0 on success 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 --- 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; }