@@ -44,6 +44,8 @@ import (
4444 taskAPI "github.com/containerd/containerd/runtime/v2/task"
4545 runcC "github.com/containerd/go-runc"
4646 "github.com/containerd/typeurl"
47+ "github.com/gogo/protobuf/proto"
48+ "github.com/gogo/protobuf/types"
4749 ptypes "github.com/gogo/protobuf/types"
4850 specs "github.com/opencontainers/runtime-spec/specs-go"
4951 "github.com/pkg/errors"
@@ -163,6 +165,31 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
163165 if err := shim .WriteAddress ("address" , address ); err != nil {
164166 return "" , err
165167 }
168+ if data , err := ioutil .ReadAll (os .Stdin ); err == nil {
169+ if len (data ) > 0 {
170+ var any types.Any
171+ if err := proto .Unmarshal (data , & any ); err != nil {
172+ return "" , err
173+ }
174+ v , err := typeurl .UnmarshalAny (& any )
175+ if err != nil {
176+ return "" , err
177+ }
178+ if opts , ok := v .(* options.Options ); ok {
179+ if opts .ShimCgroup != "" {
180+ cg , err := cgroups .Load (cgroups .V1 , cgroups .StaticPath (opts .ShimCgroup ))
181+ if err != nil {
182+ return "" , errors .Wrapf (err , "failed to load cgroup %s" , opts .ShimCgroup )
183+ }
184+ if err := cg .Add (cgroups.Process {
185+ Pid : cmd .Process .Pid ,
186+ }); err != nil {
187+ return "" , errors .Wrapf (err , "failed to join cgroup %s" , opts .ShimCgroup )
188+ }
189+ }
190+ }
191+ }
192+ }
166193 if err := shim .SetScore (cmd .Process .Pid ); err != nil {
167194 return "" , errors .Wrap (err , "failed to set OOM Score on shim" )
168195 }
0 commit comments