diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-12-11 19:50:30 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-12-14 10:42:25 +0100 |
commit | 0d5366733428b657e1b5b7700b461e878e00b578 (patch) | |
tree | e2bcdb9f85e01c79221a9f4797e11fae60166c48 /src/core/smack-setup.c | |
parent | Merge pull request #7625 from thom311/th/const-strlen (diff) | |
download | systemd-0d5366733428b657e1b5b7700b461e878e00b578.tar.xz systemd-0d5366733428b657e1b5b7700b461e878e00b578.zip |
tree-wide: use __fsetlocking() instead of fxyz_unlocked()
Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f,
FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*,
instead of doing individual per-call decision whether to use normal
calls or _unlocked() calls.
This has various benefits:
1. It's easier to read and easier not to forget
2. It's more comprehensive, as fprintf() and friends are covered too
(as these functions have no _unlocked() counterpart)
3. Philosophically, it's a bit more correct, because it's more a
property of the file handle really whether we ever pass it on to another
thread, not of the operations we then apply to it.
This patch reworks all pieces of codes that so far used fxyz_unlocked()
calls to use __fsetlocking() instead. It also reworks all places that
use open_memstream(), i.e. use stdio FILE* for string manipulations.
Note that this in some way a revert of 4b61c8751135c58be043d86b9fef4c8ec7aadf18.
Diffstat (limited to 'src/core/smack-setup.c')
-rw-r--r-- | src/core/smack-setup.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index a5b6ea2cd6..b0d3612d69 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -24,6 +24,7 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdio_ext.h> #include <stdlib.h> #include <string.h> @@ -243,20 +244,25 @@ static int write_netlabel_rules(const char* srcdir) { continue; } + (void) __fsetlocking(policy, FSETLOCKING_BYCALLER); + /* load2 write rules in the kernel require a line buffered stream */ FOREACH_LINE(buf, policy, - log_error_errno(errno, "Failed to read line from %s: %m", - entry->d_name)) { - if (!fputs_unlocked(buf, dst)) { + log_error_errno(errno, "Failed to read line from %s: %m", entry->d_name)) { + + int q; + + if (!fputs(buf, dst)) { if (r == 0) r = -EINVAL; log_error_errno(errno, "Failed to write line to /sys/fs/smackfs/netlabel"); break; } - if (fflush(dst)) { + q = fflush_and_check(dst); + if (q < 0) { if (r == 0) - r = -errno; - log_error_errno(errno, "Failed to flush writes to /sys/fs/smackfs/netlabel: %m"); + r = q; + log_error_errno(q, "Failed to flush writes to /sys/fs/smackfs/netlabel: %m"); break; } } |