1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:50:11 -07:00

http/cgi: copy some PATH environment variables to child

R=bradfitz, bradfitzwork, iant2, bradfitzgo
CC=golang-dev
https://golang.org/cl/4444058
This commit is contained in:
Ian Lance Taylor 2011-04-22 08:53:52 -07:00
parent 59c18b0b36
commit 75ca6d189c
2 changed files with 18 additions and 3 deletions

View File

@ -36,9 +36,10 @@ type Handler struct {
Path string // path to the CGI executable Path string // path to the CGI executable
Root string // root URI prefix of handler or empty for "/" Root string // root URI prefix of handler or empty for "/"
Env []string // extra environment variables to set, if any Env []string // extra environment variables to set, if any, as "key=value"
Logger *log.Logger // optional log for errors or nil to use log.Print InheritEnv []string // environment variables to inherit from host, as "key"
Args []string // optional arguments to pass to child process Logger *log.Logger // optional log for errors or nil to use log.Print
Args []string // optional arguments to pass to child process
} }
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
@ -110,6 +111,12 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
env = append(env, h.Env...) env = append(env, h.Env...)
} }
for _, e := range h.InheritEnv {
if v := os.Getenv(e); v != "" {
env = append(env, e+"="+v)
}
}
cwd, pathBase := filepath.Split(h.Path) cwd, pathBase := filepath.Split(h.Path)
if cwd == "" { if cwd == "" {
cwd = "." cwd = "."

View File

@ -22,6 +22,14 @@ func TestHostingOurselves(t *testing.T) {
Path: os.Args[0], Path: os.Args[0],
Root: "/test.go", Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"}, Args: []string{"-test.run=TestBeChildCGIProcess"},
// When using a shared library with gccgo, make sure
// we can still find the library when we exec
// ourselves.
InheritEnv: []string{
"LD_LIBRARY_PATH",
"SHLIB_PATH",
"DYLD_LIBRARY_PATH",
},
} }
expectedMap := map[string]string{ expectedMap := map[string]string{
"test": "Hello CGI-in-CGI", "test": "Hello CGI-in-CGI",