aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Müller2021-10-29 11:45:32 +0200
committerWolfgang Müller2023-10-12 12:12:47 +0200
commit4c2f7e55877aec6ede5dac7354ca401891750962 (patch)
treee84b5211ff2560e9d03d9f706abbaf46367fbc5b
parent4e4f2a8b2a10990ed977fefaa6fab92b55f4d31b (diff)
downloadslowcgi-gentoo.tar.gz
Add flag to run in the foregroundgentoo
slowcgi already has the -d flag to disable forking, but that particular flag also stops slowcgi from logging to syslog and is intended for debugging purposes. Ordinarily this would be fine, but sadly we know of no clean way to track the PID of a forked process with Gentoo's OpenRC and its start-stop-daemon(8). We could add support to write a pidfile instead, but since we want to support multiple invocations of slowcgi through OpenRC and ${RC_SVCNAME}, we need a way of specifying the pidfile location in the init script itself. To solve this reasonably cleanly, add a flag that *only* controls whether or not the program daemonizes or not. Make sure to mention this in the manual too.
-rw-r--r--slowcgi.86
-rw-r--r--slowcgi.c10
2 files changed, 12 insertions, 4 deletions
diff --git a/slowcgi.8 b/slowcgi.8
index e1f0afb..34f5f53 100644
--- a/slowcgi.8
+++ b/slowcgi.8
@@ -22,7 +22,7 @@
.Nd a FastCGI to CGI wrapper server
.Sh SYNOPSIS
.Nm
-.Op Fl dv
+.Op Fl dfv
.Op Fl p Ar path
.Op Fl s Ar socket
.Op Fl t Ar timeout
@@ -65,6 +65,10 @@ Do not daemonize.
If this option is specified,
.Nm
will run in the foreground and log to stderr.
+.It Fl f
+As
+.Fl d ,
+but log to syslog.
.It Fl p Ar path
.Xr chroot 2
to
diff --git a/slowcgi.c b/slowcgi.c
index ce1530c..fe4c3d3 100644
--- a/slowcgi.c
+++ b/slowcgi.c
@@ -278,7 +278,7 @@ usage(void)
{
extern char *__progname;
fprintf(stderr,
- "usage: %s [-dv] [-p path] [-s socket] [-t timeout] [-U user] "
+ "usage: %s [-dfv] [-p path] [-s socket] [-t timeout] [-U user] "
"[-u user]\n", __progname);
exit(1);
}
@@ -286,6 +286,7 @@ usage(void)
struct timeval timeout = { TIMEOUT_DEFAULT, 0 };
struct slowcgi_proc slowcgi_proc;
int debug = 0;
+int foreground = 0;
int verbose = 0;
int on = 1;
char *fcgi_socket = "/var/www/run/slowcgi.sock";
@@ -320,11 +321,14 @@ main(int argc, char *argv[])
}
}
- while ((c = getopt(argc, argv, "dp:s:t:U:u:v")) != -1) {
+ while ((c = getopt(argc, argv, "dfp:s:t:U:u:v")) != -1) {
switch (c) {
case 'd':
debug++;
break;
+ case 'f':
+ foreground = 1;
+ break;
case 'p':
chrootpath = optarg;
break;
@@ -355,7 +359,7 @@ main(int argc, char *argv[])
if (geteuid() != 0)
errx(1, "need root privileges");
- if (!debug && daemon(0, 0) == -1)
+ if (!debug && !foreground && daemon(0, 0) == -1)
err(1, "daemon");
if (!debug) {