2014-02-22 08:29:21 +00:00
|
|
|
package nsinit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-02-22 09:21:26 +00:00
|
|
|
"path/filepath"
|
2014-02-22 08:29:21 +00:00
|
|
|
)
|
|
|
|
|
2014-02-25 05:11:52 +00:00
|
|
|
// StateWriter handles writing and deleting the pid file
|
|
|
|
// on disk
|
2014-02-22 08:29:21 +00:00
|
|
|
type StateWriter interface {
|
|
|
|
WritePid(pid int) error
|
|
|
|
DeletePid() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultStateWriter struct {
|
2014-02-22 09:21:26 +00:00
|
|
|
Root string
|
2014-02-22 08:29:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 20:41:31 +00:00
|
|
|
// writePidFile writes the namespaced processes pid to pid in the rootfs for the container
|
2014-02-22 09:21:26 +00:00
|
|
|
func (d *DefaultStateWriter) WritePid(pid int) error {
|
2014-02-25 20:41:31 +00:00
|
|
|
return ioutil.WriteFile(filepath.Join(d.Root, "pid"), []byte(fmt.Sprint(pid)), 0655)
|
2014-02-22 08:29:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 09:21:26 +00:00
|
|
|
func (d *DefaultStateWriter) DeletePid() error {
|
2014-02-25 20:41:31 +00:00
|
|
|
return os.Remove(filepath.Join(d.Root, "pid"))
|
2014-02-22 08:29:21 +00:00
|
|
|
}
|