tree-wide: use -EBADF for fd initialization

-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-12-19 13:07:42 +01:00
parent cbff793ffb
commit 254d1313ae
284 changed files with 792 additions and 793 deletions

View file

@ -3,17 +3,17 @@
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);

View file

@ -213,7 +213,7 @@ int lock_whole_disk_from_devname(const char *devname, int open_flags, int flock_
// take the fd to avoid automatic cleanup
int ret_fd = fd;
fd = -1;
fd = -EBADF;
return ret_fd;
}

View file

@ -233,7 +233,7 @@ static int fork_and_exec_process(const char *child, char **argv, int 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) {
@ -434,7 +434,7 @@ static int parse_argv(int argc, char *argv[]) {
int main(int argc, char **argv) {
int r, n;
int epoll_fd = -1;
int epoll_fd = -EBADF;
log_show_color(true);
log_parse_environment();

View file

@ -18,7 +18,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) {
_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)

View file

@ -80,7 +80,7 @@ int chase_symlinks_at(
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;
@ -227,7 +227,7 @@ int chase_symlinks_at(
/* 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. */
@ -415,7 +415,7 @@ int chase_symlinks(
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);
@ -496,7 +496,7 @@ int chase_symlinks_and_open(
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;
@ -534,7 +534,7 @@ int chase_symlinks_and_opendir(
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;
@ -578,7 +578,7 @@ int chase_symlinks_and_stat(
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;
@ -621,7 +621,7 @@ int chase_symlinks_and_access(
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;
@ -665,7 +665,7 @@ int chase_symlinks_and_fopen_unlocked(
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);

View file

@ -20,7 +20,7 @@ int chattr_full(const char *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;
@ -149,7 +149,7 @@ int read_attr_fd(int fd, unsigned *ret) {
}
int read_attr_path(const char *p, unsigned *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(p);
assert(ret);

View file

@ -37,7 +37,7 @@ int efi_get_variable(
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 */
@ -181,7 +181,7 @@ int efi_set_variable(const char *variable, const void *value, size_t size) {
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;

View file

@ -56,11 +56,9 @@ int close_nointr(int fd) {
}
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);
*/
@ -76,7 +74,7 @@ int safe_close(int fd) {
assert_se(close_nointr(fd) != -EBADF);
}
return -1;
return -EBADF;
}
void safe_close_pair(int p[static 2]) {
@ -412,7 +410,7 @@ int close_all_fds(const int except[], size_t n_except) {
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;
@ -639,17 +637,19 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
};
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!
*
@ -701,9 +701,9 @@ int rearrange_stdio(int original_input_fd, int original_output_fd, int original_
}
}
/* 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) {
@ -800,7 +800,7 @@ int fd_reopen_condition(
return -errno;
if ((r & mask) == (flags & mask)) {
*ret_new_fd = -1;
*ret_new_fd = -EBADF;
return fd;
}

View file

@ -94,7 +94,7 @@ static inline int make_null_stdio(void) {
({ \
int *_fd_ = &(fd); \
int _ret_ = *_fd_; \
*_fd_ = -1; \
*_fd_ = -EBADF; \
_ret_; \
})

View file

@ -80,7 +80,7 @@ int take_fdopen_unlocked(int *fd, const char *options, FILE **ret) {
if (r < 0)
return r;
*fd = -1;
*fd = -EBADF;
return 0;
}
@ -92,7 +92,7 @@ FILE* take_fdopen(int *fd, const char *options) {
if (!f)
return NULL;
*fd = -1;
*fd = -EBADF;
return f;
}
@ -104,7 +104,7 @@ DIR* take_fdopendir(int *dfd) {
if (!d)
return NULL;
*dfd = -1;
*dfd = -EBADF;
return d;
}
@ -136,7 +136,7 @@ int write_string_stream_ts(
const struct timespec *ts) {
bool needs_nl;
int r, fd = -1;
int r, fd = -EBADF;
assert(f);
assert(line);
@ -558,7 +558,7 @@ int read_virtual_file_at(
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);

View file

@ -195,7 +195,7 @@ int readlink_and_make_absolute(const char *p, char **r) {
}
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);
@ -360,7 +360,7 @@ int fd_warn_permissions(const char *path, int fd) {
}
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);
@ -684,7 +684,7 @@ void unlink_tempfilep(char (*p)[]) {
}
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;
@ -815,7 +815,7 @@ int conservative_renameat(
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
@ -997,7 +997,7 @@ int parse_cifs_service(
}
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;

View file

@ -95,7 +95,7 @@ static int add_locales_from_archive(Set *locales) {
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;

View file

@ -48,9 +48,9 @@ static int log_max_level = LOG_INFO;
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;
@ -345,7 +345,7 @@ void log_close(void) {
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) {

View file

@ -113,7 +113,7 @@ int memfd_set_size(int fd, uint64_t sz) {
}
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);

View file

@ -211,7 +211,7 @@ int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, g
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);
@ -250,7 +250,7 @@ int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m
}
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)

View file

@ -97,7 +97,7 @@ int name_to_handle_at_loop(
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;
@ -322,7 +322,7 @@ fallback_fstat:
/* 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);
@ -550,7 +550,7 @@ int mount_nofollow(
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

View file

@ -34,8 +34,8 @@ const struct namespace_info namespace_info[] = {
#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);
@ -113,7 +113,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
if (r < 0)
return r;
if (r)
userns_fd = -1;
userns_fd = -EBADF;
}
if (pidns_fd >= 0)
@ -202,7 +202,7 @@ int detach_mount_namespace(void) {
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);

View file

@ -227,7 +227,7 @@ int open_extension_release(const char *root, const char *extension, bool relax_e
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;

View file

@ -587,7 +587,7 @@ char* path_extend_internal(char **x, ...) {
}
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
@ -615,7 +615,7 @@ static int check_x_access(const char *path, int *ret_fd) {
}
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;

View file

@ -75,7 +75,7 @@ static void fallback_random_bytes(void *p, size_t n) {
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;
@ -117,7 +117,7 @@ void random_bytes(void *p, size_t n) {
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;
@ -145,7 +145,7 @@ int crypto_random_bytes(void *p, size_t n) {
}
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);
@ -187,7 +187,7 @@ size_t random_pool_size(void) {
}
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);

View file

@ -182,7 +182,7 @@ int recurse_dir(
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;
@ -490,7 +490,7 @@ int recurse_dir_at(
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);

View file

@ -1049,7 +1049,7 @@ ssize_t receive_one_fd_iov(
if (found)
*ret_fd = *(int*) CMSG_DATA(found);
else
*ret_fd = -1;
*ret_fd = -EBADF;
return k;
}
@ -1426,7 +1426,7 @@ int socket_get_mtu(int fd, int af, size_t *ret) {
}
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,
};

View file

@ -65,7 +65,7 @@ int is_device_node(const char *path) {
}
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;

View file

@ -9,7 +9,7 @@
#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;
@ -86,7 +86,7 @@ int fsync_full(int fd) {
}
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)) {
@ -110,7 +110,7 @@ int fsync_path_at(int at_fd, const char *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)
@ -131,7 +131,7 @@ int fsync_parent_at(int at_fd, const char *path) {
}
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)
@ -147,7 +147,7 @@ int fsync_path_and_parent_at(int at_fd, const char *path) {
}
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)

View file

@ -53,7 +53,7 @@ static volatile int cached_color_mode = _COLOR_INVALID;
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. */
@ -300,7 +300,7 @@ finish:
}
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
@ -314,7 +314,7 @@ int reset_terminal(const char *name) {
}
int open_terminal(const char *name, int mode) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
unsigned c = 0;
/*
@ -355,7 +355,7 @@ int acquire_terminal(
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;
@ -483,7 +483,7 @@ int release_terminal(void) {
.sa_flags = SA_RESTART,
};
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct sigaction sa_old;
int r;
@ -508,7 +508,7 @@ int terminal_vhangup_fd(int fd) {
}
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)
@ -530,7 +530,7 @@ int vt_disallocate(const char *name) {
return -EINVAL;
if (tty_is_vc(name)) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
unsigned u;
const char *n;
@ -1083,7 +1083,7 @@ int ptsname_malloc(int fd, char **ret) {
}
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;
@ -1129,7 +1129,7 @@ static int ptsname_namespace(int pty, char **ret) {
}
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;
@ -1182,7 +1182,7 @@ int openpt_allocate_in_namespace(pid_t pid, int flags, char **ret_slave) {
}
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;

View file

@ -1395,7 +1395,7 @@ int get_timezones(char ***ret) {
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;
@ -1568,7 +1568,7 @@ int time_change_fd(void) {
.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));

View file

@ -21,7 +21,7 @@
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);
@ -101,7 +101,7 @@ int mkostemp_safe(char *pattern) {
}
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);
@ -309,7 +309,7 @@ int open_tmpfile_linkable(const char *target, int flags, char **ret_path) {
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);

View file

@ -26,7 +26,7 @@ int getxattr_at_malloc(
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;
@ -212,7 +212,7 @@ int listxattr_at_malloc(
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;

View file

@ -360,7 +360,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
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) {
@ -439,7 +439,7 @@ static int verb_set(int argc, char *argv[], void *userdata) {
}
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)

View file

@ -299,7 +299,7 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
}
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;
@ -899,7 +899,7 @@ static int remove_boot_efi(const char *esp_path) {
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"))

View file

@ -19,7 +19,7 @@ int install_random_seed(const char *esp) {
_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;

View file

@ -205,7 +205,7 @@ static int enumerate_binaries(
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;

View file

@ -427,7 +427,7 @@ static int measure_kernel(PcrState *pcr_states, size_t n) {
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])

View file

@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
.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;

View file

@ -73,7 +73,7 @@ static void automount_init(Unit *u) {
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;
}
@ -392,7 +392,7 @@ static int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) {
init_autofs_dev_ioctl(param);
param->size = l;
param->ioctlfd = -1;
param->ioctlfd = -EBADF;
param->openmount.devid = devid;
strcpy(param->path, where);
@ -470,7 +470,7 @@ static int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, in
}
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;
@ -572,7 +572,7 @@ static void automount_trigger_notify(Unit *u, Unit *other) {
}
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;
@ -707,7 +707,7 @@ static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void
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)

View file

@ -411,7 +411,7 @@ static int bpf_firewall_prepare_access_maps(
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;
@ -874,8 +874,8 @@ int bpf_firewall_supported(void) {
// 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) {
@ -902,8 +902,8 @@ int bpf_firewall_supported(void) {
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) {

View file

@ -55,7 +55,7 @@ static bool bpf_can_link_lsm_program(struct bpf_program *prog) {
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);

View file

@ -156,7 +156,7 @@ static int socket_bind_install_impl(Unit *u) {
_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;

View file

@ -1379,7 +1379,7 @@ static int method_dump(sd_bus_message *message, void *userdata, sd_bus_error *er
}
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)

View file

@ -112,7 +112,7 @@ static int bus_path_set_transient_property(
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);

View file

@ -371,7 +371,7 @@ static int bus_socket_set_transient_property(
return log_oom();
*p = (SocketPort) {
.fd = -1,
.fd = -EBADF,
.socket = s,
};

View file

@ -649,7 +649,7 @@ static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
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;
@ -684,7 +684,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
return 0;
}
nfd = -1;
nfd = -EBADF;
r = bus_check_peercred(bus);
if (r < 0) {
@ -897,7 +897,7 @@ int bus_init_system(Manager *m) {
}
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;

View file

@ -211,7 +211,7 @@ static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) {
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;
@ -373,7 +373,7 @@ static void unlockfp(int *fd_lock) {
if (*fd_lock < 0)
return;
lockf(*fd_lock, F_ULOCK, 0);
*fd_lock = -1;
*fd_lock = -EBADF;
}
static int dynamic_user_realize(
@ -383,8 +383,8 @@ 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;
@ -525,7 +525,7 @@ static int dynamic_user_realize(
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;
@ -568,7 +568,7 @@ static DynamicUser* dynamic_user_unref(DynamicUser *d) {
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;

View file

@ -13,7 +13,7 @@
#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);

View file

@ -329,7 +329,7 @@ static int connect_logger_as(
uid_t uid,
gid_t gid) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(context);
@ -385,7 +385,7 @@ static int open_terminal_as(const char *path, int flags, int nfd) {
}
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);
@ -766,7 +766,7 @@ static int setup_confirm_stdio(
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);
@ -818,7 +818,7 @@ static void write_confirm_error_fd(int err, int fd, const Unit *u) {
}
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);
@ -2100,7 +2100,7 @@ bool exec_needs_mount_namespace(
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;
@ -2159,7 +2159,7 @@ static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) {
if (r < 0)
return r;
if (r == 0) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
const char *a;
pid_t ppid;
@ -2554,7 +2554,7 @@ static int write_credential(
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);
@ -2852,7 +2852,7 @@ static int acquire_credentials(
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;
@ -2866,7 +2866,7 @@ static int acquire_credentials(
/* 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
@ -4084,7 +4084,7 @@ static int add_shifted_fd(int *fds, size_t fds_size, size_t *n_fds, int fd, int
assert(ret_fd);
if (fd < 0) {
*ret_fd = -1;
*ret_fd = -EBADF;
return 0;
}
@ -4781,7 +4781,7 @@ static int exec_child(
* 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)) {
@ -4812,7 +4812,7 @@ static int exec_child(
#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;
@ -5211,7 +5211,7 @@ int exec_spawn(Unit *unit,
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;
@ -6279,7 +6279,7 @@ void exec_context_free_log_extra_fields(ExecContext *c) {
}
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;

View file

@ -23,7 +23,7 @@
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;

View file

@ -146,7 +146,7 @@ static int finalize_credentials_dir(const char *dir, const char *envvar) {
static int import_credentials_boot(void) {
_cleanup_(import_credentials_context_free) ImportCredentialContext context = {
.target_dir_fd = -1,
.target_dir_fd = -EBADF,
};
int r;
@ -165,7 +165,7 @@ static int import_credentials_boot(void) {
"/.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) {
@ -186,7 +186,7 @@ static int import_credentials_boot(void) {
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;
@ -294,7 +294,7 @@ static int acquire_credential_directory(ImportCredentialContext *c) {
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;
@ -365,7 +365,7 @@ static int import_credentials_proc_cmdline(ImportCredentialContext *c) {
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);
@ -389,7 +389,7 @@ static int import_credentials_qemu(ImportCredentialContext *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;
@ -468,7 +468,7 @@ static int parse_smbios_strings(ImportCredentialContext *c, const char *data, si
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;
@ -606,7 +606,7 @@ static int import_credentials_smbios(ImportCredentialContext *c) {
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;

View file

@ -674,7 +674,7 @@ int config_parse_socket_listen(
p->type = SOCKET_SOCKET;
}
p->fd = -1;
p->fd = -EBADF;
p->auxiliary_fds = NULL;
p->n_auxiliary_fds = 0;
p->socket = s;
@ -2232,7 +2232,7 @@ int config_parse_path_spec(const char *unit,
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);

View file

@ -213,7 +213,7 @@ static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
}
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);

View file

@ -18,7 +18,7 @@
#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);

View file

@ -495,7 +495,7 @@ static int manager_setup_timezone_change(Manager *m) {
}
static int enable_special_signals(Manager *m) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(m);
@ -848,16 +848,16 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager *
.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,
@ -1000,7 +1000,7 @@ static int manager_setup_notify(Manager *m) {
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;
@ -1091,7 +1091,7 @@ static int manager_setup_cgroups_agent(Manager *m) {
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);
@ -3187,7 +3187,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
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

View file

@ -886,10 +886,10 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
_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;

View file

@ -1075,7 +1075,7 @@ static int mount_sysfs(const MountEntry *m) {
}
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
@ -2698,7 +2698,7 @@ int temporary_filesystem_add(
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 */

View file

@ -265,7 +265,7 @@ static void path_spec_dump(PathSpec *s, FILE *f, const char *prefix) {
void path_spec_done(PathSpec *s) {
assert(s);
assert(s->inotify_fd == -1);
assert(s->inotify_fd == -EBADF);
free(s->path);
}

View file

@ -101,7 +101,7 @@ static int restrict_network_interfaces_install_impl(Unit *u) {
_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;

View file

@ -111,8 +111,8 @@ static void service_init(Unit *u) {
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;
@ -480,7 +480,7 @@ static int service_add_fd_store_set(Service *s, FDSet *fds, const char *name, bo
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)
@ -495,7 +495,7 @@ static int service_add_fd_store_set(Service *s, FDSet *fds, const char *name, bo
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;
@ -959,7 +959,7 @@ static int service_is_suitable_main_pid(Service *s, pid_t pid, int prio) {
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;
@ -1483,10 +1483,10 @@ static int service_spawn_internal(
_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;
@ -3241,7 +3241,7 @@ static int service_demand_pid_file(Service *s) {
/* 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;

View file

@ -39,7 +39,7 @@ int parse_show_status(const char *v, ShowStatus *ret) {
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;

View file

@ -48,9 +48,9 @@ static int fdopen_unlocked_at(int dfd, const char *dir, const char *name, int *s
}
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) {
@ -120,9 +120,9 @@ static int write_access2_rules(const char *srcdir) {
}
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) {
@ -181,7 +181,7 @@ static int write_cipso2_rules(const char *srcdir) {
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) {
@ -238,7 +238,7 @@ static int write_netlabel_rules(const char *srcdir) {
}
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;

View file

@ -1116,7 +1116,7 @@ static int fifo_address_create(
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;
@ -1172,7 +1172,7 @@ fail:
}
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);
@ -1192,7 +1192,7 @@ static int special_address_create(const char *path, bool writable) {
}
static int usbffs_address_create(const char *path) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct stat st;
assert(path);
@ -1217,7 +1217,7 @@ static int mq_address_create(
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;
@ -1918,10 +1918,10 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
_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;
@ -2978,7 +2978,7 @@ shortcut:
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);

View file

@ -660,10 +660,10 @@ static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) {
_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;

View file

@ -115,15 +115,15 @@ Unit* unit_new(Manager *m, size_t size) {
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;
@ -5274,7 +5274,7 @@ static int unit_export_log_level_max(Unit *u, const ExecContext *c) {
}
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;

View file

@ -344,7 +344,7 @@ static int save_external_coredump(
_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;
@ -458,7 +458,7 @@ static int save_external_coredump(
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)
@ -584,7 +584,7 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
*/
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;
@ -610,7 +610,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
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)
@ -656,7 +656,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
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");
@ -771,7 +771,7 @@ static int submit_coredump(
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;
@ -976,7 +976,7 @@ static int save_context(Context *context, const struct iovec_wrapper *iovw) {
}
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;
@ -1074,7 +1074,7 @@ finish:
}
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);

View file

@ -451,7 +451,7 @@ static void analyze_coredump_file(
const char **ret_color,
uint64_t *ret_size) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
@ -965,7 +965,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
_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 */
@ -1047,7 +1047,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
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) {

View file

@ -137,7 +137,7 @@ static int add_credentials_to_table(Table *t, bool encrypted) {
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;

View file

@ -859,7 +859,7 @@ static int list_print_item(
}
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 */
@ -1063,7 +1063,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
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)
@ -1108,7 +1108,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
/* 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);
@ -1177,7 +1177,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
/* 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)
@ -1199,7 +1199,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
}
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;
@ -1219,7 +1219,7 @@ static int action_umount(const char *path) {
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

View file

@ -225,7 +225,7 @@ static int process_progress(int fd, FILE* console) {
}
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);

View file

@ -106,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
(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)

View file

@ -8,7 +8,7 @@
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"))

View file

@ -78,7 +78,7 @@ static int add_container_getty(const char *tty) {
}
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

View file

@ -1964,7 +1964,7 @@ static int with_home(int argc, char *argv[], void *userdata) {
_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;

View file

@ -597,7 +597,7 @@ int bus_home_method_acquire(
_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);
@ -635,7 +635,7 @@ int bus_home_method_ref(
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;

View file

@ -135,11 +135,11 @@ int home_new(Manager *m, UserRecord *hr, const char *sysfs, Home **ret) {
.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);
@ -1137,7 +1137,7 @@ static int home_on_worker_process(sd_event_source *s, const siginfo_t *si, void
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;
@ -1496,7 +1496,7 @@ int home_create(Home *h, UserRecord *secret, sd_bus_error *error) {
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);
@ -2630,7 +2630,7 @@ static int on_home_ref_eof(sd_event_source *s, int fd, uint32_t revents, void *u
}
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;
@ -2648,7 +2648,7 @@ int home_create_fifo(Home *h, bool please_suspend) {
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)

View file

@ -860,7 +860,7 @@ static int manager_assess_image(
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)
@ -1041,7 +1041,7 @@ static ssize_t read_datagram(
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;
@ -1119,7 +1119,7 @@ static ssize_t read_datagram(
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;
@ -1154,7 +1154,7 @@ static int on_notify_socket(sd_event_source *s, int fd, uint32_t revents, void *
}
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",

View file

@ -17,7 +17,7 @@ Operation *operation_new(OperationType type, sd_bus_message *m) {
.type = type,
.n_ref = 1,
.message = sd_bus_message_ref(m),
.send_fd = -1,
.send_fd = -EBADF,
.result = -1,
};

View file

@ -108,7 +108,7 @@ int home_activate_directory(
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;

View file

@ -491,7 +491,7 @@ int home_create_fscrypt(
_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;

View file

@ -108,7 +108,7 @@ int run_mark_dirty(int fd, bool b) {
}
int run_mark_dirty_by_path(const char *path, bool b) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
@ -178,7 +178,7 @@ static int probe_file_system_by_fd(
}
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)
@ -203,7 +203,7 @@ static int block_get_size_by_fd(int fd, uint64_t *ret) {
}
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)
@ -1135,7 +1135,7 @@ int run_fallocate(int backing_fd, const struct stat *st) {
}
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)
@ -1187,7 +1187,7 @@ static int open_image_file(
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;
@ -1959,7 +1959,7 @@ static bool supported_fs_size(const char *fstype, uint64_t host_size) {
}
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;
@ -2141,7 +2141,7 @@ int home_create_luks(
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;
@ -3079,9 +3079,9 @@ int home_resize_luks(
_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;

View file

@ -186,7 +186,7 @@ static int append_identity_range(char **text, uid_t start, uid_t next_start, uid
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));
@ -238,7 +238,7 @@ static int make_userns(uid_t stored_uid, uid_t exposed_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);
@ -261,7 +261,7 @@ int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t expos
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;
}
@ -284,7 +284,7 @@ int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t expos
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;
}

View file

@ -512,7 +512,7 @@ int home_sync_and_statfs(int root_fd, struct statfs *ret) {
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;
@ -543,7 +543,7 @@ static int read_identity_file(int root_fd, JsonVariant **ret) {
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;
@ -785,7 +785,7 @@ int home_maybe_shift_uid(
HomeSetupFlags flags,
HomeSetup *setup) {
_cleanup_close_ int mount_fd = -1;
_cleanup_close_ int mount_fd = -EBADF;
struct stat st;
assert(h);

View file

@ -50,8 +50,8 @@ typedef struct HomeSetup {
#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, \

View file

@ -477,7 +477,7 @@ static int acquire_home(
_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;

View file

@ -84,8 +84,8 @@ int raw_export_new(
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,
@ -267,7 +267,7 @@ static int reflink_snapshot(int fd, const char *path) {
}
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);

View file

@ -90,8 +90,8 @@ int tar_export_new(
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,
@ -250,7 +250,7 @@ static int tar_export_on_defer(sd_event_source *s, void *userdata) {
}
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);

View file

@ -63,7 +63,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
_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)) {
@ -139,7 +139,7 @@ static int export_raw(int argc, char *argv[], void *userdata) {
_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)) {

View file

@ -100,7 +100,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
_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)

View file

@ -105,8 +105,8 @@ int raw_import_new(
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,
@ -154,7 +154,7 @@ static void raw_import_report_progress(RawImport *i) {
}
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;

View file

@ -107,8 +107,8 @@ int tar_import_new(
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,

View file

@ -83,7 +83,7 @@ static int normalize_local(const char *local, char **ret) {
}
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);
@ -132,7 +132,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
_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)
@ -204,7 +204,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
_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)

View file

@ -157,9 +157,9 @@ static int transfer_new(Manager *m, Transfer **ret) {
*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,
};

View file

@ -27,7 +27,7 @@ void pull_job_close_disk_fd(PullJob *j) {
if (j->close_disk_fd)
safe_close(j->disk_fd);
j->disk_fd = -1;
j->disk_fd = -EBADF;
}
PullJob* pull_job_unref(PullJob *j) {
@ -692,7 +692,7 @@ int pull_job_new(
*j = (PullJob) {
.state = PULL_JOB_INIT,
.disk_fd = -1,
.disk_fd = -EBADF,
.close_disk_fd = true,
.userdata = userdata,
.glue = glue,

View file

@ -238,7 +238,7 @@ static void raw_pull_report_progress(RawPull *i, RawProgress p) {
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;
@ -346,7 +346,7 @@ static int raw_pull_copy_auxiliary_file(
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;

View file

@ -9,7 +9,7 @@
#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) {

View file

@ -19,7 +19,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
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;

View file

@ -127,7 +127,7 @@ static int request_meta_ensure_tmp(RequestMeta *m) {
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)
@ -670,7 +670,7 @@ static int request_handler_file(
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);

View file

@ -294,7 +294,7 @@ int journal_remote_add_raw_socket(RemoteServer *s, int fd) {
if (r < 0)
return r;
fd_ = -1;
fd_ = -EBADF;
s->active++;
return 0;
}
@ -483,7 +483,7 @@ static int accept_connection(
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);

View file

@ -122,7 +122,7 @@ static int parse_argv(int argc, char *argv[]) {
}
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();

View file

@ -11,7 +11,7 @@
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;

View file

@ -7,13 +7,13 @@
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,
};

View file

@ -1803,7 +1803,7 @@ static int setup_keys(void) {
_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;
@ -2101,7 +2101,7 @@ int main(int argc, char *argv[]) {
_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();

View file

@ -43,7 +43,7 @@ void server_forward_console(
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;

Some files were not shown because too many files have changed in this diff Show more