From 0a909ba75a556db6acbb2a30d2e741b365217c83 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Sat, 6 Mar 2021 09:52:23 -0800 Subject: [op] Replace syscall package usage with golang.org/x/sys/unix in test/. The syscall package has been deprecated in favor of golang.org/x/sys. Note that syscall is still used in some places because the following don't seem to have an equivalent in unix package: - syscall.SysProcIDMap - syscall.Credential Updates #214 PiperOrigin-RevId: 361332034 --- test/runner/runner.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/runner/runner.go') diff --git a/test/runner/runner.go b/test/runner/runner.go index e72c59200..1dc3c2818 100644 --- a/test/runner/runner.go +++ b/test/runner/runner.go @@ -103,18 +103,18 @@ func runTestCaseNative(testBin string, tc gtest.TestCase, t *testing.T) { cmd.Env = env cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.SysProcAttr = &syscall.SysProcAttr{} + cmd.SysProcAttr = &unix.SysProcAttr{} if specutils.HasCapabilities(capability.CAP_SYS_ADMIN) { - cmd.SysProcAttr.Cloneflags |= syscall.CLONE_NEWUTS + cmd.SysProcAttr.Cloneflags |= unix.CLONE_NEWUTS } if specutils.HasCapabilities(capability.CAP_NET_ADMIN) { - cmd.SysProcAttr.Cloneflags |= syscall.CLONE_NEWNET + cmd.SysProcAttr.Cloneflags |= unix.CLONE_NEWNET } if err := cmd.Run(); err != nil { - ws := err.(*exec.ExitError).Sys().(syscall.WaitStatus) + ws := err.(*exec.ExitError).Sys().(unix.WaitStatus) t.Errorf("test %q exited with status %d, want 0", tc.FullName(), ws.ExitStatus()) } } @@ -148,7 +148,7 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { "-log-format=text", "-TESTONLY-unsafe-nonroot=true", "-net-raw=true", - fmt.Sprintf("-panic-signal=%d", syscall.SIGTERM), + fmt.Sprintf("-panic-signal=%d", unix.SIGTERM), "-watchdog-action=panic", "-platform", *platform, "-file-access", *fileAccess, @@ -176,7 +176,7 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { } testLogDir := "" - if undeclaredOutputsDir, ok := syscall.Getenv("TEST_UNDECLARED_OUTPUTS_DIR"); ok { + if undeclaredOutputsDir, ok := unix.Getenv("TEST_UNDECLARED_OUTPUTS_DIR"); ok { // Create log directory dedicated for this test. testLogDir = filepath.Join(undeclaredOutputsDir, strings.Replace(name, "/", "_", -1)) if err := os.MkdirAll(testLogDir, 0755); err != nil { @@ -200,8 +200,8 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { // as root inside that namespace to get it. rArgs := append(args, "run", "--bundle", bundleDir, id) cmd := exec.Command(*runscPath, rArgs...) - cmd.SysProcAttr = &syscall.SysProcAttr{ - Cloneflags: syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS, + cmd.SysProcAttr = &unix.SysProcAttr{ + Cloneflags: unix.CLONE_NEWUSER | unix.CLONE_NEWNS, // Set current user/group as root inside the namespace. UidMappings: []syscall.SysProcIDMap{ {ContainerID: 0, HostID: os.Getuid(), Size: 1}, @@ -219,7 +219,7 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { cmd.Stderr = os.Stderr sig := make(chan os.Signal, 1) defer close(sig) - signal.Notify(sig, syscall.SIGTERM) + signal.Notify(sig, unix.SIGTERM) defer signal.Stop(sig) go func() { s, ok := <-sig @@ -247,7 +247,7 @@ func runRunsc(tc gtest.TestCase, spec *specs.Spec) error { log.Warningf("Send SIGTERM to the sandbox process") dArgs = append(args, "debug", - fmt.Sprintf("--signal=%d", syscall.SIGTERM), + fmt.Sprintf("--signal=%d", unix.SIGTERM), id) signal := exec.Command(*runscPath, dArgs...) signal.Stdout = os.Stdout -- cgit v1.2.3