From 0d5366733428b657e1b5b7700b461e878e00b578 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 11 Dec 2017 19:50:30 +0100 Subject: 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. --- src/fstab-generator/fstab-generator.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/fstab-generator/fstab-generator.c') diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index c0886547e0..22c4ae9861 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "alloc-util.h" #include "fd-util.h" @@ -134,11 +135,13 @@ static int add_swap( "Failed to create unit file %s: %m", unit); - fputs_unlocked("# Automatically generated by systemd-fstab-generator\n\n" - "[Unit]\n" - "SourcePath=/etc/fstab\n" - "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n" - "[Swap]\n", f); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + + fputs("# Automatically generated by systemd-fstab-generator\n\n" + "[Unit]\n" + "SourcePath=/etc/fstab\n" + "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n" + "[Swap]\n", f); r = write_what(f, what); if (r < 0) @@ -370,6 +373,8 @@ static int add_mount( "Failed to create unit file %s: %m", unit); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + fprintf(f, "# Automatically generated by systemd-fstab-generator\n\n" "[Unit]\n" @@ -491,6 +496,8 @@ static int add_mount( if (!f) return log_error_errno(errno, "Failed to create unit file %s: %m", automount_unit); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + fprintf(f, "# Automatically generated by systemd-fstab-generator\n\n" "[Unit]\n" -- cgit v1.2.1