@@ -15,7 +15,6 @@ import (
1515 "time"
1616
1717 "github.com/containerd/console"
18- "github.com/containerd/containerd/identifiers"
1918 "github.com/containerd/containerd/linux/runctypes"
2019 shimapi "github.com/containerd/containerd/linux/shim/v1"
2120 "github.com/containerd/containerd/log"
@@ -61,13 +60,26 @@ type Init struct {
6160 IoGID int
6261}
6362
63+ // NewRunc returns a new runc instance for a process
64+ func NewRunc (root , path , namespace , runtime , criu string , systemd bool ) * runc.Runc {
65+ if root == "" {
66+ root = RuncRoot
67+ }
68+ return & runc.Runc {
69+ Command : runtime ,
70+ Log : filepath .Join (path , "log.json" ),
71+ LogFormat : runc .JSON ,
72+ PdeathSignal : syscall .SIGKILL ,
73+ Root : filepath .Join (root , namespace ),
74+ Criu : criu ,
75+ SystemdCgroup : systemd ,
76+ }
77+ }
78+
6479// New returns a new init process
6580func New (context context.Context , path , workDir , runtimeRoot , namespace , criu string , systemdCgroup bool , platform Platform , r * shimapi.CreateTaskRequest ) (* Init , error ) {
6681 var success bool
6782
68- if err := identifiers .Validate (r .ID ); err != nil {
69- return nil , errors .Wrapf (err , "invalid task id" )
70- }
7183 var options runctypes.CreateOptions
7284 if r .Options != nil {
7385 v , err := typeurl .UnmarshalAny (r .Options )
@@ -99,19 +111,7 @@ func New(context context.Context, path, workDir, runtimeRoot, namespace, criu st
99111 return nil , errors .Wrapf (err , "failed to mount rootfs component %v" , m )
100112 }
101113 }
102- root := runtimeRoot
103- if root == "" {
104- root = RuncRoot
105- }
106- runtime := & runc.Runc {
107- Command : r .Runtime ,
108- Log : filepath .Join (path , "log.json" ),
109- LogFormat : runc .JSON ,
110- PdeathSignal : syscall .SIGKILL ,
111- Root : filepath .Join (root , namespace ),
112- Criu : criu ,
113- SystemdCgroup : systemdCgroup ,
114- }
114+ runtime := NewRunc (runtimeRoot , path , namespace , r .Runtime , criu , systemdCgroup )
115115 p := & Init {
116116 id : r .ID ,
117117 bundle : r .Bundle ,
@@ -339,9 +339,6 @@ func (p *Init) Runtime() *runc.Runc {
339339
340340// Exec returns a new exec'd process
341341func (p * Init ) Exec (context context.Context , path string , r * shimapi.ExecProcessRequest ) (Process , error ) {
342- if err := identifiers .Validate (r .ID ); err != nil {
343- return nil , errors .Wrapf (err , "invalid exec id" )
344- }
345342 // process exec request
346343 var spec specs.Process
347344 if err := json .Unmarshal (r .Spec .Value , & spec ); err != nil {
0 commit comments