# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1668268816 -3600
# Node ID a327cb6cc868eda145481d82b757179d4f8640f5
# Parent  6a2e7a464991e7412d230a23c3aedba2523c559b
add check if pidfile can be opened

diff -r 6a2e7a464991 -r a327cb6cc868 src/server/daemon/webserver.c
--- 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);