[lttng-dev] [PATCH lttng-tools 06/13] Misleading error handling: utils_create_pid_file() should return 0 on success

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Wed Dec 17 20:45:17 EST 2014


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 <mathieu.desnoyers at efficios.com>
---
 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 e7dccb7..3428d31 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.1.1




More information about the lttng-dev mailing list