From: Lennart Poettering Date: Fri, 21 Jul 2017 08:35:45 +0000 (+0200) Subject: tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396) X-Git-Tag: v235~305 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b61c8751135c58be043d86b9fef4c8ec7aadf18;p=thirdparty%2Fsystemd.git tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396) As a follow-up for db3f45e2d2586d78f942a43e661415bc50716d11 let's do the same for all other cases where we create a FILE* with local scope and know that no other threads hence can have access to it. For most cases this shouldn't change much really, but this should speed dbus introspection and calender time formatting up a bit. --- diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 204120ee0e9..b0712a4bada 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -257,19 +257,19 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) { if (l < 0) { if (need_comma) - fputc(',', f); + fputc_unlocked(',', f); else need_comma = true; - fputs(days[x], f); + fputs_unlocked(days[x], f); l = x; } } else if (l >= 0) { if (x > l + 1) { - fputs(x > l + 2 ? ".." : ",", f); - fputs(days[x-1], f); + fputs_unlocked(x > l + 2 ? ".." : ",", f); + fputs_unlocked(days[x-1], f); } l = -1; @@ -277,8 +277,8 @@ static void format_weekdays(FILE *f, const CalendarSpec *c) { } if (l >= 0 && x > l + 1) { - fputs(x > l + 2 ? ".." : ",", f); - fputs(days[x-1], f); + fputs_unlocked(x > l + 2 ? ".." : ",", f); + fputs_unlocked(days[x-1], f); } } @@ -288,12 +288,12 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us assert(f); if (!c) { - fputc('*', f); + fputc_unlocked('*', f); return; } if (usec && c->start == 0 && c->repeat == USEC_PER_SEC && !c->next) { - fputc('*', f); + fputc_unlocked('*', f); return; } @@ -314,7 +314,7 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us fprintf(f, ".%06i", c->repeat % d); if (c->next) { - fputc(',', f); + fputc_unlocked(',', f); format_chain(f, space, c->next, usec); } } @@ -334,23 +334,23 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) { if (c->weekdays_bits > 0 && c->weekdays_bits <= BITS_WEEKDAYS) { format_weekdays(f, c); - fputc(' ', f); + fputc_unlocked(' ', f); } format_chain(f, 4, c->year, false); - fputc('-', f); + fputc_unlocked('-', f); format_chain(f, 2, c->month, false); - fputc(c->end_of_month ? '~' : '-', f); + fputc_unlocked(c->end_of_month ? '~' : '-', f); format_chain(f, 2, c->day, false); - fputc(' ', f); + fputc_unlocked(' ', f); format_chain(f, 2, c->hour, false); - fputc(':', f); + fputc_unlocked(':', f); format_chain(f, 2, c->minute, false); - fputc(':', f); + fputc_unlocked(':', f); format_chain(f, 2, c->microsecond, true); if (c->utc) - fputs(" UTC", f); + fputs_unlocked(" UTC", f); else if (IN_SET(c->dst, 0, 1)) { /* If daylight saving is explicitly on or off, let's show the used timezone. */ @@ -358,8 +358,8 @@ int calendar_spec_to_string(const CalendarSpec *c, char **p) { tzset(); if (!isempty(tzname[c->dst])) { - fputc(' ', f); - fputs(tzname[c->dst], f); + fputc_unlocked(' ', f); + fputs_unlocked(tzname[c->dst], f); } } diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 0678db4a7ba..a0250385880 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -824,29 +824,29 @@ static void write_env_var(FILE *f, const char *v) { p = strchr(v, '='); if (!p) { /* Fallback */ - fputs(v, f); - fputc('\n', f); + fputs_unlocked(v, f); + fputc_unlocked('\n', f); return; } p++; - fwrite(v, 1, p-v, f); + fwrite_unlocked(v, 1, p-v, f); if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE SHELL_NEED_QUOTES)) { - fputc('\"', f); + fputc_unlocked('\"', f); for (; *p; p++) { if (strchr(SHELL_NEED_ESCAPE, *p)) - fputc('\\', f); + fputc_unlocked('\\', f); - fputc(*p, f); + fputc_unlocked(*p, f); } - fputc('\"', f); + fputc_unlocked('\"', f); } else - fputs(p, f); + fputs_unlocked(p, f); - fputc('\n', f); + fputc_unlocked('\n', f); } int write_env_file(const char *fname, char **l) { diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 12d3ca076bd..4e6d1effaa8 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -625,7 +625,7 @@ int bus_cgroup_set_property( if (!f) return -ENOMEM; - fputs("IODeviceWeight=\n", f); + fputs_unlocked("IODeviceWeight=\n", f); LIST_FOREACH(device_weights, a, c->io_device_weights) fprintf(f, "IODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight); @@ -774,12 +774,12 @@ int bus_cgroup_set_property( return -ENOMEM; if (read) { - fputs("BlockIOReadBandwidth=\n", f); + fputs_unlocked("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("BlockIOWriteBandwidth=\n", f); + fputs_unlocked("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); @@ -857,7 +857,7 @@ int bus_cgroup_set_property( if (!f) return -ENOMEM; - fputs("BlockIODeviceWeight=\n", f); + fputs_unlocked("BlockIODeviceWeight=\n", f); LIST_FOREACH(device_weights, a, c->blockio_device_weights) fprintf(f, "BlockIODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight); @@ -1086,7 +1086,7 @@ int bus_cgroup_set_property( if (!f) return -ENOMEM; - fputs("DeviceAllow=\n", f); + fputs_unlocked("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" : ""); diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 6458ee5c121..a20d4b3b99a 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -308,7 +308,7 @@ static int bus_service_set_transient_property( if (!f) return -ENOMEM; - fputs("ExecStart=\n", f); + fputs_unlocked("ExecStart=\n", f); LIST_FOREACH(command, c, s->exec_command[SERVICE_EXEC_START]) { _cleanup_free_ char *a; diff --git a/src/core/manager.c b/src/core/manager.c index 63893243913..d29acf500fd 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2592,15 +2592,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('\n', f); + fputc_unlocked('\n', f); HASHMAP_FOREACH_KEY(u, t, m->units, i) { if (u->id != t) continue; /* Start marker */ - fputs(u->id, f); - fputc('\n', f); + fputs_unlocked(u->id, f); + fputc_unlocked('\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 adf22931422..9f253643351 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -246,7 +246,7 @@ static int write_netlabel_rules(const char* srcdir) { FOREACH_LINE(buf, policy, log_error_errno(errno, "Failed to read line from %s: %m", entry->d_name)) { - if (!fputs(buf, dst)) { + if (!fputs_unlocked(buf, dst)) { if (r == 0) r = -EINVAL; log_error_errno(errno, "Failed to write line to /sys/fs/smackfs/netlabel"); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index a2c62e55a5f..57d1af454a3 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -564,7 +564,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) { } FOREACH_LINE(line, fdinfo, break) { - fputs(line, stream); + fputs_unlocked(line, stream); if (!endswith(line, "\n")) fputc('\n', stream); } diff --git a/src/coredump/stacktrace.c b/src/coredump/stacktrace.c index 778bee9b129..1726613623c 100644 --- a/src/coredump/stacktrace.c +++ b/src/coredump/stacktrace.c @@ -107,7 +107,7 @@ static int thread_callback(Dwfl_Thread *thread, void *userdata) { return DWARF_CB_ABORT; if (c->n_thread != 0) - fputc('\n', c->f); + fputc_unlocked('\n', c->f); c->n_frame = 0; diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 3fdf65be655..cd07f2abd98 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -102,17 +102,17 @@ static int create_disk( if (!f) return log_error_errno(errno, "Failed to create unit file %s: %m", p); - fputs("# Automatically generated by systemd-cryptsetup-generator\n\n" - "[Unit]\n" - "Description=Cryptography Setup for %I\n" - "Documentation=man:crypttab(5) man:systemd-cryptsetup-generator(8) man:systemd-cryptsetup@.service(8)\n" - "SourcePath=/etc/crypttab\n" - "DefaultDependencies=no\n" - "Conflicts=umount.target\n" - "BindsTo=dev-mapper-%i.device\n" - "IgnoreOnIsolate=true\n" - "After=cryptsetup-pre.target\n", - f); + fputs_unlocked("# Automatically generated by systemd-cryptsetup-generator\n\n" + "[Unit]\n" + "Description=Cryptography Setup for %I\n" + "Documentation=man:crypttab(5) man:systemd-cryptsetup-generator(8) man:systemd-cryptsetup@.service(8)\n" + "SourcePath=/etc/crypttab\n" + "DefaultDependencies=no\n" + "Conflicts=umount.target\n" + "BindsTo=dev-mapper-%i.device\n" + "IgnoreOnIsolate=true\n" + "After=cryptsetup-pre.target\n", + f); if (!nofail) fprintf(f, @@ -120,7 +120,7 @@ static int create_disk( if (password) { if (STR_IN_SET(password, "/dev/urandom", "/dev/random", "/dev/hw_random")) - fputs("After=systemd-random-seed.service\n", f); + fputs_unlocked("After=systemd-random-seed.service\n", f); else if (!STR_IN_SET(password, "-", "none")) { _cleanup_free_ char *uu; @@ -152,8 +152,8 @@ static int create_disk( d, d); if (swap) - fputs("Before=dev-mapper-%i.swap\n", - f); + fputs_unlocked("Before=dev-mapper-%i.swap\n", + f); } else fprintf(f, "RequiresMountsFor=%s\n", diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 8fc4c8d179e..ec70a349fcf 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -125,11 +125,11 @@ static int add_swap( "Failed to create unit file %s: %m", unit); - 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); + 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); r = write_what(f, what); if (r < 0) diff --git a/src/journal/journal-qrcode.c b/src/journal/journal-qrcode.c index 5ee10498d10..4e194bd809e 100644 --- a/src/journal/journal-qrcode.c +++ b/src/journal/journal-qrcode.c @@ -65,11 +65,11 @@ int print_qr_code( if (!f) return -ENOMEM; - fputs("fss://", f); + fputs_unlocked("fss://", f); for (i = 0; i < seed_size; i++) { if (i > 0 && i % 3 == 0) - fputc('-', f); + fputc_unlocked('-', 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 1661874a55b..6f0e51720a1 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -926,16 +926,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("DNS=", f); + fputs_unlocked("DNS=", f); serialize_in_addrs(f, addresses, r); - fputs("\n", f); + fputs_unlocked("\n", f); } r = sd_dhcp_lease_get_ntp(lease, &addresses); if (r > 0) { - fputs("NTP=", f); + fputs_unlocked("NTP=", f); serialize_in_addrs(f, addresses, r); - fputs("\n", f); + fputs_unlocked("\n", f); } r = sd_dhcp_lease_get_domainname(lease, &string); @@ -944,9 +944,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("DOMAIN_SEARCH_LIST=", f); + fputs_unlocked("DOMAIN_SEARCH_LIST=", f); fputstrv(f, search_domains, NULL, NULL); - fputs("\n", f); + fputs_unlocked("\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 8f93edb8dae..5dab4a9af3b 100644 --- a/src/libsystemd/sd-bus/bus-introspect.c +++ b/src/libsystemd/sd-bus/bus-introspect.c @@ -36,8 +36,8 @@ int introspect_begin(struct introspect *i, bool trusted) { if (!i->f) return -ENOMEM; - fputs(BUS_INTROSPECT_DOCTYPE - "\n", i->f); + fputs_unlocked(BUS_INTROSPECT_DOCTYPE + "\n", i->f); return 0; } @@ -45,12 +45,12 @@ int introspect_begin(struct introspect *i, bool trusted) { int introspect_write_default_interfaces(struct introspect *i, bool object_manager) { assert(i); - fputs(BUS_INTROSPECT_INTERFACE_PEER - BUS_INTROSPECT_INTERFACE_INTROSPECTABLE - BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f); + fputs_unlocked(BUS_INTROSPECT_INTERFACE_PEER + BUS_INTROSPECT_INTERFACE_INTROSPECTABLE + BUS_INTROSPECT_INTERFACE_PROPERTIES, i->f); if (object_manager) - fputs(BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f); + fputs_unlocked(BUS_INTROSPECT_INTERFACE_OBJECT_MANAGER, i->f); return 0; } @@ -76,27 +76,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(" \n", i->f); + fputs_unlocked(" \n", i->f); if (type == _SD_BUS_VTABLE_METHOD && (flags & SD_BUS_VTABLE_METHOD_NO_REPLY)) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); if (type == _SD_BUS_VTABLE_PROPERTY || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) { if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); if (flags & SD_BUS_VTABLE_PROPERTY_CONST) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); else if (flags & SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); else if (!(flags & SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE)) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); } if (!i->trusted && (type == _SD_BUS_VTABLE_METHOD || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) && !(flags & SD_BUS_VTABLE_UNPRIVILEGED)) - fputs(" \n", i->f); + fputs_unlocked(" \n", i->f); } static int introspect_write_arguments(struct introspect *i, const char *signature, const char *direction) { @@ -117,7 +117,7 @@ static int introspect_write_arguments(struct introspect *i, const char *signatur if (direction) fprintf(i->f, " direction=\"%s\"/>\n", direction); else - fputs("/>\n", i->f); + fputs_unlocked("/>\n", i->f); signature += l; } @@ -140,7 +140,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(" \n", i->f); + fputs_unlocked(" \n", i->f); break; case _SD_BUS_VTABLE_METHOD: @@ -148,7 +148,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(" \n", i->f); + fputs_unlocked(" \n", i->f); break; case _SD_BUS_VTABLE_PROPERTY: @@ -158,14 +158,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(" \n", i->f); + fputs_unlocked(" \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(" \n", i->f); + fputs_unlocked(" \n", i->f); break; } @@ -182,7 +182,7 @@ int introspect_finish(struct introspect *i, sd_bus *bus, sd_bus_message *m, sd_b assert(m); assert(reply); - fputs("\n", i->f); + fputs_unlocked("\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 db01f211355..02587a3e8d5 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -957,18 +957,18 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com char buf[32]; if (i != 0) - fputc(',', f); + fputc_unlocked(',', f); - fputs(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f); - fputc('=', f); - fputc('\'', f); + fputs_unlocked(bus_match_node_type_to_string(components[i].type, buf, sizeof(buf)), f); + fputc_unlocked('=', f); + fputc_unlocked('\'', f); if (components[i].type == BUS_MATCH_MESSAGE_TYPE) - fputs(bus_message_type_to_string(components[i].value_u8), f); + fputs_unlocked(bus_message_type_to_string(components[i].value_u8), f); else - fputs(components[i].value_str, f); + fputs_unlocked(components[i].value_str, f); - fputc('\'', f); + fputc_unlocked('\'', 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 98911d52036..bb06d302ca1 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -955,7 +955,7 @@ static int process_introspect( if (!streq_ptr(previous_interface, c->interface)) { if (previous_interface) - fputs(" \n", intro.f); + fputs_unlocked(" \n", intro.f); fprintf(intro.f, " \n", c->interface); } @@ -968,7 +968,7 @@ static int process_introspect( } if (previous_interface) - fputs(" \n", intro.f); + fputs_unlocked(" \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 105d9b0ee4c..ec48e8ba6d5 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -361,12 +361,12 @@ int x11_write_data(Context *c) { fchmod(fileno(f), 0644); - 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); + 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); if (!isempty(c->x11_layout)) fprintf(f, " Option \"XkbLayout\" \"%s\"\n", c->x11_layout); @@ -380,7 +380,7 @@ int x11_write_data(Context *c) { if (!isempty(c->x11_options)) fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options); - fputs("EndSection\n", f); + fputs_unlocked("EndSection\n", f); r = fflush_and_check(f); if (r < 0) diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 30dac7997b8..85258737c32 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -127,7 +127,7 @@ int seat_save(Seat *s) { if (s->sessions) { Session *i; - fputs("SESSIONS=", f); + fputs_unlocked("SESSIONS=", f); LIST_FOREACH(sessions_by_seat, i, s->sessions) { fprintf(f, "%s%c", @@ -135,7 +135,7 @@ int seat_save(Seat *s) { i->sessions_by_seat_next ? ' ' : '\n'); } - fputs("UIDS=", f); + fputs_unlocked("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 888a97c2fc2..66d9d06b5f1 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -182,18 +182,18 @@ static int user_save_internal(User *u) { Session *i; bool first; - fputs("SESSIONS=", f); + fputs_unlocked("SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->id, f); + fputs_unlocked(i->id, f); } - fputs("\nSEATS=", f); + fputs_unlocked("\nSEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!i->seat) @@ -202,12 +202,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->seat->id, f); + fputs_unlocked(i->seat->id, f); } - fputs("\nACTIVE_SESSIONS=", f); + fputs_unlocked("\nACTIVE_SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!session_is_active(i)) @@ -216,12 +216,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->id, f); + fputs_unlocked(i->id, f); } - fputs("\nONLINE_SESSIONS=", f); + fputs_unlocked("\nONLINE_SESSIONS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (session_get_state(i) == SESSION_CLOSING) @@ -230,12 +230,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->id, f); + fputs_unlocked(i->id, f); } - fputs("\nACTIVE_SEATS=", f); + fputs_unlocked("\nACTIVE_SEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (!session_is_active(i) || !i->seat) @@ -244,12 +244,12 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->seat->id, f); + fputs_unlocked(i->seat->id, f); } - fputs("\nONLINE_SEATS=", f); + fputs_unlocked("\nONLINE_SEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { if (session_get_state(i) == SESSION_CLOSING || !i->seat) @@ -258,11 +258,11 @@ static int user_save_internal(User *u) { if (first) first = false; else - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(i->seat->id, f); + fputs_unlocked(i->seat->id, f); } - fputc('\n', f); + fputc_unlocked('\n', f); } r = fflush_and_check(f); diff --git a/src/machine/machine.c b/src/machine/machine.c index d3433d9b965..399e41f8707 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -199,16 +199,16 @@ int machine_save(Machine *m) { if (m->n_netif > 0) { unsigned i; - fputs("NETIF=", f); + fputs_unlocked("NETIF=", f); for (i = 0; i < m->n_netif; i++) { if (i != 0) - fputc(' ', f); + fputc_unlocked(' ', f); fprintf(f, "%i", m->netif[i]); } - fputc('\n', f); + fputc_unlocked('\n', f); } r = fflush_and_check(f); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 4c57fa17938..03b8f8c3c40 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -3276,16 +3276,16 @@ static void print_link_hashmap(FILE *f, const char *prefix, Hashmap* h) { if (hashmap_isempty(h)) return; - fputs(prefix, f); + fputs_unlocked(prefix, f); HASHMAP_FOREACH(link, h, i) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); fprintf(f, "%i", link->ifindex); space = true; } - fputc('\n', f); + fputc_unlocked('\n', f); } int link_save(Link *link) { @@ -3343,7 +3343,7 @@ int link_save(Link *link) { fprintf(f, "NETWORK_FILE=%s\n", link->network->filename); - fputs("DNS=", f); + fputs_unlocked("DNS=", f); space = false; for (j = 0; j < link->network->n_dns; j++) { @@ -3357,8 +3357,8 @@ int link_save(Link *link) { } if (space) - fputc(' ', f); - fputs(b, f); + fputc_unlocked(' ', f); + fputs_unlocked(b, f); space = true; } @@ -3369,7 +3369,7 @@ int link_save(Link *link) { r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses); if (r > 0) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); serialize_in_addrs(f, addresses, r); space = true; } @@ -3381,7 +3381,7 @@ int link_save(Link *link) { r = sd_dhcp6_lease_get_dns(dhcp6_lease, &in6_addrs); if (r > 0) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); serialize_in6_addrs(f, in6_addrs, r); space = true; } @@ -3395,16 +3395,16 @@ int link_save(Link *link) { SET_FOREACH(dd, link->ndisc_rdnss, i) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); serialize_in6_addrs(f, &dd->address, 1); space = true; } } - fputc('\n', f); + fputc_unlocked('\n', f); - fputs("NTP=", f); + fputs_unlocked("NTP=", f); space = false; fputstrv(f, link->network->ntp, NULL, &space); @@ -3415,7 +3415,7 @@ int link_save(Link *link) { r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses); if (r > 0) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); serialize_in_addrs(f, addresses, r); space = true; } @@ -3429,7 +3429,7 @@ int link_save(Link *link) { &in6_addrs); if (r > 0) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); serialize_in6_addrs(f, in6_addrs, r); space = true; } @@ -3439,7 +3439,7 @@ int link_save(Link *link) { fputstrv(f, hosts, NULL, &space); } - fputc('\n', f); + fputc_unlocked('\n', f); if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) { if (link->dhcp_lease) { @@ -3450,7 +3450,7 @@ int link_save(Link *link) { (void) sd_dhcp6_lease_get_domains(dhcp6_lease, &dhcp6_domains); } - fputs("DOMAINS=", f); + fputs_unlocked("DOMAINS=", f); space = false; fputstrv(f, link->network->search_domains, NULL, &space); @@ -3468,9 +3468,9 @@ int link_save(Link *link) { fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space); } - fputc('\n', f); + fputc_unlocked('\n', f); - fputs("ROUTE_DOMAINS=", f); + fputs_unlocked("ROUTE_DOMAINS=", f); space = false; fputstrv(f, link->network->route_domains, NULL, &space); @@ -3488,7 +3488,7 @@ int link_save(Link *link) { fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space); } - fputc('\n', f); + fputc_unlocked('\n', f); fprintf(f, "LLMNR=%s\n", resolve_support_to_string(link->network->llmnr)); @@ -3502,14 +3502,14 @@ int link_save(Link *link) { if (!set_isempty(link->network->dnssec_negative_trust_anchors)) { const char *n; - fputs("DNSSEC_NTA=", f); + fputs_unlocked("DNSSEC_NTA=", f); space = false; SET_FOREACH(n, link->network->dnssec_negative_trust_anchors, i) fputs_with_space(f, n, NULL, &space); - fputc('\n', f); + fputc_unlocked('\n', f); } - fputs("ADDRESSES=", f); + fputs_unlocked("ADDRESSES=", f); space = false; SET_FOREACH(a, link->addresses, i) { _cleanup_free_ char *address_str = NULL; @@ -3521,9 +3521,9 @@ int link_save(Link *link) { fprintf(f, "%s%s/%u", space ? " " : "", address_str, a->prefixlen); space = true; } - fputc('\n', f); + fputc_unlocked('\n', f); - fputs("ROUTES=", f); + fputs_unlocked("ROUTES=", f); space = false; SET_FOREACH(route, link->routes, i) { _cleanup_free_ char *route_str = NULL; @@ -3537,7 +3537,7 @@ int link_save(Link *link) { space = true; } - fputc('\n', f); + fputc_unlocked('\n', f); } print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links); @@ -3555,9 +3555,9 @@ int link_save(Link *link) { r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); if (r >= 0) { - fputs("DHCP4_ADDRESS=", f); + fputs_unlocked("DHCP4_ADDRESS=", f); serialize_in_addrs(f, &address, 1); - fputc('\n', f); + fputc_unlocked('\n', f); } r = dhcp_lease_save(link->dhcp_lease, link->lease_file); @@ -3575,9 +3575,9 @@ int link_save(Link *link) { r = sd_ipv4ll_get_address(link->ipv4ll, &address); if (r >= 0) { - fputs("IPV4LL_ADDRESS=", f); + fputs_unlocked("IPV4LL_ADDRESS=", f); serialize_in_addrs(f, &address, 1); - fputc('\n', f); + fputc_unlocked('\n', f); } } diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 5f10b4f993a..c28088d3a3c 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -866,12 +866,12 @@ static void print_string_set(FILE *f, const char *field, OrderedSet *s) { if (ordered_set_isempty(s)) return; - fputs(field, f); + fputs_unlocked(field, f); ORDERED_SET_FOREACH(p, s, i) fputs_with_space(f, p, NULL, &space); - fputc('\n', f); + fputc_unlocked('\n', f); } static int manager_save(Manager *m) { diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index 61a3f203625..ea3b0618770 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -1050,7 +1050,7 @@ int link_save_user(Link *l) { if (r < 0) goto fail; - fputs("# This is private data. Do not parse.\n", f); + fputs_unlocked("# This is private data. Do not parse.\n", f); v = resolve_support_to_string(l->llmnr_support); if (v) @@ -1067,11 +1067,11 @@ int link_save_user(Link *l) { if (l->dns_servers) { DnsServer *server; - fputs("SERVERS=", f); + fputs_unlocked("SERVERS=", f); LIST_FOREACH(servers, server, l->dns_servers) { if (server != l->dns_servers) - fputc(' ', f); + fputc_unlocked(' ', f); v = dns_server_string(server); if (!v) { @@ -1079,26 +1079,26 @@ int link_save_user(Link *l) { goto fail; } - fputs(v, f); + fputs_unlocked(v, f); } - fputc('\n', f); + fputc_unlocked('\n', f); } if (l->search_domains) { DnsSearchDomain *domain; - fputs("DOMAINS=", f); + fputs_unlocked("DOMAINS=", f); LIST_FOREACH(domains, domain, l->search_domains) { if (domain != l->search_domains) - fputc(' ', f); + fputc_unlocked(' ', f); if (domain->route_only) - fputc('~', f); + fputc_unlocked('~', f); - fputs(DNS_SEARCH_DOMAIN_NAME(domain), f); + fputs_unlocked(DNS_SEARCH_DOMAIN_NAME(domain), f); } - fputc('\n', f); + fputc_unlocked('\n', f); } if (!set_isempty(l->dnssec_negative_trust_anchors)) { @@ -1106,16 +1106,16 @@ int link_save_user(Link *l) { Iterator i; char *nta; - fputs("NTAS=", f); + fputs_unlocked("NTAS=", f); SET_FOREACH(nta, l->dnssec_negative_trust_anchors, i) { if (space) - fputc(' ', f); + fputc_unlocked(' ', f); - fputs(nta, f); + fputs_unlocked(nta, f); space = true; } - fputc('\n', f); + fputc_unlocked('\n', f); } r = fflush_and_check(f); diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c index 3c625508726..f4e071ebaad 100644 --- a/src/resolve/resolved-resolv-conf.c +++ b/src/resolve/resolved-resolv-conf.c @@ -165,7 +165,7 @@ static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) { } if (*count == MAXNS) - fputs("# Too many DNS servers configured, the following entries may be ignored.\n", f); + fputs_unlocked("# Too many DNS servers configured, the following entries may be ignored.\n", f); (*count)++; fprintf(f, "nameserver %s\n", dns_server_string(s)); @@ -181,39 +181,39 @@ static void write_resolv_conf_search( assert(domains); assert(f); - fputs("search", f); + fputs_unlocked("search", f); ORDERED_SET_FOREACH(domain, domains, i) { if (++count > MAXDNSRCH) { - fputs("\n# Too many search domains configured, remaining ones ignored.", f); + fputs_unlocked("\n# Too many search domains configured, remaining ones ignored.", f); break; } length += strlen(domain) + 1; if (length > 256) { - fputs("\n# Total length of all search domains is too long, remaining ones ignored.", f); + fputs_unlocked("\n# Total length of all search domains is too long, remaining ones ignored.", f); break; } - fputc(' ', f); - fputs(domain, f); + fputc_unlocked(' ', f); + fputs_unlocked(domain, f); } - fputs("\n", f); + fputs_unlocked("\n", f); } static int write_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet *domains) { Iterator i; - 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 DNS servers.\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_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 DNS servers.\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("# No DNS servers known.\n", f); + fputs_unlocked("# No DNS servers known.\n", f); else { unsigned count = 0; DnsServer *s;