2024-03-20 19:14:31 -07:00

36 lines
949 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package container
import (
"os"
"syscall"
"upod/internal/log"
)
// RunContainerInitProcess 启动容器的init进程
/*
这里的init函数是在容器内部执行的也就是说代码执行到这里后容器所在的进程其实就已经创建出来了
这是本容器执行的第一个进程。
使用mount先去挂载proc文件系统以便后面通过ps等系统命令去查看当前进程资源的情况。
*/
func RunContainerInitProcess(command string, args []string) error {
var (
err error
)
log.Debug("RunContainerInitProcess: command=%s args=%v", command, args)
syscall.Mount("", "/", "", syscall.MS_PRIVATE|syscall.MS_REC, "")
defaultMountFlags := syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV
_ = syscall.Mount("proc", "/proc", "proc", uintptr(defaultMountFlags), "")
argv := []string{command}
if err = syscall.Exec(command, argv, os.Environ()); err != nil {
return err
}
return nil
}