diff options
Diffstat (limited to 'utils/utils.go')
| -rw-r--r-- | utils/utils.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/utils/utils.go b/utils/utils.go index f80834c..d58c6c2 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -57,7 +57,16 @@ func CmdExists(cmd string) bool { // RunCmd ... func RunCmd(timeout int, command string, args ...string) error { - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) + var ( + ctx context.Context + cancel context.CancelFunc + ) + + if timeout > 0 { + ctx, cancel = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) + } else { + ctx, cancel = context.WithCancel(context.Background()) + } defer cancel() cmd := exec.CommandContext(ctx, command, args...) |
