aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-11-17 10:21:15 +0100
committerdefault <nobody@localhost>2024-11-17 10:21:15 +0100
commit876c892960c7e45daf62369ea58f47ad42bfb98e (patch)
tree144327996158748e33c9b8b9f1edd1b0776c8e1c
parent0858f57d8a17aac6c2ca7fc2fc6b7008486293fe (diff)
The server creates a pidfile inside the base directory.
-rw-r--r--httpd.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/httpd.c b/httpd.c
index 1613e1f..81d2f9e 100644
--- a/httpd.c
+++ b/httpd.c
@@ -774,6 +774,7 @@ void httpd(void)
xs *sem_name = NULL;
xs *shm_name = NULL;
sem_t anon_job_sem;
+ xs *pidfile = xs_fmt("%s/server.pid", srv_basedir);
address = xs_dict_get(srv_config, "address");
@@ -809,6 +810,17 @@ void httpd(void)
srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "",
full_address, USER_AGENT));
+ {
+ FILE *f;
+
+ if ((f = fopen(pidfile, "w")) != NULL) {
+ fprintf(f, "%d\n", getpid());
+ fclose(f);
+ }
+ else
+ srv_log(xs_fmt("Cannot create %s: %s", pidfile, strerror(errno)));
+ }
+
/* show the number of usable file descriptors */
struct rlimit r;
getrlimit(RLIMIT_NOFILE, &r);
@@ -894,4 +906,6 @@ void httpd(void)
srv_log(xs_fmt("httpd%s stop %s (run time: %s)",
p_state->use_fcgi ? " (FastCGI)" : "",
full_address, uptime));
+
+ unlink(pidfile);
}