Misleading error handling: utils_create_pid_file() should return 0 on success
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 18 Dec 2014 01:45:17 +0000 (20:45 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 5 Jan 2015 21:20:35 +0000 (16:20 -0500)
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@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/utils.c

index e7dccb7b7490cb1c1392461304e70ea7cbf5d390..3428d312d6ee8a2c562936284bf86690229be56f 100644 (file)
@@ -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;
 }
This page took 0.031773 seconds and 4 git commands to generate.