Browse code

add ExecIDs in inspect

Signed-off-by: Victor Vieux <vieux@docker.com>

Victor Vieux authored on 2014/12/24 07:03:20
Showing 2 changed files
... ...
@@ -35,7 +35,7 @@ type execConfig struct {
35 35
 
36 36
 type execStore struct {
37 37
 	s map[string]*execConfig
38
-	sync.Mutex
38
+	sync.RWMutex
39 39
 }
40 40
 
41 41
 func newExecStore() *execStore {
... ...
@@ -49,9 +49,9 @@ func (e *execStore) Add(id string, execConfig *execConfig) {
49 49
 }
50 50
 
51 51
 func (e *execStore) Get(id string) *execConfig {
52
-	e.Lock()
52
+	e.RLock()
53 53
 	res := e.s[id]
54
-	e.Unlock()
54
+	e.RUnlock()
55 55
 	return res
56 56
 }
57 57
 
... ...
@@ -61,6 +61,16 @@ func (e *execStore) Delete(id string) {
61 61
 	e.Unlock()
62 62
 }
63 63
 
64
+func (e *execStore) List() []string {
65
+	var IDs []string
66
+	e.RLock()
67
+	for id, _ := range e.s {
68
+		IDs = append(IDs, id)
69
+	}
70
+	e.RUnlock()
71
+	return IDs
72
+}
73
+
64 74
 func (execConfig *execConfig) Resize(h, w int) error {
65 75
 	return execConfig.ProcessConfig.Terminal.Resize(h, w)
66 76
 }
... ...
@@ -249,6 +259,10 @@ func (d *Daemon) Exec(c *Container, execConfig *execConfig, pipes *execdriver.Pi
249 249
 	return exitStatus, err
250 250
 }
251 251
 
252
+func (container *Container) GetExecIDs() []string {
253
+	return container.execCommands.List()
254
+}
255
+
252 256
 func (container *Container) Exec(execConfig *execConfig) error {
253 257
 	container.Lock()
254 258
 	defer container.Unlock()
... ...
@@ -50,6 +50,8 @@ func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
50 50
 		out.SetJson("VolumesRW", container.VolumesRW)
51 51
 		out.SetJson("AppArmorProfile", container.AppArmorProfile)
52 52
 
53
+		out.SetList("ExecIDs", container.GetExecIDs())
54
+
53 55
 		if children, err := daemon.Children(container.Name); err == nil {
54 56
 			for linkAlias, child := range children {
55 57
 				container.hostConfig.Links = append(container.hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias))