summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-match.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/libsystemd/sd-bus/bus-match.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/libsystemd/sd-bus/bus-match.c')
-rw-r--r--src/libsystemd/sd-bus/bus-match.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index d5831a288c..8d798c0a58 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -18,6 +18,8 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <stdio_ext.h>
+
#include "alloc-util.h"
#include "bus-internal.h"
#include "bus-match.h"
@@ -954,22 +956,24 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com
if (!f)
return NULL;
+ __fsetlocking(f, FSETLOCKING_BYCALLER);
+
for (i = 0; i < n_components; i++) {
char buf[32];
if (i != 0)
- fputc_unlocked(',', f);
+ fputc(',', f);
- fputs_unlocked(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f);
- fputc_unlocked('=', f);
- fputc_unlocked('\'', f);
+ fputs(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f);
+ fputc('=', f);
+ fputc('\'', f);
if (components[i].type == BUS_MATCH_MESSAGE_TYPE)
- fputs_unlocked(bus_message_type_to_string(components[i].value_u8), f);
+ fputs(bus_message_type_to_string(components[i].value_u8), f);
else
- fputs_unlocked(components[i].value_str, f);
+ fputs(components[i].value_str, f);
- fputc_unlocked('\'', f);
+ fputc('\'', f);
}
r = fflush_and_check(f);