diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 6b3a9a4441..e6add0c383 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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); } } diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 5774d4dea1..6dcd531025 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1032,6 +1033,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) { if (!f) return errno == ENOENT ? -ESRCH : -errno; + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + FOREACH_LINE(line, f, return -errno) { char *e, *p; @@ -2371,6 +2374,8 @@ int cg_kernel_controllers(Set **ret) { return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + /* Ignore the header line */ (void) read_line(f, (size_t) -1, NULL); diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 3ab50bca2f..5296f1cff0 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ static int write_string_file_atomic( if (r < 0) return r; + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); (void) fchmod_umask(fileno(f), 0644); r = write_string_stream_ts(f, line, flags, ts); @@ -167,6 +169,8 @@ int write_string_file_ts( } } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + if (flags & WRITE_STRING_FILE_DISABLE_BUFFER) setvbuf(f, NULL, _IONBF, 0); @@ -203,6 +207,8 @@ int read_one_line_file(const char *fn, char **line) { if (!f) return -errno; + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + r = read_line(f, LONG_LINE_MAX, line); return r < 0 ? r : 0; } @@ -228,6 +234,8 @@ int verify_file(const char *fn, const char *blob, bool accept_extra_nl) { if (!f) return -errno; + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + /* We try to read one byte more than we need, so that we know whether we hit eof */ errno = 0; k = fread(buf, 1, l + accept_extra_nl + 1, f); @@ -323,6 +331,8 @@ int read_full_file(const char *fn, char **contents, size_t *size) { if (!f) return -errno; + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + return read_full_stream(f, contents, size); } @@ -879,7 +889,8 @@ int write_env_file(const char *fname, char **l) { if (r < 0) return r; - fchmod_umask(fileno(f), 0644); + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + (void) fchmod_umask(fileno(f), 0644); STRV_FOREACH(i, l) write_env_var(f, *i); diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index f8d615dd89..455c50fc9f 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -19,6 +19,7 @@ ***/ #include +#include #include #include #include @@ -337,6 +338,8 @@ int umount_recursive(const char *prefix, int flags) { if (!proc_self_mountinfo) return -errno; + (void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER); + for (;;) { _cleanup_free_ char *path = NULL, *p = NULL; int k; @@ -583,6 +586,8 @@ int bind_remount_recursive(const char *prefix, bool ro, char **blacklist) { if (!proc_self_mountinfo) return -errno; + (void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER); + return bind_remount_recursive_with_mountinfo(prefix, ro, blacklist, proc_self_mountinfo); } diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 5f001494f0..32c3c951a1 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -130,6 +131,8 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + if (max_length == 1) { /* If there's only room for one byte, return the empty string */ @@ -406,6 +409,8 @@ int is_kernel_thread(pid_t pid) { return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + count = fread(&c, 1, 1, f); eof = feof(f); fclose(f); @@ -487,6 +492,8 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) { return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + FOREACH_LINE(line, f, return -errno) { char *l; @@ -565,6 +572,8 @@ int get_process_environ(pid_t pid, char **env) { return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + while ((c = fgetc(f)) != EOF) { if (!GREEDY_REALLOC(outcome, allocated, sz + 5)) return -ENOMEM; @@ -749,6 +758,8 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { return -errno; } + (void) __fsetlocking(f, FSETLOCKING_BYCALLER); + l = strlen(field); r = 0; diff --git a/src/basic/string-util.c b/src/basic/string-util.c index e916000b25..7e2f596edc 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -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') diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 953816c46d..7547695e68 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -19,6 +19,7 @@ ***/ #include +#include #include "sd-bus.h" @@ -886,10 +887,8 @@ static int introspect(sd_bus *bus, char **argv) { return log_oom(); r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply_xml, ""); - if (r < 0) { - log_error("Failed to introspect object %s of service %s: %s", argv[2], argv[1], bus_error_message(&error, r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to introspect object %s of service %s: %s", argv[2], argv[1], bus_error_message(&error, r)); r = sd_bus_message_read(reply_xml, "s", &xml); if (r < 0) @@ -914,10 +913,8 @@ static int introspect(sd_bus *bus, char **argv) { continue; r = sd_bus_call_method(bus, argv[1], argv[2], "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", m->interface); - if (r < 0) { - log_error("%s", bus_error_message(&error, r)); - return r; - } + if (r < 0) + return log_error_errno(r, "%s", bus_error_message(&error, r)); r = sd_bus_message_enter_container(reply, 'a', "{sv}"); if (r < 0) @@ -949,22 +946,20 @@ 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); - fclose(mf); - mf = NULL; + mf = safe_fclose(mf); z = set_get(members, &((Member) { .type = "property", .interface = m->interface, .name = (char*) name })); - if (z) { - free(z->value); - z->value = buf; - buf = NULL; - } + if (z) + free_and_replace(z->value, buf); r = sd_bus_message_exit_container(reply); if (r < 0) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 690e3a3ca2..abca4e112d 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -19,6 +19,7 @@ ***/ #include +#include #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)]; diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 196de5658e..be25b6e987 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -19,6 +19,7 @@ ***/ #include +#include #if HAVE_SECCOMP #include @@ -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) { diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 8121765dad..0189952124 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -18,6 +18,8 @@ along with systemd; If not, see . ***/ +#include + #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; diff --git a/src/core/manager.c b/src/core/manager.c index 0681bbbbd2..7ac798348c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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) { diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index a5b6ea2cd6..b0d3612d69 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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; } } diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index c7dd61f077..e6063cc980 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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); } diff --git a/src/coredump/stacktrace.c b/src/coredump/stacktrace.c index d37ffae020..95fd27b79a 100644 --- a/src/coredump/stacktrace.c +++ b/src/coredump/stacktrace.c @@ -20,6 +20,7 @@ #include #include +#include #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); 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 +#include #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; 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" diff --git a/src/journal/journal-qrcode.c b/src/journal/journal-qrcode.c index 46ff1ce053..5a9dcaa525 100644 --- a/src/journal/journal-qrcode.c +++ b/src/journal/journal-qrcode.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #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]); } diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index a186bca38f..78b8e058b4 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c index 8a6e041748..9bd2dadfde 100644 --- a/src/libsystemd/sd-bus/bus-introspect.c +++ b/src/libsystemd/sd-bus/bus-introspect.c @@ -18,6 +18,8 @@ along with systemd; If not, see . ***/ +#include + #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 - "\n", i->f); + (void) __fsetlocking(i->f, FSETLOCKING_BYCALLER); + + fputs(BUS_INTROSPECT_DOCTYPE + "\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(" \n", i->f); + fputs(" \n", i->f); if (type == _SD_BUS_VTABLE_METHOD && (flags & SD_BUS_VTABLE_METHOD_NO_REPLY)) - fputs_unlocked(" \n", i->f); + fputs(" \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(" \n", i->f); + fputs(" \n", i->f); if (flags & SD_BUS_VTABLE_PROPERTY_CONST) - fputs_unlocked(" \n", i->f); + fputs(" \n", i->f); else if (flags & SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION) - fputs_unlocked(" \n", i->f); + fputs(" \n", i->f); else if (!(flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE)) - fputs_unlocked(" \n", i->f); + fputs(" \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(" \n", i->f); + fputs(" \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(" \n", i->f); + fputs(" \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(" \n", i->f); + fputs(" \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(" \n", i->f); + fputs(" \n", i->f); break; case _SD_BUS_VTABLE_SIGNAL: fprintf(i->f, " \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(" \n", i->f); + fputs(" \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("\n", i->f); + fputs("\n", i->f); r = fflush_and_check(i->f); if (r < 0) 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 . ***/ +#include + #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); diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index 4c7dbaa2c9..121197bbcb 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -960,7 +960,7 @@ static int process_introspect( if (!streq_ptr(previous_interface, c->interface)) { if (previous_interface) - fputs_unlocked(" \n", intro.f); + fputs(" \n", intro.f); fprintf(intro.f, " \n", c->interface); } @@ -973,7 +973,7 @@ static int process_introspect( } if (previous_interface) - fputs_unlocked(" \n", intro.f); + fputs(" \n", intro.f); if (empty) { /* Nothing?, let's see if we exist at all, and if not diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c index 2457f8705c..2d788106bb 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -20,6 +20,7 @@ ***/ #include +#include #include #include @@ -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) diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index f4aa9a6651..b99e7abf91 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -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", diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 01469438b1..94e250b94a 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -22,6 +22,7 @@ #include #include #include +#include #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); diff --git a/src/machine/machine.c b/src/machine/machine.c index 3d3c7cb6b8..0525c0cb03 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -21,6 +21,7 @@ #include #include #include +#include #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); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 6c4711e2e8..60ac980ad9 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -21,6 +21,7 @@ #include #include #include +#include #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); } } diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index c2c41d978b..cc17af9391 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -21,6 +21,7 @@ #include #include #include +#include #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, 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 +#include #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); diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 983e6c091a..2dbf432df9 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -20,6 +20,7 @@ #include #include +#include #include #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); diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c index 4ea7490ac9..bad04d6a29 100644 --- a/src/resolve/resolved-resolv-conf.c +++ b/src/resolve/resolved-resolv-conf.c @@ -19,6 +19,7 @@ ***/ #include +#include #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);