From 068d93a3726a1d11cbe9146ba26febb5e3851bc4 Mon Sep 17 00:00:00 2001 From: op Date: Sat, 6 Aug 2022 17:11:36 +0000 Subject: [PATCH] add a -t flag to change the request timeout original diff from Alfred Morgan (alfred [at] 54 dot org) ok florian@ and manpage tweaks by me. --- usr.sbin/slowcgi/slowcgi.8 | 11 +++++++++-- usr.sbin/slowcgi/slowcgi.c | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/usr.sbin/slowcgi/slowcgi.8 b/usr.sbin/slowcgi/slowcgi.8 index cfc4deee42a..e1f0afbdf2f 100644 --- a/usr.sbin/slowcgi/slowcgi.8 +++ b/usr.sbin/slowcgi/slowcgi.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: slowcgi.8,v 1.16 2021/09/02 14:14:44 jmc Exp $ +.\" $OpenBSD: slowcgi.8,v 1.17 2022/08/06 17:11:36 op Exp $ .\" .\" Copyright (c) 2013 Florian Obser .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 2 2021 $ +.Dd $Mdocdate: August 6 2022 $ .Dt SLOWCGI 8 .Os .Sh NAME @@ -25,6 +25,7 @@ .Op Fl dv .Op Fl p Ar path .Op Fl s Ar socket +.Op Fl t Ar timeout .Op Fl U Ar user .Op Fl u Ar user .Sh DESCRIPTION @@ -76,6 +77,12 @@ effectively disables the chroot. .It Fl s Ar socket Create and bind to alternative local socket at .Ar socket . +.It Fl t Ar timeout +Terminate the request after +.Ar timeout +seconds instead of the default 120 seconds. +The CGI script is left to run but its standard input, output and error +will be closed. .It Fl U Ar user Change the owner of .Pa /var/www/run/slowcgi.sock diff --git a/usr.sbin/slowcgi/slowcgi.c b/usr.sbin/slowcgi/slowcgi.c index f1bc0109920..ddf83f965d0 100644 --- a/usr.sbin/slowcgi/slowcgi.c +++ b/usr.sbin/slowcgi/slowcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slowcgi.c,v 1.62 2021/09/02 14:14:44 jmc Exp $ */ +/* $OpenBSD: slowcgi.c,v 1.63 2022/08/06 17:11:36 op Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser @@ -40,6 +40,7 @@ #include #define TIMEOUT_DEFAULT 120 +#define TIMEOUT_MAX (86400 * 365) #define SLOWCGI_USER "www" #define FCGI_CONTENT_SIZE 65535 @@ -252,8 +253,8 @@ usage(void) { extern char *__progname; fprintf(stderr, - "usage: %s [-dv] [-p path] [-s socket] [-U user] [-u user]\n", - __progname); + "usage: %s [-dv] [-p path] [-s socket] [-t timeout] [-U user] " + " [-u user]\n", __progname); exit(1); } @@ -275,6 +276,7 @@ main(int argc, char *argv[]) const char *chrootpath = NULL; const char *sock_user = SLOWCGI_USER; const char *slowcgi_user = SLOWCGI_USER; + const char *errstr; /* * Ensure we have fds 0-2 open so that we have no fd overlaps @@ -293,7 +295,7 @@ main(int argc, char *argv[]) } } - while ((c = getopt(argc, argv, "dp:s:U:u:v")) != -1) { + while ((c = getopt(argc, argv, "dp:s:t:U:u:v")) != -1) { switch (c) { case 'd': debug++; @@ -304,6 +306,12 @@ main(int argc, char *argv[]) case 's': fcgi_socket = optarg; break; + case 't': + timeout.tv_sec = strtonum(optarg, 1, TIMEOUT_MAX, + &errstr); + if (errstr != NULL) + errx(1, "timeout is %s: %s", errstr, optarg); + break; case 'U': sock_user = optarg; break; -- 2.20.1