Skip to content

Commit

Permalink
Add pid and stdio to process state
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
  • Loading branch information
crosbymichael committed Feb 4, 2016
1 parent 36eb83c commit 01176f2
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 111 deletions.
15 changes: 10 additions & 5 deletions api/grpc/server/server.go
Expand Up @@ -185,12 +185,17 @@ func (s *apiServer) State(ctx context.Context, r *types.StateRequest) (*types.St
var procs []*types.Process
for _, p := range processes {
oldProc := p.Spec()
stdio := p.Stdio()
procs = append(procs, &types.Process{
Pid: p.ID(),
Terminal: oldProc.Terminal,
Args: oldProc.Args,
Env: oldProc.Env,
Cwd: oldProc.Cwd,
Pid: p.ID(),
SystemPid: uint32(p.SystemPid()),
Terminal: oldProc.Terminal,
Args: oldProc.Args,
Env: oldProc.Env,
Cwd: oldProc.Cwd,
Stdin: stdio.Stdin,
Stdout: stdio.Stdout,
Stderr: stdio.Stderr,
User: &types.User{
Uid: oldProc.User.UID,
Gid: oldProc.User.GID,
Expand Down
205 changes: 105 additions & 100 deletions api/grpc/types/api.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions api/grpc/types/api.proto
Expand Up @@ -116,6 +116,10 @@ message Process {
repeated string args = 4; // Arguments for process, first is binary path itself
repeated string env = 5; // List of environment variables for process
string cwd = 6; // Workind directory of process
uint32 systemPid = 7;
string stdin = 8; // path to the file where stdin will be read (optional)
string stdout = 9; // path to file where stdout will be written (optional)
string stderr = 10; // path to file where stderr will be written (optional)
}

message Container {
Expand Down
1 change: 1 addition & 0 deletions containerd-shim/main.go
Expand Up @@ -61,6 +61,7 @@ func main() {
logrus.WithField("error", err).Fatal("shim: create new process")
}
if err := p.start(); err != nil {
p.delete()
logrus.WithField("error", err).Fatal("shim: start process")
}
go func() {
Expand Down
17 changes: 17 additions & 0 deletions ctr/container.go
Expand Up @@ -54,6 +54,23 @@ var containersCommand = cli.Command{
Action: listContainers,
}

var stateCommand = cli.Command{
Name: "state",
Usage: "get a raw dump of the containerd state",
Action: func(context *cli.Context) {
c := getClient(context)
resp, err := c.State(netcontext.Background(), &types.StateRequest{})
if err != nil {
fatal(err.Error(), 1)
}
data, err := json.Marshal(resp)
if err != nil {
fatal(err.Error(), 1)
}
fmt.Print(string(data))
},
}

var listCommand = cli.Command{
Name: "list",
Usage: "list all running containers",
Expand Down
1 change: 1 addition & 0 deletions ctr/main.go
Expand Up @@ -31,6 +31,7 @@ func main() {
checkpointCommand,
containersCommand,
eventsCommand,
stateCommand,
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") {
Expand Down
15 changes: 15 additions & 0 deletions runtime/process.go
Expand Up @@ -34,6 +34,10 @@ type Process interface {
Signal(os.Signal) error
// Container returns the container that the process belongs to
Container() Container
// Stdio of the container
Stdio() Stdio
// SystemPid is the pid on the system
SystemPid() int
}

func newProcess(root, id string, c *container, s specs.Process, stdio Stdio) (*process, error) {
Expand Down Expand Up @@ -82,6 +86,9 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
Stderr: s.Stderr,
},
}
if _, err := p.getPid(); err != nil {
return nil, err
}
if _, err := p.ExitStatus(); err != nil {
if err == ErrProcessNotExited {
exit, err := getExitPipe(filepath.Join(root, ExitFile))
Expand Down Expand Up @@ -131,6 +138,10 @@ func (p *process) Container() Container {
return p.container
}

func (p *process) SystemPid() int {
return p.pid
}

// ExitFD returns the fd of the exit pipe
func (p *process) ExitFD() int {
return int(p.exitPipe.Fd())
Expand Down Expand Up @@ -169,6 +180,10 @@ func (p *process) Spec() specs.Process {
return p.spec
}

func (p *process) Stdio() Stdio {
return p.stdio
}

// Close closes any open files and/or resouces on the process
func (p *process) Close() error {
return p.exitPipe.Close()
Expand Down
16 changes: 10 additions & 6 deletions supervisor/sort_test.go
Expand Up @@ -17,16 +17,20 @@ func (p *testProcess) ID() string {
return p.id
}

func (p *testProcess) Stdin() string {
return ""
func (p *testProcess) CloseStdin() error {
return nil
}

func (p *testProcess) Stdout() string {
return ""
func (p *testProcess) Resize(w, h int) error {
return nil
}

func (p *testProcess) Stderr() string {
return ""
func (p *testProcess) Stdio() runtime.Stdio {
return runtime.Stdio{}
}

func (p *testProcess) SystemPid() int {
return -1
}

func (p *testProcess) ExitFD() int {
Expand Down

0 comments on commit 01176f2

Please sign in to comment.