summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.go11
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...)