summaryrefslogtreecommitdiffstats
path: root/linux/SELinuxMeter.c
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2020-11-01 01:09:51 +0100
committerBenny Baumann <BenBE@geshi.org>2020-11-02 22:15:01 +0100
commit45869513bfebba80cc2ab42e4218f68b34b1e6ac (patch)
treef064631dbff141bf1c945db8cff40b7bb82fd169 /linux/SELinuxMeter.c
parent61e14d4bb25268593019e6df3eb02264b4ac8e0e (diff)
Embracing branches
Diffstat (limited to 'linux/SELinuxMeter.c')
-rw-r--r--linux/SELinuxMeter.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c
index 275eefef..ee1d8470 100644
--- a/linux/SELinuxMeter.c
+++ b/linux/SELinuxMeter.c
@@ -32,16 +32,19 @@ static bool enforcing = false;
static bool hasSELinuxMount(void) {
struct statfs sfbuf;
int r = statfs("/sys/fs/selinux", &sfbuf);
- if (r != 0)
+ if (r != 0) {
return false;
+ }
- if (sfbuf.f_type != SELINUX_MAGIC)
+ if (sfbuf.f_type != SELINUX_MAGIC) {
return false;
+ }
struct statvfs vfsbuf;
r = statvfs("/sys/fs/selinux", &vfsbuf);
- if (r != 0 || (vfsbuf.f_flag & ST_RDONLY))
+ if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) {
return false;
+ }
return true;
}
@@ -51,22 +54,26 @@ static bool isSelinuxEnabled(void) {
}
static bool isSelinuxEnforcing(void) {
- if (!enabled)
+ if (!enabled) {
return false;
+ }
int fd = open("/sys/fs/selinux/enforce", O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
return false;
+ }
char buf[20] = {0};
int r = read(fd, buf, sizeof(buf) - 1);
close(fd);
- if (r < 0)
+ if (r < 0) {
return false;
+ }
int enforce = 0;
- if (sscanf(buf, "%d", &enforce) != 1)
+ if (sscanf(buf, "%d", &enforce) != 1) {
return false;
+ }
return !!enforce;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy