etcdctl: lock return exit code of exec-command
Sometimes we expect to get the exit code of the command being executed.
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user