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 (
"io/ioutil"
"log"
"os"
"os/exec"
"syscall"
)
......@@ -33,7 +34,7 @@ func Restart(newCaddyfile Input) error {
caddyfileMu.Unlock()
}
if len(os.Args) == 0 { // this should never happen...
if len(os.Args) == 0 { // this should never happen, but...
os.Args = []string{""}
}
......@@ -72,12 +73,18 @@ func Restart(newCaddyfile Input) error {
}
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
execSpec := &syscall.ProcAttr{
Env: os.Environ(),
Files: fds,
}
_, err = syscall.ForkExec(os.Args[0], os.Args, execSpec)
_, err = syscall.ForkExec(exepath, os.Args, execSpec)
if err != nil {
return err
}
......
......@@ -24,14 +24,14 @@ func init() {
caddyfileMu.Lock()
if caddyfile == nil {
// 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()
continue
}
if caddyfile.IsFile() {
body, err := ioutil.ReadFile(caddyfile.Path())
if err == nil {
caddyfile = CaddyfileInput{
updatedCaddyfile = CaddyfileInput{
Filepath: caddyfile.Path(),
Contents: body,
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