diff options
Diffstat (limited to 'vendor/github.com/shirou/gopsutil/internal/common/common.go')
-rw-r--r-- | vendor/github.com/shirou/gopsutil/internal/common/common.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common.go b/vendor/github.com/shirou/gopsutil/internal/common/common.go index fcee6be..f9373ee 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common.go @@ -32,15 +32,19 @@ var ( type Invoker interface { Command(string, ...string) ([]byte, error) + CommandWithContext(context.Context, string, ...string) ([]byte, error) } type Invoke struct{} func (i Invoke) Command(name string, arg ...string) ([]byte, error) { - ctxt, cancel := context.WithTimeout(context.Background(), Timeout) + ctx, cancel := context.WithTimeout(context.Background(), Timeout) defer cancel() + return i.CommandWithContext(ctx, name, arg...) +} - cmd := exec.CommandContext(ctxt, name, arg...) +func (i Invoke) CommandWithContext(ctx context.Context, name string, arg ...string) ([]byte, error) { + cmd := exec.CommandContext(ctx, name, arg...) var buf bytes.Buffer cmd.Stdout = &buf @@ -84,6 +88,10 @@ func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) { return []byte{}, fmt.Errorf("could not find testdata: %s", fpath) } +func (i FakeInvoke) CommandWithContext(ctx context.Context, name string, arg ...string) ([]byte, error) { + return i.Command(name, arg...) +} + var ErrNotImplementedError = errors.New("not implemented yet") // ReadLines reads contents from a file and splits them by new lines. |