WIP for setup kmsg

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-20 12:00:54 -08:00
parent e133d895a6
commit f0b4dd6e58

View file

@ -43,6 +43,9 @@ func setupNewMountNamespace(rootfs, console string, readonly bool) error {
if err := setupPtmx(rootfs, console); err != nil {
return err
}
if err := setupKmsg(rootfs); err != nil {
return err
}
if err := system.Chdir(rootfs); err != nil {
return fmt.Errorf("chdir into %s %s", rootfs, err)
}
@ -211,3 +214,32 @@ func remountSys() error {
}
return nil
}
func setupKmsg(rootfs string) error {
oldMask := system.Umask(0000)
defer system.Umask(oldMask)
var (
source = filepath.Join(rootfs, "dev/kmsg")
dest = filepath.Join(rootfs, "proc/kmsg")
)
if err := system.Mkfifo(source, 0600); err != nil {
return err
}
os.Chmod(source, 0600)
os.Chown(source, 0, 0)
if err := system.Mount(source, dest, "bind", syscall.MS_BIND, ""); err != nil {
return err
}
_, err := os.OpenFile(source, syscall.O_RDWR|syscall.O_NDELAY|syscall.O_CLOEXEC, 0)
if err != nil {
return err
}
if err := syscall.Unlink(source); err != nil {
return err
}
return nil
}