@@ -7,7 +7,7 @@ package cgroup
7
7
import (
8
8
"internal/bytealg"
9
9
"internal/runtime/strconv"
10
- "internal/runtime/syscall"
10
+ "internal/runtime/syscall/linux "
11
11
)
12
12
13
13
var (
@@ -77,10 +77,10 @@ type CPU struct {
77
77
func (c CPU ) Close () {
78
78
switch c .version {
79
79
case V1 :
80
- syscall .Close (c .quotaFD )
81
- syscall .Close (c .periodFD )
80
+ linux .Close (c .quotaFD )
81
+ linux .Close (c .periodFD )
82
82
case V2 :
83
- syscall .Close (c .quotaFD )
83
+ linux .Close (c .quotaFD )
84
84
default :
85
85
throw ("impossible cgroup version" )
86
86
}
@@ -112,7 +112,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
112
112
case 1 :
113
113
n2 := copy (base [n :], v1QuotaFile )
114
114
path := base [:n + n2 ]
115
- quotaFD , errno := syscall .Open (& path [0 ], syscall .O_RDONLY | syscall .O_CLOEXEC , 0 )
115
+ quotaFD , errno := linux .Open (& path [0 ], linux .O_RDONLY | linux .O_CLOEXEC , 0 )
116
116
if errno != 0 {
117
117
// This may fail if this process was migrated out of
118
118
// the cgroup found by FindCPU and that cgroup has been
@@ -122,7 +122,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
122
122
123
123
n2 = copy (base [n :], v1PeriodFile )
124
124
path = base [:n + n2 ]
125
- periodFD , errno := syscall .Open (& path [0 ], syscall .O_RDONLY | syscall .O_CLOEXEC , 0 )
125
+ periodFD , errno := linux .Open (& path [0 ], linux .O_RDONLY | linux .O_CLOEXEC , 0 )
126
126
if errno != 0 {
127
127
// This may fail if this process was migrated out of
128
128
// the cgroup found by FindCPU and that cgroup has been
@@ -139,7 +139,7 @@ func OpenCPU(scratch []byte) (CPU, error) {
139
139
case 2 :
140
140
n2 := copy (base [n :], v2MaxFile )
141
141
path := base [:n + n2 ]
142
- maxFD , errno := syscall .Open (& path [0 ], syscall .O_RDONLY | syscall .O_CLOEXEC , 0 )
142
+ maxFD , errno := linux .Open (& path [0 ], linux .O_RDONLY | linux .O_CLOEXEC , 0 )
143
143
if errno != 0 {
144
144
// This may fail if this process was migrated out of
145
145
// the cgroup found by FindCPU and that cgroup has been
@@ -200,7 +200,7 @@ func readV1Number(fd int) (int64, error) {
200
200
//
201
201
// Always read from the beginning of the file to get a fresh value.
202
202
var b [64 ]byte
203
- n , errno := syscall .Pread (fd , b [:], 0 )
203
+ n , errno := linux .Pread (fd , b [:], 0 )
204
204
if errno != 0 {
205
205
return 0 , errSyscallFailed
206
206
}
@@ -248,7 +248,7 @@ func readV2Limit(fd int) (float64, bool, error) {
248
248
//
249
249
// Always read from the beginning of the file to get a fresh value.
250
250
var b [64 ]byte
251
- n , errno := syscall .Pread (fd , b [:], 0 )
251
+ n , errno := linux .Pread (fd , b [:], 0 )
252
252
if errno != 0 {
253
253
return 0 , false , errSyscallFailed
254
254
}
@@ -345,22 +345,22 @@ func FindCPU(out []byte, scratch []byte) (int, Version, error) {
345
345
// Returns ErrNoCgroup if the process is not in a CPU cgroup.
346
346
func FindCPURelativePath (out []byte , scratch []byte ) (int , Version , error ) {
347
347
path := []byte ("/proc/self/cgroup\x00 " )
348
- fd , errno := syscall .Open (& path [0 ], syscall .O_RDONLY | syscall .O_CLOEXEC , 0 )
349
- if errno == syscall .ENOENT {
348
+ fd , errno := linux .Open (& path [0 ], linux .O_RDONLY | linux .O_CLOEXEC , 0 )
349
+ if errno == linux .ENOENT {
350
350
return 0 , 0 , ErrNoCgroup
351
351
} else if errno != 0 {
352
352
return 0 , 0 , errSyscallFailed
353
353
}
354
354
355
355
// The relative path always starts with /, so we can directly append it
356
356
// to the mount point.
357
- n , version , err := parseCPURelativePath (fd , syscall .Read , out [:], scratch )
357
+ n , version , err := parseCPURelativePath (fd , linux .Read , out [:], scratch )
358
358
if err != nil {
359
- syscall .Close (fd )
359
+ linux .Close (fd )
360
360
return 0 , 0 , err
361
361
}
362
362
363
- syscall .Close (fd )
363
+ linux .Close (fd )
364
364
return n , version , nil
365
365
}
366
366
@@ -489,19 +489,19 @@ func FindCPUMountPoint(out []byte, scratch []byte) (int, error) {
489
489
checkBufferSize (scratch , ParseSize )
490
490
491
491
path := []byte ("/proc/self/mountinfo\x00 " )
492
- fd , errno := syscall .Open (& path [0 ], syscall .O_RDONLY | syscall .O_CLOEXEC , 0 )
493
- if errno == syscall .ENOENT {
492
+ fd , errno := linux .Open (& path [0 ], linux .O_RDONLY | linux .O_CLOEXEC , 0 )
493
+ if errno == linux .ENOENT {
494
494
return 0 , ErrNoCgroup
495
495
} else if errno != 0 {
496
496
return 0 , errSyscallFailed
497
497
}
498
498
499
- n , err := parseCPUMount (fd , syscall .Read , out , scratch )
499
+ n , err := parseCPUMount (fd , linux .Read , out , scratch )
500
500
if err != nil {
501
- syscall .Close (fd )
501
+ linux .Close (fd )
502
502
return 0 , err
503
503
}
504
- syscall .Close (fd )
504
+ linux .Close (fd )
505
505
506
506
return n , nil
507
507
}
0 commit comments