From 28b5ae8cc4492f7b3cc2eb2b30b0f41713822b25 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 31 Jan 2014 02:06:08 +0000 Subject: [PATCH] changed default value of getenvint to 0. fix tests Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- api.go | 12 ++++++++++-- config.go | 2 +- engine/env.go | 2 +- engine/env_test.go | 2 +- server.go | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api.go b/api.go index 0a7f7abea7..79df0f28fc 100644 --- a/api.go +++ b/api.go @@ -584,7 +584,11 @@ func postContainersRestart(srv *Server, version float64, w http.ResponseWriter, return fmt.Errorf("Missing parameter") } job := srv.Eng.Job("restart", vars["name"]) - job.Setenv("t", r.Form.Get("t")) + if r.Form.Get("t") == "" { + job.Setenv("t", "-1") + } else { + job.Setenv("t", r.Form.Get("t")) + } if err := job.Run(); err != nil { return err } @@ -652,7 +656,11 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r * return fmt.Errorf("Missing parameter") } job := srv.Eng.Job("stop", vars["name"]) - job.Setenv("t", r.Form.Get("t")) + if r.Form.Get("t") == "" { + job.Setenv("t", "-1") + } else { + job.Setenv("t", r.Form.Get("t")) + } if err := job.Run(); err != nil { return err } diff --git a/config.go b/config.go index ac34589640..cb7e985ca2 100644 --- a/config.go +++ b/config.go @@ -43,7 +43,7 @@ func DaemonConfigFromJob(job *engine.Job) *DaemonConfig { } else { config.BridgeIface = DefaultNetworkBridge } - if mtu := job.GetenvInt("Mtu"); mtu != -1 { + if mtu := job.GetenvInt("Mtu"); mtu != 0 { config.Mtu = mtu } else { config.Mtu = DefaultNetworkMtu diff --git a/engine/env.go b/engine/env.go index e000fe26b1..d6ca4ec07b 100644 --- a/engine/env.go +++ b/engine/env.go @@ -60,7 +60,7 @@ func (env *Env) GetInt64(key string) int64 { s := strings.Trim(env.Get(key), " \t") val, err := strconv.ParseInt(s, 10, 64) if err != nil { - return -1 + return 0 } return val } diff --git a/engine/env_test.go b/engine/env_test.go index 419c47491e..c7079ff942 100644 --- a/engine/env_test.go +++ b/engine/env_test.go @@ -62,7 +62,7 @@ func TestSetenvInt(t *testing.T) { if val := job.GetenvInt("bar"); val != 42 { t.Fatalf("GetenvInt returns incorrect value: %d", val) } - if val := job.GetenvInt("nonexistent"); val != -1 { + if val := job.GetenvInt("nonexistent"); val != 0 { t.Fatalf("GetenvInt returns incorrect value: %d", val) } } diff --git a/server.go b/server.go index 27c27f25de..6291da6699 100644 --- a/server.go +++ b/server.go @@ -1083,7 +1083,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status { }, -1) for _, container := range srv.runtime.List() { - if !container.State.IsRunning() && !all && n == -1 && since == "" && before == "" { + if !container.State.IsRunning() && !all && n <= 0 && since == "" && before == "" { continue } if before != "" && !foundBefore { @@ -1092,7 +1092,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status { } continue } - if displayed == n { + if n > 0 && displayed == n { break } if container.ID == since || utils.TruncateID(container.ID) == since { @@ -1742,7 +1742,7 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status { return engine.StatusErr } config := ContainerConfigFromJob(job) - if config.Memory > 0 && config.Memory < 524288 { + if config.Memory != 0 && config.Memory < 524288 { job.Errorf("Minimum memory limit allowed is 512k") return engine.StatusErr }