From f7a89529330044f4e2a38e85a88ec90f839ae64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 25 Nov 2020 12:42:36 +0100 Subject: Add xReadfile wrapper for reading small to medium size files Inspired by proposed Linux syscall Avoid file descriptor leaks like 4af8c63f --- linux/SELinuxMeter.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'linux/SELinuxMeter.c') 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) { -- cgit v1.2.3