commit 876c892
default
·
2024-11-17 09:21:15 +0000 UTC
parent 0858f57
The server creates a pidfile inside the base directory.
1 files changed,
+14,
-0
M
httpd.c
M
httpd.c
+14,
-0
1@@ -774,6 +774,7 @@ void httpd(void)
2 xs *sem_name = NULL;
3 xs *shm_name = NULL;
4 sem_t anon_job_sem;
5+ xs *pidfile = xs_fmt("%s/server.pid", srv_basedir);
6
7 address = xs_dict_get(srv_config, "address");
8
9@@ -809,6 +810,17 @@ void httpd(void)
10 srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "",
11 full_address, USER_AGENT));
12
13+ {
14+ FILE *f;
15+
16+ if ((f = fopen(pidfile, "w")) != NULL) {
17+ fprintf(f, "%d\n", getpid());
18+ fclose(f);
19+ }
20+ else
21+ srv_log(xs_fmt("Cannot create %s: %s", pidfile, strerror(errno)));
22+ }
23+
24 /* show the number of usable file descriptors */
25 struct rlimit r;
26 getrlimit(RLIMIT_NOFILE, &r);
27@@ -894,4 +906,6 @@ void httpd(void)
28 srv_log(xs_fmt("httpd%s stop %s (run time: %s)",
29 p_state->use_fcgi ? " (FastCGI)" : "",
30 full_address, uptime));
31+
32+ unlink(pidfile);
33 }