Commit d46967d1 authored by Matthew Holt's avatar Matthew Holt

core: Fixed minor restart bug

Actually, restart on posix systems failed entirely if caddy was executed without the path included; also fixed a related bug where a variable was declared but never assigned.
parent 4d780136
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/exec"
"syscall" "syscall"
) )
...@@ -33,7 +34,7 @@ func Restart(newCaddyfile Input) error { ...@@ -33,7 +34,7 @@ func Restart(newCaddyfile Input) error {
caddyfileMu.Unlock() caddyfileMu.Unlock()
} }
if len(os.Args) == 0 { // this should never happen... if len(os.Args) == 0 { // this should never happen, but...
os.Args = []string{""} os.Args = []string{""}
} }
...@@ -72,12 +73,18 @@ func Restart(newCaddyfile Input) error { ...@@ -72,12 +73,18 @@ func Restart(newCaddyfile Input) error {
} }
serversMu.Unlock() serversMu.Unlock()
// We're gonna need the proper path to the executable
exepath, err := exec.LookPath(os.Args[0])
if err != nil {
return err
}
// Fork the process with the current environment and file descriptors // Fork the process with the current environment and file descriptors
execSpec := &syscall.ProcAttr{ execSpec := &syscall.ProcAttr{
Env: os.Environ(), Env: os.Environ(),
Files: fds, Files: fds,
} }
_, err = syscall.ForkExec(os.Args[0], os.Args, execSpec) _, err = syscall.ForkExec(exepath, os.Args, execSpec)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -24,14 +24,14 @@ func init() { ...@@ -24,14 +24,14 @@ func init() {
caddyfileMu.Lock() caddyfileMu.Lock()
if caddyfile == nil { if caddyfile == nil {
// Hmm, did spawing process forget to close stdin? Anyhow, this is unusual. // Hmm, did spawing process forget to close stdin? Anyhow, this is unusual.
log.Println("[ERROR] SIGUSR1: no caddyfile to reload (was stdin left open?)") log.Println("[ERROR] SIGUSR1: no Caddyfile to reload (was stdin left open?)")
caddyfileMu.Unlock() caddyfileMu.Unlock()
continue continue
} }
if caddyfile.IsFile() { if caddyfile.IsFile() {
body, err := ioutil.ReadFile(caddyfile.Path()) body, err := ioutil.ReadFile(caddyfile.Path())
if err == nil { if err == nil {
caddyfile = CaddyfileInput{ updatedCaddyfile = CaddyfileInput{
Filepath: caddyfile.Path(), Filepath: caddyfile.Path(),
Contents: body, Contents: body,
RealFile: true, RealFile: true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment