+ return -ESRCH;
+ if (r < 0)
+ return r;
+@@
+expression f, path, p;
+@@
+ r = fopen_temporary(path, &f, &p);
+ if (r < 0)
+ return ...;
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+@@
+expression f, g, path, p;
+@@
+ r = fopen_temporary_label(path, g, &f, &p);
+ if (r < 0)
+ return ...;
+- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
#include <limits.h>
#include <signal.h>
#include <stddef.h>
-#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
/* SPDX-License-Identifier: LGPL-2.1+ */
-#include <stdio_ext.h>
-
#include "alloc-util.h"
#include "env-file.h"
#include "env-util.h"
if (r < 0)
return r;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod_umask(fileno(f), 0644);
STRV_FOREACH(i, l)
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);
assert(!ts);
if (flags & WRITE_STRING_FILE_CREATE) {
- f = fopen(fn, "we");
- if (!f) {
- r = -errno;
+ r = fopen_unlocked(fn, "we", &f);
+ if (r < 0)
goto fail;
- }
} else {
int fd;
safe_close(fd);
goto fail;
}
- }
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+ }
if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
setvbuf(f, NULL, _IONBF, 0);
#include <errno.h>
#include <fcntl.h>
-#include <stdio_ext.h>
#include <sys/mount.h>
#include "alloc-util.h"
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
-#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <stdio.h>
+#include <stdio_ext.h>
#include <sys/mman.h>
#include "alloc-util.h"
return -errno;
}
+ /* This assumes that returned FILE object is short-lived and used within the same single-threaded
+ * context and never shared externally, hence locking is not necessary. */
+
f = fdopen(fd, "w");
if (!f) {
unlink_noerrno(t);
return -errno;
}
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
*_f = f;
*_temp_path = t;
/* SPDX-License-Identifier: LGPL-2.1+ */
-#include <stdio_ext.h>
#include <fcntl.h>
#include "alloc-util.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <stdio_ext.h>
#include "alloc-util.h"
#include "fd-util.h"
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
-#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
-#include <stdio_ext.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
if (r < 0)
return r;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
#include <errno.h>
#include <fcntl.h>
-#include <stdio_ext.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <linux/kd.h>
#include <linux/vt.h>
#include <signal.h>
-#include <stdio_ext.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <stdio_ext.h>
#include "alloc-util.h"
#include "bus-common-errors.h"
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <stdio_ext.h>
#include <sys/stat.h>
#include "sd-messages.h"
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <linux/if.h>
#include <linux/can/netlink.h>
#include <unistd.h>
-#include <stdio_ext.h>
#include "alloc-util.h"
#include "bus-util.h"
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/fib_rules.h>
-#include <stdio_ext.h>
#include <unistd.h>
#include "sd-daemon.h"
if (r < 0)
return r;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
#include <net/if.h>
#include <linux/if.h>
-#include <stdio_ext.h>
#include <unistd.h>
#include "sd-network.h"
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fputs("# This is private data. Do not parse.\n", f);
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <resolv.h>
-#include <stdio_ext.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
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) __fsetlocking(f_stub, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f_stub), 0644);
r = write_uplink_resolv_conf_contents(f_uplink, dns, domains);
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
-#include <stdio_ext.h>
#include <unistd.h>
#include "alloc-util.h"
const char *unit;
FILE *f;
+ int r;
unit = strjoina(dest, "/", name);
- f = fopen(unit, "wxe");
- if (!f) {
- if (source && errno == EEXIST)
- return log_error_errno(errno,
+ r = fopen_unlocked(unit, "wxe", &f);
+ if (r < 0) {
+ if (source && r == -EEXIST)
+ return log_error_errno(r,
"Failed to create unit file %s, as it already exists. Duplicate entry in %s?",
unit, source);
else
- return log_error_errno(errno,
+ return log_error_errno(r,
"Failed to create unit file %s: %m",
unit);
}
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
-
fprintf(f,
"# Automatically generated by %s\n\n",
program_invocation_short_name);
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
-#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>