summaryrefslogtreecommitdiffstats
path: root/src/resolve/resolved-link.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/resolve/resolved-link.c
parentMerge pull request #7625 from thom311/th/const-strlen (diff)
downloadsystemd-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/resolve/resolved-link.c')
-rw-r--r--src/resolve/resolved-link.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index ed7bdc848a..e3e50eca53 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -19,6 +19,7 @@
***/
#include <net/if.h>
+#include <stdio_ext.h>
#include "sd-network.h"
@@ -1100,7 +1101,10 @@ int link_save_user(Link *l) {
if (r < 0)
goto fail;
- fputs_unlocked("# This is private data. Do not parse.\n", f);
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+ (void) fchmod(fileno(f), 0644);
+
+ fputs("# This is private data. Do not parse.\n", f);
v = resolve_support_to_string(l->llmnr_support);
if (v)
@@ -1117,11 +1121,11 @@ int link_save_user(Link *l) {
if (l->dns_servers) {
DnsServer *server;
- fputs_unlocked("SERVERS=", f);
+ fputs("SERVERS=", f);
LIST_FOREACH(servers, server, l->dns_servers) {
if (server != l->dns_servers)
- fputc_unlocked(' ', f);
+ fputc(' ', f);
v = dns_server_string(server);
if (!v) {
@@ -1129,26 +1133,26 @@ int link_save_user(Link *l) {
goto fail;
}
- fputs_unlocked(v, f);
+ fputs(v, f);
}
- fputc_unlocked('\n', f);
+ fputc('\n', f);
}
if (l->search_domains) {
DnsSearchDomain *domain;
- fputs_unlocked("DOMAINS=", f);
+ fputs("DOMAINS=", f);
LIST_FOREACH(domains, domain, l->search_domains) {
if (domain != l->search_domains)
- fputc_unlocked(' ', f);
+ fputc(' ', f);
if (domain->route_only)
- fputc_unlocked('~', f);
+ fputc('~', f);
- fputs_unlocked(DNS_SEARCH_DOMAIN_NAME(domain), f);
+ fputs(DNS_SEARCH_DOMAIN_NAME(domain), f);
}
- fputc_unlocked('\n', f);
+ fputc('\n', f);
}
if (!set_isempty(l->dnssec_negative_trust_anchors)) {
@@ -1156,16 +1160,16 @@ int link_save_user(Link *l) {
Iterator i;
char *nta;
- fputs_unlocked("NTAS=", f);
+ fputs("NTAS=", f);
SET_FOREACH(nta, l->dnssec_negative_trust_anchors, i) {
if (space)
- fputc_unlocked(' ', f);
+ fputc(' ', f);
- fputs_unlocked(nta, f);
+ fputs(nta, f);
space = true;
}
- fputc_unlocked('\n', f);
+ fputc('\n', f);
}
r = fflush_and_check(f);