diff --git a/onevent/hook/hook.go b/onevent/hook/hook.go index 88e0e7370..57a67f16a 100644 --- a/onevent/hook/hook.go +++ b/onevent/hook/hook.go @@ -16,7 +16,7 @@ func (cfg *Config) Hook(event caddy.EventName, info interface{}) error { } nonblock := false - if len(cfg.Args) > 1 && cfg.Args[len(cfg.Args)-1] == "&" { + if len(cfg.Args) >= 1 && cfg.Args[len(cfg.Args)-1] == "&" { // Run command in background; non-blocking nonblock = true cfg.Args = cfg.Args[:len(cfg.Args)-1] diff --git a/onevent/hook/hook_test.go b/onevent/hook/hook_test.go index a6aa44fa3..e473a37f6 100644 --- a/onevent/hook/hook_test.go +++ b/onevent/hook/hook_test.go @@ -33,6 +33,7 @@ func TestHook(t *testing.T) { }{ {name: "blocking", event: caddy.InstanceStartupEvent, command: "mkdir", args: []string{osSenitiveTestDir}, shouldErr: false, shouldRemoveErr: false}, {name: "nonBlocking", event: caddy.ShutdownEvent, command: "mkdir", args: []string{osSenitiveTestDir, "&"}, shouldErr: false, shouldRemoveErr: true}, + {name: "nonBlocking2", event: caddy.ShutdownEvent, command: "echo", args: []string{"&"}, shouldErr: false, shouldRemoveErr: true}, {name: "nonExistent", event: caddy.CertRenewEvent, command: strconv.Itoa(int(time.Now().UnixNano())), shouldErr: true, shouldRemoveErr: true}, }