github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/daemon/exec/exec.go (about) 1 package exec 2 3 import ( 4 "sync" 5 6 "github.com/docker/docker/pkg/stringid" 7 "github.com/docker/docker/runconfig" 8 ) 9 10 // Config holds the configurations for execs. The Daemon keeps 11 // track of both running and finished execs so that they can be 12 // examined both during and after completion. 13 type Config struct { 14 sync.Mutex 15 *runconfig.StreamConfig 16 ID string 17 Running bool 18 ExitCode *int 19 OpenStdin bool 20 OpenStderr bool 21 OpenStdout bool 22 CanRemove bool 23 ContainerID string 24 DetachKeys []byte 25 Entrypoint string 26 Args []string 27 Tty bool 28 Privileged bool 29 User string 30 Env []string 31 } 32 33 // NewConfig initializes the a new exec configuration 34 func NewConfig() *Config { 35 return &Config{ 36 ID: stringid.GenerateNonCryptoID(), 37 StreamConfig: runconfig.NewStreamConfig(), 38 } 39 } 40 41 // Store keeps track of the exec configurations. 42 type Store struct { 43 commands map[string]*Config 44 sync.RWMutex 45 } 46 47 // NewStore initializes a new exec store. 48 func NewStore() *Store { 49 return &Store{commands: make(map[string]*Config, 0)} 50 } 51 52 // Commands returns the exec configurations in the store. 53 func (e *Store) Commands() map[string]*Config { 54 e.RLock() 55 commands := make(map[string]*Config, len(e.commands)) 56 for id, config := range e.commands { 57 commands[id] = config 58 } 59 e.RUnlock() 60 return commands 61 } 62 63 // Add adds a new exec configuration to the store. 64 func (e *Store) Add(id string, Config *Config) { 65 e.Lock() 66 e.commands[id] = Config 67 e.Unlock() 68 } 69 70 // Get returns an exec configuration by its id. 71 func (e *Store) Get(id string) *Config { 72 e.RLock() 73 res := e.commands[id] 74 e.RUnlock() 75 return res 76 } 77 78 // Delete removes an exec configuration from the store. 79 func (e *Store) Delete(id string) { 80 e.Lock() 81 delete(e.commands, id) 82 e.Unlock() 83 } 84 85 // List returns the list of exec ids in the store. 86 func (e *Store) List() []string { 87 var IDs []string 88 e.RLock() 89 for id := range e.commands { 90 IDs = append(IDs, id) 91 } 92 e.RUnlock() 93 return IDs 94 }