summaryrefslogtreecommitdiff
path: root/src/cryptsetup/cryptsetup-generator.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-12-11 19:50:30 +0100
committerLennart Poettering <lennart@poettering.net>2017-12-14 10:42:25 +0100
commit0d5366733428b657e1b5b7700b461e878e00b578 (patch)
treee2bcdb9f85e01c79221a9f4797e11fae60166c48 /src/cryptsetup/cryptsetup-generator.c
parent966c04cf012f48686cf5359067a7b26c080f44ea (diff)
downloadsystemd-0d5366733428b657e1b5b7700b461e878e00b578.tar.gz
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/cryptsetup/cryptsetup-generator.c')
-rw-r--r--src/cryptsetup/cryptsetup-generator.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index e2dc96bdb7..7e61332e52 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -19,6 +19,7 @@
***/
#include <errno.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "dropin.h"
@@ -117,6 +118,8 @@ static int create_disk(
if (!f)
return log_error_errno(errno, "Failed to create unit file %s: %m", p);
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
fprintf(f,
"# Automatically generated by systemd-cryptsetup-generator\n\n"
"[Unit]\n"
@@ -136,7 +139,7 @@ static int create_disk(
if (password) {
if (STR_IN_SET(password, "/dev/urandom", "/dev/random", "/dev/hw_random"))
- fputs_unlocked("After=systemd-random-seed.service\n", f);
+ fputs("After=systemd-random-seed.service\n", f);
else if (!STR_IN_SET(password, "-", "none")) {
_cleanup_free_ char *uu;
@@ -168,8 +171,8 @@ static int create_disk(
d, d);
if (swap)
- fputs_unlocked("Before=dev-mapper-%i.swap\n",
- f);
+ fputs("Before=dev-mapper-%i.swap\n",
+ f);
} else
fprintf(f,
"RequiresMountsFor=%s\n",
@@ -372,6 +375,8 @@ static int add_crypttab_devices(void) {
return 0;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
if (fstat(fileno(f), &st) < 0) {
log_error_errno(errno, "Failed to stat /etc/crypttab: %m");
return 0;