Skip to content

Commit

Permalink
etcdctl/lock: return exit code of exec-command
Browse files Browse the repository at this point in the history
  • Loading branch information
garenchan committed Apr 5, 2021
1 parent dfb03ab commit e51128b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion etcdctl/ctlv3/command/lock_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e51128b

Please sign in to comment.