/* Make sure we can distinguish fd 0 and NULL */
#define FD_TO_PTR(fd) INT_TO_PTR((fd)+1)
#define PTR_TO_FD(p) (PTR_TO_INT(p)-1)
+#define PIPE_EBADF { -EBADF, -EBADF }
int close_nointr(int fd);
int safe_close(int fd);
int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF;
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
pid_t child;
int r;
int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
pid_t child;
int r;
static void automount_enter_waiting(Automount *a) {
_cleanup_close_ int ioctl_fd = -EBADF;
- int pipe_fd[2] = { -EBADF, -EBADF };
+ int pipe_fd[2] = PIPE_EBADF;
char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1];
_cleanup_free_ char *options = NULL;
bool mounted = false;
}
static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret) {
- _cleanup_close_pair_ int storage_socket[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int storage_socket[2] = PIPE_EBADF;
DynamicUser *d;
int r;
static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) {
_cleanup_free_ char *uid_map = NULL, *gid_map = NULL;
- _cleanup_close_pair_ int errno_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe[2] = PIPE_EBADF;
_cleanup_close_ int unshare_ready_fd = -EBADF;
_cleanup_(sigkill_waitp) pid_t pid = 0;
uint64_t c = 1;
*n = (ExecRuntime) {
.id = TAKE_PTR(id_copy),
- .netns_storage_socket = { -EBADF, -EBADF },
- .ipcns_storage_socket = { -EBADF, -EBADF },
+ .netns_storage_socket = PIPE_EBADF,
+ .ipcns_storage_socket = PIPE_EBADF,
};
*ret = n;
ExecRuntime **ret) {
_cleanup_(namespace_cleanup_tmpdirp) char *tmp_dir = NULL, *var_tmp_dir = NULL;
- _cleanup_close_pair_ int netns_storage_socket[2] = { -EBADF, -EBADF }, ipcns_storage_socket[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int netns_storage_socket[2] = PIPE_EBADF, ipcns_storage_socket[2] = PIPE_EBADF;
int r;
assert(m);
.notify_fd = -EBADF,
.cgroups_agent_fd = -EBADF,
.signal_fd = -EBADF,
- .user_lookup_fds = { -EBADF, -EBADF },
+ .user_lookup_fds = PIPE_EBADF,
.private_listen_fd = -EBADF,
.dev_autofs_fd = -EBADF,
.cgroup_inotify_fd = -EBADF,
sd_event_source **ret_event_source,
int *ret_exec_fd) {
- _cleanup_close_pair_ int p[] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int p[] = PIPE_EBADF;
int r;
assert(s);
const SocketAddress *address,
const char *label) {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
int fd, r;
pid_t pid;
}
static int socket_accept_in_cgroup(Socket *s, SocketPort *p, int fd) {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
int cfd, r;
pid_t pid;
}
static int run(int argc, char *argv[]) {
- _cleanup_close_pair_ int progress_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int progress_pipe[2] = PIPE_EBADF;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
_cleanup_free_ char *dpath = NULL;
_cleanup_fclose_ FILE *console = NULL;
struct iovec server_iov = IOVEC_MAKE((void*) data, size), client_iov = IOVEC_MAKE((void*) data, size);
/* Important: the declaration order matters here! we want that the fds are closed on return after the
* event sources, hence we declare the fds first, the event sources second */
- _cleanup_close_pair_ int server_pair[2] = { -EBADF, -EBADF }, client_pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int server_pair[2] = PIPE_EBADF, client_pair[2] = PIPE_EBADF;
_cleanup_(sd_event_source_unrefp) sd_event_source *idle_event_source = NULL,
*server_event_source = NULL, *client_event_source = NULL;
_cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL;
#include "tmpfile-util.h"
int import_fork_tar_x(const char *path, pid_t *ret) {
- _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
bool use_selinux;
pid_t pid;
int r;
}
int import_fork_tar_c(const char *path, pid_t *ret) {
- _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
bool use_selinux;
pid_t pid;
int r;
}
static int transfer_start(Transfer *t) {
- _cleanup_close_pair_ int pipefd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
int r;
assert(t);
const void *payload, size_t payload_size,
const void *signature, size_t signature_size) {
- _cleanup_close_pair_ int gpg_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int gpg_pipe[2] = PIPE_EBADF;
char sig_file_path[] = "/tmp/sigXXXXXX", gpg_home[] = "/tmp/gpghomeXXXXXX";
_cleanup_(sigkill_waitp) pid_t pid = 0;
bool gpg_home_created = false;
#include "fuzz-journald.h"
#include "journald-stream.h"
-static int stream_fds[2] = { -EBADF, -EBADF };
+static int stream_fds[2] = PIPE_EBADF;
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Server s;
#include "fd-util.h"
#include "fuzz.h"
-static int test_dhcp_fd[2] = { -EBADF, -EBADF };
+static int test_dhcp_fd[2] = PIPE_EBADF;
int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address, const void *packet, size_t len) {
return len;
#include "fuzz.h"
#include "lldp-network.h"
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
int lldp_network_bind_raw_socket(int ifindex) {
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
#include "sd-ndisc.h"
#include "alloc-util.h"
+#include "fd-util.h"
#include "fuzz.h"
#include "icmp6-util.h"
#include "ndisc-internal.h"
#include "socket-util.h"
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
int icmp6_bind_router_solicitation(int index) {
assert_se(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) >= 0);
static const struct ether_addr mac = {
.ether_addr_octet = { 'A', 'B', 'C', '1', '2', '3' },
};
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
static int test_ifindex = 42;
static unsigned test_client_sent_message_count = 0;
static sd_dhcp6_client *client_ref = NULL;
#define TEST_LLDP_TYPE_SYSTEM_NAME "systemd-lldp"
#define TEST_LLDP_TYPE_SYSTEM_DESC "systemd-lldp-desc"
-static int test_fd[2] = { -EBADF, -EBADF };
+static int test_fd[2] = PIPE_EBADF;
static int lldp_rx_handler_calls;
int lldp_network_bind_raw_socket(int ifindex) {
#include "string-util.h"
int bus_container_connect_socket(sd_bus *b) {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
int r, error_buf = 0;
pid_t child;
MODE_CHART,
} mode = MODE_BISECT;
Type type = TYPE_LEGACY;
- int i, pair[2] = { -EBADF, -EBADF };
+ int i, pair[2] = PIPE_EBADF;
_cleanup_free_ char *address = NULL, *server_name = NULL;
_cleanup_close_ int bus_ref = -1;
const char *unique;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
const char *hello;
int r;
- _cleanup_close_pair_ int pp[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pp[2] = PIPE_EBADF;
char x;
r = sd_bus_open_user(&bus);
}
_public_ int sd_notify_barrier(int unset_environment, uint64_t timeout) {
- _cleanup_close_pair_ int pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pipe_fd[2] = PIPE_EBADF;
int r;
if (pipe2(pipe_fd, O_CLOEXEC) < 0)
sd_event *e = NULL;
sd_event_source *w = NULL, *x = NULL, *y = NULL, *z = NULL, *q = NULL, *t = NULL;
static const char ch = 'x';
- int a[2] = { -EBADF, -EBADF }, b[2] = { -EBADF, -EBADF },
- d[2] = { -EBADF, -EBADF }, k[2] = { -EBADF, -EBADF };
+ int a[2] = PIPE_EBADF, b[2] = PIPE_EBADF,
+ d[2] = PIPE_EBADF, k[2] = PIPE_EBADF;
uint64_t event_now;
int64_t priority;
}
TEST(ratelimit) {
- _cleanup_close_pair_ int p[2] = {-1, -1};
+ _cleanup_close_pair_ int p[2] = PIPE_EBADF;
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
uint64_t interval;
}
TEST(login) {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
_cleanup_free_ char *pp = NULL, *qq = NULL,
*display_session = NULL, *cgroup = NULL,
*display = NULL, *remote_user = NULL, *remote_host = NULL,
void *userdata,
sd_bus_error *error) {
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
Image *image = ASSERT_PTR(userdata);
Manager *m = image->userdata;
pid_t child;
void *userdata,
sd_bus_error *error) {
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
Image *image = ASSERT_PTR(userdata);
Manager *m = ASSERT_PTR(image->userdata);
const char *new_name;
}
case MACHINE_CONTAINER: {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
_cleanup_free_ char *us = NULL, *them = NULL;
_cleanup_close_ int netns_fd = -EBADF;
const char *p;
case MACHINE_CONTAINER: {
_cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF;
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
_cleanup_fclose_ FILE *f = NULL;
pid_t child;
int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *host_basename = NULL, *container_basename = NULL;
const char *src, *dest, *host_path, *container_path;
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
CopyFlags copy_flags = COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS;
_cleanup_close_ int hostfd = -EBADF;
Machine *m = ASSERT_PTR(userdata);
case MACHINE_CONTAINER: {
_cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
pid_t child;
r = namespace_open(m->leader, NULL, &mntns_fd, NULL, NULL, &root_fd);
REMOVE_HIDDEN,
} mode;
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
_cleanup_close_ int result_fd = -EBADF;
Manager *m = userdata;
Operation *operation;
_cleanup_(release_lock_file) LockFile uid_shift_lock = LOCK_FILE_INIT;
_cleanup_close_ int etc_passwd_lock = -1;
_cleanup_close_pair_ int
- fd_inner_socket_pair[2] = { -EBADF, -EBADF },
- fd_outer_socket_pair[2] = { -EBADF, -EBADF };
+ fd_inner_socket_pair[2] = PIPE_EBADF,
+ fd_outer_socket_pair[2] = PIPE_EBADF;
_cleanup_close_ int notify_socket = -1, mntns_fd = -EBADF, fd_kmsg_fifo = -EBADF;
_cleanup_(barrier_destroy) Barrier barrier = BARRIER_NULL;
else {
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
_cleanup_(rmdir_and_freep) char *tmpdir = NULL;
- _cleanup_(close_pairp) int seq[2] = { -EBADF, -EBADF };
+ _cleanup_(close_pairp) int seq[2] = PIPE_EBADF;
_cleanup_(sigkill_waitp) pid_t child = 0;
/* We now have a loopback block device, let's fork off a child in its own mount namespace, mount it
Image *image,
sd_bus_error *error) {
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
_cleanup_(sigkill_waitp) pid_t child = 0;
PortableState state;
int r;
#define DATA_FD_TMP_LIMIT (1024U*1024U)
int acquire_data_fd(const void *data, size_t size, unsigned flags) {
- _cleanup_close_pair_ int pipefds[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pipefds[2] = PIPE_EBADF;
char pattern[] = "/dev/shm/data-fd-XXXXXX";
_cleanup_close_ int fd = -EBADF;
int isz = 0, r;
/* Hmm, pity, this didn't fit. Let's fall back to /tmp then, see below */
} else {
- _cleanup_(close_pairp) int pipefds[2] = { -EBADF, -EBADF };
+ _cleanup_(close_pairp) int pipefds[2] = PIPE_EBADF;
int isz;
/* If memfds aren't available, use a pipe. Set O_NONBLOCK so that we will get EAGAIN rather
};
_cleanup_strv_free_ char **machine_info = NULL, **os_release = NULL, **initrd_release = NULL, **extension_release = NULL;
- _cleanup_close_pair_ int error_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int error_pipe[2] = PIPE_EBADF;
_cleanup_(rmdir_and_freep) char *t = NULL;
_cleanup_(sigkill_waitp) pid_t child = 0;
sd_id128_t machine_id = SD_ID128_NULL;
}
int parse_elf_object(int fd, const char *executable, bool fork_disable_dump, char **ret, JsonVariant **ret_package_metadata) {
- _cleanup_close_pair_ int error_pipe[2] = { -EBADF, -EBADF },
- return_pipe[2] = { -EBADF, -EBADF },
- json_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int error_pipe[2] = PIPE_EBADF,
+ return_pipe[2] = PIPE_EBADF,
+ json_pipe[2] = PIPE_EBADF;
_cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL;
_cleanup_free_ char *buf = NULL;
int r;
}
static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
- _cleanup_close_pair_ int pair[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int pair[2] = PIPE_EBADF;
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, rootfd = -EBADF;
char buf[SD_ID128_UUID_STRING_MAX];
pid_t pid, child;
const MountOptions *options,
bool is_image) {
- _cleanup_close_pair_ int errno_pipe_fd[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int errno_pipe_fd[2] = PIPE_EBADF;
_cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, chased_src_fd = -EBADF;
char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
bool mount_slave_created = false, mount_slave_mounted = false,
}
void pager_open(PagerFlags flags) {
- _cleanup_close_pair_ int fd[2] = { -EBADF, -EBADF }, exe_name_pipe[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int fd[2] = PIPE_EBADF, exe_name_pipe[2] = PIPE_EBADF;
_cleanup_strv_free_ char **pager_args = NULL;
_cleanup_free_ char *l = NULL;
const char *pager, *less_opts;
.context = context,
.server_fd = fd,
.client_fd = -EBADF,
- .server_to_client_buffer = { -EBADF, -EBADF },
- .client_to_server_buffer = { -EBADF, -EBADF },
+ .server_to_client_buffer = PIPE_EBADF,
+ .client_to_server_buffer = PIPE_EBADF,
};
r = set_ensure_put(&context->connections, NULL, c);
size_t *ret_size) {
_cleanup_free_ char *buffer = NULL, *suffixed_url = NULL;
- _cleanup_(close_pairp) int pfd[2] = { -EBADF, -EBADF };
+ _cleanup_(close_pairp) int pfd[2] = PIPE_EBADF;
_cleanup_fclose_ FILE *manifest = NULL;
size_t size = 0;
pid_t pid;
}
TEST(copy_bytes) {
- _cleanup_close_pair_ int pipefd[2] = {-1, -1};
+ _cleanup_close_pair_ int pipefd[2] = PIPE_EBADF;
_cleanup_close_ int infd = -EBADF;
int r, r2;
char buf[1024], buf2[1024];
TEST(copy_data_fd) {
_cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
- _cleanup_(close_pairp) int sfd[2] = { -EBADF, -EBADF };
+ _cleanup_(close_pairp) int sfd[2] = PIPE_EBADF;
_cleanup_(sigkill_waitp) pid_t pid = -1;
int r;
_cleanup_(sd_event_source_unrefp) sd_event_source *sigchld_source = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *stdout_source = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *stderr_source = NULL;
- _cleanup_close_pair_ int outpipe[2] = {-1, -1}, errpipe[2] = {-1, -1};
+ _cleanup_close_pair_ int outpipe[2] = PIPE_EBADF, errpipe[2] = PIPE_EBADF;
_cleanup_strv_free_ char **libraries = NULL;
_cleanup_free_ char *result = NULL;
pid_t pid;
TEST(take_fd) {
_cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
- int array[2] = { -EBADF, -EBADF }, i = 0;
+ int array[2] = PIPE_EBADF, i = 0;
assert_se(fd1 == -EBADF);
assert_se(fd2 == -EBADF);
}
static void test_shareable_ns(unsigned long nsflag) {
- _cleanup_close_pair_ int s[2] = { -EBADF, -EBADF };
+ _cleanup_close_pair_ int s[2] = PIPE_EBADF;
pid_t pid1, pid2, pid3;
int r, n = 0;
siginfo_t si;
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
- _cleanup_(close_pairp) int block_fds[2] = { -EBADF, -EBADF };
+ _cleanup_(close_pairp) int block_fds[2] = PIPE_EBADF;
pthread_t t;
const char *sp;
size_t ressize,
bool *ret_truncated) {
- _cleanup_close_pair_ int outpipe[2] = {-1, -1}, errpipe[2] = {-1, -1};
+ _cleanup_close_pair_ int outpipe[2] = PIPE_EBADF, errpipe[2] = PIPE_EBADF;
_cleanup_strv_free_ char **argv = NULL;
char **envp = NULL;
Spawn spawn;
*manager = (Manager) {
.inotify_fd = -EBADF,
- .worker_watch = { -EBADF, -EBADF },
+ .worker_watch = PIPE_EBADF,
.cgroup = TAKE_PTR(cgroup),
};