Make fopen_temporary and fopen_temporary_label unlocked
This is partially a refactoring, but also makes many more places use unlocked operations implicitly, i.e. all users of fopen_temporary(). AFAICT, the uses are always for short-lived files which are not shared externally, and are just used within the same context. Locking is not necessary.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio_ext.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
@@ -30,23 +29,22 @@ int generator_open_unit_file(
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio_ext.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
Reference in New Issue
Block a user