1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #35614 from mlaventure/remove-exec-bypid

Remove ByPid from ExecCommands
This commit is contained in:
Michael Crosby 2017-11-30 11:17:42 -05:00 committed by GitHub
commit edbf7d8ed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 31 deletions

View file

@ -31,14 +31,6 @@ func (d *Daemon) registerExecCommand(container *container.Container, config *exe
d.execCommands.Add(config.ID, config)
}
func (d *Daemon) registerExecPidUnlocked(container *container.Container, config *exec.Config) {
logrus.Debugf("registering pid %v for exec %v", config.Pid, config.ID)
// Storing execs in container in order to kill them gracefully whenever the container is stopped or removed.
container.ExecCommands.SetPidUnlocked(config.ID, config.Pid)
// Storing execs in daemon for easy access via Engine API.
d.execCommands.SetPidUnlocked(config.ID, config.Pid)
}
// ExecExists looks up the exec instance and returns a bool if it exists or not.
// It will also return the error produced by `getConfig`
func (d *Daemon) ExecExists(name string) (bool, error) {
@ -253,7 +245,6 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
return translateContainerdStartErr(ec.Entrypoint, ec.SetExitCode, err)
}
ec.Pid = systemPid
d.registerExecPidUnlocked(c, ec)
c.ExecCommands.Unlock()
ec.Unlock()

View file

@ -88,16 +88,14 @@ func (c *Config) SetExitCode(code int) {
// Store keeps track of the exec configurations.
type Store struct {
byID map[string]*Config
byPid map[int]*Config
byID map[string]*Config
sync.RWMutex
}
// NewStore initializes a new exec store.
func NewStore() *Store {
return &Store{
byID: make(map[string]*Config),
byPid: make(map[int]*Config),
byID: make(map[string]*Config),
}
}
@ -119,14 +117,6 @@ func (e *Store) Add(id string, Config *Config) {
e.Unlock()
}
// SetPidUnlocked adds an association between a Pid and a config, it does not
// synchronized with other operations.
func (e *Store) SetPidUnlocked(id string, pid int) {
if config, ok := e.byID[id]; ok {
e.byPid[pid] = config
}
}
// Get returns an exec configuration by its id.
func (e *Store) Get(id string) *Config {
e.RLock()
@ -135,18 +125,9 @@ func (e *Store) Get(id string) *Config {
return res
}
// ByPid returns an exec configuration by its pid.
func (e *Store) ByPid(pid int) *Config {
e.RLock()
res := e.byPid[pid]
e.RUnlock()
return res
}
// Delete removes an exec configuration from the store.
func (e *Store) Delete(id string, pid int) {
e.Lock()
delete(e.byPid, pid)
delete(e.byID, id)
e.Unlock()
}

View file

@ -112,7 +112,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
return daemon.postRunProcessing(c, ei)
}
if execConfig := c.ExecCommands.ByPid(int(ei.Pid)); execConfig != nil {
if execConfig := c.ExecCommands.Get(ei.ProcessID); execConfig != nil {
ec := int(ei.ExitCode)
execConfig.Lock()
defer execConfig.Unlock()
@ -129,6 +129,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
} else {
logrus.WithFields(logrus.Fields{
"container": c.ID,
"exec-id": ei.ProcessID,
"exec-pid": ei.Pid,
}).Warnf("Ignoring Exit Event, no such exec command found")
}