Skip to content

Commit eb97de7

Browse files
Srini Brahmarouturoot
authored andcommitted
Decoder does not work properly with nested pointers using gcc
Signed-off-by: Srini Brahmaroutu <[email protected]>
1 parent b27f960 commit eb97de7

2 files changed

Lines changed: 30 additions & 41 deletions

File tree

runconfig/config.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,36 @@ type Config struct {
132132

133133
type ContainerConfigWrapper struct {
134134
*Config
135-
*hostConfigWrapper
135+
InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
136+
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
137+
*HostConfig // Deprecated. Exported to read attrubutes from json that are not in the inner host config structure.
138+
136139
}
137140

138-
func (c ContainerConfigWrapper) HostConfig() *HostConfig {
139-
if c.hostConfigWrapper == nil {
140-
return new(HostConfig)
141+
func (w *ContainerConfigWrapper) GetHostConfig() *HostConfig {
142+
hc := w.HostConfig
143+
144+
if hc == nil && w.InnerHostConfig != nil {
145+
hc = w.InnerHostConfig
146+
} else if w.InnerHostConfig != nil {
147+
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
148+
w.InnerHostConfig.Memory = hc.Memory
149+
}
150+
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
151+
w.InnerHostConfig.MemorySwap = hc.MemorySwap
152+
}
153+
if hc.CpuShares != 0 && w.InnerHostConfig.CpuShares == 0 {
154+
w.InnerHostConfig.CpuShares = hc.CpuShares
155+
}
156+
157+
hc = w.InnerHostConfig
158+
}
159+
160+
if hc != nil && w.Cpuset != "" && hc.CpusetCpus == "" {
161+
hc.CpusetCpus = w.Cpuset
141162
}
142163

143-
return c.hostConfigWrapper.GetHostConfig()
164+
return hc
144165
}
145166

146167
// DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper
@@ -155,5 +176,5 @@ func DecodeContainerConfig(src io.Reader) (*Config, *HostConfig, error) {
155176
return nil, nil, err
156177
}
157178

158-
return w.Config, w.HostConfig(), nil
179+
return w.Config, w.GetHostConfig(), nil
159180
}

runconfig/hostconfig.go

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -234,47 +234,15 @@ type HostConfig struct {
234234
func MergeConfigs(config *Config, hostConfig *HostConfig) *ContainerConfigWrapper {
235235
return &ContainerConfigWrapper{
236236
config,
237-
&hostConfigWrapper{InnerHostConfig: hostConfig},
237+
hostConfig,
238+
"", nil,
238239
}
239240
}
240241

241-
type hostConfigWrapper struct {
242-
InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
243-
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
244-
245-
*HostConfig // Deprecated. Exported to read attrubutes from json that are not in the inner host config structure.
246-
}
247-
248-
func (w hostConfigWrapper) GetHostConfig() *HostConfig {
249-
hc := w.HostConfig
250-
251-
if hc == nil && w.InnerHostConfig != nil {
252-
hc = w.InnerHostConfig
253-
} else if w.InnerHostConfig != nil {
254-
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
255-
w.InnerHostConfig.Memory = hc.Memory
256-
}
257-
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
258-
w.InnerHostConfig.MemorySwap = hc.MemorySwap
259-
}
260-
if hc.CpuShares != 0 && w.InnerHostConfig.CpuShares == 0 {
261-
w.InnerHostConfig.CpuShares = hc.CpuShares
262-
}
263-
264-
hc = w.InnerHostConfig
265-
}
266-
267-
if hc != nil && w.Cpuset != "" && hc.CpusetCpus == "" {
268-
hc.CpusetCpus = w.Cpuset
269-
}
270-
271-
return hc
272-
}
273-
274242
func DecodeHostConfig(src io.Reader) (*HostConfig, error) {
275243
decoder := json.NewDecoder(src)
276244

277-
var w hostConfigWrapper
245+
var w ContainerConfigWrapper
278246
if err := decoder.Decode(&w); err != nil {
279247
return nil, err
280248
}

0 commit comments

Comments
 (0)