runc代码目录结构
1 | ├── create.go # createCommand |
libcontainer目录结构
1 | libcontainer |
Main函数
runc的代码仓库主要使用了github.com/urfave/cli的命令框架(该框架与cobra命令框架类似)。添加了多个重要的子命令。
1 | func main() { |
runCommand
以runCommand
为例分析子命令的调用流程。
github.com/urfave/cli命令框架代码格式:
创建一个Command结构体,包含:
-
Name:命名名称
-
Usage:使用说明
-
Description:描述命令信息
-
Flags:解析参数
-
Action: command run的核心逻辑。
1 | // default action is to start a container |
startContainer
启动容器的流程:
-
setup spec信息。
-
基于spec信息创建container。
-
通过runner启动进程。
删除error处理代码
1 | func startContainer(context *cli.Context, action CtAct, criuOpts *libcontainer.CriuOpts) (int, error) { |
待完善
赞赏一下