#include <limits.h>
#include <stddef.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
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;
}
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);
}
}
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;
}
fprintf(f, ".%06i", c->repeat % d);
if (c->next) {
- fputc_unlocked(',', f);
+ fputc(',', f);
format_chain(f, space, c->next, usec);
}
}
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. */
tzset();
if (!isempty(tzname[c->dst])) {
- fputc_unlocked(' ', f);
- fputs_unlocked(tzname[c->dst], f);
+ fputc(' ', f);
+ fputs(tzname[c->dst], f);
}
}
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
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++) {
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;
}
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')
***/
#include <getopt.h>
+#include <stdio_ext.h>
#include "sd-bus.h"
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);
***/
#include <arpa/inet.h>
+#include <stdio_ext.h>
#include "af-list.h"
#include "alloc-util.h"
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])
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);
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);
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);
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" : "");
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)];
***/
#include <sys/prctl.h>
+#include <stdio_ext.h>
#if HAVE_SECCOMP
#include <seccomp.h>
if (!f)
return -ENOMEM;
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
fputs("EnvironmentFile=\n", f);
STRV_FOREACH(i, c->environment_files) {
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"
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;
if (!f)
return -errno;
- __fsetlocking(f, FSETLOCKING_BYCALLER);
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
manager_dump(m, f, NULL);
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) {
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
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;
}
}
#include <errno.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <sys/prctl.h>
#include <sys/xattr.h>
#include <unistd.h>
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;
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);
}
#include <dwarf.h>
#include <elfutils/libdwfl.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "fd-util.h"
return DWARF_CB_ABORT;
if (c->n_thread != 0)
- fputc_unlocked('\n', c->f);
+ fputc('\n', c->f);
c->n_frame = 0;
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);
***/
#include <errno.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "dropin.h"
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"
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;
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",
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;
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "fd-util.h"
"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)
"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"
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"
#include <qrencode.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include "journal-qrcode.h"
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]);
}
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
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");
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);
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);
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"
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;
}
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;
}
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) {
if (direction)
fprintf(i->f, " direction=\"%s\"/>\n", direction);
else
- fputs_unlocked("/>\n", i->f);
+ fputs("/>\n", i->f);
signature += l;
}
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:
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:
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;
}
assert(m);
assert(reply);
- fputs_unlocked("</node>\n", i->f);
+ fputs("</node>\n", i->f);
r = fflush_and_check(i->f);
if (r < 0)
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"
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);
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);
}
}
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
***/
#include <errno.h>
+#include <stdio_ext.h>
#include <string.h>
#include <unistd.h>
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);
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)
#include <errno.h>
#include <fcntl.h>
+#include <stdio_ext.h>
#include <string.h>
#include <unistd.h>
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"
if (s->sessions) {
Session *i;
- fputs_unlocked("SESSIONS=", f);
+ fputs("SESSIONS=", f);
LIST_FOREACH(sessions_by_seat, i, s->sessions) {
fprintf(f,
"%s%c",
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",
#include <string.h>
#include <sys/mount.h>
#include <unistd.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "bus-common-errors.h"
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"
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)
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))
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)
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)
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)
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);
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <stdio_ext.h>
#include "sd-messages.h"
if (r < 0)
goto fail;
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
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);
#include <netinet/ether.h>
#include <linux/if.h>
#include <unistd.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "bus-util.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) {
if (r < 0)
goto fail;
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
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++) {
}
if (space)
- fputc_unlocked(' ', f);
- fputs_unlocked(b, f);
+ fputc(' ', f);
+ fputs(b, f);
space = true;
}
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;
}
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;
}
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);
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;
}
&in6_addrs);
if (r > 0) {
if (space)
- fputc_unlocked(' ', f);
+ fputc(' ', f);
serialize_in6_addrs(f, in6_addrs, r);
space = true;
}
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) {
(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);
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);
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));
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;
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;
space = true;
}
- fputc_unlocked('\n', f);
+ fputc('\n', f);
}
print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links);
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);
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);
}
}
#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"
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) {
if (r < 0)
return r;
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
***/
#include <net/if.h>
+#include <stdio_ext.h>
#include "sd-network.h"
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)
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) {
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)) {
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);
#include <netinet/in.h>
#include <poll.h>
+#include <stdio_ext.h>
#include <sys/ioctl.h>
#if HAVE_LIBIDN2
if (!f)
return log_oom();
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
LIST_FOREACH(scopes, scope, m->dns_scopes)
dns_scope_dump(scope, f);
***/
#include <resolv.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "dns-domain.h"
}
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));
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;
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);
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);