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

Engine: fix a bug which caused handlers to be shared between multiple engine instances

This commit is contained in:
Solomon Hykes 2013-10-27 06:54:51 +00:00
parent 7b17d55599
commit 847411a1ee
2 changed files with 23 additions and 3 deletions

View file

@ -18,6 +18,10 @@ func init() {
} }
func Register(name string, handler Handler) error { func Register(name string, handler Handler) error {
_, exists := globalHandlers[name]
if exists {
return fmt.Errorf("Can't overwrite global handler for command %s", name)
}
globalHandlers[name] = handler globalHandlers[name] = handler
return nil return nil
} }
@ -31,6 +35,17 @@ type Engine struct {
hack Hack // data for temporary hackery (see hack.go) hack Hack // data for temporary hackery (see hack.go)
} }
func (eng *Engine) Register(name string, handler Handler) error {
eng.Logf("Register(%s) (handlers=%v)", name, eng.handlers)
_, exists := eng.handlers[name]
if exists {
return fmt.Errorf("Can't overwrite handler for command %s", name)
}
eng.handlers[name] = handler
return nil
}
// New initializes a new engine managing the directory specified at `root`. // New initializes a new engine managing the directory specified at `root`.
// `root` is used to store containers and any other state private to the engine. // `root` is used to store containers and any other state private to the engine.
// Changing the contents of the root without executing a job will cause unspecified // Changing the contents of the root without executing a job will cause unspecified
@ -59,7 +74,12 @@ func New(root string) (*Engine, error) {
} }
eng := &Engine{ eng := &Engine{
root: root, root: root,
handlers: globalHandlers, handlers: make(map[string]Handler),
id: utils.RandomString(),
}
// Copy existing global handlers
for k, v := range globalHandlers {
eng.handlers[k] = v
} }
return eng, nil return eng, nil
} }

View file

@ -60,10 +60,10 @@ func jobInitApi(job *engine.Job) string {
os.Exit(0) os.Exit(0)
}() }()
job.Eng.Hack_SetGlobalVar("httpapi.server", srv) job.Eng.Hack_SetGlobalVar("httpapi.server", srv)
if err := engine.Register("start", srv.ContainerStart); err != nil { if err := job.Eng.Register("start", srv.ContainerStart); err != nil {
return err.Error() return err.Error()
} }
if err := engine.Register("serveapi", srv.ListenAndServe); err != nil { if err := job.Eng.Register("serveapi", srv.ListenAndServe); err != nil {
return err.Error() return err.Error()
} }
return "0" return "0"