no max CGI runtime

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent 5d44d9c0e0
commit db73c33fa2

@ -4,7 +4,6 @@ import (
"os/exec"
"strings"
"syscall"
"time"
"github.com/grufwub/go-errors"
)
@ -94,9 +93,6 @@ func ExecuteCGIScript(client *Client, request *Request, pathInfo string) *errors
// Create cmd object
cmd := exec.Command(request.Path().Absolute())
// Set new process group id
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
// Setup cmd environment
cmd.Env = generateCGIEnv(client, request, pathInfo)
cmd.Dir = request.Path().Root()
@ -113,28 +109,9 @@ func ExecuteCGIScript(client *Client, request *Request, pathInfo string) *errors
return errors.WrapError(CGIStartErr, err)
}
// Setup goroutine to kill cmd after maxCGIRunTime
go func() {
// At least let the script try to finish...
time.Sleep(maxCGIRunTime)
// We've already finished
if cmd.ProcessState != nil {
return
}
// Get process group id.
pgid, err := syscall.Getpgid(cmd.Process.Pid)
if err != nil {
SystemLog.Fatalf(pgidNotFoundErrStr)
}
// Kill process group!
err = syscall.Kill(-pgid, syscall.SIGTERM)
if err != nil {
SystemLog.Fatalf(pgidStopErrStr, pgid, err.Error())
}
}()
// NOTE: we don't set a max CGI script run time anymore,
// we let the connection write deadline catch any longrunning
// scripts not sending content.
// Wait for command to finish
err = cmd.Wait()

@ -79,7 +79,6 @@ func ParseConfigAndSetup(tree config.Tree, proto string, defaultPort uint, newLi
// CGI configuration
cgiDir := tree.String("cgi.directory", "")
safePath := tree.String("cgi.safe-path", "/bin:/usr/bin")
tree.DurationVar(&maxCGIRunTime, "cgi.max-time", time.Duration(time.Second*3))
// User space configuration
userSpacesEnabled := tree.Bool("user-spaces", false)

@ -13,17 +13,19 @@ import (
// deadlineConn wraps net.Conn to set the read / write deadlines on each access
type deadlineConn struct {
conn net.Conn
rd *time.Duration
wd *time.Duration
}
// Read wraps the underlying net.Conn read function, setting read deadline on each access
func (c *deadlineConn) Read(b []byte) (int, error) {
c.conn.SetReadDeadline(time.Now().Add(connReadDeadline))
c.conn.SetReadDeadline(time.Now().Add(*c.rd))
return c.conn.Read(b)
}
// Read wraps the underlying net.Conn write function, setting write deadline on each access
func (c *deadlineConn) Write(b []byte) (int, error) {
c.conn.SetWriteDeadline(time.Now().Add(connWriteDeadline))
c.conn.SetWriteDeadline(time.Now().Add(*c.wd))
return c.conn.Write(b)
}
@ -42,7 +44,11 @@ type conn struct {
// wrapConn wraps a net.Conn in deadlineConn, then within conn and returns the result
func wrapConn(c net.Conn) *conn {
deadlineConn := &deadlineConn{c}
deadlineConn := &deadlineConn{
conn: c,
rd: &connReadDeadline,
wd: &connWriteDeadline,
}
return &conn{
b: connRequestBufferPool.Get(),
br: connBufferedReaderPool.Get(deadlineConn),

@ -54,9 +54,8 @@ var (
protocol string
// CGI related globals
cgiPath *Path
cgiEnv []string
maxCGIRunTime time.Duration
cgiPath *Path
cgiEnv []string
// Global OS signal channel
sigChannel chan os.Signal

@ -19,8 +19,6 @@ const (
invalidRequestErrStr = "Invalid request"
cgiStartErrStr = "CGI start error"
cgiExitCodeErrStr = "CGI non-zero exit code"
pgidNotFoundErrStr = "Process unfinished, PGID not found!"
pgidStopErrStr = "Error stopping process group %d: %s"
)
// Log string constants

@ -105,9 +105,6 @@ user-spaces = false
# CGI environment $PATH
safe-path = "/bin:/usr/bin"
# Maximum CGI script runtime
max-time = "3s"
# Gopher specific configuration, uncomment
# if you have built gophi as a gopher server
#[gopher]

Loading…
Cancel
Save