summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/basic/tmpfile-util.c4
-rw-r--r--src/home/homed-home.c4
-rw-r--r--src/home/homework.c8
-rw-r--r--src/machine/machine-dbus.c5
-rw-r--r--src/machine/machined-dbus.c4
-rw-r--r--src/nspawn/nspawn-setuid.c6
-rw-r--r--src/portable/portable.c3
-rw-r--r--src/portable/portabled-image-bus.c4
-rw-r--r--src/shared/ask-password-api.c4
-rw-r--r--src/shared/dissect-image.c4
-rw-r--r--src/shared/install.c3
-rw-r--r--src/shared/os-util.c4
12 files changed, 16 insertions, 37 deletions
diff --git a/src/basic/tmpfile-util.c b/src/basic/tmpfile-util.c
index decdafb9c9..2a2ffb21a5 100644
--- a/src/basic/tmpfile-util.c
+++ b/src/basic/tmpfile-util.c
@@ -48,14 +48,12 @@ int fopen_temporary(const char *path, FILE **ret_f, char **ret_temp_path) {
/* 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. */
- r = fdopen_unlocked(fd, "w", &f);
+ r = take_fdopen_unlocked(&fd, "w", &f);
if (r < 0) {
(void) unlink(t);
return r;
}
- TAKE_FD(fd);
-
if (ret_f)
*ret_f = TAKE_PTR(f);
diff --git a/src/home/homed-home.c b/src/home/homed-home.c
index f50de26722..f553419c41 100644
--- a/src/home/homed-home.c
+++ b/src/home/homed-home.c
@@ -360,12 +360,10 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) {
if (lseek(fd, SEEK_SET, 0) == (off_t) -1)
return log_error_errno(errno, "Failed to seek to beginning of memfd: %m");
- f = fdopen(fd, "r");
+ f = take_fdopen(&fd, "r");
if (!f)
return log_error_errno(errno, "Failed to reopen memfd: %m");
- TAKE_FD(fd);
-
if (DEBUG_LOGGING) {
_cleanup_free_ char *text = NULL;
diff --git a/src/home/homework.c b/src/home/homework.c
index 591e9a19c8..58fa087097 100644
--- a/src/home/homework.c
+++ b/src/home/homework.c
@@ -279,12 +279,10 @@ static int read_identity_file(int root_fd, JsonVariant **ret) {
if (r < 0)
return log_error_errno(r, "Embedded identity file is not a regular file, refusing: %m");
- identity_file = fdopen(identity_fd, "r");
+ identity_file = take_fdopen(&identity_fd, "r");
if (!identity_file)
return log_oom();
- identity_fd = -1;
-
r = json_parse_file(identity_file, ".identity", JSON_PARSE_SENSITIVE, ret, &line, &column);
if (r < 0)
return log_error_errno(r, "[.identity:%u:%u] Failed to parse JSON data: %m", line, column);
@@ -318,14 +316,12 @@ static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
if (identity_fd < 0)
return log_error_errno(errno, "Failed to create .identity file in home directory: %m");
- identity_file = fdopen(identity_fd, "w");
+ identity_file = take_fdopen(&identity_fd, "w");
if (!identity_file) {
r = log_oom();
goto fail;
}
- identity_fd = -1;
-
json_variant_dump(normalized, JSON_FORMAT_PRETTY, identity_file, NULL);
r = fflush_and_check(identity_file);
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index a2990452af..5c0f714184 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -20,6 +20,7 @@
#include "env-file.h"
#include "env-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "format-util.h"
#include "fs-util.h"
#include "in-addr-util.h"
@@ -399,12 +400,10 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
pair[1] = safe_close(pair[1]);
- f = fdopen(pair[0], "r");
+ f = take_fdopen(&pair[0], "r");
if (!f)
return -errno;
- pair[0] = -1;
-
r = load_env_file_pairs(f, "/etc/os-release", &l);
if (r < 0)
return r;
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index d0cc07678f..97dfb94278 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -620,12 +620,10 @@ static int clean_pool_done(Operation *operation, int ret, sd_bus_error *error) {
if (lseek(operation->extra_fd, 0, SEEK_SET) == (off_t) -1)
return -errno;
- f = fdopen(operation->extra_fd, "r");
+ f = take_fdopen(&operation->extra_fd, "r");
if (!f)
return -errno;
- operation->extra_fd = -1;
-
/* The resulting temporary file starts with a boolean value that indicates success or not. */
errno = 0;
n = fread(&success, 1, sizeof(success), f);
diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c
index cb2b2272b6..d0e575fef2 100644
--- a/src/nspawn/nspawn-setuid.c
+++ b/src/nspawn/nspawn-setuid.c
@@ -118,10 +118,9 @@ int change_uid_gid(const char *user, char **_home) {
if (fd < 0)
return fd;
- f = fdopen(fd, "r");
+ f = take_fdopen(&fd, "r");
if (!f)
return log_oom();
- fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0)
@@ -191,10 +190,9 @@ int change_uid_gid(const char *user, char **_home) {
if (fd < 0)
return fd;
- f = fdopen(fd, "r");
+ f = take_fdopen(&fd, "r");
if (!f)
return log_oom();
- fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0)
diff --git a/src/portable/portable.c b/src/portable/portable.c
index e18826ab26..58e4a6670d 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -1092,10 +1092,9 @@ static int test_chroot_dropin(
return log_debug_errno(errno, "Failed to open %s/%s: %m", where, p);
}
- r = fdopen_unlocked(fd, "r", &f);
+ r = take_fdopen_unlocked(&fd, "r", &f);
if (r < 0)
return log_debug_errno(r, "Failed to convert file handle: %m");
- TAKE_FD(fd);
r = read_line(f, LONG_LINE_MAX, &line);
if (r < 0)
diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c
index 2bd1c495e4..5988a21037 100644
--- a/src/portable/portabled-image-bus.c
+++ b/src/portable/portabled-image-bus.c
@@ -79,12 +79,10 @@ static int append_fd(sd_bus_message *m, PortableMetadata *d) {
assert(d);
assert(d->fd >= 0);
- f = fdopen(d->fd, "r");
+ f = take_fdopen(&d->fd, "r");
if (!f)
return -errno;
- d->fd = -1;
-
r = read_full_stream(f, &buf, &n);
if (r < 0)
return r;
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 0fc5501e62..b64663bd1e 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -791,14 +791,12 @@ int ask_password_agent(
(void) fchmod(fd, 0644);
- f = fdopen(fd, "w");
+ f = take_fdopen(&fd, "w");
if (!f) {
r = -errno;
goto finish;
}
- fd = -1;
-
signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
if (signal_fd < 0) {
r = -errno;
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 1ef69fdf4c..f914473a1d 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -1541,14 +1541,12 @@ int dissected_image_acquire_metadata(DissectedImage *m) {
fds[2*k+1] = safe_close(fds[2*k+1]);
- f = fdopen(fds[2*k], "r");
+ f = take_fdopen(&fds[2*k], "r");
if (!f) {
r = -errno;
goto finish;
}
- fds[2*k] = -1;
-
switch (k) {
case META_HOSTNAME:
diff --git a/src/shared/install.c b/src/shared/install.c
index 48cb6aca7e..0f18b6bee5 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1280,10 +1280,9 @@ static int unit_file_load(
if (r < 0)
return r;
- f = fdopen(fd, "r");
+ f = take_fdopen(&fd, "r");
if (!f)
return -errno;
- fd = -1;
/* c is only needed if we actually load the file (it's referenced from items[] btw, in case you wonder.) */
assert(c);
diff --git a/src/shared/os-util.c b/src/shared/os-util.c
index b2af8535f9..eacebc1ea5 100644
--- a/src/shared/os-util.c
+++ b/src/shared/os-util.c
@@ -3,6 +3,7 @@
#include "alloc-util.h"
#include "env-file.h"
#include "fd-util.h"
+#include "fileio.h"
#include "fs-util.h"
#include "macro.h"
#include "os-util.h"
@@ -76,10 +77,9 @@ int fopen_os_release(const char *root, char **ret_path, FILE **ret_file) {
if (r < 0)
return r;
- f = fdopen(fd, "r");
+ f = take_fdopen(&fd, "r");
if (!f)
return -errno;
- fd = -1;
*ret_file = f;