mirror of
https://tildegit.org/solderpunk/molly-brown
synced 2024-09-21 23:50:38 +02:00
Terminate CGI processes after 10 seconds.
This commit is contained in:
parent
efc1ecf7a7
commit
0b4fefd0ba
12
handler.go
12
handler.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -124,7 +125,9 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||||||
return
|
return
|
||||||
// If this file is executable, get dynamic content
|
// If this file is executable, get dynamic content
|
||||||
} else if info.Mode().Perm() & 0111 == 0111 {
|
} else if info.Mode().Perm() & 0111 == 0111 {
|
||||||
cmd := exec.Command(path)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, path)
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Write([]byte("42 CGI error!\r\n"))
|
conn.Write([]byte("42 CGI error!\r\n"))
|
||||||
@ -134,7 +137,12 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||||||
defer stdin.Close()
|
defer stdin.Close()
|
||||||
io.WriteString(stdin, URL.String())
|
io.WriteString(stdin, URL.String())
|
||||||
io.WriteString(stdin, "\r\n")
|
io.WriteString(stdin, "\r\n")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.Output()
|
||||||
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
|
conn.Write([]byte("42 CGI process timed out!\r\n"))
|
||||||
|
log.Status = 42
|
||||||
|
return
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Write([]byte("42 CGI error!\r\n"))
|
conn.Write([]byte("42 CGI error!\r\n"))
|
||||||
log.Status = 42
|
log.Status = 42
|
||||||
|
Loading…
Reference in New Issue
Block a user