Skip to content

Commit

Permalink
fix testcmd when command contains spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jul 28, 2023
1 parent 1900306 commit fbc6e54
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mod_gearman_worker_testcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func runTestCmd(conf *configurationStruct, args []string) (rc int, output string
typ: "service",
hostName: "test check from commandline",
serviceDescription: "test",
commandLine: strings.Join(args, " "),
commandLine: buildCommandLine(args),
}
if len(args) == 0 {
return 3, "usage: mod_gearman_worker [--job_timeout=seconds] testcmd <cmd> <args>"
Expand All @@ -32,3 +32,14 @@ func runTestCmd(conf *configurationStruct, args []string) (rc int, output string
logger.Debugf("test cmd rc: %d\n", rc)
return
}

// reconstruct command line from array of args
func buildCommandLine(args []string) string {
cmd := args[0]
for _, a := range args[1:] {
// escape quotes
a = strings.ReplaceAll(a, `"`, `\"`)
cmd = cmd + ` "` + a + `"`
}
return cmd
}

0 comments on commit fbc6e54

Please sign in to comment.