summaryrefslogtreecommitdiff
path: root/contrib/cgi/gopher.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-09-09 08:42:21 -0600
committertjpcc <tjp@ctrl-c.club>2023-09-09 08:42:21 -0600
commit33648cc286e812a8603743c29e96830de3b4acb8 (patch)
tree2253b0c71035f866fb14e6692baf5587b1925fb4 /contrib/cgi/gopher.go
parent195bdb565e9cb46e8d88ee364dcfc96a65a7159a (diff)
log stderr on failed CGIs
Diffstat (limited to 'contrib/cgi/gopher.go')
-rw-r--r--contrib/cgi/gopher.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/contrib/cgi/gopher.go b/contrib/cgi/gopher.go
index 67ea688..2f90f22 100644
--- a/contrib/cgi/gopher.go
+++ b/contrib/cgi/gopher.go
@@ -1,6 +1,7 @@
package cgi
import (
+ "bytes"
"context"
"fmt"
"os"
@@ -11,6 +12,7 @@ import (
sr "tildegit.org/tjp/sliderule"
"tildegit.org/tjp/sliderule/gopher"
"tildegit.org/tjp/sliderule/gopher/gophermap"
+ "tildegit.org/tjp/sliderule/logging"
)
// GopherCGIDirectory runs any executable files relative to a root directory on the file system.
@@ -113,11 +115,17 @@ func runGopherCGI(
pathinfo string,
settings gophermap.FileSystemSettings,
) *sr.Response {
- stdout, exitCode, err := RunCGI(ctx, request, fullpath, pathinfo)
+ stderr := &bytes.Buffer{}
+ stdout, exitCode, err := RunCGI(ctx, request, fullpath, pathinfo, stderr)
if err != nil {
return gopher.Error(err).Response()
}
if exitCode != 0 {
+ ctx.Value("warnlog").(logging.Logger).Log(
+ "msg", "cgi exited with non-zero exit code",
+ "code", exitCode,
+ "stderr", stderr.String(),
+ )
return gopher.Error(
fmt.Errorf("CGI process exited with status %d", exitCode),
).Response()