summaryrefslogtreecommitdiffstats
path: root/linux/SELinuxMeter.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-25 12:42:36 +0100
committerBenBE <BenBE@geshi.org>2020-12-02 20:39:36 +0100
commitf7a89529330044f4e2a38e85a88ec90f839ae64e (patch)
tree23b187477ea294d9a0f7d0557c3a51acdd0cbdd0 /linux/SELinuxMeter.c
parent1d8192c10b4e149c7f9126f00534f6a8488d10c4 (diff)
Add xReadfile wrapper for reading small to medium size files
Inspired by proposed Linux syscall Avoid file descriptor leaks like 4af8c63f
Diffstat (limited to 'linux/SELinuxMeter.c')
-rw-r--r--linux/SELinuxMeter.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c
index ee1d8470..4bbf030c 100644
--- a/linux/SELinuxMeter.c
+++ b/linux/SELinuxMeter.c
@@ -58,17 +58,10 @@ static bool isSelinuxEnforcing(void) {
return false;
}
- int fd = open("/sys/fs/selinux/enforce", O_RDONLY);
- if (fd < 0) {
+ char buf[20];
+ ssize_t r = xReadfile("/sys/fs/selinux/enforce", buf, sizeof(buf));
+ if (r < 0)
return false;
- }
-
- char buf[20] = {0};
- int r = read(fd, buf, sizeof(buf) - 1);
- close(fd);
- if (r < 0) {
- return false;
- }
int enforce = 0;
if (sscanf(buf, "%d", &enforce) != 1) {

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