diff --git a/etcdctl/ctlv3/command/lock_command.go b/etcdctl/ctlv3/command/lock_command.go index a78a8799b9e9..8bbb16cfd0ce 100644 --- a/etcdctl/ctlv3/command/lock_command.go +++ b/etcdctl/ctlv3/command/lock_command.go @@ -48,10 +48,25 @@ func lockCommandFunc(cmd *cobra.Command, args []string) { } c := mustClientFromCmd(cmd) if err := lockUntilSignal(c, args[0], args[1:]); err != nil { - ExitWithError(ExitError, err) + code := getExitCodeFromError(err) + ExitWithError(code, err) } } +func getExitCodeFromError(err error) int { + if err == nil { + return ExitSuccess + } + + if exitErr, ok := err.(*exec.ExitError); ok { + if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { + return status.ExitStatus() + } + } + + return ExitError +} + func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error { s, err := concurrency.NewSession(c, concurrency.WithTTL(lockTTL)) if err != nil {