mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Replace os.Is* error checking functions with their errors.Is counterpart
Signed-off-by: Curd Becker <me@curd-becker.de>
This commit is contained in:
@@ -142,7 +142,7 @@ func security(config *configs.Config) error {
|
||||
|
||||
func namespaces(config *configs.Config) error {
|
||||
if config.Namespaces.Contains(configs.NEWUSER) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); errors.Is(err, os.ErrNotExist) {
|
||||
return errors.New("user namespaces aren't enabled in the kernel")
|
||||
}
|
||||
hasPath := config.Namespaces.PathOf(configs.NEWUSER) != ""
|
||||
@@ -160,13 +160,13 @@ func namespaces(config *configs.Config) error {
|
||||
}
|
||||
|
||||
if config.Namespaces.Contains(configs.NEWCGROUP) {
|
||||
if _, err := os.Stat("/proc/self/ns/cgroup"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/cgroup"); errors.Is(err, os.ErrNotExist) {
|
||||
return errors.New("cgroup namespaces aren't enabled in the kernel")
|
||||
}
|
||||
}
|
||||
|
||||
if config.Namespaces.Contains(configs.NEWTIME) {
|
||||
if _, err := os.Stat("/proc/self/timens_offsets"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/timens_offsets"); errors.Is(err, os.ErrNotExist) {
|
||||
return errors.New("time namespaces aren't enabled in the kernel")
|
||||
}
|
||||
hasPath := config.Namespaces.PathOf(configs.NEWTIME) != ""
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package validate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -172,7 +173,7 @@ func TestValidateSecurityWithoutNEWNS(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateUserNamespace(t *testing.T) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); errors.Is(err, os.ErrNotExist) {
|
||||
t.Skip("Test requires userns.")
|
||||
}
|
||||
config := &configs.Config{
|
||||
@@ -206,7 +207,7 @@ func TestValidateUsernsMappingWithoutNamespace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateTimeNamespace(t *testing.T) {
|
||||
if _, err := os.Stat("/proc/self/ns/time"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/time"); errors.Is(err, os.ErrNotExist) {
|
||||
t.Skip("Test requires timens.")
|
||||
}
|
||||
config := &configs.Config{
|
||||
@@ -225,7 +226,7 @@ func TestValidateTimeNamespace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateTimeNamespaceWithBothPathAndTimeOffset(t *testing.T) {
|
||||
if _, err := os.Stat("/proc/self/ns/time"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/time"); errors.Is(err, os.ErrNotExist) {
|
||||
t.Skip("Test requires timens.")
|
||||
}
|
||||
config := &configs.Config{
|
||||
@@ -1020,7 +1021,7 @@ func TestValidateNetDevices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateUserSysctlWithUserNamespace(t *testing.T) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat("/proc/self/ns/user"); errors.Is(err, os.ErrNotExist) {
|
||||
t.Skip("Test requires userns.")
|
||||
}
|
||||
config := &configs.Config{
|
||||
|
||||
Reference in New Issue
Block a user