github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/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 } 31 32 // NewConfig initializes the a new exec configuration 33 func NewConfig() *Config { 34 return &Config{ 35 ID: stringid.GenerateNonCryptoID(), 36 StreamConfig: runconfig.NewStreamConfig(), 37 } 38 } 39 40 // Store keeps track of the exec configurations. 41 type Store struct { 42 commands map[string]*Config 43 sync.RWMutex 44 } 45 46 // NewStore initializes a new exec store. 47 func NewStore() *Store { 48 return &Store{commands: make(map[string]*Config, 0)} 49 } 50 51 // Commands returns the exec configurations in the store. 52 func (e *Store) Commands() map[string]*Config { 53 e.RLock() 54 commands := make(map[string]*Config, len(e.commands)) 55 for id, config := range e.commands { 56 commands[id] = config 57 } 58 e.RUnlock() 59 return commands 60 } 61 62 // Add adds a new exec configuration to the store. 63 func (e *Store) Add(id string, Config *Config) { 64 e.Lock() 65 e.commands[id] = Config 66 e.Unlock() 67 } 68 69 // Get returns an exec configuration by its id. 70 func (e *Store) Get(id string) *Config { 71 e.RLock() 72 res := e.commands[id] 73 e.RUnlock() 74 return res 75 } 76 77 // Delete removes an exec configuration from the store. 78 func (e *Store) Delete(id string) { 79 e.Lock() 80 delete(e.commands, id) 81 e.Unlock() 82 } 83 84 // List returns the list of exec ids in the store. 85 func (e *Store) List() []string { 86 var IDs []string 87 e.RLock() 88 for id := range e.commands { 89 IDs = append(IDs, id) 90 } 91 e.RUnlock() 92 return IDs 93 }