1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

on: Allow nonblocking command with no other arguments (#1913)

This commit is contained in:
Guilherme Bernal 2017-10-12 13:11:50 -03:00 committed by Matt Holt
parent c4dfbb9956
commit 99625ae3f6
2 changed files with 2 additions and 1 deletions

View file

@ -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]

View file

@ -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},
}