diff options
author | Rahat Mahmood <rahat@google.com> | 2021-04-21 13:34:51 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-21 13:36:50 -0700 |
commit | e3a5da8ce62826f56c0b531590bb472ea717eeac (patch) | |
tree | d27a0e931a57b43613b90d878d45024da6144699 /pkg/sentry/fsimpl/cgroupfs/base.go | |
parent | e2b5de65ceddbfb8f4302c423fc8e2d8669b9634 (diff) |
Stub the custom "job" controller required by some workloads.
PiperOrigin-RevId: 369724358
Diffstat (limited to 'pkg/sentry/fsimpl/cgroupfs/base.go')
-rw-r--r-- | pkg/sentry/fsimpl/cgroupfs/base.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/sentry/fsimpl/cgroupfs/base.go b/pkg/sentry/fsimpl/cgroupfs/base.go index 39c1013e1..0f54888d8 100644 --- a/pkg/sentry/fsimpl/cgroupfs/base.go +++ b/pkg/sentry/fsimpl/cgroupfs/base.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" "sort" + "strconv" "sync/atomic" "gvisor.dev/gvisor/pkg/abi/linux" @@ -26,6 +27,7 @@ import ( "gvisor.dev/gvisor/pkg/sentry/kernel" "gvisor.dev/gvisor/pkg/sentry/kernel/auth" "gvisor.dev/gvisor/pkg/sentry/vfs" + "gvisor.dev/gvisor/pkg/syserror" "gvisor.dev/gvisor/pkg/usermem" ) @@ -231,3 +233,29 @@ func (d *tasksData) Write(ctx context.Context, src usermem.IOSequence, offset in // TODO(b/183137098): Payload is the pid for a process to add to this cgroup. return src.NumBytes(), nil } + +// parseInt64FromString interprets src as string encoding a int64 value, and +// returns the parsed value. +func parseInt64FromString(ctx context.Context, src usermem.IOSequence, offset int64) (val, len int64, err error) { + const maxInt64StrLen = 20 // i.e. len(fmt.Sprintf("%d", math.MinInt64)) == 20 + + t := kernel.TaskFromContext(ctx) + src = src.DropFirst64(offset) + + buf := t.CopyScratchBuffer(maxInt64StrLen) + n, err := src.CopyIn(ctx, buf) + if err != nil { + return 0, int64(n), err + } + buf = buf[:n] + + val, err = strconv.ParseInt(string(buf), 10, 64) + if err != nil { + // Note: This also handles zero-len writes if offset is beyond the end + // of src, or src is empty. + ctx.Warningf("cgroupfs.parseInt64FromString: failed to parse %q: %v", string(buf), err) + return 0, int64(n), syserror.EINVAL + } + + return val, int64(n), nil +} |