Skip to content

Commit ce66121

Browse files
committed
source/kernel: silence misleading error on selinux detection
Silence a irrelevant error that was printed in case /sys/fs/selinux/ directory exists but selinuxfs is not mounted (i.e. the dir is empty).
1 parent c2e3de6 commit ce66121

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

source/kernel/selinux.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ func SelinuxEnabled() (bool, error) {
3232
return false, err
3333
}
3434

35-
selinuxBase := filepath.Join(sysfsBase, "selinux")
36-
if _, err := os.Stat(selinuxBase); os.IsNotExist(err) {
35+
status, err := os.ReadFile(filepath.Join(sysfsBase, "selinux", "enforce"))
36+
if os.IsNotExist(err) {
3737
klog.V(1).InfoS("selinux not available on the system")
3838
return false, nil
39-
}
40-
41-
status, err := os.ReadFile(filepath.Join(selinuxBase, "enforce"))
42-
if err != nil {
39+
} else if err != nil {
4340
return false, err
4441
}
4542
if status[0] == byte('1') {

0 commit comments

Comments
 (0)