From 81ffd6530aced5237c01bd13e80686da68de6637 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 15 May 2014 23:27:36 +0000 Subject: [PATCH] allow 2 docker events to be opened on the same computer over unix socket Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- api/server/server.go | 2 +- server/server.go | 12 ++++++------ server/server_unit_test.go | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index e2a7f651a8..9bf6da3fe2 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -244,7 +244,7 @@ func getEvents(eng *engine.Engine, version version.Version, w http.ResponseWrite return err } - var job = eng.Job("events", r.RemoteAddr) + var job = eng.Job("events") streamJSON(job, w, true) job.Setenv("since", r.Form.Get("since")) job.Setenv("until", r.Form.Get("until")) diff --git a/server/server.go b/server/server.go index cab11bcf50..49fb00ce54 100644 --- a/server/server.go +++ b/server/server.go @@ -198,7 +198,7 @@ func (srv *Server) ContainerKill(job *engine.Job) engine.Status { return engine.StatusOK } -func (srv *Server) EvictListener(from string) { +func (srv *Server) EvictListener(from int64) { srv.Lock() if old, ok := srv.listeners[from]; ok { delete(srv.listeners, from) @@ -208,12 +208,12 @@ func (srv *Server) EvictListener(from string) { } func (srv *Server) Events(job *engine.Job) engine.Status { - if len(job.Args) != 1 { - return job.Errorf("Usage: %s FROM", job.Name) + if len(job.Args) != 0 { + return job.Errorf("Usage: %s", job.Name) } var ( - from = job.Args[0] + from = time.Now().UTC().UnixNano() since = job.GetenvInt64("since") until = job.GetenvInt64("until") timeout = time.NewTimer(time.Unix(until, 0).Sub(time.Now())) @@ -2432,7 +2432,7 @@ func NewServer(eng *engine.Engine, config *daemonconfig.Config) (*Server, error) pullingPool: make(map[string]chan struct{}), pushingPool: make(map[string]chan struct{}), events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events - listeners: make(map[string]chan utils.JSONMessage), + listeners: make(map[int64]chan utils.JSONMessage), running: true, } daemon.SetServer(srv) @@ -2494,7 +2494,7 @@ type Server struct { pullingPool map[string]chan struct{} pushingPool map[string]chan struct{} events []utils.JSONMessage - listeners map[string]chan utils.JSONMessage + listeners map[int64]chan utils.JSONMessage Eng *engine.Engine running bool } diff --git a/server/server_unit_test.go b/server/server_unit_test.go index b471c5c581..47e4be8280 100644 --- a/server/server_unit_test.go +++ b/server/server_unit_test.go @@ -1,9 +1,10 @@ package server import ( - "github.com/dotcloud/docker/utils" "testing" "time" + + "github.com/dotcloud/docker/utils" ) func TestPools(t *testing.T) { @@ -47,14 +48,14 @@ func TestPools(t *testing.T) { func TestLogEvent(t *testing.T) { srv := &Server{ events: make([]utils.JSONMessage, 0, 64), - listeners: make(map[string]chan utils.JSONMessage), + listeners: make(map[int64]chan utils.JSONMessage), } srv.LogEvent("fakeaction", "fakeid", "fakeimage") listener := make(chan utils.JSONMessage) srv.Lock() - srv.listeners["test"] = listener + srv.listeners[1337] = listener srv.Unlock() srv.LogEvent("fakeaction2", "fakeid", "fakeimage")