Skip to content

Commit

Permalink
Properly retrieve Conmon PID
Browse files Browse the repository at this point in the history
Our previous method (just read the PID that we spawned) doesn't
work - Conmon double-forks to daemonize, so we end up with a PID
pointing to the first process, which dies almost immediately.

Reading from the PID file gets us the real PID.

Signed-off-by: Matthew Heon <[email protected]>
  • Loading branch information
mheon committed Jul 17, 2019
1 parent 1e3e99f commit 156b6ef
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions libpod/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -461,8 +462,21 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
return errors.Wrapf(define.ErrInternal, "container create failed")
}
ctr.state.PID = ss.si.Pid
if cmd.Process != nil {
ctr.state.ConmonPID = cmd.Process.Pid
// Let's try reading the Conmon pid at the same time.
if ctr.config.ConmonPidFile != "" {
contents, err := ioutil.ReadFile(ctr.config.ConmonPidFile)
if err != nil {
logrus.Warnf("Error reading Conmon pidfile for container %s: %v", ctr.ID(), err)
} else {
// Convert it to an int
conmonPID, err := strconv.Atoi(string(contents))
if err != nil {
logrus.Warnf("Error decoding Conmon PID %q for container %s: %v", string(contents), ctr.ID(), err)
} else {
ctr.state.ConmonPID = conmonPID
logrus.Infof("Got Conmon PID as %d", conmonPID)
}
}
}
case <-time.After(ContainerCreateTimeout):
return errors.Wrapf(define.ErrInternal, "container creation timeout")
Expand Down

0 comments on commit 156b6ef

Please sign in to comment.