Beispiel #1
0
// doesInitProcessExist checks if the init process is still the same process
// as the initial one, it could happen that the original process has exited
// and a new process has been created with the same pid, in this case, the
// container would already be stopped.
func (c *linuxContainer) doesInitProcessExist(initPid int) (bool, error) {
	startTime, err := system.GetProcessStartTime(initPid)
	if err != nil {
		return false, newSystemErrorWithCausef(err, "getting init process %d start time", initPid)
	}
	if c.initProcessStartTime != startTime {
		return false, nil
	}
	return true, nil
}
Beispiel #2
0
func newRestoredProcess(pid int, fds []string) (*restoredProcess, error) {
	var (
		err error
	)
	proc, err := os.FindProcess(pid)
	if err != nil {
		return nil, err
	}
	started, err := system.GetProcessStartTime(pid)
	if err != nil {
		return nil, err
	}
	return &restoredProcess{
		proc:             proc,
		processStartTime: started,
		fds:              fds,
	}, nil
}
Beispiel #3
0
func newProcess(id, stateDir string, status execution.Status) (execution.Process, error) {
	pid, err := runc.ReadPidFile(filepath.Join(stateDir, PidFilename))
	if err != nil {
		return nil, err
	}
	if err := syscall.Kill(pid, 0); err != nil {
		if err == syscall.ESRCH {
			status = execution.Stopped
		} else {
			return nil, err
		}
	}
	if status != execution.Stopped {
		stime, err := starttime.GetProcessStartTime(pid)
		switch {
		case os.IsNotExist(err):
			status = execution.Stopped
		case err != nil:
			return nil, err
		default:
			b, err := ioutil.ReadFile(filepath.Join(stateDir, StartTimeFilename))
			switch {
			case os.IsNotExist(err):
				err = ioutil.WriteFile(filepath.Join(stateDir, StartTimeFilename), []byte(stime), 0600)
				if err != nil {
					return nil, err
				}
			case err != nil:
				return nil, err
			case string(b) != stime:
				status = execution.Stopped
			}
		}
	}
	return &process{
		id:       id,
		pid:      pid,
		status:   status,
		exitCode: execution.UnknownStatusCode,
	}, nil
}
Beispiel #4
0
// Terminate implements the exec driver Driver interface.
func (d *Driver) Terminate(c *execdriver.Command) error {
	defer d.cleanContainer(c.ID)
	container, err := d.factory.Load(c.ID)
	if err != nil {
		return err
	}
	defer container.Destroy()
	state, err := container.State()
	if err != nil {
		return err
	}
	pid := state.InitProcessPid
	currentStartTime, err := system.GetProcessStartTime(pid)
	if err != nil {
		return err
	}
	if state.InitProcessStartTime == currentStartTime {
		err = syscall.Kill(pid, 9)
		syscall.Wait4(pid, nil, 0, nil)
	}
	return err
}
Beispiel #5
0
func (p *setnsProcess) startTime() (string, error) {
	return system.GetProcessStartTime(p.pid())
}