mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3863 from vieux/default_getint_0
changed default value of getenvint to 0. fix tests
This commit is contained in:
commit
a0d82b17c7
5 changed files with 22 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,10 @@ func (job *Job) String() string {
|
|||
return fmt.Sprintf("%s.%s%s", job.Eng, job.CallString(), job.StatusString())
|
||||
}
|
||||
|
||||
func (job *Job) EnvExists(key string) (value bool) {
|
||||
return job.env.Exists(key)
|
||||
}
|
||||
|
||||
func (job *Job) Getenv(key string) (value string) {
|
||||
return job.env.Get(key)
|
||||
}
|
||||
|
|
26
server.go
26
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
|
||||
}
|
||||
|
@ -1798,10 +1798,12 @@ func (srv *Server) ContainerRestart(job *engine.Job) engine.Status {
|
|||
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
name := job.Args[0]
|
||||
t := job.GetenvInt("t")
|
||||
if t == -1 {
|
||||
t = 10
|
||||
var (
|
||||
name = job.Args[0]
|
||||
t = 10
|
||||
)
|
||||
if job.EnvExists("t") {
|
||||
t = job.GetenvInt("t")
|
||||
}
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
if err := container.Restart(int(t)); err != nil {
|
||||
|
@ -2239,10 +2241,12 @@ func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
|
|||
job.Errorf("Usage: %s CONTAINER\n", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
name := job.Args[0]
|
||||
t := job.GetenvInt("t")
|
||||
if t == -1 {
|
||||
t = 10
|
||||
var (
|
||||
name = job.Args[0]
|
||||
t = 10
|
||||
)
|
||||
if job.EnvExists("t") {
|
||||
t = job.GetenvInt("t")
|
||||
}
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
if err := container.Stop(int(t)); err != nil {
|
||||
|
|
Loading…
Reference in a new issue