mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
96e33a7646
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
28 lines
598 B
Go
28 lines
598 B
Go
package nsinit
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// StateWriter handles writing and deleting the pid file
|
|
// on disk
|
|
type StateWriter interface {
|
|
WritePid(pid int) error
|
|
DeletePid() error
|
|
}
|
|
|
|
type DefaultStateWriter struct {
|
|
Root string
|
|
}
|
|
|
|
// writePidFile writes the namespaced processes pid to pid in the rootfs for the container
|
|
func (d *DefaultStateWriter) WritePid(pid int) error {
|
|
return ioutil.WriteFile(filepath.Join(d.Root, "pid"), []byte(fmt.Sprint(pid)), 0655)
|
|
}
|
|
|
|
func (d *DefaultStateWriter) DeletePid() error {
|
|
return os.Remove(filepath.Join(d.Root, "pid"))
|
|
}
|