Skip to content

Commit

Permalink
cephfs: use util.ExecCommand() instead of execCommand()
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <ndevos@redhat.com>
  • Loading branch information
nixpanic authored and mergify[bot] committed Jul 24, 2020
1 parent 47d5b60 commit 457d846
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
31 changes: 2 additions & 29 deletions internal/cephfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cephfs/volumemounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 457d846

Please sign in to comment.