libcontainer: optimize updateStateFile()

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2014-12-17 18:05:39 +03:00
parent 5ecd29c1f2
commit 7996829914
1 changed files with 2 additions and 6 deletions

View File

@ -81,20 +81,16 @@ func (c *linuxContainer) StartProcess(pconfig *ProcessConfig) (int, error) {
}
func (c *linuxContainer) updateStateFile() error {
data, err := json.MarshalIndent(c.state, "", "\t")
if err != nil {
return newGenericError(err, SystemError)
}
fnew := filepath.Join(c.root, fmt.Sprintf("%s.new", stateFilename))
f, err := os.Create(fnew)
if err != nil {
return newGenericError(err, SystemError)
}
_, err = f.Write(data)
err = json.NewEncoder(f).Encode(c.state)
if err != nil {
f.Close()
os.Remove(fnew)
return newGenericError(err, SystemError)
}
f.Close()