func New(containerDepotPath, binPath string, runner command_runner.CommandRunner) (*LinuxQuotaManager, error) { dfOut := new(bytes.Buffer) df := &exec.Cmd{ Path: "df", Args: []string{"-P", containerDepotPath}, Stdout: dfOut, } err := runner.Run(df) if err != nil { return nil, err } dfOutputWords := strings.Split(string(dfOut.Bytes()), " ") mountPoint := strings.Trim(dfOutputWords[len(dfOutputWords)-1], "\n") return &LinuxQuotaManager{ enabled: true, binPath: binPath, runner: runner, mountPoint: mountPoint, }, nil }
func NewBigApp(runner command_runner.CommandRunner, appPath string, sizeInMegabytes int) (*BigApp, error) { tempDirName, err := ioutil.TempDir("", "big-app") if err != nil { return nil, err } cmd := &exec.Cmd{Path: "cp", Args: []string{"-r", appPath + "/", tempDirName}} err = runner.Run(cmd) if err != nil { return nil, err } ddOutputArg := "of=" + tempDirName + "/payload" ddCountArg := fmt.Sprintf("count=%d", sizeInMegabytes) cmd = &exec.Cmd{Path: "dd", Args: []string{"if=/dev/urandom", ddOutputArg, ddCountArg, "bs=1048576"}} err = runner.Run(cmd) if err != nil { return nil, err } return &BigApp{ Location: tempDirName, runner: runner, Name: "big-app-" + generator.RandomName(), }, nil }
func (c *BtrfsCleaningCake) run(runner command_runner.CommandRunner, cmd *exec.Cmd) (string, error) { var buffer bytes.Buffer cmd.Stdout = &buffer if err := runner.Run(cmd); err != nil { return "", err } return buffer.String(), nil }
func (n *rule) destroy(chain string, runner command_runner.CommandRunner) error { return runner.Run(exec.Command("/sbin/iptables", flags("-D", chain, n)...)) }