Skip to content

Commit 8c10986

Browse files
authored
Merge pull request #269 from dcantah/rm-syscall
cg2: syscall -> x/sys/unix
2 parents 157c4da + 3dd08f5 commit 8c10986

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

cgroup2/manager.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"path/filepath"
2828
"strconv"
2929
"strings"
30-
"syscall"
3130
"time"
3231

3332
"github.com/containerd/cgroups/v3/cgroup2/stats"
@@ -707,19 +706,19 @@ func (c *Manager) isCgroupEmpty() bool {
707706
// MemoryEventFD returns inotify file descriptor and 'memory.events' inotify watch descriptor
708707
func (c *Manager) MemoryEventFD() (int, uint32, error) {
709708
fpath := filepath.Join(c.path, "memory.events")
710-
fd, err := syscall.InotifyInit()
709+
fd, err := unix.InotifyInit()
711710
if err != nil {
712711
return 0, 0, errors.New("failed to create inotify fd")
713712
}
714-
wd, err := syscall.InotifyAddWatch(fd, fpath, unix.IN_MODIFY)
713+
wd, err := unix.InotifyAddWatch(fd, fpath, unix.IN_MODIFY)
715714
if err != nil {
716-
syscall.Close(fd)
715+
unix.Close(fd)
717716
return 0, 0, fmt.Errorf("failed to add inotify watch for %q: %w", fpath, err)
718717
}
719718
// monitor to detect process exit/cgroup deletion
720719
evpath := filepath.Join(c.path, "cgroup.events")
721-
if _, err = syscall.InotifyAddWatch(fd, evpath, unix.IN_MODIFY); err != nil {
722-
syscall.Close(fd)
720+
if _, err = unix.InotifyAddWatch(fd, evpath, unix.IN_MODIFY); err != nil {
721+
unix.Close(fd)
723722
return 0, 0, fmt.Errorf("failed to add inotify watch for %q: %w", evpath, err)
724723
}
725724

@@ -777,16 +776,16 @@ func (c *Manager) waitForEvents(ec chan<- Event, errCh chan<- error) {
777776
errCh <- err
778777
return
779778
}
780-
defer syscall.Close(fd)
779+
defer unix.Close(fd)
781780

782781
for {
783-
buffer := make([]byte, syscall.SizeofInotifyEvent*10)
784-
bytesRead, err := syscall.Read(fd, buffer)
782+
buffer := make([]byte, unix.SizeofInotifyEvent*10)
783+
bytesRead, err := unix.Read(fd, buffer)
785784
if err != nil {
786785
errCh <- err
787786
return
788787
}
789-
if bytesRead >= syscall.SizeofInotifyEvent {
788+
if bytesRead >= unix.SizeofInotifyEvent {
790789
out := make(map[string]interface{})
791790
if err := readKVStatsFile(c.path, "memory.events", out); err != nil {
792791
// When cgroup is deleted read may return -ENODEV instead of -ENOENT from open.

cgroup2/testutils_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ import (
2020
"os"
2121
"path/filepath"
2222
"strings"
23-
"syscall"
2423
"testing"
2524

2625
"github.com/stretchr/testify/assert"
2726
"golang.org/x/sys/unix"
2827
)
2928

3029
func checkCgroupMode(t *testing.T) {
31-
var st syscall.Statfs_t
32-
if err := syscall.Statfs(defaultCgroup2Path, &st); err != nil {
30+
var st unix.Statfs_t
31+
if err := unix.Statfs(defaultCgroup2Path, &st); err != nil {
3332
t.Fatal("cannot statfs cgroup root")
3433
}
3534
isUnified := st.Type == unix.CGROUP2_SUPER_MAGIC

0 commit comments

Comments
 (0)