File tree 4 files changed +28
-6
lines changed
4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ before_install:
26
26
- sudo apt-get update -y && sudo apt-get install -y libattr1-dev libblkid-dev linux-headers-$(uname -r) tree uuid-dev
27
27
- mkdir -p $HOME/zfs
28
28
- cd $HOME/zfs
29
- - [[ -d spl-$rel.tar.gz ]] || curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/spl-$rel.tar.gz | tar xz
30
- - [[ -d zfs-$rel.tar.gz ]] || curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/zfs-$rel.tar.gz | tar xz
29
+ - " [[ -d spl-$rel.tar.gz ]] || curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/spl-$rel.tar.gz | tar xz"
30
+ - " [[ -d zfs-$rel.tar.gz ]] || curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/zfs-$rel.tar.gz | tar xz"
31
31
- (cd spl-$rel && ./configure --prefix=/usr && make && sudo make install)
32
32
- (cd zfs-$rel && ./configure --prefix=/usr && make && sudo make install)
33
33
- sudo modprobe zfs
Original file line number Diff line number Diff line change @@ -2,28 +2,50 @@ package zfs
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"errors"
6
7
"fmt"
7
8
"io"
9
+ "os"
8
10
"os/exec"
9
11
"regexp"
10
12
"runtime"
11
13
"strconv"
12
14
"strings"
15
+ "time"
13
16
14
17
"github.com/pborman/uuid"
15
18
)
16
19
20
+ const (
21
+ cmdtimeoutEnv = "COMMAND_TIMEOUT"
22
+ )
23
+
17
24
type command struct {
18
25
Command string
19
26
Stdin io.Reader
20
27
Stdout io.Writer
28
+ timeout * time.Duration
21
29
}
22
30
23
- func (c * command ) Run (arg ... string ) ([][]string , error ) {
31
+ func getCommandTimeout () * time.Duration {
32
+ value := os .Getenv (cmdtimeoutEnv )
33
+ if timeout , err := time .ParseDuration (value ); value != "" && err == nil {
34
+ return & timeout
35
+ }
36
+ return nil
37
+ }
24
38
25
- cmd := exec .Command (c .Command , arg ... )
39
+ func (c * command ) Run (arg ... string ) ([][]string , error ) {
40
+ var cmd * exec.Cmd
26
41
42
+ if c .timeout == nil {
43
+ cmd = exec .Command (c .Command , arg ... )
44
+ } else {
45
+ ctx , cancel := context .WithTimeout (context .TODO (), * c .timeout )
46
+ defer cancel ()
47
+ cmd = exec .CommandContext (ctx , c .Command , arg ... )
48
+ }
27
49
var stdout , stderr bytes.Buffer
28
50
29
51
if c .Stdout == nil {
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ func SetLogger(l Logger) {
111
111
112
112
// zfs is a helper function to wrap typical calls to zfs.
113
113
func zfs (arg ... string ) ([][]string , error ) {
114
- c := command {Command : "zfs" }
114
+ c := command {Command : "zfs" , timeout : getCommandTimeout () }
115
115
return c .Run (arg ... )
116
116
}
117
117
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ type Zpool struct {
29
29
30
30
// zpool is a helper function to wrap typical calls to zpool.
31
31
func zpool (arg ... string ) ([][]string , error ) {
32
- c := command {Command : "zpool" }
32
+ c := command {Command : "zpool" , timeout : getCommandTimeout () }
33
33
return c .Run (arg ... )
34
34
}
35
35
You can’t perform that action at this time.
0 commit comments