data-fd-util: accept size == SIZE_MAX and translate that to strlen
Like what we already do at other places
This commit is contained in:
@@ -627,7 +627,7 @@ static int method_dump_memory_state_by_fd(sd_bus_message *message, void *userdat
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
fd = acquire_data_fd(dump, dump_size, 0);
|
||||
fd = acquire_data_fd_full(dump, dump_size, /* flags = */ 0);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/* If memfd/pipe didn't work out, then let's use a file in /tmp up to a size of 1M. If it's large than that use /var/tmp instead. */
|
||||
#define DATA_FD_TMP_LIMIT (1U * U64_MB)
|
||||
|
||||
int acquire_data_fd(const void *data, size_t size, DataFDFlags flags) {
|
||||
int acquire_data_fd_full(const void *data, size_t size, DataFDFlags flags) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
ssize_t n;
|
||||
int r;
|
||||
@@ -51,6 +51,9 @@ int acquire_data_fd(const void *data, size_t size, DataFDFlags flags) {
|
||||
* It sucks a bit that depending on the situation we return very different objects here, but that's Linux I
|
||||
* figure. */
|
||||
|
||||
if (size == SIZE_MAX)
|
||||
size = strlen(data);
|
||||
|
||||
if (size == 0 && !FLAGS_SET(flags, ACQUIRE_NO_DEV_NULL))
|
||||
/* As a special case, return /dev/null if we have been called for an empty data block */
|
||||
return RET_NERRNO(open("/dev/null", O_RDONLY|O_CLOEXEC|O_NOCTTY));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum DataFDFlags {
|
||||
ACQUIRE_NO_DEV_NULL = 1 << 0,
|
||||
@@ -11,6 +12,10 @@ typedef enum DataFDFlags {
|
||||
ACQUIRE_NO_REGULAR = 1 << 4,
|
||||
} DataFDFlags;
|
||||
|
||||
int acquire_data_fd(const void *data, size_t size, DataFDFlags flags);
|
||||
int acquire_data_fd_full(const void *data, size_t size, DataFDFlags flags);
|
||||
static inline int acquire_data_fd(const void *data) {
|
||||
return acquire_data_fd_full(data, SIZE_MAX, 0);
|
||||
}
|
||||
|
||||
int copy_data_fd(int fd);
|
||||
int memfd_clone_fd(int fd, const char *name, int mode);
|
||||
|
||||
Reference in New Issue
Block a user