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
|
|
|
}
|
|
|
|
|
|
|
|
// writePidFile writes the namespaced processes pid to .nspid in the rootfs for the container
|
2014-02-22 09:21:26 +00:00
|
|
|
func (d *DefaultStateWriter) WritePid(pid int) error {
|
|
|
|
return ioutil.WriteFile(filepath.Join(d.Root, ".nspid"), []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 {
|
|
|
|
return os.Remove(filepath.Join(d.Root, ".nspid"))
|
2014-02-22 08:29:21 +00:00
|
|
|
}
|