forked from docker-archive/libcontainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace pid and started file with State type
Docker-DCO-1.1-Signed-off-by: Michael Crosby <[email protected]> (github: crosbymichael)
- Loading branch information
Michael Crosby
committed
Jun 25, 2014
1 parent
e49f5f4
commit 81e5a3f
Showing
6 changed files
with
64 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package libcontainer | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// State represents a running container's state | ||
type State struct { | ||
// Pid1 is the process id for the container's pid 1 in it's parent namespace | ||
Pid1 int `json:"pid1,omitempty"` | ||
// Pid1StartTime is the process start time for the container's pid 1 | ||
Pid1StartTime string `json:"pid1_start_time,omitempty"` | ||
} | ||
|
||
// WriteState writes the container's runtime state to a state.json file | ||
// in the specified path | ||
func WriteState(basePath string, state *State) error { | ||
f, err := os.Create(filepath.Join(basePath, "state.json")) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
return json.NewEncoder(f).Encode(state) | ||
} | ||
|
||
// LoadState reads the state.json file for a running container | ||
func LoadState(basePath string) (*State, error) { | ||
f, err := os.Open(filepath.Join(basePath, "state.json")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
var state *State | ||
if err := json.NewDecoder(f).Decode(&state); err != nil { | ||
return nil, err | ||
} | ||
|
||
return state, nil | ||
} | ||
|
||
// DeleteState deletes the state.json file | ||
func DeleteState(basePath string) error { | ||
return os.Remove(filepath.Join(basePath, "state.json")) | ||
} |