Skip to content

Loading…

STDERR redirection back through the FCGI socket #5

Merged
merged 2 commits into from

2 participants

@goochjj

You mention in the docs that the current method of sending STDERR to fcgiwrap's STDERR, and that that is by design, though it could be modified easily. I have made those easy modifications. The default behavior is unchanged, but supplying the -f option will allow the STDERR to be redirected through FCGI.

Would appreciate inclusion!

@goochjj

Also listed in Debian bugtracker as issue 633116.

@gnosek
Owner

Sure, why not.

@gnosek gnosek merged commit 1328862 into gnosek:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 2 deletions.
  1. +6 −0 fcgiwrap.8
  2. +10 −2 fcgiwrap.c
View
6 fcgiwrap.8
@@ -28,6 +28,12 @@ that may need it).
.B \-c \fInumber\fP
Number of fcgiwrap processes to prefork.
.TP
+.B \-f
+Redirect STDERR output from executed CGI through FastCGI so it shows in the web server
+error log. Otherwise it would be returned on \fBfcgiwrap\fP's STDERR, which could be redirected.
+If running through \fBspawn-fcgi\fP, \fBfcgiwrap\fP's STDERR is sent to /dev/null, so this option
+provides a way to get that output back.
+.TP
.B \-s \fIsocket_url\fP
A URL for the listen socket to bind to. By default \fBfcgiwrap\fP expects
a listen socket to be passed on file descriptor 0, matching the FastCGI convention.
View
12 fcgiwrap.c
@@ -76,6 +76,8 @@ static const char * blacklisted_env_vars[] = {
NULL,
};
+static int stderr_to_fastcgi = 0;
+
#define FCGI_BUF_SIZE 4096
@@ -326,7 +328,10 @@ static void fcgi_pass(struct fcgi_context *fc)
}
}
if (fc->fd_stderr >= 0 && FD_ISSET(fc->fd_stderr, &rset)) {
- err = fcgi_pass_raw_fd(&fc->fd_stderr, 2, buf, sizeof(buf));
+ if (stderr_to_fastcgi)
+ err = fcgi_pass_fd(fc, &fc->fd_stderr, FCGI_stderr, buf, sizeof(buf));
+ else
+ err = fcgi_pass_raw_fd(&fc->fd_stderr, 2, buf, sizeof(buf));
if (err) {
fcgi_finish(fc, err);
return;
@@ -739,8 +744,11 @@ int main(int argc, char **argv)
char *socket_url = NULL;
int c;
- while ((c = getopt(argc, argv, "c:hs:")) != -1) {
+ while ((c = getopt(argc, argv, "c:hfs:")) != -1) {
switch (c) {
+ case 'f':
+ stderr_to_fastcgi++;
+ break;
case 'h':
printf("Usage: %s [OPTION]\nInvokes CGI scripts as FCGI.\n\n"
PACKAGE_NAME" version "PACKAGE_VERSION"\n\n"
Something went wrong with that request. Please try again.