github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/fsimpl/cgroupfs/job.go (about) 1 // Copyright 2021 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cgroupfs 16 17 import ( 18 "github.com/nicocha30/gvisor-ligolo/pkg/atomicbitops" 19 "github.com/nicocha30/gvisor-ligolo/pkg/context" 20 "github.com/nicocha30/gvisor-ligolo/pkg/sentry/fsimpl/kernfs" 21 "github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel" 22 "github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel/auth" 23 ) 24 25 // +stateify savable 26 type jobController struct { 27 controllerCommon 28 controllerStateless 29 controllerNoResource 30 31 id atomicbitops.Int64 32 } 33 34 var _ controller = (*jobController)(nil) 35 36 func newJobController(fs *filesystem) *jobController { 37 c := &jobController{} 38 c.controllerCommon.init(kernel.CgroupControllerJob, fs) 39 return c 40 } 41 42 // Clone implements controller.Clone. 43 func (c *jobController) Clone() controller { 44 new := &jobController{ 45 id: atomicbitops.FromInt64(c.id.Load()), 46 } 47 new.controllerCommon.cloneFromParent(c) 48 return new 49 } 50 51 func (c *jobController) AddControlFiles(ctx context.Context, creds *auth.Credentials, _ *cgroupInode, contents map[string]kernfs.Inode) { 52 contents["job.id"] = c.fs.newStubControllerFile(ctx, creds, &c.id, true) 53 }