Beispiel #1
0
func RunIn(containerName string, nsPid int, args []string, env []string) (int, error) {
	container, err := createContainer(containerName, nsPid, args, env)
	if err != nil {
		return -1, fmt.Errorf("error creating container %s", err)
	}

	pid, err := namespaces.ExecIn(container, container.Command)
	if err != nil {
		return -1, fmt.Errorf("error execin container %s", err)
	}
	exitcode, err := utils.WaitOnPid(pid)
	if err != nil {
		return -1, fmt.Errorf("error waiting on child %s", err)
	}
	return exitcode, nil
}
Beispiel #2
0
func JoinContainer(containerName string, nsPid int, args []string, env []string) error {
	container, err := CreateContainer(containerName, nsPid, args, env)
	if err != nil {
		return fmt.Errorf("error creating container %s", err)
	}

	pid, err := namespaces.ExecIn(container, container.Command)
	if err != nil {
		return fmt.Errorf("error exexin container %s", err)
	}
	exitcode, err := utils.WaitOnPid(pid)
	if err != nil {
		return fmt.Errorf("error waiting on child %s", err)
	}
	os.Exit(exitcode)
	return nil
}
Beispiel #3
0
func execIn(container *libcontainer.Container) error {
	f, err := os.Open("/root/nsroot/test")
	if err != nil {
		return err
	}
	container.NetNsFd = f.Fd()
	pid, err := namespaces.ExecIn(container, &libcontainer.Command{
		Env: container.Command.Env,
		Args: []string{
			newCommand,
		},
	})
	if err != nil {
		return fmt.Errorf("error exexin container %s", err)
	}
	exitcode, err := utils.WaitOnPid(pid)
	if err != nil {
		return fmt.Errorf("error waiting on child %s", err)
	}
	os.Exit(exitcode)
	return nil
}