tree-wide: use __fsetlocking() instead of fxyz_unlocked()
authorLennart Poettering <lennart@poettering.net>
Mon, 11 Dec 2017 18:50:30 +0000 (19:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 14 Dec 2017 09:42:25 +0000 (10:42 +0100)
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.

26 files changed:
src/basic/calendarspec.c
src/basic/string-util.c
src/busctl/busctl.c
src/core/dbus-cgroup.c
src/core/dbus-execute.c
src/core/dbus-service.c
src/core/manager.c
src/core/smack-setup.c
src/coredump/coredump.c
src/coredump/stacktrace.c
src/cryptsetup/cryptsetup-generator.c
src/fstab-generator/fstab-generator.c
src/journal/journal-qrcode.c
src/libsystemd-network/sd-dhcp-lease.c
src/libsystemd/sd-bus/bus-introspect.c
src/libsystemd/sd-bus/bus-match.c
src/libsystemd/sd-bus/bus-objects.c
src/locale/keymap-util.c
src/login/logind-seat.c
src/login/logind-user.c
src/machine/machine.c
src/network/networkd-link.c
src/network/networkd-manager.c
src/resolve/resolved-link.c
src/resolve/resolved-manager.c
src/resolve/resolved-resolv-conf.c

index 6b3a9a4..e6add0c 100644 (file)
@@ -24,6 +24,7 @@
 #include <limits.h>
 #include <stddef.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -261,19 +262,19 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) {
 
                         if (l < 0) {
                                 if (need_comma)
-                                        fputc_unlocked(',', f);
+                                        fputc(',', f);
                                 else
                                         need_comma = true;
 
-                                fputs_unlocked(days[x], f);
+                                fputs(days[x], f);
                                 l = x;
                         }
 
                 } else if (l >= 0) {
 
                         if (x > l + 1) {
-                                fputs_unlocked(x > l + 2 ? ".." : ",", f);
-                                fputs_unlocked(days[x-1], f);
+                                fputs(x > l + 2 ? ".." : ",", f);
+                                fputs(days[x-1], f);
                         }
 
                         l = -1;
@@ -281,8 +282,8 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) {
         }
 
         if (l >= 0 && x > l + 1) {
-                fputs_unlocked(x > l + 2 ? ".." : ",", f);
-                fputs_unlocked(days[x-1], f);
+                fputs(x > l + 2 ? ".." : ",", f);
+                fputs(days[x-1], f);
         }
 }
 
@@ -292,12 +293,12 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us
         assert(f);
 
         if (!c) {
-                fputc_unlocked('*', f);
+                fputc('*', f);
                 return;
         }
 
         if (usec && c->start == 0 && c->repeat == USEC_PER_SEC && !c->next) {
-                fputc_unlocked('*', f);
+                fputc('*', f);
                 return;
         }
 
@@ -318,7 +319,7 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us
                 fprintf(f, ".%06i", c->repeat % d);
 
         if (c->next) {
-                fputc_unlocked(',', f);
+                fputc(',', f);
                 format_chain(f, space, c->next, usec);
         }
 }
@@ -336,28 +337,30 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
         if (!f)
                 return -ENOMEM;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         if (c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS) {
                 format_weekdays(f, c);
-                fputc_unlocked(' ', f);
+                fputc(' ', f);
         }
 
         format_chain(f, 4, c->year, false);
-        fputc_unlocked('-', f);
+        fputc('-', f);
         format_chain(f, 2, c->month, false);
-        fputc_unlocked(c->end_of_month ? '~' : '-', f);
+        fputc(c->end_of_month ? '~' : '-', f);
         format_chain(f, 2, c->day, false);
-        fputc_unlocked(' ', f);
+        fputc(' ', f);
         format_chain(f, 2, c->hour, false);
-        fputc_unlocked(':', f);
+        fputc(':', f);
         format_chain(f, 2, c->minute, false);
-        fputc_unlocked(':', f);
+        fputc(':', f);
         format_chain(f, 2, c->microsecond, true);
 
         if (c->utc)
-                fputs_unlocked(" UTC", f);
+                fputs(" UTC", f);
         else if (c->timezone != NULL) {
-                fputc_unlocked(' ', f);
-                fputs_unlocked(c->timezone, f);
+                fputc(' ', f);
+                fputs(c->timezone, f);
         } else if (IN_SET(c->dst, 0, 1)) {
 
                 /* If daylight saving is explicitly on or off, let's show the used timezone. */
@@ -365,8 +368,8 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) {
                 tzset();
 
                 if (!isempty(tzname[c->dst])) {
-                        fputc_unlocked(' ', f);
-                        fputs_unlocked(tzname[c->dst], f);
+                        fputc(' ', f);
+                        fputs(tzname[c->dst], f);
                 }
         }
 
index e916000..7e2f596 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -669,10 +670,10 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) {
         if (!f)
                 return NULL;
 
-        /* Note we use the _unlocked() stdio variants on f for performance
-         * reasons.  It's safe to do so since we created f here and it
-         * doesn't leave our scope.
-         */
+        /* Note we turn off internal locking on f for performance reasons.  It's safe to do so since we created f here
+         * and it doesn't leave our scope. */
+
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
 
         for (i = *ibuf; i < *ibuf + isz + 1; i++) {
 
@@ -684,21 +685,21 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) {
                         else if (*i == '\x1B')
                                 state = STATE_ESCAPE;
                         else if (*i == '\t')
-                                fputs_unlocked("        ", f);
+                                fputs("        ", f);
                         else
-                                fputc_unlocked(*i, f);
+                                fputc(*i, f);
                         break;
 
                 case STATE_ESCAPE:
                         if (i >= *ibuf + isz) { /* EOT */
-                                fputc_unlocked('\x1B', f);
+                                fputc('\x1B', f);
                                 break;
                         } else if (*i == '[') {
                                 state = STATE_BRACKET;
                                 begin = i + 1;
                         } else {
-                                fputc_unlocked('\x1B', f);
-                                fputc_unlocked(*i, f);
+                                fputc('\x1B', f);
+                                fputc(*i, f);
                                 state = STATE_OTHER;
                         }
 
@@ -708,8 +709,8 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) {
 
                         if (i >= *ibuf + isz || /* EOT */
                             (!(*i >= '0' && *i <= '9') && !IN_SET(*i, ';', 'm'))) {
-                                fputc_unlocked('\x1B', f);
-                                fputc_unlocked('[', f);
+                                fputc('\x1B', f);
+                                fputc('[', f);
                                 state = STATE_OTHER;
                                 i = begin-1;
                         } else if (*i == 'm')
index 953816c..81140f9 100644 (file)
@@ -19,6 +19,7 @@
 ***/
 
 #include <getopt.h>
+#include <stdio_ext.h>
 
 #include "sd-bus.h"
 
@@ -949,6 +950,8 @@ static int introspect(sd_bus *bus, char **argv) {
                         if (!mf)
                                 return log_oom();
 
+                        (void) __fsetlocking(mf, FSETLOCKING_BYCALLER);
+
                         r = format_cmdline(reply, mf, false);
                         if (r < 0)
                                 return bus_log_parse_error(r);
index 690e3a3..abca4e1 100644 (file)
@@ -19,6 +19,7 @@
 ***/
 
 #include <arpa/inet.h>
+#include <stdio_ext.h>
 
 #include "af-list.h"
 #include "alloc-util.h"
@@ -687,6 +688,8 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
                         fprintf(f, "%s=\n", name);
                         LIST_FOREACH(device_limits, a, c->io_device_limits)
                                         if (a->limits[iol_type] != cgroup_io_limit_defaults[iol_type])
@@ -764,7 +767,9 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
-                        fputs_unlocked("IODeviceWeight=\n", f);
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+                        fputs("IODeviceWeight=\n", f);
                         LIST_FOREACH(device_weights, a, c->io_device_weights)
                                 fprintf(f, "IODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight);
 
@@ -912,13 +917,15 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
                         if (read) {
-                                fputs_unlocked("BlockIOReadBandwidth=\n", f);
+                                fputs("BlockIOReadBandwidth=\n", f);
                                 LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
                                         if (a->rbps != CGROUP_LIMIT_MAX)
                                                 fprintf(f, "BlockIOReadBandwidth=%s %" PRIu64 "\n", a->path, a->rbps);
                         } else {
-                                fputs_unlocked("BlockIOWriteBandwidth=\n", f);
+                                fputs("BlockIOWriteBandwidth=\n", f);
                                 LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
                                         if (a->wbps != CGROUP_LIMIT_MAX)
                                                 fprintf(f, "BlockIOWriteBandwidth=%s %" PRIu64 "\n", a->path, a->wbps);
@@ -997,7 +1004,9 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
-                        fputs_unlocked("BlockIODeviceWeight=\n", f);
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+                        fputs("BlockIODeviceWeight=\n", f);
                         LIST_FOREACH(device_weights, a, c->blockio_device_weights)
                                 fprintf(f, "BlockIODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight);
 
@@ -1229,7 +1238,9 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
-                        fputs_unlocked("DeviceAllow=\n", f);
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+                        fputs("DeviceAllow=\n", f);
                         LIST_FOREACH(device_allow, a, c->device_allow)
                                 fprintf(f, "DeviceAllow=%s %s%s%s\n", a->path, a->r ? "r" : "", a->w ? "w" : "", a->m ? "m" : "");
 
@@ -1399,8 +1410,10 @@ int bus_cgroup_set_property(
                         if (!f)
                                 return -ENOMEM;
 
-                        fputs_unlocked(name, f);
-                        fputs_unlocked("=\n", f);
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+                        fputs(name, f);
+                        fputs("=\n", f);
 
                         LIST_FOREACH(items, item, *list) {
                                 char buffer[CONST_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)];
index 196de56..be25b6e 100644 (file)
@@ -19,6 +19,7 @@
 ***/
 
 #include <sys/prctl.h>
+#include <stdio_ext.h>
 
 #if HAVE_SECCOMP
 #include <seccomp.h>
@@ -2202,6 +2203,8 @@ int bus_exec_context_set_transient_property(
                 if (!f)
                         return -ENOMEM;
 
+                (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
                 fputs("EnvironmentFile=\n", f);
 
                 STRV_FOREACH(i, c->environment_files) {
index 8121765..0189952 100644 (file)
@@ -18,6 +18,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <stdio_ext.h>
+
 #include "alloc-util.h"
 #include "async.h"
 #include "bus-util.h"
@@ -313,7 +315,9 @@ static int bus_service_set_transient_property(
                         if (!f)
                                 return -ENOMEM;
 
-                        fputs_unlocked("ExecStart=\n", f);
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+                        fputs("ExecStart=\n", f);
 
                         LIST_FOREACH(command, c, s->exec_command[ci]) {
                                 _cleanup_free_ char *a = NULL, *t = NULL;
index 0681bbb..7ac7983 100644 (file)
@@ -1754,7 +1754,7 @@ int manager_get_dump_string(Manager *m, char **ret) {
         if (!f)
                 return -errno;
 
-        __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
 
         manager_dump(m, f, NULL);
 
@@ -2704,15 +2704,15 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) {
         manager_serialize_uid_refs(m, f);
         manager_serialize_gid_refs(m, f);
 
-        fputc_unlocked('\n', f);
+        (void) fputc('\n', f);
 
         HASHMAP_FOREACH_KEY(u, t, m->units, i) {
                 if (u->id != t)
                         continue;
 
                 /* Start marker */
-                fputs_unlocked(u->id, f);
-                fputc_unlocked('\n', f);
+                fputs(u->id, f);
+                fputc('\n', f);
 
                 r = unit_serialize(u, f, fds, !switching_root);
                 if (r < 0) {
index a5b6ea2..b0d3612 100644 (file)
@@ -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;
                         }
                 }
index c7dd61f..e6063cc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <sys/prctl.h>
 #include <sys/xattr.h>
 #include <unistd.h>
@@ -540,6 +541,8 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
         if (!stream)
                 return -ENOMEM;
 
+        (void) __fsetlocking(stream, FSETLOCKING_BYCALLER);
+
         FOREACH_DIRENT(dent, proc_fd_dir, return -errno) {
                 _cleanup_fclose_ FILE *fdinfo = NULL;
                 _cleanup_free_ char *fdname = NULL;
@@ -560,12 +563,12 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
 
                 fdinfo = fdopen(fd, "re");
                 if (!fdinfo) {
-                        close(fd);
+                        safe_close(fd);
                         continue;
                 }
 
                 FOREACH_LINE(line, fdinfo, break) {
-                        fputs_unlocked(line, stream);
+                        fputs(line, stream);
                         if (!endswith(line, "\n"))
                                 fputc('\n', stream);
                 }
index d37ffae..95fd27b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <dwarf.h>
 #include <elfutils/libdwfl.h>
+#include <stdio_ext.h>
 
 #include "alloc-util.h"
 #include "fd-util.h"
@@ -108,7 +109,7 @@ static int thread_callback(Dwfl_Thread *thread, void *userdata) {
                 return DWARF_CB_ABORT;
 
         if (c->n_thread != 0)
-                fputc_unlocked('\n', c->f);
+                fputc('\n', c->f);
 
         c->n_frame = 0;
 
@@ -145,6 +146,8 @@ int coredump_make_stack_trace(int fd, const char *executable, char **ret) {
         if (!c.f)
                 return -ENOMEM;
 
+        (void) __fsetlocking(c.f, FSETLOCKING_BYCALLER);
+
         elf_version(EV_CURRENT);
 
         c.elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
index e2dc96b..7e61332 100644 (file)
@@ -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;
index c088654..22c4ae9 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdio_ext.h>
 
 #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"
index 46ff1ce..5a9dcaa 100644 (file)
@@ -22,6 +22,7 @@
 #include <qrencode.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 
 #include "journal-qrcode.h"
@@ -66,11 +67,13 @@ int print_qr_code(
         if (!f)
                 return -ENOMEM;
 
-        fputs_unlocked("fss://", f);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
+        fputs("fss://", f);
 
         for (i = 0; i < seed_size; i++) {
                 if (i > 0 && i % 3 == 0)
-                        fputc_unlocked('-', f);
+                        fputc('-', f);
                 fprintf(f, "%02x", ((uint8_t*) seed)[i]);
         }
 
index a186bca..78b8e05 100644 (file)
@@ -22,6 +22,7 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -876,7 +877,8 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
         if (r < 0)
                 goto fail;
 
-        fchmod(fileno(f), 0644);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
                 "# This is private data. Do not parse.\n");
@@ -923,16 +925,16 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
 
         r = sd_dhcp_lease_get_dns(lease, &addresses);
         if (r > 0) {
-                fputs_unlocked("DNS=", f);
+                fputs("DNS=", f);
                 serialize_in_addrs(f, addresses, r);
-                fputs_unlocked("\n", f);
+                fputs("\n", f);
         }
 
         r = sd_dhcp_lease_get_ntp(lease, &addresses);
         if (r > 0) {
-                fputs_unlocked("NTP=", f);
+                fputs("NTP=", f);
                 serialize_in_addrs(f, addresses, r);
-                fputs_unlocked("\n", f);
+                fputs("\n", f);
         }
 
         r = sd_dhcp_lease_get_domainname(lease, &string);
@@ -941,9 +943,9 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
 
         r = sd_dhcp_lease_get_search_domains(lease, &search_domains);
         if (r > 0) {
-                fputs_unlocked("DOMAIN_SEARCH_LIST=", f);
+                fputs("DOMAIN_SEARCH_LIST=", f);
                 fputstrv(f, search_domains, NULL, NULL);
-                fputs_unlocked("\n", f);
+                fputs("\n", f);
         }
 
         r = sd_dhcp_lease_get_hostname(lease, &string);
index 8a6e041..9bd2dad 100644 (file)
@@ -18,6 +18,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <stdio_ext.h>
+
 #include "bus-internal.h"
 #include "bus-introspect.h"
 #include "bus-protocol.h"
@@ -37,8 +39,10 @@ int introspect_begin(struct introspect *i, bool trusted) {
         if (!i->f)
                 return -ENOMEM;
 
-        fputs_unlocked(BUS_INTROSPECT_DOCTYPE
-                       "<node>\n", i->f);
+        (void) __fsetlocking(i->f, FSETLOCKING_BYCALLER);
+
+        fputs(BUS_INTROSPECT_DOCTYPE
+              "<node>\n", i->f);
 
         return 0;
 }
@@ -46,12 +50,12 @@ int introspect_begin(struct introspect *i, bool trusted) {
 int introspect_write_default_interfaces(struct introspect *i, bool object_manager) {
         assert(i);
 
-        fputs_unlocked(BUS_INTROSPECT_INTERFACE_PEER
-                       BUS_INTROSPECT_INTERFACE_INTROSPECTABLE
-                       BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f);
+        fputs(BUS_INTROSPECT_INTERFACE_PEER
+              BUS_INTROSPECT_INTERFACE_INTROSPECTABLE
+              BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f);
 
         if (object_manager)
-                fputs_unlocked(BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f);
+                fputs(BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f);
 
         return 0;
 }
@@ -77,27 +81,27 @@ int introspect_write_child_nodes(struct introspect *i, Set *s, const char *prefi
 
 static void introspect_write_flags(struct introspect *i, int type, int flags) {
         if (flags & SD_BUS_VTABLE_DEPRECATED)
-                fputs_unlocked("   <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
+                fputs("   <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
 
         if (type == _SD_BUS_VTABLE_METHOD && (flags & SD_BUS_VTABLE_METHOD_NO_REPLY))
-                fputs_unlocked("   <annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n", i->f);
+                fputs("   <annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n", i->f);
 
         if (IN_SET(type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY)) {
                 if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT)
-                        fputs_unlocked("   <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
+                        fputs("   <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
 
                 if (flags & SD_BUS_VTABLE_PROPERTY_CONST)
-                        fputs_unlocked("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n", i->f);
+                        fputs("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n", i->f);
                 else if (flags & SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION)
-                        fputs_unlocked("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"invalidates\"/>\n", i->f);
+                        fputs("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"invalidates\"/>\n", i->f);
                 else if (!(flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE))
-                        fputs_unlocked("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"false\"/>\n", i->f);
+                        fputs("   <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"false\"/>\n", i->f);
         }
 
         if (!i->trusted &&
             IN_SET(type, _SD_BUS_VTABLE_METHOD, _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
             !(flags & SD_BUS_VTABLE_UNPRIVILEGED))
-                fputs_unlocked("   <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
+                fputs("   <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
 }
 
 static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) {
@@ -118,7 +122,7 @@ static int introspect_write_arguments(struct introspect *i, const char *signatur
                 if (direction)
                         fprintf(i->f, " direction=\"%s\"/>\n", direction);
                 else
-                        fputs_unlocked("/>\n", i->f);
+                        fputs("/>\n", i->f);
 
                 signature += l;
         }
@@ -141,7 +145,7 @@ int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
 
                 case _SD_BUS_VTABLE_START:
                         if (v->flags & SD_BUS_VTABLE_DEPRECATED)
-                                fputs_unlocked("  <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
+                                fputs("  <annotation name=\"org.freedesktop.DBus.Deprecated\" value=\"true\"/>\n", i->f);
                         break;
 
                 case _SD_BUS_VTABLE_METHOD:
@@ -149,7 +153,7 @@ int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
                         introspect_write_arguments(i, strempty(v->x.method.signature), "in");
                         introspect_write_arguments(i, strempty(v->x.method.result), "out");
                         introspect_write_flags(i, v->type, v->flags);
-                        fputs_unlocked("  </method>\n", i->f);
+                        fputs("  </method>\n", i->f);
                         break;
 
                 case _SD_BUS_VTABLE_PROPERTY:
@@ -159,14 +163,14 @@ int introspect_write_interface(struct introspect *i, const sd_bus_vtable *v) {
                                 v->x.property.signature,
                                 v->type == _SD_BUS_VTABLE_WRITABLE_PROPERTY ? "readwrite" : "read");
                         introspect_write_flags(i, v->type, v->flags);
-                        fputs_unlocked("  </property>\n", i->f);
+                        fputs("  </property>\n", i->f);
                         break;
 
                 case _SD_BUS_VTABLE_SIGNAL:
                         fprintf(i->f, "  <signal name=\"%s\">\n", v->x.signal.member);
                         introspect_write_arguments(i, strempty(v->x.signal.signature), NULL);
                         introspect_write_flags(i, v->type, v->flags);
-                        fputs_unlocked("  </signal>\n", i->f);
+                        fputs("  </signal>\n", i->f);
                         break;
                 }
 
@@ -183,7 +187,7 @@ int introspect_finish(struct introspect *i, sd_bus *bus, sd_bus_message *m, sd_b
         assert(m);
         assert(reply);
 
-        fputs_unlocked("</node>\n", i->f);
+        fputs("</node>\n", i->f);
 
         r = fflush_and_check(i->f);
         if (r < 0)
index d5831a2..8d798c0 100644 (file)
@@ -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);
index 4c7dbaa..121197b 100644 (file)
@@ -960,7 +960,7 @@ static int process_introspect(
                 if (!streq_ptr(previous_interface, c->interface)) {
 
                         if (previous_interface)
-                                fputs_unlocked(" </interface>\n", intro.f);
+                                fputs(" </interface>\n", intro.f);
 
                         fprintf(intro.f, " <interface name=\"%s\">\n", c->interface);
                 }
@@ -973,7 +973,7 @@ static int process_introspect(
         }
 
         if (previous_interface)
-                fputs_unlocked(" </interface>\n", intro.f);
+                fputs(" </interface>\n", intro.f);
 
         if (empty) {
                 /* Nothing?, let's see if we exist at all, and if not
index 2457f87..2d78810 100644 (file)
@@ -20,6 +20,7 @@
 ***/
 
 #include <errno.h>
+#include <stdio_ext.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -358,14 +359,15 @@ int x11_write_data(Context *c) {
         if (r < 0)
                 return r;
 
-        fchmod(fileno(f), 0644);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) fchmod(fileno(f), 0644);
 
-        fputs_unlocked("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
-                       "# probably wise not to edit this file manually. Use localectl(1) to\n"
-                       "# instruct systemd-localed to update it.\n"
-                       "Section \"InputClass\"\n"
-                       "        Identifier \"system-keyboard\"\n"
-                       "        MatchIsKeyboard \"on\"\n", f);
+        fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
+              "# probably wise not to edit this file manually. Use localectl(1) to\n"
+              "# instruct systemd-localed to update it.\n"
+              "Section \"InputClass\"\n"
+              "        Identifier \"system-keyboard\"\n"
+              "        MatchIsKeyboard \"on\"\n", f);
 
         if (!isempty(c->x11_layout))
                 fprintf(f, "        Option \"XkbLayout\" \"%s\"\n", c->x11_layout);
@@ -379,7 +381,7 @@ int x11_write_data(Context *c) {
         if (!isempty(c->x11_options))
                 fprintf(f, "        Option \"XkbOptions\" \"%s\"\n", c->x11_options);
 
-        fputs_unlocked("EndSection\n", f);
+        fputs("EndSection\n", f);
 
         r = fflush_sync_and_check(f);
         if (r < 0)
index f4aa9a6..b99e7ab 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdio_ext.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -102,7 +103,8 @@ int seat_save(Seat *s) {
         if (r < 0)
                 goto fail;
 
-        fchmod(fileno(f), 0644);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
                 "# This is private data. Do not parse.\n"
@@ -128,7 +130,7 @@ int seat_save(Seat *s) {
         if (s->sessions) {
                 Session *i;
 
-                fputs_unlocked("SESSIONS=", f);
+                fputs("SESSIONS=", f);
                 LIST_FOREACH(sessions_by_seat, i, s->sessions) {
                         fprintf(f,
                                 "%s%c",
@@ -136,7 +138,7 @@ int seat_save(Seat *s) {
                                 i->sessions_by_seat_next ? ' ' : '\n');
                 }
 
-                fputs_unlocked("UIDS=", f);
+                fputs("UIDS=", f);
                 LIST_FOREACH(sessions_by_seat, i, s->sessions)
                         fprintf(f,
                                 UID_FMT"%c",
index 0146943..94e250b 100644 (file)
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <sys/mount.h>
 #include <unistd.h>
+#include <stdio_ext.h>
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
@@ -150,7 +151,8 @@ static int user_save_internal(User *u) {
         if (r < 0)
                 goto fail;
 
-        fchmod(fileno(f), 0644);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
                 "# This is private data. Do not parse.\n"
@@ -183,18 +185,18 @@ static int user_save_internal(User *u) {
                 Session *i;
                 bool first;
 
-                fputs_unlocked("SESSIONS=", f);
+                fputs("SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->id, f);
+                        fputs(i->id, f);
                 }
 
-                fputs_unlocked("\nSEATS=", f);
+                fputs("\nSEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!i->seat)
@@ -203,12 +205,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->seat->id, f);
+                        fputs(i->seat->id, f);
                 }
 
-                fputs_unlocked("\nACTIVE_SESSIONS=", f);
+                fputs("\nACTIVE_SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!session_is_active(i))
@@ -217,12 +219,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->id, f);
+                        fputs(i->id, f);
                 }
 
-                fputs_unlocked("\nONLINE_SESSIONS=", f);
+                fputs("\nONLINE_SESSIONS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (session_get_state(i) == SESSION_CLOSING)
@@ -231,12 +233,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->id, f);
+                        fputs(i->id, f);
                 }
 
-                fputs_unlocked("\nACTIVE_SEATS=", f);
+                fputs("\nACTIVE_SEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (!session_is_active(i) || !i->seat)
@@ -245,12 +247,12 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->seat->id, f);
+                        fputs(i->seat->id, f);
                 }
 
-                fputs_unlocked("\nONLINE_SEATS=", f);
+                fputs("\nONLINE_SEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
                         if (session_get_state(i) == SESSION_CLOSING || !i->seat)
@@ -259,11 +261,11 @@ static int user_save_internal(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
-                        fputs_unlocked(i->seat->id, f);
+                        fputs(i->seat->id, f);
                 }
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
         }
 
         r = fflush_and_check(f);
index 3d3c7cb..0525c0c 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdio_ext.h>
 
 #include "sd-messages.h"
 
@@ -138,6 +139,7 @@ int machine_save(Machine *m) {
         if (r < 0)
                 goto fail;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
         (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
@@ -201,16 +203,16 @@ int machine_save(Machine *m) {
         if (m->n_netif > 0) {
                 unsigned i;
 
-                fputs_unlocked("NETIF=", f);
+                fputs("NETIF=", f);
 
                 for (i = 0; i < m->n_netif; i++) {
                         if (i != 0)
-                                fputc_unlocked(' ', f);
+                                fputc(' ', f);
 
                         fprintf(f, "%i", m->netif[i]);
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
         }
 
         r = fflush_and_check(f);
index 6c4711e..60ac980 100644 (file)
@@ -21,6 +21,7 @@
 #include <netinet/ether.h>
 #include <linux/if.h>
 #include <unistd.h>
+#include <stdio_ext.h>
 
 #include "alloc-util.h"
 #include "bus-util.h"
@@ -3360,16 +3361,16 @@ static void print_link_hashmap(FILE *f, const char *prefix, Hashmap* h) {
         if (hashmap_isempty(h))
                 return;
 
-        fputs_unlocked(prefix, f);
+        fputs(prefix, f);
         HASHMAP_FOREACH(link, h, i) {
                 if (space)
-                        fputc_unlocked(' ', f);
+                        fputc(' ', f);
 
                 fprintf(f, "%i", link->ifindex);
                 space = true;
         }
 
-        fputc_unlocked('\n', f);
+        fputc('\n', f);
 }
 
 int link_save(Link *link) {
@@ -3403,6 +3404,7 @@ int link_save(Link *link) {
         if (r < 0)
                 goto fail;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
         (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
@@ -3430,7 +3432,7 @@ int link_save(Link *link) {
 
                 fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
 
-                fputs_unlocked("DNS=", f);
+                fputs("DNS=", f);
                 space = false;
 
                 for (j = 0; j < link->network->n_dns; j++) {
@@ -3444,8 +3446,8 @@ int link_save(Link *link) {
                         }
 
                         if (space)
-                                fputc_unlocked(' ', f);
-                        fputs_unlocked(b, f);
+                                fputc(' ', f);
+                        fputs(b, f);
                         space = true;
                 }
 
@@ -3456,7 +3458,7 @@ int link_save(Link *link) {
                         r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses);
                         if (r > 0) {
                                 if (space)
-                                        fputc_unlocked(' ', f);
+                                        fputc(' ', f);
                                 serialize_in_addrs(f, addresses, r);
                                 space = true;
                         }
@@ -3468,7 +3470,7 @@ int link_save(Link *link) {
                         r = sd_dhcp6_lease_get_dns(dhcp6_lease, &in6_addrs);
                         if (r > 0) {
                                 if (space)
-                                        fputc_unlocked(' ', f);
+                                        fputc(' ', f);
                                 serialize_in6_addrs(f, in6_addrs, r);
                                 space = true;
                         }
@@ -3482,16 +3484,16 @@ int link_save(Link *link) {
 
                         SET_FOREACH(dd, link->ndisc_rdnss, i) {
                                 if (space)
-                                        fputc_unlocked(' ', f);
+                                        fputc(' ', f);
 
                                 serialize_in6_addrs(f, &dd->address, 1);
                                 space = true;
                         }
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
 
-                fputs_unlocked("NTP=", f);
+                fputs("NTP=", f);
                 space = false;
                 fputstrv(f, link->network->ntp, NULL, &space);
 
@@ -3502,7 +3504,7 @@ int link_save(Link *link) {
                         r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses);
                         if (r > 0) {
                                 if (space)
-                                        fputc_unlocked(' ', f);
+                                        fputc(' ', f);
                                 serialize_in_addrs(f, addresses, r);
                                 space = true;
                         }
@@ -3516,7 +3518,7 @@ int link_save(Link *link) {
                                                          &in6_addrs);
                         if (r > 0) {
                                 if (space)
-                                        fputc_unlocked(' ', f);
+                                        fputc(' ', f);
                                 serialize_in6_addrs(f, in6_addrs, r);
                                 space = true;
                         }
@@ -3526,7 +3528,7 @@ int link_save(Link *link) {
                                 fputstrv(f, hosts, NULL, &space);
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
 
                 if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) {
                         if (link->dhcp_lease) {
@@ -3537,7 +3539,7 @@ int link_save(Link *link) {
                                 (void) sd_dhcp6_lease_get_domains(dhcp6_lease, &dhcp6_domains);
                 }
 
-                fputs_unlocked("DOMAINS=", f);
+                fputs("DOMAINS=", f);
                 space = false;
                 fputstrv(f, link->network->search_domains, NULL, &space);
 
@@ -3555,9 +3557,9 @@ int link_save(Link *link) {
                                 fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
 
-                fputs_unlocked("ROUTE_DOMAINS=", f);
+                fputs("ROUTE_DOMAINS=", f);
                 space = false;
                 fputstrv(f, link->network->route_domains, NULL, &space);
 
@@ -3575,7 +3577,7 @@ int link_save(Link *link) {
                                 fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space);
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
 
                 fprintf(f, "LLMNR=%s\n",
                         resolve_support_to_string(link->network->llmnr));
@@ -3589,14 +3591,14 @@ int link_save(Link *link) {
                 if (!set_isempty(link->network->dnssec_negative_trust_anchors)) {
                         const char *n;
 
-                        fputs_unlocked("DNSSEC_NTA=", f);
+                        fputs("DNSSEC_NTA=", f);
                         space = false;
                         SET_FOREACH(n, link->network->dnssec_negative_trust_anchors, i)
                                 fputs_with_space(f, n, NULL, &space);
-                        fputc_unlocked('\n', f);
+                        fputc('\n', f);
                 }
 
-                fputs_unlocked("ADDRESSES=", f);
+                fputs("ADDRESSES=", f);
                 space = false;
                 SET_FOREACH(a, link->addresses, i) {
                         _cleanup_free_ char *address_str = NULL;
@@ -3608,9 +3610,9 @@ int link_save(Link *link) {
                         fprintf(f, "%s%s/%u", space ? " " : "", address_str, a->prefixlen);
                         space = true;
                 }
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
 
-                fputs_unlocked("ROUTES=", f);
+                fputs("ROUTES=", f);
                 space = false;
                 SET_FOREACH(route, link->routes, i) {
                         _cleanup_free_ char *route_str = NULL;
@@ -3625,7 +3627,7 @@ int link_save(Link *link) {
                         space = true;
                 }
 
-                fputc_unlocked('\n', f);
+                fputc('\n', f);
         }
 
         print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links);
@@ -3643,9 +3645,9 @@ int link_save(Link *link) {
 
                 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address);
                 if (r >= 0) {
-                        fputs_unlocked("DHCP4_ADDRESS=", f);
+                        fputs("DHCP4_ADDRESS=", f);
                         serialize_in_addrs(f, &address, 1);
-                        fputc_unlocked('\n', f);
+                        fputc('\n', f);
                 }
 
                 r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
@@ -3663,9 +3665,9 @@ int link_save(Link *link) {
 
                 r = sd_ipv4ll_get_address(link->ipv4ll, &address);
                 if (r >= 0) {
-                        fputs_unlocked("IPV4LL_ADDRESS=", f);
+                        fputs("IPV4LL_ADDRESS=", f);
                         serialize_in_addrs(f, &address, 1);
-                        fputc_unlocked('\n', f);
+                        fputc('\n', f);
                 }
         }
 
index c2c41d9..cc17af9 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/socket.h>
 #include <linux/if.h>
 #include <linux/fib_rules.h>
+#include <stdio_ext.h>
 
 #include "sd-daemon.h"
 #include "sd-netlink.h"
@@ -991,12 +992,12 @@ static void print_string_set(FILE *f, const char *field, OrderedSet *s) {
         if (ordered_set_isempty(s))
                 return;
 
-        fputs_unlocked(field, f);
+        fputs(field, f);
 
         ORDERED_SET_FOREACH(p, s, i)
                 fputs_with_space(f, p, NULL, &space);
 
-        fputc_unlocked('\n', f);
+        fputc('\n', f);
 }
 
 static int manager_save(Manager *m) {
@@ -1114,6 +1115,7 @@ static int manager_save(Manager *m) {
         if (r < 0)
                 return r;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
         (void) fchmod(fileno(f), 0644);
 
         fprintf(f,
index ed7bdc8..e3e50ec 100644 (file)
@@ -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);
index 983e6c0..2dbf432 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <netinet/in.h>
 #include <poll.h>
+#include <stdio_ext.h>
 #include <sys/ioctl.h>
 
 #if HAVE_LIBIDN2
@@ -535,6 +536,8 @@ static int manager_sigusr1(sd_event_source *s, const struct signalfd_siginfo *si
         if (!f)
                 return log_oom();
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         LIST_FOREACH(scopes, scope, m->dns_scopes)
                 dns_scope_dump(scope, f);
 
index 4ea7490..bad04d6 100644 (file)
@@ -19,6 +19,7 @@
  ***/
 
 #include <resolv.h>
+#include <stdio_ext.h>
 
 #include "alloc-util.h"
 #include "dns-domain.h"
@@ -201,7 +202,7 @@ static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) {
         }
 
         if (*count == MAXNS)
-                fputs_unlocked("# Too many DNS servers configured, the following entries may be ignored.\n", f);
+                fputs("# Too many DNS servers configured, the following entries may be ignored.\n", f);
         (*count)++;
 
         fprintf(f, "nameserver %s\n", dns_server_string(s));
@@ -217,43 +218,43 @@ static void write_resolv_conf_search(
         assert(domains);
         assert(f);
 
-        fputs_unlocked("search", f);
+        fputs("search", f);
 
         ORDERED_SET_FOREACH(domain, domains, i) {
                 if (++count > MAXDNSRCH) {
-                        fputs_unlocked("\n# Too many search domains configured, remaining ones ignored.", f);
+                        fputs("\n# Too many search domains configured, remaining ones ignored.", f);
                         break;
                 }
                 length += strlen(domain) + 1;
                 if (length > 256) {
-                        fputs_unlocked("\n# Total length of all search domains is too long, remaining ones ignored.", f);
+                        fputs("\n# Total length of all search domains is too long, remaining ones ignored.", f);
                         break;
                 }
-                fputc_unlocked(' ', f);
-                fputs_unlocked(domain, f);
+                fputc(' ', f);
+                fputs(domain, f);
         }
 
-        fputs_unlocked("\n", f);
+        fputs("\n", f);
 }
 
 static int write_uplink_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet *domains) {
         Iterator i;
 
-        fputs_unlocked("# This file is managed by man:systemd-resolved(8). Do not edit.\n"
-                       "#\n"
-                       "# This is a dynamic resolv.conf file for connecting local clients directly to\n"
-                       "# all known uplink DNS servers. This file lists all configured search domains.\n"
-                       "#\n"
-                       "# Third party programs must not access this file directly, but only through the\n"
-                       "# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,\n"
-                       "# replace this symlink by a static file or a different symlink.\n"
-                       "#\n"
-                       "# See man:systemd-resolved.service(8) for details about the supported modes of\n"
-                       "# operation for /etc/resolv.conf.\n"
-                       "\n", f);
+        fputs("# This file is managed by man:systemd-resolved(8). Do not edit.\n"
+              "#\n"
+              "# This is a dynamic resolv.conf file for connecting local clients directly to\n"
+              "# all known uplink DNS servers. This file lists all configured search domains.\n"
+              "#\n"
+              "# Third party programs must not access this file directly, but only through the\n"
+              "# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,\n"
+              "# replace this symlink by a static file or a different symlink.\n"
+              "#\n"
+              "# See man:systemd-resolved.service(8) for details about the supported modes of\n"
+              "# operation for /etc/resolv.conf.\n"
+              "\n", f);
 
         if (ordered_set_isempty(dns))
-                fputs_unlocked("# No DNS servers known.\n", f);
+                fputs("# No DNS servers known.\n", f);
         else {
                 unsigned count = 0;
                 DnsServer *s;
@@ -296,10 +297,8 @@ static int write_stub_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet
 int manager_write_resolv_conf(Manager *m) {
 
         _cleanup_ordered_set_free_ OrderedSet *dns = NULL, *domains = NULL;
-        _cleanup_free_ char *temp_path_uplink = NULL;
-        _cleanup_free_ char *temp_path_stub = NULL;
-        _cleanup_fclose_ FILE *f_uplink = NULL;
-        _cleanup_fclose_ FILE *f_stub = NULL;
+        _cleanup_free_ char *temp_path_uplink = NULL, *temp_path_stub = NULL;
+        _cleanup_fclose_ FILE *f_uplink = NULL, *f_stub = NULL;
         int r;
 
         assert(m);
@@ -319,10 +318,15 @@ int manager_write_resolv_conf(Manager *m) {
         r = fopen_temporary_label(PRIVATE_UPLINK_RESOLV_CONF, PRIVATE_UPLINK_RESOLV_CONF, &f_uplink, &temp_path_uplink);
         if (r < 0)
                 return log_warning_errno(r, "Failed to open private resolv.conf file for writing: %m");
+
+        (void) __fsetlocking(f_uplink, FSETLOCKING_BYCALLER);
+        (void) fchmod(fileno(f_uplink), 0644);
+
         r = fopen_temporary_label(PRIVATE_STUB_RESOLV_CONF, PRIVATE_STUB_RESOLV_CONF, &f_stub, &temp_path_stub);
         if (r < 0)
                 return log_warning_errno(r, "Failed to open private stub-resolv.conf file for writing: %m");
-        (void) fchmod(fileno(f_uplink), 0644);
+
+        (void) __fsetlocking(f_stub, FSETLOCKING_BYCALLER);
         (void) fchmod(fileno(f_stub), 0644);
 
         r = write_uplink_resolv_conf_contents(f_uplink, dns, domains);