add check if pidfile can be opened

Sat, 12 Nov 2022 17:00:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 12 Nov 2022 17:00:16 +0100
changeset 427
a327cb6cc868
parent 426
6a2e7a464991
child 428
ab58e46b50a5

add check if pidfile can be opened

src/server/daemon/webserver.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/webserver.c	Sat Nov 12 16:52:32 2022 +0100
+++ b/src/server/daemon/webserver.c	Sat Nov 12 17:00:16 2022 +0100
@@ -205,7 +205,11 @@
 
     char *pid_file_path = NULL;
     asprintf(&pid_file_path, "%s/pid", cfg->tmp.ptr);
-    FILE *pidfile = fopen(pid_file_path, "w"); // TODO: check error
+    FILE *pidfile = fopen(pid_file_path, "w");
+    if(!pidfile) {
+        log_ereport(LOG_FAILURE, "cannot open pid file %s: %s", pid_file_path, strerror(errno));
+        return -1;
+    }
     pid_t pid = getpid();
     fprintf(pidfile, "%d", pid);
     fclose(pidfile);

mercurial