summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-03-10 09:33:20 +0100
committerGitHub <noreply@github.com>2023-03-10 09:33:20 +0100
commite0e818bb14face674664eb6a6eeb8d8a0d10899d (patch)
treea314ea0b083788dabb3aeecd2009a02c515c2731
parentload-fragment: add user credential specifiers to user.conf (diff)
parentdata-fd-util: use fd_reopen() a bit more (diff)
downloadsystemd-e0e818bb14face674664eb6a6eeb8d8a0d10899d.tar.xz
systemd-e0e818bb14face674664eb6a6eeb8d8a0d10899d.zip
Merge pull request #26741 from poettering/acquire-fd-fixes
trivial fixes to acquire_data_fd()
-rw-r--r--src/basic/fd-util.h8
-rw-r--r--src/shared/data-fd-util.c7
-rw-r--r--src/shared/data-fd-util.h10
3 files changed, 12 insertions, 13 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h
index f5357860f5..76be00e4f4 100644
--- a/src/basic/fd-util.h
+++ b/src/basic/fd-util.h
@@ -74,14 +74,6 @@ int fd_get_path(int fd, char **ret);
int move_fd(int from, int to, int cloexec);
-enum {
- ACQUIRE_NO_DEV_NULL = 1 << 0,
- ACQUIRE_NO_MEMFD = 1 << 1,
- ACQUIRE_NO_PIPE = 1 << 2,
- ACQUIRE_NO_TMPFILE = 1 << 3,
- ACQUIRE_NO_REGULAR = 1 << 4,
-};
-
int fd_move_above_stdio(int fd);
int rearrange_stdio(int original_input_fd, int original_output_fd, int original_error_fd);
diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c
index 895d8e8b33..209898fa61 100644
--- a/src/shared/data-fd-util.c
+++ b/src/shared/data-fd-util.c
@@ -27,7 +27,6 @@
int acquire_data_fd(const void *data, size_t size, unsigned flags) {
_cleanup_close_pair_ int pipefds[2] = PIPE_EBADF;
- char pattern[] = "/dev/shm/data-fd-XXXXXX";
_cleanup_close_ int fd = -EBADF;
int isz = 0, r;
ssize_t n;
@@ -135,6 +134,8 @@ try_dev_shm:
try_dev_shm_without_o_tmpfile:
if ((flags & ACQUIRE_NO_REGULAR) == 0) {
+ char pattern[] = "/dev/shm/data-fd-XXXXXX";
+
fd = mkostemp_safe(pattern);
if (fd < 0)
return fd;
@@ -150,9 +151,7 @@ try_dev_shm_without_o_tmpfile:
}
/* Let's reopen the thing, in order to get an O_RDONLY fd for the original O_RDWR one */
- r = open(pattern, O_RDONLY|O_CLOEXEC);
- if (r < 0)
- r = -errno;
+ r = fd_reopen(fd, O_RDONLY|O_CLOEXEC);
unlink_and_return:
(void) unlink(pattern);
diff --git a/src/shared/data-fd-util.h b/src/shared/data-fd-util.h
index f0e7923556..4f3d8b8e74 100644
--- a/src/shared/data-fd-util.h
+++ b/src/shared/data-fd-util.h
@@ -1,7 +1,15 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include <stddef.h>
+#include <inttypes.h>
+
+enum {
+ ACQUIRE_NO_DEV_NULL = 1 << 0,
+ ACQUIRE_NO_MEMFD = 1 << 1,
+ ACQUIRE_NO_PIPE = 1 << 2,
+ ACQUIRE_NO_TMPFILE = 1 << 3,
+ ACQUIRE_NO_REGULAR = 1 << 4,
+};
int acquire_data_fd(const void *data, size_t size, unsigned flags);
int copy_data_fd(int fd);