expression fd;
@@
- close(fd);
-- fd = -1;
+- fd = -EBADF;
+ fd = safe_close(fd);
@@
expression fd;
@@
- close_nointr(fd);
-- fd = -1;
+- fd = -EBADF;
+ fd = safe_close(fd);
@@
expression fd;
@@
- safe_close(fd);
-- fd = -1;
+- fd = -EBADF;
+ fd = safe_close(fd);
// take the fd to avoid automatic cleanup
int ret_fd = fd;
- fd = -1;
+ fd = -EBADF;
return ret_fd;
}
static int do_accept(const char *name, char **argv, int fd) {
_cleanup_free_ char *local = NULL, *peer = NULL;
- _cleanup_close_ int fd_accepted = -1;
+ _cleanup_close_ int fd_accepted = -EBADF;
fd_accepted = accept4(fd, NULL, NULL, 0);
if (fd_accepted < 0) {
int main(int argc, char **argv) {
int r, n;
- int epoll_fd = -1;
+ int epoll_fd = -EBADF;
log_show_color(true);
log_parse_environment();
_cleanup_(json_variant_unrefp) JsonVariant *package_metadata = NULL;
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *abspath = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
r = path_make_absolute_cwd(*filename, &abspath);
if (r < 0)
int *ret_fd) {
_cleanup_free_ char *buffer = NULL, *done = NULL;
- _cleanup_close_ int fd = -1, root_fd = -1;
+ _cleanup_close_ int fd = -EBADF, root_fd = -EBADF;
unsigned max_follow = CHASE_SYMLINKS_MAX; /* how many symlinks to follow before giving up and returning ELOOP */
bool exists = true, append_trail_slash = false;
struct stat previous_stat;
/* Two dots? Then chop off the last bit of what we already found out. */
if (path_equal(first, "..")) {
_cleanup_free_ char *parent = NULL;
- _cleanup_close_ int fd_parent = -1;
+ _cleanup_close_ int fd_parent = -EBADF;
/* If we already are at the top, then going up will not change anything. This is
* in-line with how the kernel handles this. */
int *ret_fd) {
_cleanup_free_ char *root = NULL, *absolute = NULL, *p = NULL;
- _cleanup_close_ int fd = -1, pfd = -1;
+ _cleanup_close_ int fd = -EBADF, pfd = -EBADF;
int r;
assert(path);
int open_flags,
char **ret_path) {
- _cleanup_close_ int path_fd = -1;
+ _cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r;
char **ret_path,
DIR **ret_dir) {
- _cleanup_close_ int path_fd = -1;
+ _cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL;
DIR *d;
int r;
struct stat *ret_stat,
int *ret_fd) {
- _cleanup_close_ int path_fd = -1;
+ _cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r;
char **ret_path,
int *ret_fd) {
- _cleanup_close_ int path_fd = -1;
+ _cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r;
FILE **ret_file) {
_cleanup_free_ char *final_path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int mode_flags, r;
assert(path);
unsigned *ret_final,
ChattrApplyFlags flags) {
- _cleanup_close_ int fd_will_close = -1;
+ _cleanup_close_ int fd_will_close = -EBADF;
unsigned old_attr, new_attr;
int set_flags_errno = 0;
struct stat st;
}
int read_attr_path(const char *p, unsigned *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(p);
assert(ret);
void **ret_value,
size_t *ret_size) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ void *buf = NULL;
struct stat st;
usec_t begin = 0; /* Unnecessary initialization to appease gcc */
uint32_t attr;
char buf[];
} _packed_ * _cleanup_free_ buf = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint32_t attr = EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS;
bool saved_flags_valid = false;
unsigned saved_flags;
}
int safe_close(int fd) {
-
/*
- * Like close_nointr() but cannot fail. Guarantees errno is
- * unchanged. Is a NOP with negative fds passed, and returns
- * -1, so that it can be used in this syntax:
+ * Like close_nointr() but cannot fail. Guarantees errno is unchanged. Is a noop for negative fds,
+ * and returns -EBADF, so that it can be used in this syntax:
*
* fd = safe_close(fd);
*/
assert_se(close_nointr(fd) != -EBADF);
}
- return -1;
+ return -EBADF;
}
void safe_close_pair(int p[static 2]) {
return close_all_fds_frugal(except, n_except); /* ultimate fallback if /proc/ is not available */
FOREACH_DIRENT(de, d, return -errno) {
- int fd = -1, q;
+ int fd = -EBADF, q;
if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
continue;
};
int r, i,
- null_fd = -1, /* if we open /dev/null, we store the fd to it here */
- copy_fd[3] = { -1, -1, -1 }; /* This contains all fds we duplicate here temporarily, and hence need to close at the end */
+ null_fd = -EBADF, /* If we open /dev/null, we store the fd to it here */
+ copy_fd[3] = { -EBADF, -EBADF, -EBADF }; /* This contains all fds we duplicate here
+ * temporarily, and hence need to close at the end. */
bool null_readable, null_writable;
- /* Sets up stdin, stdout, stderr with the three file descriptors passed in. If any of the descriptors is
- * specified as -1 it will be connected with /dev/null instead. If any of the file descriptors is passed as
- * itself (e.g. stdin as STDIN_FILENO) it is left unmodified, but the O_CLOEXEC bit is turned off should it be
- * on.
+ /* Sets up stdin, stdout, stderr with the three file descriptors passed in. If any of the descriptors
+ * is specified as -EBADF it will be connected with /dev/null instead. If any of the file descriptors
+ * is passed as itself (e.g. stdin as STDIN_FILENO) it is left unmodified, but the O_CLOEXEC bit is
+ * turned off should it be on.
*
- * Note that if any of the passed file descriptors are > 2 they will be closed — both on success and on
- * failure! Thus, callers should assume that when this function returns the input fds are invalidated.
+ * Note that if any of the passed file descriptors are > 2 they will be closed — both on success and
+ * on failure! Thus, callers should assume that when this function returns the input fds are
+ * invalidated.
*
* Note that when this function fails stdin/stdout/stderr might remain half set up!
*
}
}
- /* At this point we now have the fds to use in fd[], and they are all above the stdio range, so that we
- * have freedom to move them around. If the fds already were at the right places then the specific fds are
- * -1. Let's now move them to the right places. This is the point of no return. */
+ /* At this point we now have the fds to use in fd[], and they are all above the stdio range, so that
+ * we have freedom to move them around. If the fds already were at the right places then the specific
+ * fds are -EBADF. Let's now move them to the right places. This is the point of no return. */
for (i = 0; i < 3; i++) {
if (fd[i] == i) {
return -errno;
if ((r & mask) == (flags & mask)) {
- *ret_new_fd = -1;
+ *ret_new_fd = -EBADF;
return fd;
}
({ \
int *_fd_ = &(fd); \
int _ret_ = *_fd_; \
- *_fd_ = -1; \
+ *_fd_ = -EBADF; \
_ret_; \
})
if (r < 0)
return r;
- *fd = -1;
+ *fd = -EBADF;
return 0;
}
if (!f)
return NULL;
- *fd = -1;
+ *fd = -EBADF;
return f;
}
if (!d)
return NULL;
- *dfd = -1;
+ *dfd = -EBADF;
return d;
}
const struct timespec *ts) {
bool needs_nl;
- int r, fd = -1;
+ int r, fd = -EBADF;
assert(f);
assert(line);
char **ret_contents,
size_t *ret_size) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
}
int chmod_and_chown_at(int dir_fd, const char *path, mode_t mode, uid_t uid, gid_t gid) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
}
int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r, ret;
assert(path);
}
int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
- _cleanup_close_ int truncate_fd = -1;
+ _cleanup_close_ int truncate_fd = -EBADF;
struct stat st;
off_t l, bs;
int olddirfd, const char *oldpath,
int newdirfd, const char *newpath) {
- _cleanup_close_ int old_fd = -1, new_fd = -1;
+ _cleanup_close_ int old_fd = -EBADF, new_fd = -EBADF;
struct stat old_stat, new_stat;
/* Renames the old path to thew new path, much like renameat() — except if both are regular files and
}
int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) {
- _cleanup_close_ int fd = -1, parent_fd = -1;
+ _cleanup_close_ int fd = -EBADF, parent_fd = -EBADF;
_cleanup_free_ char *fname = NULL;
bool made;
int r;
const struct locarhead *h;
const struct namehashent *e;
const void *p = MAP_FAILED;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
size_t sz = 0;
struct stat st;
int r;
static int log_facility = LOG_DAEMON;
static int console_fd = STDERR_FILENO;
-static int syslog_fd = -1;
-static int kmsg_fd = -1;
-static int journal_fd = -1;
+static int syslog_fd = -EBADF;
+static int kmsg_fd = -EBADF;
+static int journal_fd = -EBADF;
static bool syslog_is_stream = false;
void log_forget_fds(void) {
/* Do not call from library code. */
- console_fd = kmsg_fd = syslog_fd = journal_fd = -1;
+ console_fd = kmsg_fd = syslog_fd = journal_fd = -EBADF;
}
void log_set_max_level(int level) {
}
int memfd_new_and_map(const char *name, size_t sz, void **p) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(sz > 0);
int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) {
_cleanup_free_ char *pp = NULL, *bn = NULL;
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
int r;
r = path_extract_directory(p, &pp);
}
if (uid_is_valid(uid) || gid_is_valid(gid)) {
- _cleanup_close_ int nfd = -1;
+ _cleanup_close_ int nfd = -EBADF;
nfd = openat(dfd, bn, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
if (nfd < 0)
static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mnt_id) {
char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
_cleanup_free_ char *fdinfo = NULL;
- _cleanup_close_ int subfd = -1;
+ _cleanup_close_ int subfd = -EBADF;
char *p;
int r;
/* flags can be AT_SYMLINK_FOLLOW or 0 */
int path_is_mount_point(const char *t, const char *root, int flags) {
_cleanup_free_ char *canonical = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(t);
unsigned long mountflags,
const void *data) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* In almost all cases we want to manipulate the mount table without following symlinks, hence
* mount_nofollow() is usually the way to go. The only exceptions are environments where /proc/ is
#define pid_namespace_path(pid, type) procfs_file_alloca(pid, namespace_info[type].proc_path)
int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd) {
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, netnsfd = -1, usernsfd = -1;
- int rfd = -1;
+ _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, netnsfd = -EBADF, usernsfd = -EBADF;
+ int rfd = -EBADF;
assert(pid >= 0);
if (r < 0)
return r;
if (r)
- userns_fd = -1;
+ userns_fd = -EBADF;
}
if (pidns_fd >= 0)
int userns_acquire(const char *uid_map, const char *gid_map) {
char path[STRLEN("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1];
_cleanup_(sigkill_waitp) pid_t pid = 0;
- _cleanup_close_ int userns_fd = -1;
+ _cleanup_close_ int userns_fd = -EBADF;
int r;
assert(uid_map);
int fopen_extension_release(const char *root, const char *extension, bool relax_extension_release_check, char **ret_path, FILE **ret_file) {
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
FILE *f;
int r;
}
static int check_x_access(const char *path, int *ret_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
/* We need to use O_PATH because there may be executables for which we have only exec
}
static int find_executable_impl(const char *name, const char *root, char **ret_filename, int *ret_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *path_name = NULL;
int r;
void random_bytes(void *p, size_t n) {
static bool have_getrandom = true, have_grndinsecure = true;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (n == 0)
return;
int crypto_random_bytes(void *p, size_t n) {
static bool have_getrandom = true, seen_initialized = false;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (n == 0)
return 0;
}
if (!seen_initialized) {
- _cleanup_close_ int ready_fd = -1;
+ _cleanup_close_ int ready_fd = -EBADF;
int r;
ready_fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
}
int random_write_entropy(int fd, const void *seed, size_t size, bool credit) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
int r;
assert(seed || size == 0);
return r;
for (size_t i = 0; i < de->n_entries; i++) {
- _cleanup_close_ int inode_fd = -1, subdir_fd = -1;
+ _cleanup_close_ int inode_fd = -EBADF, subdir_fd = -EBADF;
_cleanup_free_ char *joined = NULL;
STRUCT_STATX_DEFINE(sx);
bool sx_valid = false;
recurse_dir_func_t func,
void *userdata) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(atfd >= 0 || atfd == AT_FDCWD);
assert(func);
if (found)
*ret_fd = *(int*) CMSG_DATA(found);
else
- *ret_fd = -1;
+ *ret_fd = -EBADF;
return k;
}
}
int connect_unix_path(int fd, int dir_fd, const char *path) {
- _cleanup_close_ int inode_fd = -1;
+ _cleanup_close_ int inode_fd = -EBADF;
union sockaddr_union sa = {
.un.sun_family = AF_UNIX,
};
}
int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct dirent *buf;
size_t m;
#include "sync-util.h"
int fsync_directory_of_file(int fd) {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
struct stat st;
int r;
}
int fsync_path_at(int at_fd, const char *path) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
int fd;
if (isempty(path)) {
}
int fsync_parent_at(int at_fd, const char *path) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
if (isempty(path)) {
if (at_fd != AT_FDCWD)
}
int fsync_path_and_parent_at(int at_fd, const char *path) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
if (isempty(path)) {
if (at_fd != AT_FDCWD)
}
int syncfs_path(int at_fd, const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (isempty(path)) {
if (at_fd != AT_FDCWD)
static volatile int cached_underline_enabled = -1;
int chvt(int vt) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* Switch to the specified vt number. If the VT is specified <= 0 switch to the VT the kernel log messages go,
* if that's configured. */
}
int reset_terminal(const char *name) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* We open the terminal with O_NONBLOCK here, to ensure we
* don't block on carrier if this is a terminal with carrier
}
int open_terminal(const char *name, int mode) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
unsigned c = 0;
/*
AcquireTerminalFlags flags,
usec_t timeout) {
- _cleanup_close_ int notify = -1, fd = -1;
+ _cleanup_close_ int notify = -EBADF, fd = -EBADF;
usec_t ts = USEC_INFINITY;
int r, wd = -1;
.sa_flags = SA_RESTART,
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct sigaction sa_old;
int r;
}
int terminal_vhangup(const char *name) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return -EINVAL;
if (tty_is_vc(name)) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
unsigned u;
const char *n;
}
int openpt_allocate(int flags, char **ret_slave) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r;
}
int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1, fd = -1;
+ _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF, fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
pid_t child;
int r;
}
int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
+ _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
pid_t child;
int r;
int verify_timezone(const char *name, int log_level) {
bool slash = false;
const char *p, *t;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char buf[4];
int r;
.it_value.tv_sec = TIME_T_MAX,
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
static int fopen_temporary_internal(int dir_fd, const char *path, FILE **ret_file) {
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
}
int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
FILE *f;
fd = mkostemp_safe(pattern);
int fopen_tmpfile_linkable(const char *target, int flags, char **ret_path, FILE **ret_file) {
_cleanup_free_ char *path = NULL;
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(target);
assert(ret_file);
int flags,
char **ret) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
unsigned n_attempts = 7;
bool by_procfs = false;
size_t l = 100;
int flags,
char **ret) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
bool by_procfs = false;
unsigned n_attempts = 7;
size_t l = 100;
left, done);
STRV_FOREACH(p, arg_path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
if (fd < 0) {
}
STRV_FOREACH(p, arg_path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
if (fd < 0)
}
static int copy_file_with_version_check(const char *from, const char *to, bool force) {
- _cleanup_close_ int fd_from = -1, fd_to = -1;
+ _cleanup_close_ int fd_from = -EBADF, fd_to = -EBADF;
_cleanup_free_ char *t = NULL;
int r;
return log_error_errno(r, "Failed to open directory \"%s/EFI/BOOT\": %m", esp_path);
FOREACH_DIRENT(de, d, break) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *v = NULL;
if (!endswith_no_case(de->d_name, ".efi"))
_cleanup_(unlink_and_freep) char *tmp = NULL;
uint8_t buffer[RANDOM_EFI_SEED_SIZE];
_cleanup_free_ char *path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
size_t token_size;
ssize_t n;
int r;
FOREACH_DIRENT(de, d, break) {
_cleanup_free_ char *v = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (!endswith_no_case(de->d_name, ".efi"))
continue;
for (UnifiedSection c = 0; c < _UNIFIED_SECTION_MAX; c++) {
_cleanup_(evp_md_ctx_free_all) EVP_MD_CTX **mdctx = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t m = 0;
if (!arg_sections[c])
.un.sun_path = "/run/systemd/cgroups-agent",
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
ssize_t n;
size_t l;
int r;
assert(u);
assert(u->load_state == UNIT_STUB);
- a->pipe_fd = -1;
+ a->pipe_fd = -EBADF;
a->directory_mode = 0755;
UNIT(a)->ignore_on_isolate = true;
}
init_autofs_dev_ioctl(param);
param->size = l;
- param->ioctlfd = -1;
+ param->ioctlfd = -EBADF;
param->openmount.devid = devid;
strcpy(param->path, where);
}
static int automount_send_ready(Automount *a, Set *tokens, int status) {
- _cleanup_close_ int ioctl_fd = -1;
+ _cleanup_close_ int ioctl_fd = -EBADF;
unsigned token;
int r;
}
static void automount_enter_waiting(Automount *a) {
- _cleanup_close_ int ioctl_fd = -1;
+ _cleanup_close_ int ioctl_fd = -EBADF;
int p[2] = { -1, -1 };
char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1];
_cleanup_free_ char *options = NULL;
if (!data)
return log_oom();
- data->ioctl_fd = -1;
+ data->ioctl_fd = -EBADF;
data->dev_autofs_fd = fcntl(UNIT(a)->manager->dev_autofs_fd, F_DUPFD_CLOEXEC, 3);
if (data->dev_autofs_fd < 0)
int *ret_ipv6_map_fd,
bool *ret_has_any) {
- _cleanup_close_ int ipv4_map_fd = -1, ipv6_map_fd = -1;
+ _cleanup_close_ int ipv4_map_fd = -EBADF, ipv6_map_fd = -EBADF;
size_t n_ipv4 = 0, n_ipv6 = 0;
Unit *p;
int r;
// Ideally it should behave like GCC, so that we can remove these workarounds.
zero(attr);
attr.attach_type = BPF_CGROUP_INET_EGRESS;
- attr.target_fd = -1;
- attr.attach_bpf_fd = -1;
+ attr.target_fd = -EBADF;
+ attr.attach_bpf_fd = -EBADF;
if (bpf(BPF_PROG_DETACH, &attr, sizeof(attr)) < 0) {
if (errno != EBADF) {
zero(attr);
attr.attach_type = BPF_CGROUP_INET_EGRESS;
- attr.target_fd = -1;
- attr.attach_bpf_fd = -1;
+ attr.target_fd = -EBADF;
+ attr.attach_bpf_fd = -EBADF;
attr.attach_flags = BPF_F_ALLOW_MULTI;
if (bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)) < 0) {
static int prepare_restrict_fs_bpf(struct restrict_fs_bpf **ret_obj) {
_cleanup_(restrict_fs_bpf_freep) struct restrict_fs_bpf *obj = NULL;
- _cleanup_close_ int inner_map_fd = -1;
+ _cleanup_close_ int inner_map_fd = -EBADF;
int r;
assert(ret_obj);
_cleanup_(bpf_link_freep) struct bpf_link *ipv4 = NULL, *ipv6 = NULL;
_cleanup_(socket_bind_bpf_freep) struct socket_bind_bpf *obj = NULL;
_cleanup_free_ char *cgroup_path = NULL;
- _cleanup_close_ int cgroup_fd = -1;
+ _cleanup_close_ int cgroup_fd = -EBADF;
CGroupContext *cc;
int r;
}
static int reply_dump_by_fd(sd_bus_message *message, char *dump) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = acquire_data_fd(dump, strlen(dump), 0);
if (fd < 0)
s->unit = u;
s->path = TAKE_PTR(k);
s->type = t;
- s->inotify_fd = -1;
+ s->inotify_fd = -EBADF;
LIST_PREPEND(spec, p->specs, s);
return log_oom();
*p = (SocketPort) {
- .fd = -1,
+ .fd = -EBADF,
.socket = s,
};
static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
_cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
- _cleanup_close_ int nfd = -1;
+ _cleanup_close_ int nfd = -EBADF;
Manager *m = ASSERT_PTR(userdata);
sd_id128_t id;
int r;
return 0;
}
- nfd = -1;
+ nfd = -EBADF;
r = bus_check_peercred(bus);
if (r < 0) {
}
int bus_init_private(Manager *m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t sa_len;
sd_event_source *s;
for (;;) {
char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1];
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
uid_t candidate;
ssize_t l;
if (*fd_lock < 0)
return;
lockf(*fd_lock, F_ULOCK, 0);
- *fd_lock = -1;
+ *fd_lock = -EBADF;
}
static int dynamic_user_realize(
bool is_user) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
- _cleanup_close_ int uid_lock_fd = -1;
- _cleanup_close_ int etc_passwd_lock_fd = -1;
+ _cleanup_close_ int uid_lock_fd = -EBADF;
+ _cleanup_close_ int etc_passwd_lock_fd = -EBADF;
uid_t num = UID_INVALID; /* a uid if is_user, and a gid otherwise */
gid_t gid = GID_INVALID; /* a gid if is_user, ignored otherwise */
bool flush_cache = false;
int dynamic_user_current(DynamicUser *d, uid_t *ret) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
uid_t uid;
int r;
static int dynamic_user_close(DynamicUser *d) {
_cleanup_(unlockfp) int storage_socket0_lock = -1;
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
uid_t uid;
int r;
#include "strv.h"
void lock_down_efi_variables(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
fd = open(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken)), O_RDONLY|O_CLOEXEC);
uid_t uid,
gid_t gid) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(context);
}
static int acquire_path(const char *path, int flags, mode_t mode) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(path);
int *ret_saved_stdin,
int *ret_saved_stdout) {
- _cleanup_close_ int fd = -1, saved_stdin = -1, saved_stdout = -1;
+ _cleanup_close_ int fd = -EBADF, saved_stdin = -EBADF, saved_stdout = -EBADF;
int r;
assert(ret_saved_stdin);
}
static void write_confirm_error(int err, const char *vc, const Unit *u) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(vc);
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] = { -1, -1 };
- _cleanup_close_ int unshare_ready_fd = -1;
+ _cleanup_close_ int unshare_ready_fd = -EBADF;
_cleanup_(sigkill_waitp) pid_t pid = 0;
uint64_t c = 1;
ssize_t n;
if (r < 0)
return r;
if (r == 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *a;
pid_t ppid;
bool ownership_ok) {
_cleanup_(unlink_and_freep) char *tmp = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
r = tempfn_random_child("", "cred", &tmp);
bool ownership_ok) {
uint64_t left = CREDENTIALS_TOTAL_SIZE_MAX;
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
ExecLoadCredential *lc;
ExecSetCredential *sc;
int r;
/* First, load credentials off disk (or acquire via AF_UNIX socket) */
HASHMAP_FOREACH(lc, context->load_credentials) {
- _cleanup_close_ int sub_fd = -1;
+ _cleanup_close_ int sub_fd = -EBADF;
/* If this is an absolute path, then try to open it as a directory. If that works, then we'll
* recurse into it. If it is an absolute path but it isn't a directory, then we'll open it as
assert(ret_fd);
if (fd < 0) {
- *ret_fd = -1;
+ *ret_fd = -EBADF;
return 0;
}
* shall execute. */
_cleanup_free_ char *executable = NULL;
- _cleanup_close_ int executable_fd = -1;
+ _cleanup_close_ int executable_fd = -EBADF;
r = find_executable_full(command->path, /* root= */ NULL, context->exec_search_path, false, &executable, &executable_fd);
if (r < 0) {
if (r != -ENOMEM && (command->flags & EXEC_COMMAND_IGNORE_FAILURE)) {
#if HAVE_SELINUX
if (needs_sandboxing && use_selinux && params->selinux_context_net) {
- int fd = -1;
+ int fd = -EBADF;
if (socket_fd >= 0)
fd = socket_fd;
socket_fd = params->fds[0];
} else {
- socket_fd = -1;
+ socket_fd = -EBADF;
fds = params->fds;
n_socket_fds = params->n_socket_fds;
n_storage_fds = params->n_storage_fds;
}
void exec_context_revert_tty(ExecContext *c) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *path;
struct stat st;
int r;
int ima_setup(void) {
#if ENABLE_IMA
_cleanup_fclose_ FILE *input = NULL;
- _cleanup_close_ int imafd = -1;
+ _cleanup_close_ int imafd = -EBADF;
unsigned lineno = 0;
int r;
static int import_credentials_boot(void) {
_cleanup_(import_credentials_context_free) ImportCredentialContext context = {
- .target_dir_fd = -1,
+ .target_dir_fd = -EBADF,
};
int r;
"/.extra/global_credentials/") { /* boot partition wide */
_cleanup_free_ DirectoryEntries *de = NULL;
- _cleanup_close_ int source_dir_fd = -1;
+ _cleanup_close_ int source_dir_fd = -EBADF;
source_dir_fd = open(p, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (source_dir_fd < 0) {
for (size_t i = 0; i < de->n_entries; i++) {
const struct dirent *d = de->entries[i];
- _cleanup_close_ int cfd = -1, nfd = -1;
+ _cleanup_close_ int cfd = -EBADF, nfd = -EBADF;
_cleanup_free_ char *n = NULL;
const char *e;
struct stat st;
static int proc_cmdline_callback(const char *key, const char *value, void *data) {
ImportCredentialContext *c = ASSERT_PTR(data);
_cleanup_free_ char *n = NULL;
- _cleanup_close_ int nfd = -1;
+ _cleanup_close_ int nfd = -EBADF;
const char *colon;
size_t l;
int r;
static int import_credentials_qemu(ImportCredentialContext *c) {
_cleanup_free_ DirectoryEntries *de = NULL;
- _cleanup_close_ int source_dir_fd = -1;
+ _cleanup_close_ int source_dir_fd = -EBADF;
int r;
assert(c);
for (size_t i = 0; i < de->n_entries; i++) {
const struct dirent *d = de->entries[i];
- _cleanup_close_ int vfd = -1, rfd = -1, nfd = -1;
+ _cleanup_close_ int vfd = -EBADF, rfd = -EBADF, nfd = -EBADF;
_cleanup_free_ char *szs = NULL;
uint64_t sz;
for (p = data, left = size; left > 0; p += skip, left -= skip) {
_cleanup_free_ void *buf = NULL;
_cleanup_free_ char *cn = NULL;
- _cleanup_close_ int nfd = -1;
+ _cleanup_close_ int nfd = -EBADF;
const char *nul, *n, *eq;
const void *cdata;
size_t buflen, cdata_len;
static int import_credentials_trusted(void) {
_cleanup_(import_credentials_context_free) ImportCredentialContext c = {
- .target_dir_fd = -1,
+ .target_dir_fd = -EBADF,
};
int q, w, r;
p->type = SOCKET_SOCKET;
}
- p->fd = -1;
+ p->fd = -EBADF;
p->auxiliary_fds = NULL;
p->n_auxiliary_fds = 0;
p->socket = s;
s->unit = UNIT(p);
s->path = TAKE_PTR(k);
s->type = b;
- s->inotify_fd = -1;
+ s->inotify_fd = -EBADF;
LIST_PREPEND(spec, p->specs, s);
}
static int console_setup(void) {
- _cleanup_close_ int tty_fd = -1;
+ _cleanup_close_ int tty_fd = -EBADF;
int r;
tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
#include "varlink-internal.h"
int manager_open_serialization(Manager *m, FILE **ret_f) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
FILE *f;
assert(ret_f);
}
static int enable_special_signals(Manager *m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(m);
.show_status_overridden = _SHOW_STATUS_INVALID,
- .notify_fd = -1,
- .cgroups_agent_fd = -1,
- .signal_fd = -1,
- .user_lookup_fds = { -1, -1 },
- .private_listen_fd = -1,
- .dev_autofs_fd = -1,
- .cgroup_inotify_fd = -1,
- .pin_cgroupfs_fd = -1,
- .ask_password_inotify_fd = -1,
- .idle_pipe = { -1, -1, -1, -1},
+ .notify_fd = -EBADF,
+ .cgroups_agent_fd = -EBADF,
+ .signal_fd = -EBADF,
+ .user_lookup_fds = { -EBADF, -EBADF },
+ .private_listen_fd = -EBADF,
+ .dev_autofs_fd = -EBADF,
+ .cgroup_inotify_fd = -EBADF,
+ .pin_cgroupfs_fd = -EBADF,
+ .ask_password_inotify_fd = -EBADF,
+ .idle_pipe = { -EBADF, -EBADF, -EBADF, -EBADF},
/* start as id #1, so that we can leave #0 around as "null-like" value */
.current_job_id = 1,
return 0;
if (m->notify_fd < 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t sa_len;
return 0;
if (m->cgroups_agent_fd < 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* First free all secondary fields */
m->cgroups_agent_event_source = sd_event_source_disable_unref(m->cgroups_agent_event_source);
void manager_send_unit_plymouth(Manager *m, Unit *u) {
static const union sockaddr_union sa = PLYMOUTH_SOCKET;
_cleanup_free_ char *message = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int n = 0;
/* Don't generate plymouth events if the service was already
_cleanup_(exec_params_clear) ExecParameters exec_params = {
.flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
- .stdin_fd = -1,
- .stdout_fd = -1,
- .stderr_fd = -1,
- .exec_fd = -1,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .stderr_fd = -EBADF,
+ .exec_fd = -EBADF,
};
pid_t pid;
int r;
}
static bool mount_option_supported(const char *fstype, const char *key, const char *value) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
/* This function assumes support by default. Only if the fsconfig() call fails with -EINVAL/-EOPNOTSUPP
static int make_tmp_prefix(const char *prefix) {
_cleanup_free_ char *t = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
/* Don't do anything unless we know the dir is actually missing */
void path_spec_done(PathSpec *s) {
assert(s);
- assert(s->inotify_fd == -1);
+ assert(s->inotify_fd == -EBADF);
free(s->path);
}
_cleanup_(bpf_link_freep) struct bpf_link *egress_link = NULL, *ingress_link = NULL;
_cleanup_(restrict_ifaces_bpf_freep) struct restrict_ifaces_bpf *obj = NULL;
_cleanup_free_ char *cgroup_path = NULL;
- _cleanup_close_ int cgroup_fd = -1;
+ _cleanup_close_ int cgroup_fd = -EBADF;
CGroupContext *cc;
int r;
s->restart_usec = u->manager->default_restart_usec;
s->runtime_max_usec = USEC_INFINITY;
s->type = _SERVICE_TYPE_INVALID;
- s->socket_fd = -1;
- s->stdin_fd = s->stdout_fd = s->stderr_fd = -1;
+ s->socket_fd = -EBADF;
+ s->stdin_fd = s->stdout_fd = s->stderr_fd = -EBADF;
s->guess_main_pid = true;
s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
assert(s);
while (fdset_size(fds) > 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = fdset_steal_first(fds);
if (fd < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to add fd to store: %m");
if (r > 0)
log_unit_debug(UNIT(s), "Added fd %i (%s) to fd store.", fd, strna(name));
- fd = -1;
+ fd = -EBADF;
}
return 0;
static int service_load_pid_file(Service *s, bool may_warn) {
bool questionable_pid_file = false;
_cleanup_free_ char *k = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r, prio;
pid_t pid;
_cleanup_(exec_params_clear) ExecParameters exec_params = {
.flags = flags,
- .stdin_fd = -1,
- .stdout_fd = -1,
- .stderr_fd = -1,
- .exec_fd = -1,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .stderr_fd = -EBADF,
+ .exec_fd = -EBADF,
};
_cleanup_(sd_event_source_unrefp) sd_event_source *exec_fd_source = NULL;
_cleanup_strv_free_ char **final_env = NULL, **our_env = NULL;
/* PATH_CHANGED would not be enough. There are daemons (sendmail) that
* keep their PID file open all the time. */
ps->type = PATH_MODIFIED;
- ps->inotify_fd = -1;
+ ps->inotify_fd = -EBADF;
s->pid_file_pathspec = ps;
int status_vprintf(const char *status, ShowStatusFlags flags, const char *format, va_list ap) {
static const char status_indent[] = " "; /* "[" STATUS "] " */
_cleanup_free_ char *s = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct iovec iovec[7] = {};
int n = 0;
static bool prev_ephemeral;
}
static int write_access2_rules(const char *srcdir) {
- _cleanup_close_ int load2_fd = -1, change_fd = -1;
+ _cleanup_close_ int load2_fd = -EBADF, change_fd = -EBADF;
_cleanup_closedir_ DIR *dir = NULL;
- int dfd = -1, r = 0;
+ int dfd = -EBADF, r = 0;
load2_fd = open("/sys/fs/smackfs/load2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (load2_fd < 0) {
}
static int write_cipso2_rules(const char *srcdir) {
- _cleanup_close_ int cipso2_fd = -1;
+ _cleanup_close_ int cipso2_fd = -EBADF;
_cleanup_closedir_ DIR *dir = NULL;
- int dfd = -1, r = 0;
+ int dfd = -EBADF, r = 0;
cipso2_fd = open("/sys/fs/smackfs/cipso2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (cipso2_fd < 0) {
static int write_netlabel_rules(const char *srcdir) {
_cleanup_fclose_ FILE *dst = NULL;
_cleanup_closedir_ DIR *dir = NULL;
- int dfd = -1, r = 0;
+ int dfd = -EBADF, r = 0;
dst = fopen("/sys/fs/smackfs/netlabel", "we");
if (!dst) {
}
static int write_onlycap_list(void) {
- _cleanup_close_ int onlycap_fd = -1;
+ _cleanup_close_ int onlycap_fd = -EBADF;
_cleanup_free_ char *list = NULL;
_cleanup_fclose_ FILE *f = NULL;
size_t len = 0;
mode_t directory_mode,
mode_t socket_mode) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
mode_t old_mask;
struct stat st;
int r;
}
static int special_address_create(const char *path, bool writable) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
assert(path);
}
static int usbffs_address_create(const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
assert(path);
long maxmsg,
long msgsize) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
mode_t old_mask;
struct mq_attr _attr, *attr = NULL;
_cleanup_(exec_params_clear) ExecParameters exec_params = {
.flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
- .stdin_fd = -1,
- .stdout_fd = -1,
- .stderr_fd = -1,
- .exec_fd = -1,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .stderr_fd = -EBADF,
+ .exec_fd = -EBADF,
};
pid_t pid;
int r;
static int socket_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
SocketPort *p = ASSERT_PTR(userdata);
- int cfd = -1;
+ int cfd = -EBADF;
assert(fd >= 0);
_cleanup_(exec_params_clear) ExecParameters exec_params = {
.flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN,
- .stdin_fd = -1,
- .stdout_fd = -1,
- .stderr_fd = -1,
- .exec_fd = -1,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .stderr_fd = -EBADF,
+ .exec_fd = -EBADF,
};
pid_t pid;
int r;
u->cgroup_invalidated_mask |= CGROUP_MASK_BPF_FIREWALL;
u->failure_action_exit_status = u->success_action_exit_status = -1;
- u->ip_accounting_ingress_map_fd = -1;
- u->ip_accounting_egress_map_fd = -1;
+ u->ip_accounting_ingress_map_fd = -EBADF;
+ u->ip_accounting_egress_map_fd = -EBADF;
for (CGroupIOAccountingMetric i = 0; i < _CGROUP_IO_ACCOUNTING_METRIC_MAX; i++)
u->io_accounting_last[i] = UINT64_MAX;
- u->ipv4_allow_map_fd = -1;
- u->ipv6_allow_map_fd = -1;
- u->ipv4_deny_map_fd = -1;
- u->ipv6_deny_map_fd = -1;
+ u->ipv4_allow_map_fd = -EBADF;
+ u->ipv6_allow_map_fd = -EBADF;
+ u->ipv4_deny_map_fd = -EBADF;
+ u->ipv6_deny_map_fd = -EBADF;
u->last_section_private = -1;
}
static int unit_export_log_extra_fields(Unit *u, const ExecContext *c) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct iovec *iovec;
const char *p;
char *pattern;
_cleanup_(unlink_and_freep) char *tmp = NULL;
_cleanup_free_ char *fn = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t rlimit, process_limit, max_size;
bool truncated, storage_on_tmpfs;
struct stat st;
if (arg_compress) {
_cleanup_(unlink_and_freep) char *tmp_compressed = NULL;
_cleanup_free_ char *fn_compressed = NULL;
- _cleanup_close_ int fd_compressed = -1;
+ _cleanup_close_ int fd_compressed = -EBADF;
uint64_t uncompressed_size = 0;
if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
*/
static int compose_open_fds(pid_t pid, char **open_fds) {
_cleanup_closedir_ DIR *proc_fd_dir = NULL;
- _cleanup_close_ int proc_fdinfo_fd = -1;
+ _cleanup_close_ int proc_fdinfo_fd = -EBADF;
_cleanup_free_ char *buffer = NULL;
_cleanup_fclose_ FILE *stream = NULL;
const char *fddelim = "", *path;
FOREACH_DIRENT(de, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
r = readlinkat_malloc(dirfd(proc_fd_dir), de->d_name, &fdname);
if (r < 0)
static int get_process_ns(pid_t pid, const char *namespace, ino_t *ns) {
const char *p;
struct stat stbuf;
- _cleanup_close_ int proc_ns_dir_fd = -1;
+ _cleanup_close_ int proc_ns_dir_fd = -EBADF;
p = procfs_file_alloca(pid, "ns");
int input_fd) {
_cleanup_(json_variant_unrefp) JsonVariant *json_metadata = NULL;
- _cleanup_close_ int coredump_fd = -1, coredump_node_fd = -1;
+ _cleanup_close_ int coredump_fd = -EBADF, coredump_node_fd = -EBADF;
_cleanup_free_ char *filename = NULL, *coredump_data = NULL;
_cleanup_free_ char *stacktrace = NULL;
char *core_message;
}
static int process_socket(int fd) {
- _cleanup_close_ int input_fd = -1;
+ _cleanup_close_ int input_fd = -EBADF;
Context context = {};
struct iovec_wrapper iovw = {};
struct iovec iovec;
}
static int send_iovec(const struct iovec_wrapper *iovw, int input_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(iovw);
const char **ret_color,
uint64_t *ret_size) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
_cleanup_free_ char *filename = NULL;
size_t len;
int r, fd;
- _cleanup_close_ int fdt = -1;
+ _cleanup_close_ int fdt = -EBADF;
char *temp = NULL;
assert(!(file && path)); /* At most one can be specified */
if (filename) {
#if HAVE_COMPRESSION
- _cleanup_close_ int fdf = -1;
+ _cleanup_close_ int fdf = -EBADF;
fdf = open(filename, O_RDONLY | O_CLOEXEC);
if (fdf < 0) {
for (;;) {
_cleanup_free_ char *j = NULL;
const char *secure, *secure_color = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct dirent *de;
struct stat st;
}
static int get_file_sha256(int inode_fd, uint8_t ret[static SHA256_DIGEST_SIZE]) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct sha256_ctx ctx;
/* convert O_PATH fd into a regular one */
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
if (arg_action == ACTION_COPY_FROM) {
- _cleanup_close_ int source_fd = -1, target_fd = -1;
+ _cleanup_close_ int source_fd = -EBADF, target_fd = -EBADF;
source_fd = chase_symlinks_and_open(arg_source, mounted_dir, CHASE_PREFIX_ROOT|CHASE_WARN, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (source_fd < 0)
/* When this is a regular file we don't copy ownership! */
} else if (arg_action == ACTION_COPY_TO) {
- _cleanup_close_ int source_fd = -1, target_fd = -1, dfd = -1;
+ _cleanup_close_ int source_fd = -EBADF, target_fd = -EBADF, dfd = -EBADF;
_cleanup_free_ char *dn = NULL, *bn = NULL;
r = path_extract_directory(arg_target, &dn);
/* When this is a regular file we don't copy ownership! */
} else {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
dfd = open(mounted_dir, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
if (dfd < 0)
}
static int action_umount(const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *canonical = NULL;
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
r = block_device_new_from_fd(fd, BLOCK_DEVICE_LOOKUP_WHOLE_DISK | BLOCK_DEVICE_LOOKUP_BACKING, &dev);
if (r < 0) {
- _cleanup_close_ int usr_fd = -1;
+ _cleanup_close_ int usr_fd = -EBADF;
/* The command `systemd-dissect --mount` expects that the image at least has the root or /usr
* partition. If it does not have the root partition, then we mount the /usr partition on a
}
static int fsck_progress_socket(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
(void) boot_config_select_special_entries(&config, /* skip_efivars= */ false);
- _cleanup_close_ int orig_stdout_fd = -1;
+ _cleanup_close_ int orig_stdout_fd = -EBADF;
if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0) {
orig_stdout_fd = fcntl(fileno(stdout), F_DUPFD_CLOEXEC, 3);
if (orig_stdout_fd < 0)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-catalog.XXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
if (!getenv("SYSTEMD_LOG_LEVEL"))
}
static int verify_tty(const char *name) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *p;
/* Some TTYs are weird and have been enumerated but don't work
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(user_record_unrefp) UserRecord *secret = NULL;
- _cleanup_close_ int acquired_fd = -1;
+ _cleanup_close_ int acquired_fd = -EBADF;
_cleanup_strv_free_ char **cmdline = NULL;
const char *home;
int r, ret;
_cleanup_(user_record_unrefp) UserRecord *secret = NULL;
_cleanup_(operation_unrefp) Operation *o = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r, please_suspend;
Home *h = ASSERT_PTR(userdata);
void *userdata,
sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
Home *h = ASSERT_PTR(userdata);
HomeState state;
int please_suspend, r;
.user_name = TAKE_PTR(nm),
.uid = hr->uid,
.state = _HOME_STATE_INVALID,
- .worker_stdout_fd = -1,
+ .worker_stdout_fd = -EBADF,
.sysfs = TAKE_PTR(ns),
.signed_locally = -1,
- .pin_fd = -1,
- .luks_lock_fd = -1,
+ .pin_fd = -EBADF,
+ .luks_lock_fd = -EBADF,
};
r = hashmap_put(m->homes_by_name, home->user_name, home);
static int home_start_work(Home *h, const char *verb, UserRecord *hr, UserRecord *secret) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
_cleanup_(erase_and_freep) char *formatted = NULL;
- _cleanup_close_ int stdin_fd = -1, stdout_fd = -1;
+ _cleanup_close_ int stdin_fd = -EBADF, stdout_fd = -EBADF;
pid_t pid = 0;
int r;
if (IN_SET(t, USER_TEST_MAYBE, USER_TEST_UNDEFINED))
break; /* And if the image path test isn't conclusive, let's also go on */
- if (IN_SET(t, -EBADFD, -ENOTDIR))
+ if (IN_SET(t, -EBADF, -ENOTDIR))
return sd_bus_error_setf(error, BUS_ERROR_HOME_EXISTS, "Selected home image of user %s already exists or has wrong inode type.", h->user_name);
return sd_bus_error_setf(error, BUS_ERROR_HOME_EXISTS, "Selected home image of user %s already exists.", h->user_name);
}
int home_create_fifo(Home *h, bool please_suspend) {
- _cleanup_close_ int ret_fd = -1;
+ _cleanup_close_ int ret_fd = -EBADF;
sd_event_source **ss;
const char *fn, *suffix;
int r;
fn = strjoina("/run/systemd/home/", h->user_name, suffix);
if (!*ss) {
- _cleanup_close_ int ref_fd = -1;
+ _cleanup_close_ int ref_fd = -EBADF;
(void) mkdir("/run/systemd/home/", 0755);
if (mkfifo(fn, 0600) < 0 && errno != EEXIST)
if (S_ISDIR(st.st_mode)) {
_cleanup_free_ char *n = NULL, *user_name = NULL, *realm = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
UserStorage storage;
if (!directory_suffix)
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int))) control;
_cleanup_free_ void *buffer = NULL;
- _cleanup_close_ int passed_fd = -1;
+ _cleanup_close_ int passed_fd = -EBADF;
struct ucred *sender = NULL;
struct cmsghdr *cmsg;
struct msghdr mh;
static int on_notify_socket(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
_cleanup_strv_free_ char **l = NULL;
_cleanup_free_ void *datagram = NULL;
- _cleanup_close_ int passed_fd = -1;
+ _cleanup_close_ int passed_fd = -EBADF;
struct ucred sender = UCRED_INVALID;
Manager *m = ASSERT_PTR(userdata);
ssize_t n;
}
static int manager_listen_notify(Manager *m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa = {
.un.sun_family = AF_UNIX,
.un.sun_path = "/run/systemd/home/notify",
.type = type,
.n_ref = 1,
.message = sd_bus_message_ref(m),
- .send_fd = -1,
+ .send_fd = -EBADF,
.result = -1,
};
int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
_cleanup_(rm_rf_subvolume_and_freep) char *temporary = NULL;
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
- _cleanup_close_ int mount_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF;
_cleanup_free_ char *d = NULL;
bool is_subvolume = false;
const char *ip;
_cleanup_(rm_rf_physical_and_freep) char *temporary = NULL;
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
_cleanup_(erase_and_freep) void *volume_key = NULL;
- _cleanup_close_ int mount_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF;
struct fscrypt_policy policy = {};
size_t volume_key_size = 512 / 8;
_cleanup_free_ char *d = NULL;
}
int run_mark_dirty_by_path(const char *path, bool b) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
}
static int probe_file_system_by_path(const char *path, char **ret_fstype, sd_id128_t *ret_uuid) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (fd < 0)
}
static int block_get_size_by_path(const char *path, uint64_t *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (fd < 0)
}
int run_fallocate_by_path(const char *backing_path) {
- _cleanup_close_ int backing_fd = -1;
+ _cleanup_close_ int backing_fd = -EBADF;
backing_fd = open(backing_path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (backing_fd < 0)
const char *force_image_path,
struct stat *ret_stat) {
- _cleanup_close_ int image_fd = -1;
+ _cleanup_close_ int image_fd = -EBADF;
struct stat st;
const char *ip;
int r;
}
static int wait_for_devlink(const char *path) {
- _cleanup_close_ int inotify_fd = -1;
+ _cleanup_close_ int inotify_fd = -EBADF;
usec_t until;
int r;
host_size = 0, partition_offset = 0, partition_size = 0; /* Unnecessary initialization to appease gcc */
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
sd_id128_t partition_uuid, fs_uuid, luks_uuid, disk_uuid;
- _cleanup_close_ int mount_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF;
const char *fstype, *ip;
struct statfs sfs;
int r;
_cleanup_(user_record_unrefp) UserRecord *header_home = NULL, *embedded_home = NULL, *new_home = NULL;
_cleanup_(fdisk_unref_tablep) struct fdisk_table *table = NULL;
struct fdisk_partition *partition = NULL;
- _cleanup_close_ int opened_image_fd = -1;
+ _cleanup_close_ int opened_image_fd = -EBADF;
_cleanup_free_ char *whole_disk = NULL;
- int r, resize_type, image_fd = -1;
+ int r, resize_type, image_fd = -EBADF;
sd_id128_t disk_uuid;
const char *ip, *ipo;
struct statfs sfs;
static int make_userns(uid_t stored_uid, uid_t exposed_uid) {
_cleanup_free_ char *text = NULL;
- _cleanup_close_ int userns_fd = -1;
+ _cleanup_close_ int userns_fd = -EBADF;
int r;
assert(uid_is_valid(stored_uid));
}
int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t exposed_uid, int *ret_mount_fd) {
- _cleanup_close_ int mount_fd = -1, userns_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF, userns_fd = -EBADF;
int r;
assert(dir_fd >= 0);
log_debug_errno(errno, "The open_tree() syscall is not supported, not setting up UID shift mount: %m");
if (ret_mount_fd)
- *ret_mount_fd = -1;
+ *ret_mount_fd = -EBADF;
return 0;
}
log_debug_errno(errno, "UID/GID mapping for shifted mount not available, not setting it up: %m");
if (ret_mount_fd)
- *ret_mount_fd = -1;
+ *ret_mount_fd = -EBADF;
return 0;
}
static int read_identity_file(int root_fd, JsonVariant **ret) {
_cleanup_(fclosep) FILE *identity_file = NULL;
- _cleanup_close_ int identity_fd = -1;
+ _cleanup_close_ int identity_fd = -EBADF;
unsigned line, column;
int r;
static int write_identity_file(int root_fd, JsonVariant *v, uid_t uid) {
_cleanup_(json_variant_unrefp) JsonVariant *normalized = NULL;
_cleanup_(fclosep) FILE *identity_file = NULL;
- _cleanup_close_ int identity_fd = -1;
+ _cleanup_close_ int identity_fd = -EBADF;
_cleanup_free_ char *fn = NULL;
int r;
HomeSetupFlags flags,
HomeSetup *setup) {
- _cleanup_close_ int mount_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF;
struct stat st;
assert(h);
#define HOME_SETUP_INIT \
{ \
- .root_fd = -1, \
- .image_fd = -1, \
+ .root_fd = -EBADF, \
+ .image_fd = -EBADF, \
.partition_offset = UINT64_MAX, \
.partition_size = UINT64_MAX, \
.key_serial = -1, \
_cleanup_(user_record_unrefp) UserRecord *ur = NULL, *secret = NULL;
bool do_auth = please_authenticate, home_not_active = false, home_locked = false;
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
- _cleanup_close_ int acquired_fd = -1;
+ _cleanup_close_ int acquired_fd = -EBADF;
_cleanup_free_ char *fd_field = NULL;
const void *home_fd_ptr = NULL;
const char *username = NULL;
return -ENOMEM;
*e = (RawExport) {
- .output_fd = -1,
- .input_fd = -1,
+ .output_fd = -EBADF,
+ .input_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
}
int raw_export_start(RawExport *e, const char *path, int fd, ImportCompressType compress) {
- _cleanup_close_ int sfd = -1, tfd = -1;
+ _cleanup_close_ int sfd = -EBADF, tfd = -EBADF;
int r;
assert(e);
return -ENOMEM;
*e = (TarExport) {
- .output_fd = -1,
- .tar_fd = -1,
+ .output_fd = -EBADF,
+ .tar_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.quota_referenced = UINT64_MAX,
}
int tar_export_start(TarExport *e, const char *path, int fd, ImportCompressType compress) {
- _cleanup_close_ int sfd = -1;
+ _cleanup_close_ int sfd = -EBADF;
int r;
assert(e);
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(image_unrefp) Image *image = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (hostname_is_valid(argv[1], 0)) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(image_unrefp) Image *image = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (hostname_is_valid(argv[1], 0)) {
_cleanup_(progress_info_free) ProgressInfo progress = {};
_cleanup_free_ char *l = NULL, *final_path = NULL;
const char *path = NULL, *local = NULL, *dest = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
return -ENOMEM;
*i = (RawImport) {
- .input_fd = -1,
- .output_fd = -1,
+ .input_fd = -EBADF,
+ .output_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
}
static int raw_import_maybe_convert_qcow2(RawImport *i) {
- _cleanup_close_ int converted_fd = -1;
+ _cleanup_close_ int converted_fd = -EBADF;
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_free_ char *f = NULL;
int r;
return -ENOMEM;
*i = (TarImport) {
- .input_fd = -1,
- .tar_fd = -1,
+ .input_fd = -EBADF,
+ .tar_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
}
static int open_source(const char *path, const char *local, int *ret_open_fd) {
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int retval;
assert(local);
_cleanup_free_ char *ll = NULL, *normalized = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
_cleanup_free_ char *ll = NULL, *normalized = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
*t = (Transfer) {
.type = _TRANSFER_TYPE_INVALID,
- .log_fd = -1,
- .stdin_fd = -1,
- .stdout_fd = -1,
+ .log_fd = -EBADF,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
.verify = _IMPORT_VERIFY_INVALID,
.progress_percent= UINT_MAX,
};
if (j->close_disk_fd)
safe_close(j->disk_fd);
- j->disk_fd = -1;
+ j->disk_fd = -EBADF;
}
PullJob* pull_job_unref(PullJob *j) {
*j = (PullJob) {
.state = PULL_JOB_INIT,
- .disk_fd = -1,
+ .disk_fd = -EBADF,
.close_disk_fd = true,
.userdata = userdata,
.glue = glue,
static int raw_pull_maybe_convert_qcow2(RawPull *i) {
_cleanup_(unlink_and_freep) char *t = NULL;
- _cleanup_close_ int converted_fd = -1;
+ _cleanup_close_ int converted_fd = -EBADF;
_cleanup_free_ char *f = NULL;
int r;
static int raw_pull_make_local_copy(RawPull *i) {
_cleanup_(unlink_and_freep) char *tp = NULL;
_cleanup_free_ char *f = NULL;
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
const char *p;
int r;
#include "qcow2-util.h"
int main(int argc, char *argv[]) {
- _cleanup_close_ int sfd = -1, dfd = -1;
+ _cleanup_close_ int sfd = -EBADF, dfd = -EBADF;
int r;
if (argc != 3) {
int fdin;
void *mem;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journal-remote.XXXXXX.journal";
- _cleanup_close_ int fdout = -1;
+ _cleanup_close_ int fdout = -EBADF;
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
_cleanup_(journal_remote_server_destroy) RemoteServer s = {};
int r;
if (m->tmp)
rewind(m->tmp);
else {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open_tmpfile_unlinkable("/tmp", O_RDWR|O_CLOEXEC);
if (fd < 0)
const char *mime_type) {
_cleanup_(MHD_destroy_responsep) struct MHD_Response *response = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
assert(connection);
if (r < 0)
return r;
- fd_ = -1;
+ fd_ = -EBADF;
s->active++;
return 0;
}
SocketAddress *addr,
char **hostname) {
- _cleanup_close_ int fd2 = -1;
+ _cleanup_close_ int fd2 = -EBADF;
int r;
log_debug("Accepting new %s connection on fd:%d", type, fd);
}
static int run(int argc, char *argv[]) {
- _cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
+ _cleanup_close_ int outfd = -EBADF, errfd = -EBADF, saved_stderr = -EBADF;
int r;
log_setup();
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Server s;
- _cleanup_close_ int sealed_fd = -1, unsealed_fd = -1;
+ _cleanup_close_ int sealed_fd = -EBADF, unsealed_fd = -EBADF;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-journald-native-fd.XXXXXX";
char *label = NULL;
size_t label_len = 0;
void dummy_server_init(Server *s, const uint8_t *buffer, size_t size) {
*s = (Server) {
- .syslog_fd = -1,
- .native_fd = -1,
- .stdout_fd = -1,
- .dev_kmsg_fd = -1,
- .audit_fd = -1,
- .hostname_fd = -1,
- .notify_fd = -1,
+ .syslog_fd = -EBADF,
+ .native_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .dev_kmsg_fd = -EBADF,
+ .audit_fd = -EBADF,
+ .hostname_fd = -EBADF,
+ .notify_fd = -EBADF,
.storage = STORAGE_NONE,
.line_max = 64,
};
_cleanup_(unlink_and_freep) char *k = NULL;
_cleanup_free_ char *p = NULL;
uint8_t *mpk, *seed, *state;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_id128_t machine, boot;
struct stat st;
uint64_t n;
_cleanup_(sd_journal_closep) sd_journal *j = NULL;
sd_id128_t previous_boot_id = SD_ID128_NULL, previous_boot_id_output = SD_ID128_NULL;
dual_timestamp previous_ts_output = DUAL_TIMESTAMP_NULL;
- int n_shown = 0, r, poll_fd = -1;
+ int n_shown = 0, r, poll_fd = -EBADF;
setlocale(LC_ALL, "");
log_setup();
char tbuf[STRLEN("[] ") + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1];
char header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t)];
_cleanup_free_ char *ident_buf = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *tty;
int n = 0;
}
int server_open_kernel_seqnum(Server *s) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *fn;
uint64_t *p;
int r;
for (;;) {
_cleanup_free_ char *u = NULL, *full = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *a, *b;
struct dirent *de;
ManagedJournalFile *f;
int server_init(Server *s, const char *namespace) {
const char *native_socket, *syslog_socket, *stdout_socket, *varlink_socket, *e;
_cleanup_fdset_free_ FDSet *fds = NULL;
- int n, r, fd, varlink_fd = -1;
+ int n, r, fd, varlink_fd = -EBADF;
bool no_sockets;
assert(s);
*s = (Server) {
- .syslog_fd = -1,
- .native_fd = -1,
- .stdout_fd = -1,
- .dev_kmsg_fd = -1,
- .audit_fd = -1,
- .hostname_fd = -1,
- .notify_fd = -1,
+ .syslog_fd = -EBADF,
+ .native_fd = -EBADF,
+ .stdout_fd = -EBADF,
+ .dev_kmsg_fd = -EBADF,
+ .audit_fd = -EBADF,
+ .hostname_fd = -EBADF,
+ .notify_fd = -EBADF,
.compress.enabled = true,
.compress.threshold_bytes = UINT64_MAX,
return log_oom();
*stream = (StdoutStream) {
- .fd = -1,
+ .fd = -EBADF,
.priority = LOG_INFO,
.ucred = UCRED_INVALID,
};
}
static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
Server *s = ASSERT_PTR(userdata);
int r;
.ll.sll_family = AF_PACKET,
.ll.sll_ifindex = ifindex,
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(ifindex > 0);
.n_ref = 1,
.state = DHCP_STATE_INIT,
.ifindex = -1,
- .fd = -1,
+ .fd = -EBADF,
.mtu = DHCP_MIN_PACKET_SIZE,
.port = DHCP_PORT_CLIENT,
.anonymize = !!anonymize,
*server = (sd_dhcp_server) {
.n_ref = 1,
- .fd_raw = -1,
- .fd = -1,
- .fd_broadcast = -1,
+ .fd_raw = -EBADF,
+ .fd = -EBADF,
+ .fd_broadcast = -EBADF,
.address = htobe32(INADDR_ANY),
.netmask = htobe32(INADDR_ANY),
.ifindex = ifindex,
.ia_pd.type = SD_DHCP6_OPTION_IA_PD,
.ifindex = -1,
.request_ia = DHCP6_REQUEST_IA_NA | DHCP6_REQUEST_IA_PD,
- .fd = -1,
+ .fd = -EBADF,
.rapid_commit = true,
};
.n_ref = 1,
.state = IPV4ACD_STATE_INIT,
.ifindex = -1,
- .fd = -1,
+ .fd = -EBADF,
};
*ret = TAKE_PTR(acd);
*lldp_rx = (sd_lldp_rx) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.neighbors_max = LLDP_DEFAULT_NEIGHBORS_MAX,
.capability_mask = UINT16_MAX,
};
}
static int lldp_tx_send_packet(sd_lldp_tx *lldp_tx, size_t packet_size, const uint8_t *packet) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
ssize_t l;
*nd = (sd_ndisc) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
};
*ret = TAKE_PTR(nd);
*ra = (sd_radv) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC,
};
int bus_container_connect_socket(sd_bus *b) {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, usernsfd = -1, rootfd = -1;
+ _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, usernsfd = -EBADF, rootfd = -EBADF;
int r, error_buf = 0;
pid_t child;
ssize_t n;
m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(m->fields_size);
m->body.size = sz;
m->body.sealed = true;
- m->body.memfd = -1;
+ m->body.memfd = -EBADF;
}
m->n_iovec = 1;
m->body_end->next = part;
}
- part->memfd = -1;
+ part->memfd = -EBADF;
m->body_end = part;
m->n_body_parts++;
}
int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct bus_container *c;
ssize_t align, sz;
uint32_t u32;
if (c->enclosing != SD_BUS_TYPE_ARRAY)
c->index++;
- fd = -1;
+ fd = -EBADF;
return 0;
}
uint64_t offset,
uint64_t size) {
- _cleanup_close_ int copy_fd = -1;
+ _cleanup_close_ int copy_fd = -EBADF;
struct bus_body_part *part;
ssize_t align, sz;
uint64_t real_size;
part->memfd_offset = offset;
part->sealed = true;
part->size = size;
- copy_fd = -1;
+ copy_fd = -EBADF;
m->body_size += size;
message_extend_containers(m, size);
uint64_t offset,
uint64_t size) {
- _cleanup_close_ int copy_fd = -1;
+ _cleanup_close_ int copy_fd = -EBADF;
struct bus_body_part *part;
struct bus_container *c;
uint64_t real_size;
part->memfd_offset = offset;
part->sealed = true;
part->size = size;
- copy_fd = -1;
+ copy_fd = -EBADF;
m->body_size += size;
message_extend_containers(m, size);
*b = (sd_bus) {
.n_ref = 1,
- .input_fd = -1,
- .output_fd = -1,
- .inotify_fd = -1,
+ .input_fd = -EBADF,
+ .output_fd = -EBADF,
+ .inotify_fd = -EBADF,
.message_version = 1,
.creds_mask = SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME,
.accept_fd = true,
static void* thread_server(void *p) {
_cleanup_free_ char *suffixed = NULL, *suffixed2 = NULL, *d = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union u;
const char *path = p;
int r;
.msg_iovlen = 1,
.msg_name = &sockaddr,
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct cmsghdr *cmsg = NULL;
const char *e;
bool send_ucred;
int device_open_from_devnum(mode_t mode, dev_t devnum, int flags, char **ret) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
r = device_new_from_mode_and_devnum(&dev, mode, devnum);
assert(_syspath);
if (verify) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* The input path maybe a symlink located outside of /sys. Let's try to chase the symlink at first.
* The primary usecase is that e.g. /proc/device-tree is a symlink to /sys/firmware/devicetree/base.
}
_public_ int sd_device_open(sd_device *device, int flags) {
- _cleanup_close_ int fd = -1, fd2 = -1;
+ _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
const char *devname, *subsystem = NULL;
uint64_t q, diskseq = 0;
struct stat st;
assert_se(streq(syspath, val));
dev = sd_device_unref(dev);
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = sd_device_open(d, O_CLOEXEC| O_NONBLOCK | (is_block ? O_RDONLY : O_NOCTTY | O_PATH));
assert_se(fd >= 0 || ERRNO_IS_PRIVILEGE(fd));
} else
int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) {
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(e);
*e = (sd_event) {
.n_ref = 1,
- .epoll_fd = -1,
- .watchdog_fd = -1,
+ .epoll_fd = -EBADF,
+ .watchdog_fd = -EBADF,
.realtime.wakeup = WAKEUP_CLOCK_DATA,
- .realtime.fd = -1,
+ .realtime.fd = -EBADF,
.realtime.next = USEC_INFINITY,
.boottime.wakeup = WAKEUP_CLOCK_DATA,
- .boottime.fd = -1,
+ .boottime.fd = -EBADF,
.boottime.next = USEC_INFINITY,
.monotonic.wakeup = WAKEUP_CLOCK_DATA,
- .monotonic.fd = -1,
+ .monotonic.fd = -EBADF,
.monotonic.next = USEC_INFINITY,
.realtime_alarm.wakeup = WAKEUP_CLOCK_DATA,
- .realtime_alarm.fd = -1,
+ .realtime_alarm.fd = -EBADF,
.realtime_alarm.next = USEC_INFINITY,
.boottime_alarm.wakeup = WAKEUP_CLOCK_DATA,
- .boottime_alarm.fd = -1,
+ .boottime_alarm.fd = -EBADF,
.boottime_alarm.next = USEC_INFINITY,
.perturb = USEC_INFINITY,
.original_pid = getpid_cached(),
*d = (struct signal_data) {
.wakeup = WAKEUP_SIGNAL_DATA,
- .fd = -1,
+ .fd = -EBADF,
.priority = priority,
};
if (_likely_(d->fd >= 0))
return 0;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC);
if (fd < 0)
} else
s->child.pidfd_owned = true; /* If we allocate the pidfd we own it by default */
} else
- s->child.pidfd = -1;
+ s->child.pidfd = -EBADF;
if (EVENT_SOURCE_WATCH_PIDFD(s)) {
/* We have a pidfd and we only want to watch for exit */
int64_t priority,
struct inotify_data **ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct inotify_data *d;
int r;
.dev = dev,
.ino = ino,
.wd = -1,
- .fd = -1,
+ .fd = -EBADF,
.inotify_data = inotify_data,
};
got_a = false, got_b = false, got_c = false, got_d = 0;
- /* Add a oneshot handler, trigger it, reenable it, and trigger
- * it again. */
+ /* Add a oneshot handler, trigger it, reenable it, and trigger it again. */
assert_se(sd_event_add_io(e, &w, d[0], EPOLLIN, io_handler, INT_TO_PTR('d')) >= 0);
assert_se(sd_event_source_set_enabled(w, SD_EVENT_ONESHOT) >= 0);
assert_se(write(d[1], &ch, 1) >= 0);
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
char path[] = "/tmp/inotifyXXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* Tests that destroying an inotify event source from its own handler is safe */
}
int id128_read(const char *p, Id128FormatFlag f, sd_id128_t *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
}
int id128_write(const char *p, Id128FormatFlag f, sd_id128_t id) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(p, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444);
if (fd < 0)
}
static int open_mmap(const char *database, int *_fd, struct stat *_st, void **_p) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const CatalogHeader *h;
struct stat st;
void *p;
}
int catalog_get(const char* database, sd_id128_t id, char **_text) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
void *p = NULL;
struct stat st = {};
char *text = NULL;
}
int catalog_list(FILE *f, const char *database, bool oneline) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
void *p = NULL;
struct stat st;
const CatalogHeader *h;
}
int journal_file_fss_load(JournalFile *f) {
- int r, fd = -1;
+ int r, fd = -EBADF;
char *p = NULL;
struct stat st;
FSSHeader *m = NULL;
_public_ int sd_journal_sendv(const struct iovec *iov, int n) {
PROTECT_ERRNO;
int fd, r;
- _cleanup_close_ int buffer_fd = -1;
+ _cleanup_close_ int buffer_fd = -EBADF;
struct iovec *w;
uint64_t *l;
int i, j = 0;
}
_public_ int sd_journal_stream_fd(const char *identifier, int priority, int level_prefix) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char *header;
size_t l;
int r;
}
static int journal_file_empty(int dir_fd, const char *name) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
le64_t n_entries;
ssize_t n;
bool entry_seqnum_set = false, entry_monotonic_set = false, entry_realtime_set = false, found_main_entry_array = false;
uint64_t n_objects = 0, n_entries = 0, n_data = 0, n_fields = 0, n_data_hash_tables = 0, n_field_hash_tables = 0, n_entry_arrays = 0, n_tags = 0;
usec_t last_usec = 0;
- _cleanup_close_ int data_fd = -1, entry_fd = -1, entry_array_fd = -1;
+ _cleanup_close_ int data_fd = -EBADF, entry_fd = -EBADF, entry_array_fd = -EBADF;
_cleanup_fclose_ FILE *data_fp = NULL, *entry_fp = NULL, *entry_array_fp = NULL;
MMapFileDescriptor *cache_data_fd = NULL, *cache_entry_fd = NULL, *cache_entry_array_fd = NULL;
unsigned i;
int fd,
const char *path) {
- _cleanup_close_ int our_fd = -1;
+ _cleanup_close_ int our_fd = -EBADF;
JournalFile *f;
struct stat st;
int r;
goto fail;
}
} else {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
/* If there's no path specified, then we use the top-level fd itself. We duplicate the fd here, since
* opendir() will take possession of the fd, and close it, which we don't want. */
return NULL;
j->original_pid = getpid_cached();
- j->toplevel_fd = -1;
- j->inotify_fd = -1;
+ j->toplevel_fd = -EBADF;
+ j->inotify_fd = -EBADF;
j->flags = flags;
j->data_threshold = DEFAULT_DATA_THRESHOLD;
int main(int argc, char *argv[]) {
_cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *text = NULL;
int r;
}
_public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool good = false;
int k;
}
int netlink_open_family(sd_netlink **ret, int family) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
fd = socket_open(family);
*nl = (sd_netlink) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.sockaddr.nl.nl_family = AF_NETLINK,
.original_pid = getpid_cached(),
.protocol = -1,
r = socket_bind(nl);
if (r < 0) {
- nl->fd = -1; /* on failure, the caller remains owner of the fd, hence don't close it here */
+ nl->fd = -EBADF; /* on failure, the caller remains owner of the fd, hence don't close it here */
nl->protocol = -1;
return r;
}
}
int sd_network_monitor_new(sd_network_monitor **m, const char *category) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int k;
bool good = false;
resolve->original_pid = getpid_cached();
for (i = 0; i < _FD_MAX; i++)
- resolve->fds[i] = -1;
+ resolve->fds[i] = -EBADF;
if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolve->fds + REQUEST_RECV_FD) < 0)
return -errno;
*udev_queue = (struct udev_queue) {
.udev = udev,
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
};
return udev_queue;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **arguments = NULL;
_cleanup_free_ char *w = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
pid_t pid;
/* Ignore SIGINT and allow the forked process to receive it */
}
b->manager = m;
- b->fd = -1;
+ b->fd = -EBADF;
return b;
}
}
int button_open(Button *b) {
- _cleanup_(asynchronous_closep) int fd = -1;
+ _cleanup_(asynchronous_closep) int fd = -EBADF;
const char *p;
char name[256];
int r;
static int vt_is_busy(unsigned vtnr) {
struct vt_stat vt_stat;
int r;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(vtnr >= 1);
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
const char *who, *why, *what, *mode;
_cleanup_free_ char *id = NULL;
- _cleanup_close_ int fifo_fd = -1;
+ _cleanup_close_ int fifo_fd = -EBADF;
Manager *m = ASSERT_PTR(userdata);
InhibitMode mm;
InhibitWhat w;
.what = _INHIBIT_WHAT_INVALID,
.mode = _INHIBIT_MODE_INVALID,
.uid = UID_INVALID,
- .fifo_fd = -1,
+ .fifo_fd = -EBADF,
};
i->state_file = path_join("/run/systemd/inhibit", id);
}
if (i->fifo_path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* Let's re-open the FIFO on both sides, and close the writing side right away */
fd = inhibitor_create_fifo(i);
static int vt_allocate(unsigned vtnr) {
char p[sizeof("/dev/tty") + DECIMAL_STR_MAX(unsigned)];
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(vtnr >= 1);
int session_send_create_reply(Session *s, sd_bus_error *error) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *c = NULL;
- _cleanup_close_ int fifo_fd = -1;
+ _cleanup_close_ int fifo_fd = -EBADF;
_cleanup_free_ char *p = NULL;
assert(s);
sd->session = s;
sd->dev = dev;
- sd->fd = -1;
+ sd->fd = -EBADF;
sd->type = DEVICE_TYPE_UNKNOWN;
r = session_device_verify(sd);
*s = (Session) {
.manager = m,
- .fifo_fd = -1,
- .vtfd = -1,
+ .fifo_fd = -EBADF,
+ .vtfd = -EBADF,
.audit_id = AUDIT_SESSION_INVALID,
.tty_validity = _TTY_VALIDITY_INVALID,
};
return -ENOMEM;
*m = (Manager) {
- .console_active_fd = -1,
- .reserve_vt_fd = -1,
+ .console_active_fd = -EBADF,
+ .reserve_vt_fd = -EBADF,
.enable_wall_messages = true,
.idle_action_not_before_usec = now(CLOCK_MONOTONIC),
};
active = m->seat0->active;
if (!active || active->vtnr < 1) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
/* We are requested to acknowledge the VT-switch signal by the kernel but
char *c;
union sockaddr_union sa;
socklen_t sa_len;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(display);
static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
_cleanup_free_ char *sys_path = NULL, *tty = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct ucred ucred;
int v, r;
dev_t display_ctty;
*memory_max = NULL, *tasks_max = NULL, *cpu_weight = NULL, *io_weight = NULL, *runtime_max_sec = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(user_record_unrefp) UserRecord *ur = NULL;
- int session_fd = -1, existing, r;
+ int session_fd = -EBADF, existing, r;
bool debug = false, remote;
uint32_t vtnr = 0;
uid_t original_uid;
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
case MACHINE_CONTAINER: {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_free_ char *us = NULL, *them = NULL;
- _cleanup_close_ int netns_fd = -1;
+ _cleanup_close_ int netns_fd = -EBADF;
const char *p;
pid_t child;
break;
case MACHINE_CONTAINER: {
- _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1;
+ _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_fclose_ FILE *f = NULL;
pid_t child;
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
if (r == 0) {
- int fd = -1;
+ int fd = -EBADF;
pair[0] = safe_close(pair[0]);
const char *src, *dest, *host_path, *container_path;
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
CopyFlags copy_flags = COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS;
- _cleanup_close_ int hostfd = -1;
+ _cleanup_close_ int hostfd = -EBADF;
Machine *m = ASSERT_PTR(userdata);
bool copy_from;
pid_t child;
(void) sigkill_wait(child);
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
int bus_machine_method_open_root_directory(sd_bus_message *message, void *userdata, sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
Machine *m = ASSERT_PTR(userdata);
int r;
break;
case MACHINE_CONTAINER: {
- _cleanup_close_ int mntns_fd = -1, root_fd = -1;
+ _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
pid_t child;
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
if (r == 0) {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
pair[0] = safe_close(pair[0]);
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
const char *local = NULL, *path = NULL;
_cleanup_free_ char *fn = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
static int export_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *local = NULL, *path = NULL;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
static int export_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *local = NULL, *path = NULL;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
void *userdata,
sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t usage = UINT64_MAX;
assert(bus);
void *userdata,
sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t size = UINT64_MAX;
assert(bus);
} mode;
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
- _cleanup_close_ int result_fd = -1;
+ _cleanup_close_ int result_fd = -EBADF;
Manager *m = userdata;
Operation *operation;
const char *mm;
operation->extra_fd = result_fd;
operation->done = clean_pool_done;
- result_fd = -1;
- errno_pipe_fd[0] = -1;
+ result_fd = -EBADF;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
if (!o)
return -ENOMEM;
- o->extra_fd = -1;
+ o->extra_fd = -EBADF;
r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o);
if (r < 0) {
}
static int netdev_create_tuntap(NetDev *netdev) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct ifreq ifr = {};
TunTap *t;
int r;
t = TUNTAP(netdev);
assert(t);
- t->fd = -1;
+ t->fd = -EBADF;
}
static void tuntap_drop(NetDev *netdev) {
static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, LinkInfo **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
_cleanup_(link_info_array_freep) LinkInfo *links = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
size_t c = 0;
int r;
static int manager_listen_fds(Manager *m, int *ret_rtnl_fd) {
_cleanup_strv_free_ char **names = NULL;
- int n, rtnl_fd = -1;
+ int n, rtnl_fd = -EBADF;
assert(m);
assert(ret_rtnl_fd);
}
int manager_setup(Manager *m) {
- _cleanup_close_ int rtnl_fd = -1;
+ _cleanup_close_ int rtnl_fd = -EBADF;
int r;
assert(m);
.online_state = _LINK_ONLINE_STATE_INVALID,
.manage_foreign_routes = true,
.manage_foreign_rules = true,
- .ethtool_fd = -1,
+ .ethtool_fd = -EBADF,
.dhcp_duid.type = DUID_TYPE_EN,
.dhcp6_duid.type = DUID_TYPE_EN,
.duid_product_uuid.type = DUID_TYPE_UUID,
#include "user-util.h"
static int chown_cgroup_path(const char *path, uid_t uid_shift) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
}
int expose_port_send_rtnl(int send_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(send_fd >= 0);
assert(ret);
if (name) {
- _cleanup_close_ int child_fd = -1;
+ _cleanup_close_ int child_fd = -EBADF;
child_fd = openat(fd, name, O_PATH|O_CLOEXEC|O_NOFOLLOW);
if (child_fd < 0)
assert(acl);
if (name) {
- _cleanup_close_ int child_fd = -1;
+ _cleanup_close_ int child_fd = -EBADF;
child_fd = openat(fd, name, O_PATH|O_CLOEXEC|O_NOFOLLOW);
if (child_fd < 0)
_cleanup_free_ gid_t *gids = NULL;
_cleanup_free_ char *home = NULL, *line = NULL;
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
unsigned n_gids = 0;
uid_t uid;
gid_t gid;
for (size_t i = 0; i < arg_n_credentials; i++) {
_cleanup_free_ char *j = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
j = path_join(q, arg_credentials[i].id);
if (!j)
static int setup_kmsg(int fd_inner_socket) {
_cleanup_(unlink_and_freep) char *from = NULL;
_cleanup_free_ char *fifo = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(fd_inner_socket >= 0);
}
static int setup_notify_child(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
static const union sockaddr_union sa = {
.un.sun_family = AF_UNIX,
.un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH,
_cleanup_(bind_user_context_freep) BindUserContext *bind_user_context = NULL;
_cleanup_strv_free_ char **os_release_pairs = NULL;
- _cleanup_close_ int fd = -1, mntns_fd = -EBADF;
+ _cleanup_close_ int fd = -EBADF, mntns_fd = -EBADF;
bool idmap = false;
const char *p;
pid_t pid;
int ifi = 0, r;
ssize_t l;
sigset_t mask_chld;
- _cleanup_close_ int child_netns_fd = -1;
+ _cleanup_close_ int child_netns_fd = -EBADF;
assert_se(sigemptyset(&mask_chld) == 0);
assert_se(sigaddset(&mask_chld, SIGCHLD) == 0);
}
if (arg_console_mode != CONSOLE_PIPE) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
PTYForwardFlags flags = 0;
/* Retrieve the master pty allocated by inner child */
return r;
if (r == 0) {
- _cleanup_close_ int parent_netns_fd = -1;
+ _cleanup_close_ int parent_netns_fd = -EBADF;
r = namespace_open(getpid(), NULL, NULL, &parent_netns_fd, NULL, NULL);
if (r < 0) {
}
static int cant_be_in_netns(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct ucred ucred;
int r;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
- int fd = -1;
+ int fd = -EBADF;
int r;
r = sd_bus_open_system(&bus);
static int bus_method_dump_by_fd(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *dump = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
Manager *m = ASSERT_PTR(userdata);
int r;
static void test_oomd_system_context_acquire(void) {
_cleanup_(unlink_tempfilep) char path[] = "/oomdgetsysctxtestXXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
OomdSystemContext ctx;
if (geteuid() != 0)
static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_devno) {
_cleanup_free_ char *devpath = NULL, *main_devpath = NULL;
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
- _cleanup_close_ int main_devfd = -1;
+ _cleanup_close_ int main_devfd = -EBADF;
uint64_t size;
int r;
}
static int run(int argc, char *argv[]) {
- _cleanup_close_ int mountfd = -1, devfd = -1;
+ _cleanup_close_ int mountfd = -EBADF, devfd = -EBADF;
_cleanup_free_ char *devpath = NULL;
uint64_t size, newsize;
dev_t devno;
static int run(int argc, char *argv[]) {
_cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL;
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
sd_id128_t uuid;
struct stat st;
int r;
.padding_max = UINT64_MAX,
.partno = UINT64_MAX,
.offset = UINT64_MAX,
- .copy_blocks_fd = -1,
+ .copy_blocks_fd = -EBADF,
.copy_blocks_size = UINT64_MAX,
.no_auto = -1,
.read_only = -1,
static int prepare_temporary_file(PartitionTarget *t, uint64_t size) {
_cleanup_(unlink_and_freep) char *temp = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *vt;
int r;
if (!t)
return log_oom();
*t = (PartitionTarget) {
- .fd = -1,
- .whole_fd = -1,
+ .fd = -EBADF,
+ .whole_fd = -EBADF,
};
if (!need_path) {
assert(root);
STRV_FOREACH_PAIR(source, target, p->copy_files) {
- _cleanup_close_ int sfd = -1, pfd = -1, tfd = -1;
+ _cleanup_close_ int sfd = -EBADF, pfd = -EBADF, tfd = -EBADF;
sfd = chase_symlinks_and_open(*source, arg_root, CHASE_PREFIX_ROOT, O_CLOEXEC|O_NOCTTY, NULL);
if (sfd < 0)
static int partition_populate_directory(Partition *p, const Set *denylist, char **ret) {
_cleanup_(rm_rf_physical_and_freep) char *root = NULL;
- _cleanup_close_ int rfd = -1;
+ _cleanup_close_ int rfd = -EBADF;
int r;
assert(ret);
}
static int context_split(Context *context) {
- int fd = -1, r;
+ int fd = -EBADF, r;
if (!arg_split)
return 0;
return r;
LIST_FOREACH(partitions, p, context->partitions) {
- _cleanup_close_ int fdt = -1;
+ _cleanup_close_ int fdt = -EBADF;
if (p->dropped)
continue;
return 0;
if (!arg_randomize) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, NULL);
if (fd == -ENOENT)
sd_id128_t *ret_uuid) {
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *p = NULL;
const char *pttype, *t;
sd_id128_t pt_parsed, u;
assert(context);
LIST_FOREACH(partitions, p, context->partitions) {
- _cleanup_close_ int source_fd = -1;
+ _cleanup_close_ int source_fd = -EBADF;
_cleanup_free_ char *opened = NULL;
sd_id128_t uuid = SD_ID128_NULL;
uint64_t size;
_cleanup_(rm_rf_physical_and_freep) char *root = NULL;
_cleanup_(unlink_and_freep) char *temp = NULL;
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_id128_t fs_uuid;
uint64_t fsz;
_cleanup_free_ char *found_path = NULL;
dev_t devno, fd_devno = MODE_INVALID;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
if (arg_node) {
if (arg_empty == EMPTY_CREATE) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *s = NULL;
s = strdup(arg_node);
const char *backing_file, /* If the above refers to a loopback device, the backing regular file for that, which we can grow */
LoopDevice *loop_device) {
- _cleanup_close_ int writable_fd = -1;
+ _cleanup_close_ int writable_fd = -EBADF;
uint64_t current_size;
struct stat st;
int r;
size_t iovlen,
int fd) {
- _cleanup_close_ int data_fd = -1;
+ _cleanup_close_ int data_fd = -EBADF;
assert(iov || iovlen == 0);
assert(socket_fd >= 0);
_cleanup_hashmap_free_ Hashmap *unit_files = NULL;
_cleanup_(portable_metadata_unrefp) PortableMetadata *os_release = NULL;
_cleanup_(lookup_paths_free) LookupPaths paths = {};
- _cleanup_close_ int os_release_fd = -1;
+ _cleanup_close_ int os_release_fd = -EBADF;
_cleanup_free_ char *os_release_path = NULL;
const char *os_release_id;
int r;
if (!os_release)
return -ENOMEM;
- os_release_fd = -1;
+ os_release_fd = -EBADF;
os_release->source = TAKE_PTR(os_release_path);
}
}
FOREACH_DIRENT(de, d, return log_debug_errno(errno, "Failed to read directory: %m")) {
_cleanup_(portable_metadata_unrefp) PortableMetadata *m = NULL;
_cleanup_(mac_selinux_freep) char *con = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
continue;
m = portable_metadata_new(de->d_name, where, con, fd);
if (!m)
return -ENOMEM;
- fd = -1;
+ fd = -EBADF;
m->source = path_join(resolved, de->d_name);
if (!m->source)
for (;;) {
_cleanup_(portable_metadata_unrefp) PortableMetadata *add = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* We use NAME_MAX space for the SELinux label here. The kernel currently enforces no limit, but
* according to suggestions from the SELinux people this will change and it will probably be
* identical to NAME_MAX. For now we use that, but this should be updated one day when the final
add = portable_metadata_new(iov_buffer, path, selinux_label, fd);
if (!add)
return -ENOMEM;
- fd = -1;
+ fd = -EBADF;
/* Note that we do not initialize 'add->source' here, as the source path is not usable here as
* it refers to a path only valid in the short-living namespaced child process we forked
_cleanup_(portable_metadata_unrefp) PortableMetadata *extension_release_meta = NULL;
_cleanup_hashmap_free_ Hashmap *extra_unit_files = NULL;
_cleanup_strv_free_ char **extension_release = NULL;
- _cleanup_close_ int extension_release_fd = -1;
+ _cleanup_close_ int extension_release_fd = -EBADF;
_cleanup_fclose_ FILE *f = NULL;
const char *e;
} else {
_cleanup_(unlink_and_freep) char *tmp = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
(void) mac_selinux_create_file_prepare_label(path, m->selinux_label);
_cleanup_free_ char *line = NULL, *marker = NULL;
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *p, *e, *k;
int r;
void *userdata,
sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t usage = UINT64_MAX;
assert(bus);
void *userdata,
sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint64_t size = UINT64_MAX;
assert(bus);
return r;
child = 0;
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
if (!o)
return -ENOMEM;
- o->extra_fd = -1;
+ o->extra_fd = -EBADF;
r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o);
if (r < 0) {
static int append_dmesg(PStoreEntry *pe, const char *subdir1, const char *subdir2) {
/* Append dmesg chunk to end, create if needed */
_cleanup_free_ char *ofd_path = NULL;
- _cleanup_close_ int ofd = -1;
+ _cleanup_close_ int ofd = -EBADF;
ssize_t wr;
assert(pe);
struct sha256_ctx hash_state;
_cleanup_free_ void *seed_file_bytes = NULL;
_cleanup_free_ char *esp_path = NULL;
- _cleanup_close_ int seed_fd = -1, dir_fd = -1;
+ _cleanup_close_ int seed_fd = -EBADF, dir_fd = -EBADF;
size_t len;
ssize_t n;
int r;
static int run(int argc, char *argv[]) {
_cleanup_free_ struct sha256_ctx *hash_state = NULL;
- _cleanup_close_ int seed_fd = -1, random_fd = -1;
+ _cleanup_close_ int seed_fd = -EBADF, random_fd = -EBADF;
bool read_seed_file, write_seed_file, synchronous;
size_t seed_size;
int r;
static int run(int argc, char *argv[]) {
_cleanup_(erase_and_freep) char *packet = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
size_t length = 0;
int r;
uint16_t port,
union sockaddr_union *ret_socket_address) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t salen;
int r, ifindex;
*s = (DnsStream) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.protocol = protocol,
.type = type,
};
int type) {
sd_event_source **event_source;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
int r;
static int manager_dns_stub_fd_extra(Manager *m, DnsStubListenerExtra *l, int type) {
_cleanup_free_ char *pretty = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
int r;
return -ENOMEM;
*t = (DnsTransaction) {
- .dns_udp_fd = -1,
+ .dns_udp_fd = -EBADF,
.answer_source = _DNS_TRANSACTION_SOURCE_INVALID,
.answer_dnssec_result = _DNSSEC_RESULT_INVALID,
.answer_nsec_ttl = UINT32_MAX,
static int dns_transaction_emit_tcp(DnsTransaction *t) {
usec_t stream_timeout_usec = DNS_STREAM_DEFAULT_TIMEOUT_USEC;
_cleanup_(dns_stream_unrefp) DnsStream *s = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
DnsStreamType type;
int r;
if (r < 0)
return r;
- fd = -1;
+ fd = -EBADF;
#if ENABLE_DNS_OVER_TLS
if (t->scope->protocol == DNS_PROTOCOL_DNS &&
return -ENOMEM;
*m = (Manager) {
- .llmnr_ipv4_udp_fd = -1,
- .llmnr_ipv6_udp_fd = -1,
- .llmnr_ipv4_tcp_fd = -1,
- .llmnr_ipv6_tcp_fd = -1,
- .mdns_ipv4_fd = -1,
- .mdns_ipv6_fd = -1,
- .hostname_fd = -1,
+ .llmnr_ipv4_udp_fd = -EBADF,
+ .llmnr_ipv6_udp_fd = -EBADF,
+ .llmnr_ipv4_tcp_fd = -EBADF,
+ .llmnr_ipv6_tcp_fd = -EBADF,
+ .mdns_ipv4_fd = -EBADF,
+ .mdns_ipv6_fd = -EBADF,
+ .hostname_fd = -EBADF,
.llmnr_support = DEFAULT_LLMNR_MODE,
.mdns_support = DEFAULT_MDNS_MODE,
}
static void *tcp_dns_server(void *p) {
- _cleanup_close_ int bindfd = -1, acceptfd = -1;
+ _cleanup_close_ int bindfd = -EBADF, acceptfd = -EBADF;
assert_se((bindfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0);
assert_se(setsockopt(bindfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) >= 0);
static void *tls_dns_server(void *p) {
pid_t openssl_pid;
int r;
- _cleanup_close_ int fd_server = -1, fd_tls = -1;
+ _cleanup_close_ int fd_server = -EBADF, fd_tls = -EBADF;
_cleanup_free_ char *cert_path = NULL, *key_path = NULL;
_cleanup_free_ char *bind_str = NULL;
Manager manager = {};
_cleanup_(dns_stream_unrefp) DnsStream *stream = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
- _cleanup_close_ int clientfd = -1;
+ _cleanup_close_ int clientfd = -EBADF;
int r;
void *(*server_entrypoint)(void *);
}
static void try_isolate_network(void) {
- _cleanup_close_ int socket_fd = -1;
+ _cleanup_close_ int socket_fd = -EBADF;
int r;
/* First test if CLONE_NEWUSER/CLONE_NEWNET can actually work for us, i.e. we can open the namespaces
struct acpi_fpdt_header *rec;
int r;
uint64_t ptr = 0;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct acpi_fpdt_boot_header hbrec;
struct acpi_fpdt_boot brec;
char ***ret) {
static const union sockaddr_union sa = PLYMOUTH_SOCKET;
- _cleanup_close_ int fd = -1, notify = -1;
+ _cleanup_close_ int fd = -EBADF, notify = -EBADF;
_cleanup_free_ char *packet = NULL;
ssize_t k;
int r, n;
};
bool reset_tty = false, dirty = false, use_color = false, press_tab_visible = false;
- _cleanup_close_ int cttyfd = -1, notify = -1;
+ _cleanup_close_ int cttyfd = -EBADF, notify = -EBADF;
struct termios old_termios, new_termios;
char passphrase[LINE_MAX + 1] = {}, *x;
_cleanup_strv_free_erase_ char **l = NULL;
_cleanup_free_ char *path = NULL;
union sockaddr_union sa;
socklen_t sa_len;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(ret);
_FD_MAX
};
- _cleanup_close_ int socket_fd = -1, signal_fd = -1, notify = -1, fd = -1;
+ _cleanup_close_ int socket_fd = -EBADF, signal_fd = -EBADF, notify = -EBADF, fd = -EBADF;
char temp[] = "/run/systemd/ask-password/tmp.XXXXXX";
char final[sizeof(temp)] = "";
_cleanup_free_ char *socket_name = NULL;
#endif
int base_filesystem_create(const char *root, uid_t uid, gid_t gid) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
}
int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flags, sd_device **ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
}
int get_block_device(const char *path, dev_t *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
}
int get_block_device_harder(const char *path, dev_t *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
}
int lock_whole_block_device(dev_t devt, int operation) {
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
dev_t whole_devt;
int r;
}
int path_get_whole_disk(const char *path, bool backing, dev_t *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_CLOEXEC|O_PATH);
if (fd < 0)
int block_device_remove_all_partitions(sd_device *dev, int fd) {
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev_unref = NULL;
- _cleanup_close_ int fd_close = -1;
+ _cleanup_close_ int fd_close = -EBADF;
bool has_partitions = false;
sd_device *part;
int r, k = 0;
}
int blockdev_reread_partition_table(sd_device *dev) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(dev);
_cleanup_free_ DirectoryEntries *dentries = NULL;
_cleanup_free_ char *full = NULL;
- _cleanup_close_ int dir_fd = -1;
+ _cleanup_close_ int dir_fd = -EBADF;
int r;
assert(config);
FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read %s: %m", full)) {
_cleanup_free_ char *j = NULL, *osrelease = NULL, *cmdline = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (!dirent_is_file(de))
continue;
*p = (BPFProgram) {
.prog_type = prog_type,
- .kernel_fd = -1,
+ .kernel_fd = -EBADF,
.prog_name = TAKE_PTR(name),
};
*p = (BPFProgram) {
.prog_type = BPF_PROG_TYPE_UNSPEC,
- .kernel_fd = -1,
+ .kernel_fd = -EBADF,
};
r = bpf_program_load_from_bpf_fs(p, path);
int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags) {
_cleanup_free_ char *copy = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union bpf_attr attr;
int r;
}
int bpf_program_cgroup_detach(BPFProgram *p) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(p);
int bpf_program_deserialize_attachment(const char *v, FDSet *fds, BPFProgram **bpfp) {
_cleanup_free_ char *sfd = NULL, *sat = NULL, *unescaped = NULL;
_cleanup_(bpf_program_freep) BPFProgram *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
ssize_t l;
int ifd, at, r;
}
int btrfs_is_subvol(const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
int btrfs_subvol_make_fd(int fd, const char *subvolume) {
struct btrfs_ioctl_vol_args args = {};
- _cleanup_close_ int real_fd = -1;
+ _cleanup_close_ int real_fd = -EBADF;
int r;
assert(subvolume);
}
int btrfs_subvol_make(const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *subvolume;
int r;
}
int btrfs_subvol_set_read_only(const char *path, bool b) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
int btrfs_get_block_device_fd(int fd, dev_t *dev) {
struct btrfs_ioctl_fs_info_args fsi = {};
- _cleanup_close_ int regfd = -1;
+ _cleanup_close_ int regfd = -EBADF;
uint64_t id;
int r;
}
int btrfs_get_block_device(const char *path, dev_t *dev) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(path);
assert(dev);
}
int btrfs_subvol_get_id(int fd, const char *subvol, uint64_t *ret) {
- _cleanup_close_ int subvol_fd = -1;
+ _cleanup_close_ int subvol_fd = -EBADF;
assert(fd >= 0);
assert(ret);
}
int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
}
int btrfs_subvol_get_subtree_quota(const char *path, uint64_t subvol_id, BtrfsQuotaInfo *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
}
int btrfs_defrag(const char *p) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
}
int btrfs_quota_enable(const char *path, bool b) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
}
int btrfs_qgroup_set_limit(const char *path, uint64_t qgroupid, uint64_t referenced_max) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
}
int btrfs_subvol_set_subtree_quota_limit(const char *path, uint64_t subvol_id, uint64_t referenced_max) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
};
struct btrfs_ioctl_vol_args vol_args = {};
- _cleanup_close_ int subvol_fd = -1;
+ _cleanup_close_ int subvol_fd = -EBADF;
struct stat st;
bool made_writable = false;
int r;
* directory of the subvolume. */
r = subvol_remove_children(subvol_fd, p, sh->objectid, flags);
else {
- _cleanup_close_ int child_fd = -1;
+ _cleanup_close_ int child_fd = -EBADF;
/* Subvolume is somewhere further down,
* hence we need to open the
}
int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *subvolume;
int r;
.flags = flags & BTRFS_SNAPSHOT_READ_ONLY ? BTRFS_SUBVOL_RDONLY : 0,
.fd = old_fd,
};
- _cleanup_close_ int subvolume_fd = -1;
+ _cleanup_close_ int subvolume_fd = -EBADF;
uint64_t new_subvol_id;
int r;
FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
_cleanup_free_ char *p = NULL, *c = NULL, *np = NULL;
const struct btrfs_root_ref *ref;
- _cleanup_close_ int old_child_fd = -1, new_child_fd = -1;
+ _cleanup_close_ int old_child_fd = -EBADF, new_child_fd = -EBADF;
btrfs_ioctl_search_args_set(&args, sh);
copy_progress_bytes_t progress_bytes,
void *userdata) {
- _cleanup_close_ int new_fd = -1;
+ _cleanup_close_ int new_fd = -EBADF;
const char *subvolume;
int r;
copy_progress_bytes_t progress_bytes,
void *userdata) {
- _cleanup_close_ int old_fd = -1;
+ _cleanup_close_ int old_fd = -EBADF;
assert(old_path);
assert(new_path);
int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermediary_qgroup) {
_cleanup_free_ uint64_t *qgroups = NULL;
- _cleanup_close_ int real_fd = -1;
+ _cleanup_close_ int real_fd = -EBADF;
uint64_t parent_subvol;
bool changed = false;
int n = 0, r;
}
int btrfs_subvol_auto_qgroup(const char *path, uint64_t subvol_id, bool create_intermediary_qgroup) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
uint64_t cgroupid = UINT64_MAX;
_cleanup_free_ char *b = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool delegate;
int r;
}
FOREACH_DIRENT_ALL(de, d, return -errno) {
- _cleanup_close_ int path_fd = -1;
+ _cleanup_close_ int path_fd = -EBADF;
struct stat fst;
if (dot_or_dot_dot(de->d_name))
gid_t gid,
mode_t mask) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
gid_t gid,
mode_t mask) {
- int duplicated_fd = -1;
+ int duplicated_fd = -EBADF;
struct stat st;
/* Note that the slightly different order of fstat() and the checks here and in
#include "string-util.h"
int clock_get_hwclock(struct tm *tm) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(tm);
}
int clock_set_hwclock(const struct tm *tm) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(tm);
copy_progress_bytes_t progress,
void *userdata) {
- _cleanup_close_ int fdf = -1, fdt = -1;
+ _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
int r, q;
assert(from);
void *userdata) {
_cleanup_(hardlink_context_destroy) HardlinkContext our_hardlink_context = {
- .dir_fd = -1,
- .parent_fd = -1,
+ .dir_fd = -EBADF,
+ .parent_fd = -EBADF,
};
- _cleanup_close_ int fdf = -1, fdt = -1;
+ _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
_cleanup_closedir_ DIR *d = NULL;
bool exists, created;
int r;
copy_progress_bytes_t progress_bytes,
void *userdata) {
- _cleanup_close_ int fdf = -1;
+ _cleanup_close_ int fdf = -EBADF;
struct stat st;
int r;
copy_progress_bytes_t progress_bytes,
void *userdata) {
- _cleanup_close_ int fdf = -1, fdt = -1;
+ _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
struct stat st;
int r;
void *userdata) {
_cleanup_(unlink_and_freep) char *t = NULL;
- _cleanup_close_ int fdt = -1;
+ _cleanup_close_ int fdt = -EBADF;
int r;
assert(from);
struct credential_host_secret_format buf;
_cleanup_free_ char *t = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(dfd >= 0);
int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *ret_size) {
_cleanup_free_ char *_dirname = NULL, *_filename = NULL;
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
sd_id128_t machine_id;
const char *dirname, *filename;
int r;
for (unsigned attempt = 0;; attempt++) {
_cleanup_(erase_and_freep) struct credential_host_secret_format *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
size_t l = 0;
ssize_t n = 0;
struct stat st;
int acquire_data_fd(const void *data, size_t size, unsigned flags) {
_cleanup_close_pair_ int pipefds[2] = { -1, -1 };
char pattern[] = "/dev/shm/data-fd-XXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int isz = 0, r;
ssize_t n;
off_t f;
}
int copy_data_fd(int fd) {
- _cleanup_close_ int copy_fd = -1, tmp_fd = -1;
+ _cleanup_close_ int copy_fd = -EBADF, tmp_fd = -EBADF;
_cleanup_free_ void *remains = NULL;
size_t remains_size = 0;
const char *td;
return r;
if (ro) {
- _cleanup_close_ int rfd = -1;
+ _cleanup_close_ int rfd = -EBADF;
r = memfd_set_sealed(mfd);
if (r < 0)
(faccessat(dfd, filename, W_OK, AT_EACCESS) < 0 && errno == EROFS);
if (S_ISDIR(st->st_mode)) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
unsigned file_attr = 0;
usec_t crtime = 0;
return 0;
} else if (S_ISBLK(st->st_mode)) {
- _cleanup_close_ int block_fd = -1;
+ _cleanup_close_ int block_fd = -EBADF;
uint64_t size = UINT64_MAX;
/* A block device */
}
case IMAGE_BLOCK: {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int state = b;
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to chase /etc/machine-id in image %s: %m", i->name);
else if (r >= 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
#if HAVE_BLKID
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
_cleanup_free_ char *path_by_fd = NULL;
- _cleanup_close_ int fd_close = -1;
+ _cleanup_close_ int fd_close = -EBADF;
const char *fstype;
int r;
static int open_partition(const char *node, bool is_partition, const LoopDevice *loop) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
dev_t devnum;
int r;
if (STRPTR_IN_SET(usage, "filesystem", "crypto")) {
_cleanup_free_ char *t = NULL, *n = NULL, *o = NULL;
const char *fstype = NULL, *options = NULL, *suuid = NULL;
- _cleanup_close_ int mount_node_fd = -1;
+ _cleanup_close_ int mount_node_fd = -EBADF;
sd_id128_t uuid = SD_ID128_NULL;
if (FLAGS_SET(flags, DISSECT_IMAGE_PIN_PARTITION_DEVICES)) {
if (type.designator != _PARTITION_DESIGNATOR_INVALID) {
_cleanup_free_ char *t = NULL, *o = NULL, *l = NULL;
- _cleanup_close_ int mount_node_fd = -1;
+ _cleanup_close_ int mount_node_fd = -EBADF;
const char *options = NULL;
if (m->partitions[type.designator].found) {
break;
case 0xEA: { /* Boot Loader Spec extended $BOOT partition */
- _cleanup_close_ int mount_node_fd = -1;
+ _cleanup_close_ int mount_node_fd = -EBADF;
_cleanup_free_ char *o = NULL;
sd_id128_t id = SD_ID128_NULL;
const char *options = NULL;
/* If we didn't find a generic node, then we can't fix this up either */
if (generic_node) {
- _cleanup_close_ int mount_node_fd = -1;
+ _cleanup_close_ int mount_node_fd = -EBADF;
_cleanup_free_ char *o = NULL;
const char *options;
#if HAVE_BLKID
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(path);
}
static int fs_grow(const char *node_path, const char *mount_path) {
- _cleanup_close_ int mount_fd = -1, node_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF, node_fd = -EBADF;
uint64_t size, newsize;
int r;
_cleanup_free_ char *node = NULL, *name = NULL;
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(m);
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_(dm_deferred_remove_cleanp) char *restore_deferred_remove = NULL;
_cleanup_free_ char *node = NULL, *name = NULL;
- _cleanup_close_ int mount_node_fd = -1;
+ _cleanup_close_ int mount_node_fd = -EBADF;
int r;
assert(m);
* retry a few times before giving up. */
for (unsigned i = 0; i < N_DEVICE_NODE_LIST_ATTEMPTS; i++) {
_cleanup_(sym_crypt_freep) struct crypt_device *existing_cd = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* First, check if the device already exists. */
fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
for (; n_meta_initialized < _META_MAX; n_meta_initialized ++) {
if (!paths[n_meta_initialized]) {
- fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -1;
+ fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -EBADF;
continue;
}
((DissectedPartition) { \
.partno = -1, \
.architecture = _ARCHITECTURE_INVALID, \
- .mount_node_fd = -1, \
+ .mount_node_fd = -EBADF, \
})
#define TAKE_PARTITION(p) \
({ \
#include "string-util.h"
int dm_deferred_remove_cancel(const char *name) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct message {
struct dm_ioctl dm_ioctl;
struct dm_target_msg dm_target_msg;
}
int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct {
struct ethtool_perm_addr addr;
uint8_t space[HW_ADDR_MAX_SIZE];
STRV_FOREACH(path, paths) {
_cleanup_free_ char *t = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
pid_t pid;
t = strdup(*path);
return log_error_errno(errno, "Failed to seek on serialization fd: %m");
r = callbacks[STDOUT_GENERATE](fd, callback_args[STDOUT_GENERATE]);
- fd = -1;
+ fd = -EBADF;
if (r < 0)
return log_error_errno(r, "Failed to process output from %s: %m", *path);
}
ExecDirFlags flags) {
char **dirs = (char**) directories;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char *name;
int r;
pid_t executor_pid;
return log_error_errno(errno, "Failed to rewind serialization fd: %m");
r = callbacks[STDOUT_CONSUME](fd, callback_args[STDOUT_CONSUME]);
- fd = -1;
+ fd = -EBADF;
if (r < 0)
return log_error_errno(r, "Failed to parse returned data: %m");
return 0;
}
FOREACH_DIRENT(de, d, return -errno) {
- int fd = -1;
+ int fd = -EBADF;
r = safe_atoi(de->d_name, &fd);
if (r < 0)
bool unprivileged_mode,
dev_t *ret_dev) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
STRUCT_NEW_STATX_DEFINE(sxa);
STRUCT_NEW_STATX_DEFINE(sxb);
int r;
return 0;
if (sxa.sx.stx_dev_major == 0) { /* Hmm, maybe a btrfs device, and the caller asked for the backing device? Then let's try to get it. */
- _cleanup_close_ int real_fd = -1;
+ _cleanup_close_ int real_fd = -EBADF;
/* The statx() above we can execute on an O_PATH fd. But the btrfs ioctl we cannot. Hence
* acquire a "real" fd first, without the O_PATH flag. */
int target_atfd, const char *target_name,
InstallFileFlags flags) {
- _cleanup_close_ int rofd = -1;
+ _cleanup_close_ int rofd = -EBADF;
int r;
/* Moves a file or directory tree into place, with some bells and whistles:
* target_name=NULL and flags=0 this call is a NOP */
if ((flags & (INSTALL_FSYNC|INSTALL_FSYNC_FULL|INSTALL_SYNCFS|INSTALL_READ_ONLY)) != 0) {
- _cleanup_close_ int pfd = -1;
+ _cleanup_close_ int pfd = -EBADF;
struct stat st;
/* Open an O_PATH fd for the source if we need to sync things or mark things read only. */
switch (st.st_mode & S_IFMT) {
case S_IFREG: {
- _cleanup_close_ int regfd = -1;
+ _cleanup_close_ int regfd = -EBADF;
regfd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
if (regfd < 0)
}
case S_IFDIR: {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
dfd = fd_reopen(pfd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
if (dfd < 0)
if (flags & INSTALL_REPLACE) {
/* First, try a simple renamat(), maybe that's enough */
if (renameat(source_atfd, source_name, target_atfd, target_name) < 0) {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
if (!IN_SET(errno, EEXIST, ENOTDIR, ENOTEMPTY, EISDIR, EBUSY))
return -errno;
InstallChange **changes,
size_t *n_changes) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool restart;
int r = 0;
UnitType type;
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
}
for (int i = 0; i < n_gateways; i++) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t salen;
#include "path-util.h"
int make_lock_file(const char *p, int operation, LockFile *ret) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *t = NULL;
int r;
ret->fd = fd;
ret->operation = operation;
- fd = -1;
+ fd = -EBADF;
t = NULL;
return r;
int make_lock_file_for(const char *p, int operation, LockFile *ret);
void release_lock_file(LockFile *f);
-#define LOCK_FILE_INIT { .fd = -1, .path = NULL }
+#define LOCK_FILE_INIT { .fd = -EBADF, .path = NULL }
static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
- _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
+ _cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, rootfd = -EBADF;
char buf[SD_ID128_UUID_STRING_MAX];
pid_t pid, child;
ssize_t k;
}
static int open_lock_fd(int primary_fd, int operation) {
- _cleanup_close_ int lock_fd = -1;
+ _cleanup_close_ int lock_fd = -EBADF;
assert(primary_fd >= 0);
assert(IN_SET(operation & ~LOCK_NB, LOCK_SH, LOCK_EX));
static bool loop_configure_broken = false;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
- _cleanup_(cleanup_clear_loop_close) int loop_with_fd = -1; /* This must be declared before lock_fd. */
- _cleanup_close_ int fd = -1, lock_fd = -1;
+ _cleanup_(cleanup_clear_loop_close) int loop_with_fd = -EBADF; /* This must be declared before lock_fd. */
+ _cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
_cleanup_free_ char *node = NULL;
uint64_t diskseq = 0, seqnum = UINT64_MAX;
usec_t timestamp = USEC_INFINITY;
LoopDevice **ret) {
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
- _cleanup_close_ int direct_io_fd = -1, control = -1;
+ _cleanup_close_ int direct_io_fd = -EBADF, control = -EBADF;
_cleanup_free_ char *backing_file = NULL;
struct loop_config config;
int r, f_flags;
LoopDevice **ret) {
int r, basic_flags, direct_flags, rdwr_flags;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool direct = false;
assert(path);
int lock_op,
LoopDevice **ret) {
- _cleanup_close_ int fd = -1, lock_fd = -1;
+ _cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
_cleanup_free_ char *node = NULL, *backing_file = NULL;
struct loop_info64 info;
uint64_t diskseq = 0;
char sysfs[STRLEN("/sys/dev/block/:/partition") + 2*DECIMAL_STR_MAX(dev_t) + 1];
_cleanup_free_ char *buffer = NULL;
uint64_t current_offset, current_size, partno;
- _cleanup_close_ int whole_fd = -1;
+ _cleanup_close_ int whole_fd = -EBADF;
struct stat st;
dev_t devno;
int r;
static int generate_machine_id(const char *root, sd_id128_t *ret) {
const char *dbus_machine_id;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(ret);
int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_id, sd_id128_t *ret) {
const char *etc_machine_id, *run_machine_id;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool writable;
int r;
}
int machine_id_commit(const char *root) {
- _cleanup_close_ int fd = -1, initial_mntns_fd = -1;
+ _cleanup_close_ int fd = -EBADF, initial_mntns_fd = -EBADF;
const char *etc_machine_id;
sd_id128_t id;
int r;
static int do_mcopy(const char *node, const char *root) {
_cleanup_free_ char *mcopy = NULL;
_cleanup_strv_free_ char **argv = NULL;
- _cleanup_close_ int rfd = -1;
+ _cleanup_close_ int rfd = -EBADF;
_cleanup_free_ DirectoryEntries *de = NULL;
struct stat st;
int r;
bool is_image) {
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
- _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1, chased_src_fd = -1;
+ _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,
mount_tmp_created = false, mount_tmp_mounted = false,
}
static int make_userns(uid_t uid_shift, uid_t uid_range, uid_t owner, RemountIdmapping idmapping) {
- _cleanup_close_ int userns_fd = -1;
+ _cleanup_close_ int userns_fd = -EBADF;
_cleanup_free_ char *line = NULL;
/* Allocates a userns file descriptor with the mapping we need. For this we'll fork off a child
uid_t owner,
RemountIdmapping idmapping) {
- _cleanup_close_ int mount_fd = -1, userns_fd = -1;
+ _cleanup_close_ int mount_fd = -EBADF, userns_fd = -EBADF;
int r;
assert(p);
static int nscd_flush_cache_one(const char *database, usec_t end) {
size_t req_size, has_written = 0, has_read = 0, l;
struct nscdInvalidateRequest *req;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int32_t resp;
int events, r;
*f = (struct PTYForward) {
.flags = flags,
- .master = -1,
- .input_fd = -1,
- .output_fd = -1,
+ .master = -EBADF,
+ .input_fd = -EBADF,
+ .output_fd = -EBADF,
};
if (event)
static int xen_kexec_loaded(void) {
#if HAVE_XENCTRL
- _cleanup_close_ int privcmd_fd = -1, buf_fd = -1;
+ _cleanup_close_ int privcmd_fd = -EBADF, buf_fd = -EBADF;
xen_kexec_status_t *buffer;
size_t size;
int r;
assert(atfd >= 0 || inode_path);
#if HAVE_SELINUX
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int inode_fd, r;
* filesystems, a debug message is logged and ret_offset is set to UINT64_MAX.
*/
static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offset) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ struct fiemap *fiemap = NULL;
struct stat sb;
int r;
const char *label_path,
LabelFixFlags flags) {
- _cleanup_close_ int opened_fd = -1;
+ _cleanup_close_ int opened_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r, inode_fd;
mode_t socket_mode,
const char *label) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *p;
int r;
assert(ret);
if (root) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd < 0)
unsigned long mount_flags) { /* MS_MOVE or MS_BIND */
_cleanup_free_ char *resolved_old_root_after = NULL;
- _cleanup_close_ int old_root_fd = -1;
+ _cleanup_close_ int old_root_fd = -EBADF;
int r;
assert(new_root);
}
int write_tmpfile(char *pattern, const char *contents) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(pattern);
assert(contents);
}
int udev_queue_init(void) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = inotify_init1(IN_CLOEXEC);
if (fd < 0)
#define TIMEOUT_USEC (50 * USEC_PER_MSEC)
static int write_to_terminal(const char *tty, const char *message) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *p;
size_t left;
usec_t end;
*v = (Varlink) {
.n_ref = 1,
- .fd = -1,
+ .fd = -EBADF,
.state = _VARLINK_STATE_INVALID,
r = varlink_attach_event(v, server->event, server->event_priority);
if (r < 0) {
varlink_log_errno(v, r, "Failed to attach new connection: %m");
- v->fd = -1; /* take the fd out of the connection again */
+ v->fd = -EBADF; /* take the fd out of the connection again */
varlink_close(v);
return r;
}
static int connect_callback(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
VarlinkServerSocket *ss = ASSERT_PTR(userdata);
- _cleanup_close_ int cfd = -1;
+ _cleanup_close_ int cfd = -EBADF;
Varlink *v = NULL;
int r;
_cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
union sockaddr_union sockaddr;
socklen_t sockaddr_len;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert_return(s, -EINVAL);
_cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
_cleanup_free_ char *address = NULL;
const char *v = ASSERT_PTR(value);
- int r, fd = -1;
+ int r, fd = -EBADF;
char *buf;
size_t n;
#include "time-util.h"
#include "watchdog.h"
-static int watchdog_fd = -1;
+static int watchdog_fd = -EBADF;
static char *watchdog_device = NULL;
static usec_t watchdog_timeout = 0; /* 0 → close device and USEC_INFINITY → don't change timeout */
static usec_t watchdog_pretimeout = 0; /* 0 → disable pretimeout and USEC_INFINITY → don't change pretimeout */
}
static int delete_loopback(const char *device) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct loop_info64 info;
assert(device);
}
static int delete_dm(MountPoint *m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(m);
}
static int delete_md(MountPoint *m) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(m);
assert(major(m->devnum) != 0);
assert(sleep_config);
while (battery_is_low() == 0) {
- _cleanup_close_ int tfd = -1;
+ _cleanup_close_ int tfd = -EBADF;
struct itimerspec ts = {};
usec_t suspend_interval = sleep_config->hibernate_delay_sec, before_timestamp = 0, after_timestamp = 0, total_suspend_interval;
bool woken_by_timer;
*c = (Connection) {
.context = context,
.server_fd = fd,
- .client_fd = -1,
+ .client_fd = -EBADF,
.server_to_client_buffer = {-1, -1},
.client_to_server_buffer = {-1, -1},
};
static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
_cleanup_free_ char *peer = NULL;
Context *context = ASSERT_PTR(userdata);
- int nfd = -1, r;
+ int nfd = -EBADF, r;
assert(s);
assert(fd >= 0);
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_strv_free_ char **argv = NULL;
- _cleanup_close_ int orig_stdout_fd = -1;
+ _cleanup_close_ int orig_stdout_fd = -EBADF;
int r;
if (size > 16*1024)
int talk_initctl(char rl) {
#if HAVE_SYSV_COMPAT
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *path;
int r;
d = orig_root_stats.st_rdev;
} else if (rr->type == RESOURCE_PARTITION) {
- _cleanup_close_ int fd = -1, real_fd = -1;
+ _cleanup_close_ int fd = -EBADF, real_fd = -EBADF;
_cleanup_free_ char *resolved = NULL;
struct stat st;
TEST_RET(add_acls_for_user) {
char fn[] = "/tmp/test-empty.XXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char *cmd;
uid_t uid;
int r;
for (int i = optind; i < argc; i++) {
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
printf("%s ", argv[i]);
fflush(stdout);
if (arg_open)
assert_se(fd >= 0);
else
- assert_se(fd == -1);
+ assert_se(fd == -EBADF);
}
}
TEST(copy_file_fd) {
char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
- _cleanup_close_ int in_fd = -1, out_fd = -1;
+ _cleanup_close_ int in_fd = -EBADF, out_fd = -EBADF;
const char *text = "boohoo\nfoo\n\tbar\n";
char buf[64] = {};
TEST(copy_bytes) {
_cleanup_close_pair_ int pipefd[2] = {-1, -1};
- _cleanup_close_ int infd = -1;
+ _cleanup_close_ int infd = -EBADF;
int r, r2;
char buf[1024], buf2[1024];
static void test_copy_bytes_regular_file_one(const char *src, bool try_reflink, uint64_t max_bytes) {
char fn2[] = "/tmp/test-copy-file-XXXXXX";
char fn3[] = "/tmp/test-copy-file-XXXXXX";
- _cleanup_close_ int fd = -1, fd2 = -1, fd3 = -1;
+ _cleanup_close_ int fd = -EBADF, fd2 = -EBADF, fd3 = -EBADF;
int r;
struct stat buf, buf2, buf3;
}
TEST(copy_data_fd) {
- _cleanup_close_ int fd1 = -1, fd2 = -1;
+ _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
_cleanup_(close_pairp) int sfd[2] = { -1, -1 };
_cleanup_(sigkill_waitp) pid_t pid = -1;
int r;
TEST(same_fd) {
_cleanup_close_pair_ int p[2] = { -1, -1 };
- _cleanup_close_ int a = -1, b = -1, c = -1;
+ _cleanup_close_ int a, b, c;
assert_se(pipe2(p, O_CLOEXEC) >= 0);
assert_se((a = fcntl(p[0], F_DUPFD, 3)) >= 0);
}
TEST(open_serialization_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open_serialization_fd("test");
assert_se(fd >= 0);
}
TEST(fd_reopen) {
- _cleanup_close_ int fd1 = -1, fd2 = -1;
+ _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
struct stat st1, st2;
int fl;
/* Also check the right error is generated if the fd is already closed */
safe_close(fd1);
assert_se(fd_reopen(fd1, O_RDONLY|O_CLOEXEC) == -EBADF);
- fd1 = -1;
+ fd1 = -EBADF;
}
TEST(fd_reopen_condition) {
- _cleanup_close_ int fd1 = -1, fd3 = -1;
+ _cleanup_close_ int fd1 = -EBADF, fd3 = -EBADF;
int fd2, fl;
/* Open without O_PATH */
}
TEST(take_fd) {
- _cleanup_close_ int fd1 = -1, fd2 = -1;
- int array[2] = { -1, -1 }, i = 0;
+ _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF;
+ int array[2] = { -EBADF, -EBADF }, i = 0;
- assert_se(fd1 == -1);
- assert_se(fd2 == -1);
+ assert_se(fd1 == -EBADF);
+ assert_se(fd2 == -EBADF);
fd1 = eventfd(0, EFD_CLOEXEC);
assert_se(fd1 >= 0);
fd2 = TAKE_FD(fd1);
- assert_se(fd1 == -1);
+ assert_se(fd1 == -EBADF);
assert_se(fd2 >= 0);
- assert_se(array[0] == -1);
- assert_se(array[1] == -1);
+ assert_se(array[0] == -EBADF);
+ assert_se(array[1] == -EBADF);
array[0] = TAKE_FD(fd2);
- assert_se(fd1 == -1);
- assert_se(fd2 == -1);
+ assert_se(fd1 == -EBADF);
+ assert_se(fd2 == -EBADF);
assert_se(array[0] >= 0);
- assert_se(array[1] == -1);
+ assert_se(array[1] == -EBADF);
array[1] = TAKE_FD(array[i]);
- assert_se(array[0] == -1);
+ assert_se(array[0] == -EBADF);
assert_se(array[1] >= 0);
i = 1 - i;
array[0] = TAKE_FD(*(array + i));
assert_se(array[0] >= 0);
- assert_se(array[1] == -1);
+ assert_se(array[1] == -EBADF);
i = 1 - i;
fd1 = TAKE_FD(array[i]);
assert_se(fd1 >= 0);
- assert_se(array[0] == -1);
- assert_se(array[1] == -1);
+ assert_se(array[0] == -EBADF);
+ assert_se(array[1] == -EBADF);
}
DEFINE_TEST_MAIN(LOG_DEBUG);
#include "tmpfile-util.h"
TEST(fdset_new_fill) {
- int fd = -1;
+ int fd = -EBADF;
_cleanup_fdset_free_ FDSet *fdset = NULL;
char name[] = "/tmp/test-fdset_new_fill.XXXXXX";
}
TEST(fdset_put_dup) {
- _cleanup_close_ int fd = -1;
- int copyfd = -1;
+ _cleanup_close_ int fd = -EBADF;
+ int copyfd = -EBADF;
_cleanup_fdset_free_ FDSet *fdset = NULL;
char name[] = "/tmp/test-fdset_put_dup.XXXXXX";
}
TEST(fdset_cloexec) {
- int fd = -1;
+ int fd = -EBADF;
_cleanup_fdset_free_ FDSet *fdset = NULL;
int flags = -1;
char name[] = "/tmp/test-fdset_cloexec.XXXXXX";
}
TEST(fdset_close_others) {
- int fd = -1;
- int copyfd = -1;
+ int fd = -EBADF;
+ int copyfd = -EBADF;
_cleanup_fdset_free_ FDSet *fdset = NULL;
int flags = -1;
char name[] = "/tmp/test-fdset_close_others.XXXXXX";
}
TEST(fdset_remove) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
FDSet *fdset = NULL;
char name[] = "/tmp/test-fdset_remove.XXXXXX";
}
TEST(fdset_iterate) {
- int fd = -1;
+ int fd = -EBADF;
FDSet *fdset = NULL;
char name[] = "/tmp/test-fdset_iterate.XXXXXX";
int c = 0;
char name[] = "/tmp/test-search_and_fopen.XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *e;
int r;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-search_and_fopen.XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *e;
int r;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
_cleanup_free_ char *contents = NULL;
size_t size;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
struct iovec iov[] = {
if (r == 0) {
union sockaddr_union peer = {};
socklen_t peerlen = sizeof(peer);
- _cleanup_close_ int rfd = -1;
+ _cleanup_close_ int rfd = -EBADF;
/* child */
rfd = accept4(listener, NULL, 0, SOCK_CLOEXEC);
TEST(chase_symlinks) {
_cleanup_free_ char *result = NULL, *pwd = NULL;
- _cleanup_close_ int pfd = -1;
+ _cleanup_close_ int pfd = -EBADF;
char *temp;
const char *top, *p, *pslash, *q, *qslash;
struct stat st;
r = chase_symlinks(p, NULL, 0, NULL, &pfd);
if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_id128_t a, b;
assert_se(pfd >= 0);
TEST(access_fd) {
_cleanup_(rmdir_and_freep) char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *a;
a = strjoina(arg_test_dir ?: "/tmp", "/access-fd.XXXXXX");
TEST(unlinkat_deallocate) {
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
assert_se(tempfn_random_child(arg_test_dir, "unlink-deallocation", &p) >= 0);
}
TEST(fsync_directory_of_file) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open_tmpfile_unlinkable(arg_test_dir, O_RDWR);
assert_se(fd >= 0);
}
static void create_binary_file(const char *p, const void *data, size_t l) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open(p, O_CREAT|O_WRONLY|O_EXCL|O_CLOEXEC, 0600);
assert_se(fd >= 0);
}
TEST(open_mkdir_at) {
- _cleanup_close_ int fd = -1, subdir_fd = -1, subsubdir_fd = -1;
+ _cleanup_close_ int fd = -EBADF, subdir_fd = -EBADF, subsubdir_fd = -EBADF;
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
assert_se(open_mkdir_at(AT_FDCWD, "/proc", O_EXCL|O_CLOEXEC, 0) == -EEXIST);
TEST(openat_report_new) {
_cleanup_free_ char *j = NULL;
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool b;
assert_se(mkdtemp_malloc(NULL, &d) >= 0);
TEST(glob_first) {
char *first, name[] = "/tmp/test-glob_first.XXXXXX";
- int fd = -1;
+ int fd = -EBADF;
int r;
fd = mkostemp_safe(name);
TEST(glob_exists) {
char name[] = "/tmp/test-glob_exists.XXXXXX";
- int fd = -1;
+ int fd = -EBADF;
int r;
fd = mkostemp_safe(name);
sd_id128_t id, id2;
char t[SD_ID128_STRING_MAX], q[SD_ID128_UUID_STRING_MAX];
_cleanup_free_ char *b = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert_se(sd_id128_randomize(&id) == 0);
printf("random: %s\n", sd_id128_to_string(id, t));
const char test_c[] = "\0\0test\0\0\0\0";
const char test_d[] = "\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0test\0\0\0test\0\0\0\0test\0\0\0\0\0\0\0\0";
const char test_e[] = "test\0\0\0\0test";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char fn[] = "/tmp/sparseXXXXXX";
fd = mkostemp(fn, O_CLOEXEC);
_cleanup_free_ char *p = NULL, *cmd = NULL;
_cleanup_(pclosep) FILE *sfdisk = NULL;
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
test_setup_logging(LOG_DEBUG);
}
TEST(fd_is_mount_point) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
assert_se(pid >= 0);
if (pid == 0) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = open("/dev/kmsg", O_RDONLY | O_CLOEXEC);
assert_se(fd > 0);
TEST(find_executable_full) {
char *p;
char* test_file_name;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char fn[] = "/tmp/test-XXXXXX";
assert_se(find_executable_full("sh", NULL, NULL, true, &p, NULL) == 0);
static void test_find_executable_exec_one(const char *path) {
_cleanup_free_ char *t = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
pid_t pid;
int r;
TEST(get_process_cmdline_harder) {
char path[] = "/tmp/test-cmdlineXXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *line = NULL;
pid_t pid;
TEST(read_mem_pressure) {
_cleanup_(unlink_tempfilep) char path[] = "/tmp/pressurereadtestXXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
ResourcePressure rp;
if (geteuid() != 0)
if (pid == 0) {
char path[] = "/tmp/suidsgidXXXXXX", dir[] = "/tmp/suidsgiddirXXXXXX";
- int fd = -1, k = -1;
+ int fd = -EBADF, k = -EBADF;
const char *z;
fd = mkostemp_safe(path);
static void test_misc(const char* fname) {
_cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
int r;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
log_info("============ %s ==========", __func__);
#include "tests.h"
int main(int argc, char *argv[]) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char template[] = "/tmp/sigbus-test-XXXXXX";
void *addr = NULL;
uint8_t *p;
static int test_fiemap_one(const char *path) {
_cleanup_free_ struct fiemap *fiemap = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
log_info("/* %s */", __func__);
/* Parent */
char buf[64];
struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1);
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd;
pair[1] = safe_close(pair[1]);
/* Parent */
char buf[64];
struct iovec iov = IOVEC_INIT(buf, sizeof(buf)-1);
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd;
ssize_t k;
pair[1] = safe_close(pair[1]);
assert_se(streq(buf, wire_contents));
/* no fd passed here, confirm it was reset */
- assert_se(fd == -1);
+ assert_se(fd == -EBADF);
}
TEST(send_nodata_nofd) {
}
TEST(flush_accept) {
- _cleanup_close_ int listen_stream = -1, listen_dgram = -1, listen_seqpacket = 1, connect_stream = -1, connect_dgram = -1, connect_seqpacket = -1;
+ _cleanup_close_ int listen_stream, listen_dgram, listen_seqpacket, connect_stream, connect_dgram, connect_seqpacket;
static const union sockaddr_union sa = { .un.sun_family = AF_UNIX };
union sockaddr_union lsa;
socklen_t l;
_cleanup_(unlink_and_freep) char *sh = NULL;
_cleanup_free_ char *j = NULL;
union sockaddr_union sa;
- _cleanup_close_ int fd1 = -1, fd2 = -1, fd3 = -1;
+ _cleanup_close_ int fd1, fd2, fd3;
assert_se(mkdtemp_malloc("/tmp/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaXXXXXX", &t) >= 0);
assert_se(strlen(t) > SUN_PATH_LEN);
}
TEST(files_same) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char name[] = "/tmp/test-files_same.XXXXXX";
char name_alias[] = "/tmp/test-files_same.alias";
TEST(is_symlink) {
char name[] = "/tmp/test-is_symlink.XXXXXX";
char name_link[] = "/tmp/test-is_symlink.link";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = mkostemp_safe(name);
assert_se(fd >= 0);
}
TEST(fd_is_ns) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert_se(fd_is_ns(STDIN_FILENO, CLONE_NEWNET) == 0);
assert_se(fd_is_ns(STDERR_FILENO, CLONE_NEWNET) == 0);
TEST(tmpfiles) {
_cleanup_free_ char *cmd = NULL, *cmd2 = NULL, *ans = NULL, *ans2 = NULL, *d = NULL, *tmp = NULL, *line = NULL;
- _cleanup_close_ int fd = -1, fd2 = -1;
+ _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
const char *p = saved_argv[1] ?: "/tmp";
char *pattern;
#define OVERLOAD_CONNECTIONS 333
static int n_done = 0;
-static int block_write_fd = -1;
+static int block_write_fd = -EBADF;
static int method_something(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
_cleanup_(json_variant_unrefp) JsonVariant *ret = NULL;
TEST(getxattr_at_malloc) {
char t[] = "/var/tmp/xattrtestXXXXXX";
_cleanup_free_ char *value = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *x;
int r;
}
TEST(getcrtime) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *vt;
usec_t usec, k;
int r;
static int load_clock_timestamp(uid_t uid, gid_t gid) {
usec_t min = TIME_EPOCH * USEC_PER_SEC, ct;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
/* Let's try to make sure that the clock is always
static int run(int argc, char * argv[]) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(clock_state_release) ClockState state = {
- .timerfd_fd = -1,
- .inotify_fd = -1,
+ .timerfd_fd = -EBADF,
+ .inotify_fd = -EBADF,
.run_systemd_wd = -1,
.run_systemd_timesync_wd = -1,
};
static int open_passwd_file(const char *root, const char *fname, FILE **ret_file) {
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = chase_symlinks_and_open(fname, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, &p);
if (fd < 0)
const char *path,
CreationMode creation) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(i);
assert(path);
const char *path,
CreationMode creation) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(i);
assert(path);
static int path_set_acls(Item *item, const char *path, CreationMode creation) {
int r = 0;
#if HAVE_ACL
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(item);
assert(path);
const struct stat *st,
CreationMode creation) {
- _cleanup_close_ int procfs_fd = -1;
+ _cleanup_close_ int procfs_fd = -EBADF;
struct stat stbuf;
unsigned f;
int r;
}
static int path_set_attribute(Item *item, const char *path, CreationMode creation) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
if (!item->attribute_set || item->attribute_mask == 0)
return 0;
}
static int write_one_file(Item *i, const char *path, CreationMode creation) {
- _cleanup_close_ int fd = -1, dir_fd = -1;
+ _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
_cleanup_free_ char *bn = NULL;
int r;
}
static int create_file(Item *i, const char *path) {
- _cleanup_close_ int fd = -1, dir_fd = -1;
+ _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
_cleanup_free_ char *bn = NULL;
struct stat stbuf, *st = NULL;
CreationMode creation;
}
static int truncate_file(Item *i, const char *path) {
- _cleanup_close_ int fd = -1, dir_fd = -1;
+ _cleanup_close_ int fd = -EBADF, dir_fd = -EBADF;
_cleanup_free_ char *bn = NULL;
struct stat stbuf, *st = NULL;
CreationMode creation;
}
static int copy_files(Item *i) {
- _cleanup_close_ int dfd = -1, fd = -1;
+ _cleanup_close_ int dfd = -EBADF, fd = -EBADF;
_cleanup_free_ char *bn = NULL;
struct stat st, a;
int r;
CreationMode *ret_creation) {
_cleanup_free_ char *bn = NULL;
- _cleanup_close_ int pfd = -1;
+ _cleanup_close_ int pfd = -EBADF;
CreationMode creation;
struct stat st;
int r, fd;
}
static int create_directory(Item *i, const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
CreationMode creation;
struct stat st;
}
static int create_subvolume(Item *i, const char *path) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
CreationMode creation;
struct stat st;
int r, q = 0;
}
static int empty_directory(Item *i, const char *path, CreationMode creation) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
}
static int create_device(Item *i, mode_t file_type) {
- _cleanup_close_ int dfd = -1, fd = -1;
+ _cleanup_close_ int dfd = -EBADF, fd = -EBADF;
_cleanup_free_ char *bn = NULL;
CreationMode creation;
struct stat st;
}
static int create_fifo(Item *i) {
- _cleanup_close_ int pfd = -1, fd = -1;
+ _cleanup_close_ int pfd = -EBADF, fd = -EBADF;
_cleanup_free_ char *bn = NULL;
CreationMode creation;
struct stat st;
}
static int create_symlink(Item *i) {
- _cleanup_close_ int pfd = -1, fd = -1;
+ _cleanup_close_ int pfd = -EBADF, fd = -EBADF;
_cleanup_free_ char *bn = NULL;
CreationMode creation;
struct stat st;
return log_error_errno(k, "glob(%s) failed: %m", i->path);
STRV_FOREACH(fn, g.gl_pathv) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
/* Make sure we won't trigger/follow file object (such as
* device nodes, automounts, ...) pointed out by 'fn' with
r = k;
/* we passed fd ownership to the previous call */
- fd = -1;
+ fd = -EBADF;
}
return r;
"Not removing \"%s/%s\" because it is a mount point.", strna(parent_name), name);
if ((st.st_mode & S_IFMT) == S_IFDIR) {
- _cleanup_close_ int child_fd = -1;
+ _cleanup_close_ int child_fd = -EBADF;
child_fd = openat(parent_fd, name, O_NOCTTY | O_CLOEXEC | O_DIRECTORY);
if (child_fd < 0)
/* If child_mode is non-zero, rm_if_wrong_type_safe will be executed for the last path component. */
static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
- _cleanup_close_ int parent_fd = -1;
+ _cleanup_close_ int parent_fd = -EBADF;
struct stat parent_st;
size_t path_len;
int r;
/* Check every parent directory in the path, except the last component */
for (const char *e = path;;) {
- _cleanup_close_ int next_fd = -1;
+ _cleanup_close_ int next_fd = -EBADF;
char t[path_len + 1];
const char *s;
static int send_passwords(const char *socket_name, char **passwords) {
_cleanup_(erase_and_freep) char *packet = NULL;
- _cleanup_close_ int socket_fd = -1;
+ _cleanup_close_ int socket_fd = -EBADF;
union sockaddr_union sa;
socklen_t sa_len;
size_t packet_length = 1;
static bool wall_tty_match(const char *path, bool is_local, void *userdata) {
_cleanup_free_ char *p = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
assert(path_is_absolute(path));
const char *flag_file,
char ***ret) {
- int tty_fd = -1, r;
+ int tty_fd = -EBADF, r;
const char *con = arg_device ?: "/dev/console";
if (arg_console) {
_FD_MAX
};
- _unused_ _cleanup_close_ int tty_block_fd = -1;
- _cleanup_close_ int notify = -1, signal_fd = -1;
+ _unused_ _cleanup_close_ int tty_block_fd = -EBADF;
+ _cleanup_close_ int notify = -1, signal_fd = -EBADF;
struct pollfd pollfd[_FD_MAX];
sigset_t mask;
int r;
char revision[9];
const char *node = NULL;
int export = 0;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
uint16_t word;
int is_packet_device = 0;
static const struct option options[] = {
} Context;
#define CONTEXT_EMPTY { \
- .fd = -1, \
+ .fd = -EBADF, \
.media_feature = _FEATURE_INVALID, \
.media_state = _MEDIA_STATE_INVALID, \
}
static int run(int argc, char **argv) {
_cleanup_(sd_device_unrefp) struct sd_device *device = NULL;
_cleanup_free_ char *desc_path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct sd_device *hid_device;
const char *sys_path;
#include "mtd_probe.h"
int main(int argc, char** argv) {
- _cleanup_close_ int mtd_fd = -1;
+ _cleanup_close_ int mtd_fd = -EBADF;
mtd_info_t mtd_info;
if (argc != 2) {
return -ENOMEM;
*ctx = (LinkConfigContext) {
- .ethtool_fd = -1,
+ .ethtool_fd = -EBADF,
};
*ret = TAKE_PTR(ctx);
int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname,
int page_code, int len) {
unsigned char page0[SCSI_INQ_BUFF_LEN];
- int fd = -1;
+ int fd = -EBADF;
int cnt;
int ind;
int retval;
const char *devnode, *root_partition = NULL, *data, *name;
_cleanup_(blkid_free_probep) blkid_probe pr = NULL;
bool noraid = false, is_gpt = false;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int64_t offset = 0;
int r;
static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
struct btrfs_ioctl_vol_args args = {};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
if (argc != 3 || !streq(argv[1], "ready"))
static void extract_info(sd_device *dev, bool test) {
char width[DECIMAL_STR_MAX(int)], height[DECIMAL_STR_MAX(int)];
struct input_absinfo xabsinfo = {}, yabsinfo = {};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
static int builtin_keyboard(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
unsigned release[1024];
unsigned release_count = 0;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *node, *key, *value;
int has_abs = -1, r;
#define USB_DT_INTERFACE 0x04
static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
ssize_t size;
unsigned char buf[18 + 65535];
size_t pos = 0;
}
static int stack_directory_open(const char *dirname) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
int r;
assert(dirname);
}
static int stack_directory_lock(int dirfd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
assert(dirfd >= 0);
static int link_update(sd_device *dev, const char *slink, bool add) {
_cleanup_free_ char *dirname = NULL, *devnode = NULL;
- _cleanup_close_ int dirfd = -1, lockfd = -1;
+ _cleanup_close_ int dirfd = -EBADF, lockfd = -EBADF;
int r;
assert(dev);
OrderedHashmap *seclabel_list) {
const char *devnode;
- _cleanup_close_ int node_fd = -1;
+ _cleanup_close_ int node_fd = -EBADF;
int r;
assert(dev);
char **tags) {
_cleanup_free_ char *unescaped_filename = NULL;
- _cleanup_close_ int node_fd = -1;
+ _cleanup_close_ int node_fd = -EBADF;
const char *devnode;
struct stat stats;
int r;
int udev_watch_begin(int inotify_fd, sd_device *dev) {
char wd_str[DECIMAL_STR_MAX(int)];
- _cleanup_close_ int dirfd = -1;
+ _cleanup_close_ int dirfd = -EBADF;
const char *devnode, *id;
int wd, r;
}
int udev_watch_end(int inotify_fd, sd_device *dev) {
- _cleanup_close_ int dirfd = -1;
+ _cleanup_close_ int dirfd = -EBADF;
int wd, r;
assert(dev);
dev_t devno,
usec_t deadline) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
if (arg_print)
printf("%s\n", node);
else {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
fd = lock_device(node, devnos[i], deadline);
if (fd < 0)
}
static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_device *dev_whole_disk;
const char *val;
int r;
return 1;
nolock:
- *ret_fd = -1;
+ *ret_fd = -EBADF;
return 0;
}
static int worker_mark_block_device_read_only(sd_device *dev) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *val;
int state = 1, r;
static int worker_process_device(Manager *manager, sd_device *dev) {
_cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
- _cleanup_close_ int fd_lock = -1;
+ _cleanup_close_ int fd_lock = -EBADF;
int r;
assert(manager);
}
static int listen_fds(int *ret_ctrl, int *ret_netlink) {
- int ctrl_fd = -1, netlink_fd = -1;
+ int ctrl_fd = -EBADF, netlink_fd = -EBADF;
int fd, n;
assert(ret_ctrl);
return log_oom();
*manager = (Manager) {
- .inotify_fd = -1,
+ .inotify_fd = -EBADF,
.worker_watch = { -1, -1 },
.cgroup = TAKE_PTR(cgroup),
};
int run_udevd(int argc, char *argv[]) {
_cleanup_(manager_freep) Manager *manager = NULL;
- int fd_ctrl = -1, fd_uevent = -1;
+ int fd_ctrl = -EBADF, fd_uevent = -EBADF;
int r;
log_set_target(LOG_TARGET_AUTO);
{ "help", no_argument, NULL, 'h' },
{}
};
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char *device;
struct v4l2_capability v2cap;
int c;
#if HAVE_AUDIT
if (c->audit_fd >= 0)
audit_close(c->audit_fd);
- c->audit_fd = -1;
+ c->audit_fd = -EBADF;
#endif
}
static int run(int argc, char *argv[]) {
_cleanup_(context_clear) Context c = {
#if HAVE_AUDIT
- .audit_fd = -1,
+ .audit_fd = -EBADF,
#endif
};
int r;
FOREACH_DIRENT(de, d, return -errno) {
_cleanup_free_ char *j = NULL, *no = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
j = path_join("/run/systemd/userdb/", de->d_name);
if (!j)
return -ENOMEM;
*m = (Manager) {
- .listen_fd = -1,
+ .listen_fd = -EBADF,
.worker_ratelimit = {
.interval = 5 * USEC_PER_SEC,
.burst = 50,
start_time = now(CLOCK_MONOTONIC);
for (;;) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
usec_t n;
/* Exit the worker in regular intervals, to flush out all memory use */
for (i = 1; i <= 63; i++) {
char ttyname[sizeof("/dev/tty63")];
- _cleanup_close_ int fd_d = -1;
+ _cleanup_close_ int fd_d = -EBADF;
if (i == src_idx || verify_vc_allocation(i) < 0)
continue;
return log_oom();
for (i = 1; i <= 63; i++) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
r = verify_vc_allocation(i);
if (r < 0) {
}
static int verify_source_vc(char **ret_path, const char *src_vc) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
char *path;
int r;
*vc = NULL,
*vc_keymap = NULL, *vc_keymap_toggle = NULL,
*vc_font = NULL, *vc_font_map = NULL, *vc_font_unimap = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
bool utf8, keyboard_ok;
unsigned idx = 0;
int r;
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(unlink_tempfilep) char name[] = "/tmp/fuzz-xdg-desktop.XXXXXX";
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
_cleanup_(xdg_autostart_service_freep) XdgAutostartService *service = NULL;
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;