summaryrefslogtreecommitdiff
path: root/src/core/ima-setup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-18 19:22:43 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-18 19:31:34 +0100
commit03e334a1c7dc8c20c38902aa039440763acc9b17 (patch)
treebc30b522de8ef9c251bf3ff2fe2d52c92dd8b1ea /src/core/ima-setup.c
parent9459781ee66eb57709c8b8701701365ba60a9f1c (diff)
util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed, and returns -1 unconditionally. This makes it easy to write lines like this: fd = safe_close(fd); Which will close an fd if it is open, and reset the fd variable correctly. By making use of this new scheme we can drop a > 200 lines of code that was required to test for non-negative fds or to reset the closed fd variable afterwards.
Diffstat (limited to 'src/core/ima-setup.c')
-rw-r--r--src/core/ima-setup.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c
index 7f8ec23d58..ed65096f04 100644
--- a/src/core/ima-setup.c
+++ b/src/core/ima-setup.c
@@ -47,7 +47,7 @@ int ima_setup(void) {
struct stat st;
ssize_t policy_size = 0, written = 0;
char *policy;
- int policyfd = -1, imafd = -1;
+ _cleanup_close_ int policyfd = -1, imafd = -1;
int result = 0;
if (stat(IMA_POLICY_PATH, &st) < 0)
@@ -98,10 +98,6 @@ int ima_setup(void) {
out_mmap:
munmap(policy, policy_size);
out:
- if (policyfd >= 0)
- close_nointr_nofail(policyfd);
- if (imafd >= 0)
- close_nointr_nofail(imafd);
if (result)
return result;
#endif /* HAVE_IMA */