Fixes a bug in runhcs shim Exec.Pid
When an exec occurs the pid was not properly updated on the in memory state value causing many queries to see a 0. Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
@@ -46,7 +46,6 @@ func newProcess(ctx context.Context, s *service, id string, pid uint32, pr *pipe
|
||||
process := &process{
|
||||
cid: id,
|
||||
id: id,
|
||||
pid: pid,
|
||||
bundle: bundle,
|
||||
stdin: stdin,
|
||||
stdout: stdout,
|
||||
@@ -55,6 +54,12 @@ func newProcess(ctx context.Context, s *service, id string, pid uint32, pr *pipe
|
||||
relay: pr,
|
||||
waitBlock: make(chan struct{}),
|
||||
}
|
||||
go waitForProcess(ctx, process, p, s)
|
||||
return process, nil
|
||||
}
|
||||
|
||||
func waitForProcess(ctx context.Context, process *process, p *os.Process, s *service) {
|
||||
pid := uint32(p.Pid)
|
||||
// Store the default non-exited value for calls to stat
|
||||
process.exit.Store(&processExit{
|
||||
pid: pid,
|
||||
@@ -62,11 +67,7 @@ func newProcess(ctx context.Context, s *service, id string, pid uint32, pr *pipe
|
||||
exitedAt: time.Time{},
|
||||
exitErr: nil,
|
||||
})
|
||||
go waitForProcess(ctx, process, p, s)
|
||||
return process, nil
|
||||
}
|
||||
|
||||
func waitForProcess(ctx context.Context, process *process, p *os.Process, s *service) {
|
||||
var status int
|
||||
_, eerr := p.Wait()
|
||||
if eerr != nil {
|
||||
@@ -79,7 +80,7 @@ func waitForProcess(ctx context.Context, process *process, p *os.Process, s *ser
|
||||
}
|
||||
now := time.Now()
|
||||
process.exit.Store(&processExit{
|
||||
pid: process.pid,
|
||||
pid: pid,
|
||||
exitStatus: uint32(status),
|
||||
exitedAt: now,
|
||||
exitErr: eerr,
|
||||
@@ -97,7 +98,7 @@ func waitForProcess(ctx context.Context, process *process, p *os.Process, s *ser
|
||||
&eventstypes.TaskExit{
|
||||
ContainerID: process.cid,
|
||||
ID: process.id,
|
||||
Pid: process.pid,
|
||||
Pid: pid,
|
||||
ExitStatus: uint32(status),
|
||||
ExitedAt: now,
|
||||
})
|
||||
@@ -117,6 +118,7 @@ func newExecProcess(ctx context.Context, s *service, cid, id string, pr *pipeRel
|
||||
}
|
||||
// Store the default non-exited value for calls to stat
|
||||
process.exit.Store(&processExit{
|
||||
pid: 0, // This is updated when the call to Start happens and the state is overwritten in waitForProcess.
|
||||
exitStatus: 255,
|
||||
exitedAt: time.Time{},
|
||||
exitErr: nil,
|
||||
@@ -129,7 +131,6 @@ type process struct {
|
||||
|
||||
cid string
|
||||
id string
|
||||
pid uint32
|
||||
|
||||
bundle string
|
||||
stdin string
|
||||
|
||||
Reference in New Issue
Block a user