From 457d846241e86eaca9f68485244870dd65da4a1a Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 22 Jul 2020 10:42:37 +0200 Subject: [PATCH] cephfs: use util.ExecCommand() instead of execCommand() Signed-off-by: Niels de Vos --- internal/cephfs/util.go | 31 ++----------------------------- internal/cephfs/volumemounter.go | 2 +- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/internal/cephfs/util.go b/internal/cephfs/util.go index 120b5008b..895fab15d 100644 --- a/internal/cephfs/util.go +++ b/internal/cephfs/util.go @@ -17,11 +17,9 @@ limitations under the License. package cephfs import ( - "bytes" "context" "encoding/json" "fmt" - "os/exec" "github.com/ceph/ceph-csi/internal/util" @@ -32,38 +30,13 @@ import ( type volumeID string -func execCommand(ctx context.Context, program string, args ...string) (stdout, stderr []byte, err error) { - var ( - cmd = exec.Command(program, args...) // #nosec:G204, not called with user specified parameters. - sanitizedArgs = util.StripSecretInArgs(args) - stdoutBuf bytes.Buffer - stderrBuf bytes.Buffer - ) - - cmd.Stdout = &stdoutBuf - cmd.Stderr = &stderrBuf - - util.DebugLog(ctx, "cephfs: EXEC %s %s", program, sanitizedArgs) - - if err := cmd.Run(); err != nil { - if cmd.Process == nil { - return nil, nil, fmt.Errorf("cannot get process pid while running %s %v: %w: %s", - program, sanitizedArgs, err, stderrBuf.Bytes()) - } - return nil, nil, fmt.Errorf("an error occurred while running (%d) %s %v: %w: %s", - cmd.Process.Pid, program, sanitizedArgs, err, stderrBuf.Bytes()) - } - - return stdoutBuf.Bytes(), stderrBuf.Bytes(), nil -} - func execCommandErr(ctx context.Context, program string, args ...string) error { - _, _, err := execCommand(ctx, program, args...) + _, _, err := util.ExecCommand(program, args...) return err } func execCommandJSON(ctx context.Context, v interface{}, program string, args ...string) error { - stdout, _, err := execCommand(ctx, program, args...) + stdout, _, err := util.ExecCommand(program, args...) if err != nil { return err } diff --git a/internal/cephfs/volumemounter.go b/internal/cephfs/volumemounter.go index 52039690b..39adeee1a 100644 --- a/internal/cephfs/volumemounter.go +++ b/internal/cephfs/volumemounter.go @@ -167,7 +167,7 @@ func mountFuse(ctx context.Context, mountPoint string, cr *util.Credentials, vol args = append(args, "--client_mds_namespace="+volOptions.FsName) } - _, stderr, err := execCommand(ctx, "ceph-fuse", args[:]...) + _, stderr, err := util.ExecCommand("ceph-fuse", args[:]...) if err != nil { return err }