Misleading error handling: utils_create_pid_file() should return 0 on success
[lttng-tools.git] / src / common / utils.c
index 365510b3c37de51bacdeafee888b7f87e9776ac5..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;
 }
@@ -514,7 +518,9 @@ int utils_create_lock_file(const char *filepath)
        if (ret) {
                WARN("Could not get lock file %s, another instance is running.",
                        filepath);
-               close(fd);
+               if (close(fd)) {
+                       PERROR("close lock file");
+               }
                fd = ret;
                goto error;
        }
This page took 0.026074 seconds and 4 git commands to generate.