libpod: forward NOTIFY_SOCKET for sd-notify container mode

Backports be5d1261b4

* mountNotifySocket consulted c.notifySocket, which was never populated.
  Use persisted c.config.SdNotifySocket instead so the path matches
  conmon's --sdnotify-socket and survives container restarts.

* Add WithSdNotifySocket and have MakeContainer read NOTIFY_SOCKET from
  the environment when sdnotify mode is container.

* Related to upstream be5d1261b4 (libpod: Move mountNotifySocket to
  container_internal_common.go), which introduced the shared
  mountNotifySocket path this wiring completes.

Created/Modified with the assistance of AI: Cursor <Auto>
Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
Chris Evich 2026-03-30 15:30:08 -04:00
parent 0fdacefba6
commit 45aff3bd29
No known key found for this signature in database
GPG key ID: 03EDC70FD578067F
4 changed files with 22 additions and 8 deletions

View file

@ -128,10 +128,6 @@ type Container struct {
// This is true if a container is restored from a checkpoint.
restoreFromCheckpoint bool
// Used to query the NOTIFY_SOCKET once along with setting up
// mounts etc.
notifySocket string
slirp4netnsSubnet *net.IPNet
}

View file

@ -751,11 +751,10 @@ func lookupHostUser(name string) (*runcuser.ExecUser, error) {
return &execUser, nil
}
// mountNotifySocket mounts the NOTIFY_SOCKET into the container if it's set
// and if the sdnotify mode is set to container. It also sets c.notifySocket
// to avoid redundantly looking up the env variable.
// mountNotifySocket mounts the NOTIFY_SOCKET into the container if the host
// notify socket path is stored in config and sdnotify mode is container.
func (c *Container) mountNotifySocket(g generate.Generator) error {
if c.notifySocket == "" {
if c.config.SdNotifySocket == "" {
return nil
}
if c.config.SdNotifyMode != define.SdNotifyModeContainer {

View file

@ -626,6 +626,19 @@ func WithSdNotifyMode(mode string) CtrCreateOption {
}
}
// WithSdNotifySocket sets the host path to the systemd notify socket (e.g. from
// NOTIFY_SOCKET) when using sd-notify container mode.
func WithSdNotifySocket(socket string) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return define.ErrCtrFinalized
}
ctr.config.SdNotifySocket = socket
return nil
}
}
// WithShmSize sets the size of /dev/shm tmpfs mount.
func WithShmSize(size int64) CtrCreateOption {
return func(ctr *Container) error {

View file

@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@ -361,6 +362,11 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
if len(s.SdNotifyMode) > 0 {
options = append(options, libpod.WithSdNotifyMode(s.SdNotifyMode))
}
if notifySocket, ok := os.LookupEnv("NOTIFY_SOCKET"); ok && notifySocket != "" {
if strings.EqualFold(s.SdNotifyMode, define.SdNotifyModeContainer) {
options = append(options, libpod.WithSdNotifySocket(notifySocket))
}
}
if pod != nil {
logrus.Debugf("adding container to pod %s", pod.Name())
options = append(options, rt.WithPod(pod))