diff --git a/coccinelle/safe_close.cocci b/coccinelle/safe_close.cocci index 36a85372517..49254b6fff5 100644 --- a/coccinelle/safe_close.cocci +++ b/coccinelle/safe_close.cocci @@ -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); diff --git a/docs/BLOCK_DEVICE_LOCKING.md b/docs/BLOCK_DEVICE_LOCKING.md index 862d6f0369d..a6e3374bc79 100644 --- a/docs/BLOCK_DEVICE_LOCKING.md +++ b/docs/BLOCK_DEVICE_LOCKING.md @@ -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; } diff --git a/src/activate/activate.c b/src/activate/activate.c index 5934e7a57a6..16463a9b93f 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -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(); diff --git a/src/analyze/analyze-inspect-elf.c b/src/analyze/analyze-inspect-elf.c index cb6692e2771..70226a842b2 100644 --- a/src/analyze/analyze-inspect-elf.c +++ b/src/analyze/analyze-inspect-elf.c @@ -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) diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c index 385d0aed698..a9de17b4763 100644 --- a/src/basic/chase-symlinks.c +++ b/src/basic/chase-symlinks.c @@ -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); diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c index eddde132aae..3c66a3e0c83 100644 --- a/src/basic/chattr-util.c +++ b/src/basic/chattr-util.c @@ -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); diff --git a/src/basic/efivars.c b/src/basic/efivars.c index 17e0fb895e6..e7ece805d4c 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -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; diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index b97039284cd..4ab972b13e3 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -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; } diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index fbaa4586134..530270a73fe 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -94,7 +94,7 @@ static inline int make_null_stdio(void) { ({ \ int *_fd_ = &(fd); \ int _ret_ = *_fd_; \ - *_fd_ = -1; \ + *_fd_ = -EBADF; \ _ret_; \ }) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 5078cae2df1..a9015979620 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -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); diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index fbc7492b152..ed020b1b08b 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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; diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 40c6e46ab88..d94fbcff4b9 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -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; diff --git a/src/basic/log.c b/src/basic/log.c index 173643196e7..282130345f3 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -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) { diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index f05fb1524e8..fb86ac2b5ba 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -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); diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 6796d4aeda9..7ad19ee33b7 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -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) diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index 1136454b7df..bc74fbef8f7 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -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 diff --git a/src/basic/namespace-util.c b/src/basic/namespace-util.c index a87a875943c..f5c0e04cecb 100644 --- a/src/basic/namespace-util.c +++ b/src/basic/namespace-util.c @@ -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); diff --git a/src/basic/os-util.c b/src/basic/os-util.c index 8f8bb0881e9..9c21dc3bdc5 100644 --- a/src/basic/os-util.c +++ b/src/basic/os-util.c @@ -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; diff --git a/src/basic/path-util.c b/src/basic/path-util.c index bf93990fde1..cc45cb311e7 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -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; diff --git a/src/basic/random-util.c b/src/basic/random-util.c index d8734cc7d0f..28ace92f194 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -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); diff --git a/src/basic/recurse-dir.c b/src/basic/recurse-dir.c index fe18b98d5b8..5e98b7a5d8d 100644 --- a/src/basic/recurse-dir.c +++ b/src/basic/recurse-dir.c @@ -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); diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index f39be19a598..54f5f1cc5bc 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -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, }; diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 0974f6178ab..693e1f7eb62 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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; diff --git a/src/basic/sync-util.c b/src/basic/sync-util.c index e2d4a3d895f..52c8c417dee 100644 --- a/src/basic/sync-util.c +++ b/src/basic/sync-util.c @@ -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) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7bc2f71bcfd..da03a884f84 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -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; diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 71b2f673505..d5c10571c9b 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -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)); diff --git a/src/basic/tmpfile-util.c b/src/basic/tmpfile-util.c index dbbd54027e6..95adf9d3744 100644 --- a/src/basic/tmpfile-util.c +++ b/src/basic/tmpfile-util.c @@ -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); diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 0b661d93250..5b6131b56a3 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -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; diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c index b2dd60f8ad4..59f02b761ac 100644 --- a/src/boot/bless-boot.c +++ b/src/boot/bless-boot.c @@ -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) diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index c14bdb69f83..d6c2feaeafb 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -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")) diff --git a/src/boot/bootctl-random-seed.c b/src/boot/bootctl-random-seed.c index 0b3ff74eaa1..7d6e863728c 100644 --- a/src/boot/bootctl-random-seed.c +++ b/src/boot/bootctl-random-seed.c @@ -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; diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index 44f38004f5a..a0fee7d3c73 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -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; diff --git a/src/boot/measure.c b/src/boot/measure.c index 4ee5b1de3b1..a153455904d 100644 --- a/src/boot/measure.c +++ b/src/boot/measure.c @@ -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]) diff --git a/src/cgroups-agent/cgroups-agent.c b/src/cgroups-agent/cgroups-agent.c index 91267362351..d6480097b5e 100644 --- a/src/cgroups-agent/cgroups-agent.c +++ b/src/cgroups-agent/cgroups-agent.c @@ -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; diff --git a/src/core/automount.c b/src/core/automount.c index a44b8e878d9..d2976d6734e 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -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) diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c index ce3b76c5123..5878a818791 100644 --- a/src/core/bpf-firewall.c +++ b/src/core/bpf-firewall.c @@ -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) { diff --git a/src/core/bpf-lsm.c b/src/core/bpf-lsm.c index de601c48d75..0be250af5cc 100644 --- a/src/core/bpf-lsm.c +++ b/src/core/bpf-lsm.c @@ -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); diff --git a/src/core/bpf-socket-bind.c b/src/core/bpf-socket-bind.c index 660ffdb7232..9f290ab412c 100644 --- a/src/core/bpf-socket-bind.c +++ b/src/core/bpf-socket-bind.c @@ -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; diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index f01c67ecf14..9e529d6375c 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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) diff --git a/src/core/dbus-path.c b/src/core/dbus-path.c index 65fb7d7eb7e..22de551c548 100644 --- a/src/core/dbus-path.c +++ b/src/core/dbus-path.c @@ -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); diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c index 43edbb60e4b..d0d92507d6a 100644 --- a/src/core/dbus-socket.c +++ b/src/core/dbus-socket.c @@ -371,7 +371,7 @@ static int bus_socket_set_transient_property( return log_oom(); *p = (SocketPort) { - .fd = -1, + .fd = -EBADF, .socket = s, }; diff --git a/src/core/dbus.c b/src/core/dbus.c index c6024a061eb..c295e1fbd41 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -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; diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index 18b36e74bfa..e0b371a4c4e 100644 --- a/src/core/dynamic-user.c +++ b/src/core/dynamic-user.c @@ -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; diff --git a/src/core/efi-random.c b/src/core/efi-random.c index 61516775fc7..dffde57c912 100644 --- a/src/core/efi-random.c +++ b/src/core/efi-random.c @@ -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); diff --git a/src/core/execute.c b/src/core/execute.c index 42c95556ac7..94021f20e81 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -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; diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c index 7f517a09099..37916bb474a 100644 --- a/src/core/ima-setup.c +++ b/src/core/ima-setup.c @@ -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; diff --git a/src/core/import-creds.c b/src/core/import-creds.c index 1f2017ee5a5..0bcd407e682 100644 --- a/src/core/import-creds.c +++ b/src/core/import-creds.c @@ -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; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 3a95f0d504b..e5766a58a7c 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -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); diff --git a/src/core/main.c b/src/core/main.c index 4adb4165acb..f779410fda5 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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); diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c index dd16d17afa8..61a464c06bf 100644 --- a/src/core/manager-serialize.c +++ b/src/core/manager-serialize.c @@ -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); diff --git a/src/core/manager.c b/src/core/manager.c index 292e82fd87a..4e15f5cb8b1 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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 diff --git a/src/core/mount.c b/src/core/mount.c index f16e5c487bc..4ea609a4fde 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -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; diff --git a/src/core/namespace.c b/src/core/namespace.c index 3bac6bb6a3b..d7c911a509f 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -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 */ diff --git a/src/core/path.c b/src/core/path.c index 3a46e449288..3881c77a868 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -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); } diff --git a/src/core/restrict-ifaces.c b/src/core/restrict-ifaces.c index 134f70a07b8..4dd86567189 100644 --- a/src/core/restrict-ifaces.c +++ b/src/core/restrict-ifaces.c @@ -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; diff --git a/src/core/service.c b/src/core/service.c index bb190b1e8aa..5181826c84c 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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; diff --git a/src/core/show-status.c b/src/core/show-status.c index 2ba7a8588d2..c6b106fc9c5 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -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; diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index 58552f79e73..bcaa237c8dc 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -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; diff --git a/src/core/socket.c b/src/core/socket.c index 55847c2f7c7..e0e91dba53e 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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); diff --git a/src/core/swap.c b/src/core/swap.c index 5c83c4780f5..2d25014e5f4 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -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; diff --git a/src/core/unit.c b/src/core/unit.c index 641993b836d..e14238b3bae 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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; diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 50220c5ec71..4ca19370f3e 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -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); diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 6a6a968149a..8a4f31aa624 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -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) { diff --git a/src/creds/creds.c b/src/creds/creds.c index 3c86b10aab0..d987f04ef43 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -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; diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index b7bcf731f75..ed923c2c863 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -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 diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 73c76fceea5..f5c0732cf59 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -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); diff --git a/src/fuzz/fuzz-bootspec.c b/src/fuzz/fuzz-bootspec.c index c08f76c14a3..cea674c4c8b 100644 --- a/src/fuzz/fuzz-bootspec.c +++ b/src/fuzz/fuzz-bootspec.c @@ -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) diff --git a/src/fuzz/fuzz-catalog.c b/src/fuzz/fuzz-catalog.c index f0134557301..f3029f49d04 100644 --- a/src/fuzz/fuzz-catalog.c +++ b/src/fuzz/fuzz-catalog.c @@ -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")) diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index b3f5ddc5860..d255e90db52 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -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 diff --git a/src/home/homectl.c b/src/home/homectl.c index a6d25c84fc1..0a4c01834aa 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -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; diff --git a/src/home/homed-home-bus.c b/src/home/homed-home-bus.c index 4e3fd5f0ae6..a47f4d8a844 100644 --- a/src/home/homed-home-bus.c +++ b/src/home/homed-home-bus.c @@ -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; diff --git a/src/home/homed-home.c b/src/home/homed-home.c index 19be186400d..c2514aafc9a 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -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) diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 61ef9790494..2fd1d67eff2 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -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", diff --git a/src/home/homed-operation.c b/src/home/homed-operation.c index 3847fc5d687..618e920a596 100644 --- a/src/home/homed-operation.c +++ b/src/home/homed-operation.c @@ -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, }; diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index d3bc5474298..6668edb7491 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -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; diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index f29c55c8952..f8f9f462bbc 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -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; diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 2b803bc0bdd..f215558ae04 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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; diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index cd03f79a739..cf42a0b94df 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -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; } diff --git a/src/home/homework.c b/src/home/homework.c index bc38437f2cf..28907386a46 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -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); diff --git a/src/home/homework.h b/src/home/homework.h index b27c31d56ba..cef3f4eb98b 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -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, \ diff --git a/src/home/pam_systemd_home.c b/src/home/pam_systemd_home.c index 8b414165780..8a7bfc5837f 100644 --- a/src/home/pam_systemd_home.c +++ b/src/home/pam_systemd_home.c @@ -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; diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 6b15884e777..7c61aef3b68 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -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); diff --git a/src/import/export-tar.c b/src/import/export-tar.c index b9953a4bf37..4aa8204983a 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -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); diff --git a/src/import/export.c b/src/import/export.c index 690e1944533..84609cbe124 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -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)) { diff --git a/src/import/import-fs.c b/src/import/import-fs.c index ca5d33c0082..d81dd13ffde 100644 --- a/src/import/import-fs.c +++ b/src/import/import-fs.c @@ -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) diff --git a/src/import/import-raw.c b/src/import/import-raw.c index ee904bc4e0e..5d4dedf66d6 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -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; diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 90b4e51d2c1..dff6d3276ab 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -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, diff --git a/src/import/import.c b/src/import/import.c index 13f34633d2a..a81617d38e8 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -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) diff --git a/src/import/importd.c b/src/import/importd.c index 4f6be5f20c9..b2d176b4e73 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -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, }; diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 1e105bc769f..ce7642e897c 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -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, diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index d3d14af6d1d..a4a844bf072 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -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; diff --git a/src/import/test-qcow2.c b/src/import/test-qcow2.c index 77fed01dd37..ca31fd678d3 100644 --- a/src/import/test-qcow2.c +++ b/src/import/test-qcow2.c @@ -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) { diff --git a/src/journal-remote/fuzz-journal-remote.c b/src/journal-remote/fuzz-journal-remote.c index db10c2b0127..da0d83ec9a9 100644 --- a/src/journal-remote/fuzz-journal-remote.c +++ b/src/journal-remote/fuzz-journal-remote.c @@ -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; diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index b3b44bceb8b..747e0be743b 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -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); diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 3d7b552e95e..a6704688841 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -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); diff --git a/src/journal/cat.c b/src/journal/cat.c index 404a7487363..0ba427a660b 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -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(); diff --git a/src/journal/fuzz-journald-native-fd.c b/src/journal/fuzz-journald-native-fd.c index fcfc5dfaba4..9adbb8b0dc5 100644 --- a/src/journal/fuzz-journald-native-fd.c +++ b/src/journal/fuzz-journald-native-fd.c @@ -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; diff --git a/src/journal/fuzz-journald.c b/src/journal/fuzz-journald.c index ff1746e1221..c96fad58e8d 100644 --- a/src/journal/fuzz-journald.c +++ b/src/journal/fuzz-journald.c @@ -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, }; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ba5636af141..7805c9cd9db 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -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(); diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 2035e2d9b69..c8a3e18360f 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -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; diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 99eace08487..685863ff50c 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -431,7 +431,7 @@ fail: } 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; diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index b268db0220e..9e2d239abd2 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -560,7 +560,7 @@ static int vacuum_offline_user_journals(Server *s) { 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; @@ -2299,19 +2299,19 @@ static int set_namespace(Server *s, const char *namespace) { 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, diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 4446b2daec7..735e2c5e8ba 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -669,7 +669,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) { return log_oom(); *stream = (StdoutStream) { - .fd = -1, + .fd = -EBADF, .priority = LOG_INFO, .ucred = UCRED_INVALID, }; @@ -716,7 +716,7 @@ int stdout_stream_install(Server *s, int fd, StdoutStream **ret) { } 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; diff --git a/src/libsystemd-network/lldp-network.c b/src/libsystemd-network/lldp-network.c index 24edc371db0..598669fe20c 100644 --- a/src/libsystemd-network/lldp-network.c +++ b/src/libsystemd-network/lldp-network.c @@ -37,7 +37,7 @@ int lldp_network_bind_raw_socket(int ifindex) { .ll.sll_family = AF_PACKET, .ll.sll_ifindex = ifindex, }; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(ifindex > 0); diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 47b4cb121f5..48174e7c4b0 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -2207,7 +2207,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) { .n_ref = 1, .state = DHCP_STATE_INIT, .ifindex = -1, - .fd = -1, + .fd = -EBADF, .mtu = DHCP_MIN_PACKET_SIZE, .port = DHCP_PORT_CLIENT, .anonymize = !!anonymize, diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 11ab2338cec..b5aff7d4fab 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -200,9 +200,9 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) { *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, diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 3f34b462808..29cd0035063 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -1499,7 +1499,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) { .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, }; diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 9b11b2f1606..d34c63e854a 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -151,7 +151,7 @@ int sd_ipv4acd_new(sd_ipv4acd **ret) { .n_ref = 1, .state = IPV4ACD_STATE_INIT, .ifindex = -1, - .fd = -1, + .fd = -EBADF, }; *ret = TAKE_PTR(acd); diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 0479cff5f57..03e89860498 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -405,7 +405,7 @@ int sd_lldp_rx_new(sd_lldp_rx **ret) { *lldp_rx = (sd_lldp_rx) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, .neighbors_max = LLDP_DEFAULT_NEIGHBORS_MAX, .capability_mask = UINT16_MAX, }; diff --git a/src/libsystemd-network/sd-lldp-tx.c b/src/libsystemd-network/sd-lldp-tx.c index d2d24be089e..2b822af01a9 100644 --- a/src/libsystemd-network/sd-lldp-tx.c +++ b/src/libsystemd-network/sd-lldp-tx.c @@ -451,7 +451,7 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u } 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; diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index 2cf0cebdeb7..2e446fece3d 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -171,7 +171,7 @@ int sd_ndisc_new(sd_ndisc **ret) { *nd = (sd_ndisc) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, }; *ret = TAKE_PTR(nd); diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index a3a5a21b3d7..20458b9f97e 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -37,7 +37,7 @@ int sd_radv_new(sd_radv **ret) { *ra = (sd_radv) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, .lifetime_usec = RADV_DEFAULT_ROUTER_LIFETIME_USEC, }; diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c index b9a38269d9d..3047dce8581 100644 --- a/src/libsystemd/sd-bus/bus-container.c +++ b/src/libsystemd/sd-bus/bus-container.c @@ -13,7 +13,7 @@ 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; diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 39e21480ac2..07168f660b8 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -433,7 +433,7 @@ int bus_message_from_malloc( 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; @@ -1108,7 +1108,7 @@ static struct bus_body_part *message_append_part(sd_bus_message *m) { m->body_end->next = part; } - part->memfd = -1; + part->memfd = -EBADF; m->body_end = part; m->n_body_parts++; @@ -1303,7 +1303,7 @@ static int message_push_fd(sd_bus_message *m, int fd) { } 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; @@ -1422,7 +1422,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void if (c->enclosing != SD_BUS_TYPE_ARRAY) c->index++; - fd = -1; + fd = -EBADF; return 0; } @@ -2172,7 +2172,7 @@ _public_ int sd_bus_message_append_array_memfd( 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; @@ -2234,7 +2234,7 @@ _public_ int sd_bus_message_append_array_memfd( 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); @@ -2248,7 +2248,7 @@ _public_ int sd_bus_message_append_string_memfd( 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; @@ -2319,7 +2319,7 @@ _public_ int sd_bus_message_append_string_memfd( 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); diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index c75276f4bac..d85dcc52c17 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -240,9 +240,9 @@ _public_ int sd_bus_new(sd_bus **ret) { *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, diff --git a/src/libsystemd/sd-bus/test-bus-watch-bind.c b/src/libsystemd/sd-bus/test-bus-watch-bind.c index 6e522ae54be..987d151b55e 100644 --- a/src/libsystemd/sd-bus/test-bus-watch-bind.c +++ b/src/libsystemd/sd-bus/test-bus-watch-bind.c @@ -40,7 +40,7 @@ static const sd_bus_vtable vtable[] = { 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; diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 80206a7d914..91f96051717 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -447,7 +447,7 @@ _public_ int sd_pid_notify_with_fds( .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; diff --git a/src/libsystemd/sd-device/device-util.c b/src/libsystemd/sd-device/device-util.c index b192914b1d0..56acec67f6d 100644 --- a/src/libsystemd/sd-device/device-util.c +++ b/src/libsystemd/sd-device/device-util.c @@ -35,7 +35,7 @@ int devname_from_devnum(mode_t mode, dev_t devnum, char **ret) { 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); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 9c4743f0550..2fcdce7bac9 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -145,7 +145,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { 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. @@ -2535,7 +2535,7 @@ _public_ int sd_device_trigger_with_uuid( } _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; diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index 2bb9c287889..9d5cab75b3a 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -131,7 +131,7 @@ static void test_sd_device_one(sd_device *d) { 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 diff --git a/src/libsystemd/sd-event/event-util.c b/src/libsystemd/sd-event/event-util.c index a36eba90293..9863b07653f 100644 --- a/src/libsystemd/sd-event/event-util.c +++ b/src/libsystemd/sd-event/event-util.c @@ -111,7 +111,7 @@ int event_reset_time_relative( 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); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index c936fcb3b64..b9df1c86c36 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -378,22 +378,22 @@ _public_ int sd_event_new(sd_event** ret) { *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(), @@ -643,7 +643,7 @@ static int event_make_signal_data( *d = (struct signal_data) { .wakeup = WAKEUP_SIGNAL_DATA, - .fd = -1, + .fd = -EBADF, .priority = priority, }; @@ -1180,7 +1180,7 @@ static int event_setup_timer_fd( 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) @@ -1516,7 +1516,7 @@ _public_ int sd_event_add_child( } 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 */ @@ -1779,7 +1779,7 @@ static int event_make_inotify_data( int64_t priority, struct inotify_data **ret) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct inotify_data *d; int r; @@ -1976,7 +1976,7 @@ static int event_make_inode_data( .dev = dev, .ino = ino, .wd = -1, - .fd = -1, + .fd = -EBADF, .inotify_data = inotify_data, }; diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 9ec988d76e6..8d0cb5861bd 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -225,8 +225,7 @@ static void test_basic_one(bool with_pidfd) { 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); @@ -742,7 +741,7 @@ TEST(inotify_self_destroy) { _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 */ diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index eae2562410c..a27f4bf7427 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -102,7 +102,7 @@ int id128_read_fd(int fd, Id128FormatFlag f, sd_id128_t *ret) { } 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) @@ -142,7 +142,7 @@ int id128_write_fd(int fd, Id128FormatFlag f, sd_id128_t id) { } 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) diff --git a/src/libsystemd/sd-journal/catalog.c b/src/libsystemd/sd-journal/catalog.c index b988ee3bba4..7527abf636c 100644 --- a/src/libsystemd/sd-journal/catalog.c +++ b/src/libsystemd/sd-journal/catalog.c @@ -504,7 +504,7 @@ int catalog_update(const char* database, const char* root, const char* const* di } 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; @@ -601,7 +601,7 @@ static const char *find_id(void *p, sd_id128_t id) { } 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; @@ -668,7 +668,7 @@ static void dump_catalog_entry(FILE *f, sd_id128_t id, const char *s, bool oneli } 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; diff --git a/src/libsystemd/sd-journal/journal-authenticate.c b/src/libsystemd/sd-journal/journal-authenticate.c index 1cb89433897..3c5d9d7e497 100644 --- a/src/libsystemd/sd-journal/journal-authenticate.c +++ b/src/libsystemd/sd-journal/journal-authenticate.c @@ -308,7 +308,7 @@ int journal_file_hmac_put_header(JournalFile *f) { } int journal_file_fss_load(JournalFile *f) { - int r, fd = -1; + int r, fd = -EBADF; char *p = NULL; struct stat st; FSSHeader *m = NULL; diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index db53dd7debb..3b74d2246e2 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -239,7 +239,7 @@ finish: _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; @@ -419,7 +419,7 @@ _public_ int sd_journal_perror(const char *message) { } _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; diff --git a/src/libsystemd/sd-journal/journal-vacuum.c b/src/libsystemd/sd-journal/journal-vacuum.c index 7b5e0fa65fa..d62cf3eb3af 100644 --- a/src/libsystemd/sd-journal/journal-vacuum.c +++ b/src/libsystemd/sd-journal/journal-vacuum.c @@ -85,7 +85,7 @@ static void patch_realtime( } 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; diff --git a/src/libsystemd/sd-journal/journal-verify.c b/src/libsystemd/sd-journal/journal-verify.c index 34b1d8b9093..1eca48536cf 100644 --- a/src/libsystemd/sd-journal/journal-verify.c +++ b/src/libsystemd/sd-journal/journal-verify.c @@ -823,7 +823,7 @@ int journal_file_verify( 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; diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 0f3376823bb..204886b1e43 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -1266,7 +1266,7 @@ static int add_any_file( int fd, const char *path) { - _cleanup_close_ int our_fd = -1; + _cleanup_close_ int our_fd = -EBADF; JournalFile *f; struct stat st; int r; @@ -1730,7 +1730,7 @@ static int add_root_directory(sd_journal *j, const char *p, bool missing_ok) { 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. */ @@ -1888,8 +1888,8 @@ static sd_journal *journal_new(int flags, const char *path, const char *namespac 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; diff --git a/src/libsystemd/sd-journal/test-catalog.c b/src/libsystemd/sd-journal/test-catalog.c index 526b8200ba1..49185cc2b32 100644 --- a/src/libsystemd/sd-journal/test-catalog.c +++ b/src/libsystemd/sd-journal/test-catalog.c @@ -195,7 +195,7 @@ static void test_catalog_file_lang(void) { 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; diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 872d39e9ab7..90b5ebb4b7f 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -944,7 +944,7 @@ static sd_login_monitor* FD_TO_MONITOR(int fd) { } _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; diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index af601bd347c..6cd916a2097 100644 --- a/src/libsystemd/sd-netlink/netlink-util.c +++ b/src/libsystemd/sd-netlink/netlink-util.c @@ -658,7 +658,7 @@ static int socket_open(int family) { } 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); diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index fe888926a1d..132f63e57de 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -31,7 +31,7 @@ static int netlink_new(sd_netlink **ret) { *nl = (sd_netlink) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, .sockaddr.nl.nl_family = AF_NETLINK, .original_pid = getpid_cached(), .protocol = -1, @@ -93,7 +93,7 @@ int sd_netlink_open_fd(sd_netlink **ret, int fd) { 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; } diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 00687e5cc82..56de3f965c4 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -344,7 +344,7 @@ static int monitor_add_inotify_watch(int fd) { } 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; diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 5362ec0fa84..48a92ac6153 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -494,7 +494,7 @@ _public_ int sd_resolve_new(sd_resolve **ret) { 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; diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index 7ca17fa6c39..7c5bb5500c6 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -50,7 +50,7 @@ _public_ struct udev_queue *udev_queue_new(struct udev *udev) { *udev_queue = (struct udev_queue) { .udev = udev, .n_ref = 1, - .fd = -1, + .fd = -EBADF, }; return udev_queue; diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 6184d10cde5..7cd2fd3e668 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -287,7 +287,7 @@ static int run(int argc, char *argv[]) { _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 */ diff --git a/src/login/logind-button.c b/src/login/logind-button.c index f16be0f4e1a..727dad0b160 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -48,7 +48,7 @@ Button* button_new(Manager *m, const char *name) { } b->manager = m; - b->fd = -1; + b->fd = -EBADF; return b; } @@ -463,7 +463,7 @@ static int button_set_mask(const char *name, int fd) { } 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; diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 02adc81909b..7d4ff6c98be 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -492,7 +492,7 @@ int config_parse_n_autovts( 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); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 2ab26b9c6d4..7024bba82da 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -3196,7 +3196,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error _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; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 9cf00a502f9..95b11ed9e73 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -44,7 +44,7 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { .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); @@ -264,7 +264,7 @@ int inhibitor_load(Inhibitor *i) { } 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); diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 863b8cc3b48..65323f6c923 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -167,7 +167,7 @@ int seat_load(Seat *s) { 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); diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index ea4800d8276..e3bebc9188b 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -774,7 +774,7 @@ static bool session_ready(Session *s) { 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); diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index eccc1aeb5d4..a8b3b489922 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -333,7 +333,7 @@ int session_device_new(Session *s, dev_t dev, bool open_device, SessionDevice ** sd->session = s; sd->dev = dev; - sd->fd = -1; + sd->fd = -EBADF; sd->type = DEVICE_TYPE_UNKNOWN; r = session_device_verify(sd); diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 85cb4eba9ea..2a121faea59 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -61,8 +61,8 @@ int session_new(Session **ret, Manager *m, const char *id) { *s = (Session) { .manager = m, - .fifo_fd = -1, - .vtfd = -1, + .fifo_fd = -EBADF, + .vtfd = -EBADF, .audit_id = AUDIT_SESSION_INVALID, .tty_validity = _TTY_VALIDITY_INVALID, }; diff --git a/src/login/logind.c b/src/login/logind.c index a564f94bfe9..def2f5a4428 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -53,8 +53,8 @@ static int manager_new(Manager **ret) { 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), }; @@ -701,7 +701,7 @@ static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo 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 diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index a288b3602a9..ba2fca32c6b 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -188,7 +188,7 @@ static int socket_from_display(const char *display) { char *c; union sockaddr_union sa; socklen_t sa_len; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(display); @@ -236,7 +236,7 @@ static int socket_from_display(const char *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; @@ -671,7 +671,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( *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; diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index 84dc95eca13..698052dd866 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -88,7 +88,7 @@ int bus_image_method_remove( return r; } - errno_pipe_fd[0] = -1; + errno_pipe_fd[0] = -EBADF; return 1; } @@ -211,7 +211,7 @@ int bus_image_method_clone( return r; } - errno_pipe_fd[0] = -1; + errno_pipe_fd[0] = -EBADF; return 1; } diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 75f397dd6ba..26ba5d42921 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -225,7 +225,7 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd 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; @@ -370,7 +370,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s 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; @@ -388,7 +388,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s 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]); @@ -890,7 +890,7 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro 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; @@ -1042,13 +1042,13 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro (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; @@ -1084,7 +1084,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda 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; @@ -1100,7 +1100,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda 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]); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 93761a1da9b..149b5d8e609 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1800,7 +1800,7 @@ static int import_tar(int argc, char *argv[], void *userdata) { _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; @@ -1861,7 +1861,7 @@ static int import_raw(int argc, char *argv[], void *userdata) { _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; @@ -1922,7 +1922,7 @@ static int import_fs(int argc, char *argv[], void *userdata) { _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; @@ -1987,7 +1987,7 @@ static void determine_compression_from_filename(const char *p) { 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; @@ -2027,7 +2027,7 @@ static int export_tar(int argc, char *argv[], void *userdata) { 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; diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 3da639279d8..aef3e905426 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -44,7 +44,7 @@ static int property_get_pool_usage( void *userdata, sd_bus_error *error) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; uint64_t usage = UINT64_MAX; assert(bus); @@ -70,7 +70,7 @@ static int property_get_pool_limit( void *userdata, sd_bus_error *error) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; uint64_t size = UINT64_MAX; assert(bus); @@ -684,7 +684,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err } 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; @@ -824,8 +824,8 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err 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; } diff --git a/src/machine/operation.c b/src/machine/operation.c index c97b29aba83..49b6d31bdc0 100644 --- a/src/machine/operation.c +++ b/src/machine/operation.c @@ -81,7 +81,7 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag 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) { diff --git a/src/network/netdev/tuntap.c b/src/network/netdev/tuntap.c index 39ea7c1d739..1a37ba34652 100644 --- a/src/network/netdev/tuntap.c +++ b/src/network/netdev/tuntap.c @@ -101,7 +101,7 @@ static int tuntap_take_fd(NetDev *netdev) { } static int netdev_create_tuntap(NetDev *netdev) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct ifreq ifr = {}; TunTap *t; int r; @@ -180,7 +180,7 @@ static void tuntap_init(NetDev *netdev) { t = TUNTAP(netdev); assert(t); - t->fd = -1; + t->fd = -EBADF; } static void tuntap_drop(NetDev *netdev) { diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 8146125fc8a..357d38f5ea6 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -711,7 +711,7 @@ static void acquire_wlan_link_info(LinkInfo *link) { 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; diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index f3ebeadd2cd..7d067a8c46b 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -235,7 +235,7 @@ static int manager_connect_udev(Manager *m) { 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); @@ -499,7 +499,7 @@ static int manager_set_keep_configuration(Manager *m) { } int manager_setup(Manager *m) { - _cleanup_close_ int rtnl_fd = -1; + _cleanup_close_ int rtnl_fd = -EBADF; int r; assert(m); @@ -583,7 +583,7 @@ int manager_new(Manager **ret, bool test_mode) { .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, diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index d7ca3afc8ac..0deb4ebb304 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -20,7 +20,7 @@ #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) diff --git a/src/nspawn/nspawn-expose-ports.c b/src/nspawn/nspawn-expose-ports.c index a8b14371711..b35f8b6a9ba 100644 --- a/src/nspawn/nspawn-expose-ports.c +++ b/src/nspawn/nspawn-expose-ports.c @@ -160,7 +160,7 @@ int expose_port_execute(sd_netlink *rtnl, FirewallContext **fw_ctx, ExposePort * } int expose_port_send_rtnl(int send_fd) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(send_fd >= 0); diff --git a/src/nspawn/nspawn-patch-uid.c b/src/nspawn/nspawn-patch-uid.c index 1535d19bbb6..9f369315810 100644 --- a/src/nspawn/nspawn-patch-uid.c +++ b/src/nspawn/nspawn-patch-uid.c @@ -28,7 +28,7 @@ static int get_acl(int fd, const char *name, acl_type_t type, acl_t *ret) { 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) @@ -53,7 +53,7 @@ static int set_acl(int fd, const char *name, acl_type_t type, acl_t acl) { 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) diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c index 54f56725a85..a91ab9f25ec 100644 --- a/src/nspawn/nspawn-setuid.c +++ b/src/nspawn/nspawn-setuid.c @@ -93,7 +93,7 @@ int change_uid_gid(const char *user, bool chown_stdio, char **ret_home) { _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; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a1bf5bb1d19..de3e95145b6 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2459,7 +2459,7 @@ static int setup_credentials(const char *root) { 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) @@ -2500,7 +2500,7 @@ static int setup_credentials(const char *root) { 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); @@ -3590,7 +3590,7 @@ static int inner_child( } 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, @@ -3631,7 +3631,7 @@ static int outer_child( _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; @@ -4760,7 +4760,7 @@ static int run_container( 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); @@ -5168,7 +5168,7 @@ static int run_container( } 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 */ @@ -5236,7 +5236,7 @@ static int run_container( 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) { @@ -5373,7 +5373,7 @@ static int initialize_rlimits(void) { } static int cant_be_in_netns(void) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct ucred ucred; int r; diff --git a/src/oom/oomctl.c b/src/oom/oomctl.c index e527abf5da2..d18f9998410 100644 --- a/src/oom/oomctl.c +++ b/src/oom/oomctl.c @@ -46,7 +46,7 @@ static int dump_state(int argc, char *argv[], void *userdata) { _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); diff --git a/src/oom/oomd-manager-bus.c b/src/oom/oomd-manager-bus.c index 3a3308f0c48..0581d58016a 100644 --- a/src/oom/oomd-manager-bus.c +++ b/src/oom/oomd-manager-bus.c @@ -12,7 +12,7 @@ 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; diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c index faa75c55788..ed988123991 100644 --- a/src/oom/test-oomd-util.c +++ b/src/oom/test-oomd-util.c @@ -205,7 +205,7 @@ static void test_oomd_update_cgroup_contexts_between_hashmaps(void) { 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) diff --git a/src/partition/growfs.c b/src/partition/growfs.c index bb2b53103ff..248746f7247 100644 --- a/src/partition/growfs.c +++ b/src/partition/growfs.c @@ -37,7 +37,7 @@ static bool arg_dry_run = false; 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; @@ -206,7 +206,7 @@ static int parse_argv(int argc, char *argv[]) { } 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; diff --git a/src/partition/makefs.c b/src/partition/makefs.c index 9ffdcb6db85..3f54bbb0da0 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -19,7 +19,7 @@ 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; diff --git a/src/partition/repart.c b/src/partition/repart.c index 010d775c0b6..71018a79cc8 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -336,7 +336,7 @@ static Partition *partition_new(void) { .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, @@ -3079,7 +3079,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(PartitionTarget*, partition_target_free); 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; @@ -3128,8 +3128,8 @@ static int partition_target_prepare( if (!t) return log_oom(); *t = (PartitionTarget) { - .fd = -1, - .whole_fd = -1, + .fd = -EBADF, + .whole_fd = -EBADF, }; if (!need_path) { @@ -3736,7 +3736,7 @@ static int do_copy_files( 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) @@ -3858,7 +3858,7 @@ static bool partition_needs_populate(Partition *p) { 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); @@ -4627,7 +4627,7 @@ static int split_name_resolve(Context *context) { } static int context_split(Context *context) { - int fd = -1, r; + int fd = -EBADF, r; if (!arg_split) return 0; @@ -4642,7 +4642,7 @@ static int context_split(Context *context) { return r; LIST_FOREACH(partitions, p, context->partitions) { - _cleanup_close_ int fdt = -1; + _cleanup_close_ int fdt = -EBADF; if (p->dropped) continue; @@ -4766,7 +4766,7 @@ static int context_read_seed(Context *context, const char *root) { 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) @@ -4856,7 +4856,7 @@ static int resolve_copy_blocks_auto_candidate( 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; @@ -5141,7 +5141,7 @@ static int context_open_copy_block_paths( 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; @@ -5302,7 +5302,7 @@ static int context_minimize(Context *context) { _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; @@ -6005,7 +6005,7 @@ static int acquire_root_devno( _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; @@ -6076,7 +6076,7 @@ static int find_root(Context *context) { 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); @@ -6176,7 +6176,7 @@ static int resize_backing_fd( 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; diff --git a/src/portable/portable.c b/src/portable/portable.c index 0909e14aab6..45dd70b13d7 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -150,7 +150,7 @@ static int send_one_fd_iov_with_data_fd( 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); @@ -179,7 +179,7 @@ static int extract_now( _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; @@ -224,7 +224,7 @@ static int extract_now( if (!os_release) return -ENOMEM; - os_release_fd = -1; + os_release_fd = -EBADF; os_release->source = TAKE_PTR(os_release_path); } } @@ -253,7 +253,7 @@ static int extract_now( 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; @@ -298,7 +298,7 @@ static int extract_now( 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) @@ -428,7 +428,7 @@ static int portable_extract_by_path( 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 @@ -461,7 +461,7 @@ static int portable_extract_by_path( 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 @@ -594,7 +594,7 @@ static int extract_image_and_extensions( _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; @@ -1172,7 +1172,7 @@ static int attach_unit_file( } 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); @@ -1502,7 +1502,7 @@ static int test_chroot_dropin( _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; diff --git a/src/portable/portabled-bus.c b/src/portable/portabled-bus.c index be321b8f031..768964231a1 100644 --- a/src/portable/portabled-bus.c +++ b/src/portable/portabled-bus.c @@ -41,7 +41,7 @@ static int property_get_pool_usage( void *userdata, sd_bus_error *error) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; uint64_t usage = UINT64_MAX; assert(bus); @@ -67,7 +67,7 @@ static int property_get_pool_limit( void *userdata, sd_bus_error *error) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; uint64_t size = UINT64_MAX; assert(bus); diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c index b108fd34af6..704b51d81d8 100644 --- a/src/portable/portabled-image-bus.c +++ b/src/portable/portabled-image-bus.c @@ -553,7 +553,7 @@ int bus_image_common_remove( return r; child = 0; - errno_pipe_fd[0] = -1; + errno_pipe_fd[0] = -EBADF; return 1; } diff --git a/src/portable/portabled-operation.c b/src/portable/portabled-operation.c index 26adb9091a6..6897ed0b280 100644 --- a/src/portable/portabled-operation.c +++ b/src/portable/portabled-operation.c @@ -80,7 +80,7 @@ int operation_new(Manager *manager, pid_t child, sd_bus_message *message, int er 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) { diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index 6c3d5775077..306540650fd 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -174,7 +174,7 @@ static int move_file(PStoreEntry *pe, const char *subdir1, const char *subdir2) 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); diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index 020840e0dfd..90890e33f29 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -320,7 +320,7 @@ static int refresh_boot_seed(void) { 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; @@ -485,7 +485,7 @@ static int parse_argv(int argc, char *argv[]) { 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; diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c index feb1d1ef7c4..ce4582afe86 100644 --- a/src/reply-password/reply-password.c +++ b/src/reply-password/reply-password.c @@ -34,7 +34,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s 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; diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 635763954be..0c062efc985 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -351,7 +351,7 @@ static int dns_scope_socket( 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; diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 95fbb56cd7a..0a10a0d17e5 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -523,7 +523,7 @@ int dns_stream_new( *s = (DnsStream) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, .protocol = protocol, .type = type, }; diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c index 8a8a0b19eee..facd95aeb8a 100644 --- a/src/resolve/resolved-dns-stub.c +++ b/src/resolve/resolved-dns-stub.c @@ -1138,7 +1138,7 @@ static int manager_dns_stub_fd( int type) { sd_event_source **event_source; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; union sockaddr_union sa; int r; @@ -1225,7 +1225,7 @@ static int manager_dns_stub_fd( 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; diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 0212569fb03..8d76630adb6 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -273,7 +273,7 @@ int dns_transaction_new( 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, @@ -669,7 +669,7 @@ static uint16_t dns_transaction_port(DnsTransaction *t) { 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; @@ -753,7 +753,7 @@ static int dns_transaction_emit_tcp(DnsTransaction *t) { if (r < 0) return r; - fd = -1; + fd = -EBADF; #if ENABLE_DNS_OVER_TLS if (t->scope->protocol == DNS_PROTOCOL_DNS && diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 1c9048670bf..6c6c98566f1 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -554,13 +554,13 @@ int manager_new(Manager **ret) { 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, diff --git a/src/resolve/test-resolved-stream.c b/src/resolve/test-resolved-stream.c index 96395ad27a7..c708eb4da8d 100644 --- a/src/resolve/test-resolved-stream.c +++ b/src/resolve/test-resolved-stream.c @@ -107,7 +107,7 @@ static void server_handle(int fd) { } 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); @@ -125,7 +125,7 @@ static void *tcp_dns_server(void *p) { 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; @@ -213,7 +213,7 @@ static void test_dns_stream(bool tls) { 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 *); @@ -331,7 +331,7 @@ static void test_dns_stream(bool tls) { } 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 diff --git a/src/shared/acpi-fpdt.c b/src/shared/acpi-fpdt.c index 9f77997d5a5..22a36bdd243 100644 --- a/src/shared/acpi-fpdt.c +++ b/src/shared/acpi-fpdt.c @@ -100,7 +100,7 @@ int acpi_get_boot_usec(usec_t *ret_loader_start, usec_t *ret_loader_exit) { 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; diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 0b1b9c6861b..dc3d70bf1f3 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -213,7 +213,7 @@ int ask_password_plymouth( 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; @@ -394,7 +394,7 @@ int ask_password_tty( }; 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; @@ -670,7 +670,7 @@ static int create_socket(char **ret) { _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); @@ -715,7 +715,7 @@ int ask_password_agent( _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; diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 9b7270ae535..c3f6c1f9f49 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -123,7 +123,7 @@ static const BaseFilesystem table[] = { #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); diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index eb9f54306f6..85ae8ff8078 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -198,7 +198,7 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flags, sd_device **re } 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); @@ -283,7 +283,7 @@ int get_block_device_fd(int fd, dev_t *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); @@ -333,7 +333,7 @@ int get_block_device_harder_fd(int fd, dev_t *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); @@ -346,7 +346,7 @@ int get_block_device_harder(const char *path, dev_t *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; @@ -519,7 +519,7 @@ int fd_get_whole_disk(int fd, bool backing, dev_t *ret) { } 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) @@ -662,7 +662,7 @@ int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) { 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; @@ -740,7 +740,7 @@ int block_device_has_partitions(sd_device *dev) { } int blockdev_reread_partition_table(sd_device *dev) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(dev); diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 4cced23adcb..2a47f30b8f3 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -585,7 +585,7 @@ static int boot_entries_find_type1( _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); @@ -860,7 +860,7 @@ static int boot_entries_find_unified( 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; diff --git a/src/shared/bpf-program.c b/src/shared/bpf-program.c index 31fa4448b03..531ae9b6805 100644 --- a/src/shared/bpf-program.c +++ b/src/shared/bpf-program.c @@ -98,7 +98,7 @@ int bpf_program_new(uint32_t prog_type, const char *prog_name, BPFProgram **ret) *p = (BPFProgram) { .prog_type = prog_type, - .kernel_fd = -1, + .kernel_fd = -EBADF, .prog_name = TAKE_PTR(name), }; @@ -121,7 +121,7 @@ int bpf_program_new_from_bpffs_path(const char *path, BPFProgram **ret) { *p = (BPFProgram) { .prog_type = BPF_PROG_TYPE_UNSPEC, - .kernel_fd = -1, + .kernel_fd = -EBADF, }; r = bpf_program_load_from_bpf_fs(p, path); @@ -207,7 +207,7 @@ int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *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; @@ -268,7 +268,7 @@ int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_ } int bpf_program_cgroup_detach(BPFProgram *p) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(p); @@ -420,7 +420,7 @@ int bpf_program_serialize_attachment_set(FILE *f, FDSet *fds, const char *key, S 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; diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index b1aaf746cf9..0a4bd48b880 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -85,7 +85,7 @@ int btrfs_is_subvol_fd(int fd) { } int btrfs_is_subvol(const char *path) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(path); @@ -98,7 +98,7 @@ int btrfs_is_subvol(const char *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); @@ -119,7 +119,7 @@ int btrfs_subvol_make_fd(int fd, const char *subvolume) { } int btrfs_subvol_make(const char *path) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *subvolume; int r; @@ -184,7 +184,7 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) { } 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) @@ -247,7 +247,7 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offs 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; @@ -312,7 +312,7 @@ int btrfs_get_block_device_fd(int fd, dev_t *dev) { } 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); @@ -347,7 +347,7 @@ int btrfs_subvol_get_id_fd(int fd, uint64_t *ret) { } 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); @@ -629,7 +629,7 @@ finish: } 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) @@ -722,7 +722,7 @@ int btrfs_subvol_get_subtree_quota_fd(int fd, uint64_t subvol_id, BtrfsQuotaInfo } 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) @@ -744,7 +744,7 @@ int btrfs_defrag_fd(int fd) { } 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) @@ -771,7 +771,7 @@ int btrfs_quota_enable_fd(int fd, bool b) { } 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) @@ -822,7 +822,7 @@ int btrfs_qgroup_set_limit_fd(int fd, uint64_t qgroupid, uint64_t referenced_max } 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) @@ -845,7 +845,7 @@ int btrfs_subvol_set_subtree_quota_limit_fd(int fd, uint64_t subvol_id, uint64_t } 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) @@ -1049,7 +1049,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol }; 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; @@ -1149,7 +1149,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol * 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 @@ -1180,7 +1180,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol } int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *subvolume; int r; @@ -1414,7 +1414,7 @@ static int subvol_snapshot_children( .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; @@ -1468,7 +1468,7 @@ static int subvol_snapshot_children( 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); @@ -1578,7 +1578,7 @@ int btrfs_subvol_snapshot_fd_full( 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; @@ -1661,7 +1661,7 @@ int btrfs_subvol_snapshot_full( 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); @@ -1762,7 +1762,7 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) { 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; @@ -1914,7 +1914,7 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed } 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) diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index e6f67fc7149..2d2858c3b48 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -161,7 +161,7 @@ static int show_cgroup_name( uint64_t cgroupid = UINT64_MAX; _cleanup_free_ char *b = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; bool delegate; int r; diff --git a/src/shared/chown-recursive.c b/src/shared/chown-recursive.c index bbc270d34b2..883c1ccee4e 100644 --- a/src/shared/chown-recursive.c +++ b/src/shared/chown-recursive.c @@ -63,7 +63,7 @@ static int chown_recursive_internal( } 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)) @@ -113,7 +113,7 @@ int path_chown_recursive( 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); @@ -142,7 +142,7 @@ int fd_chown_recursive( 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 diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c index a4c00d713e3..b0cbe300720 100644 --- a/src/shared/clock-util.c +++ b/src/shared/clock-util.c @@ -19,7 +19,7 @@ #include "string-util.h" int clock_get_hwclock(struct tm *tm) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(tm); @@ -40,7 +40,7 @@ int clock_get_hwclock(struct tm *tm) { } int clock_set_hwclock(const struct tm *tm) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(tm); diff --git a/src/shared/copy.c b/src/shared/copy.c index e2ce4b29074..e103aa0f7ff 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -713,7 +713,7 @@ static int fd_copy_regular( 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); @@ -904,11 +904,11 @@ static int fd_copy_directory( 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; @@ -1286,7 +1286,7 @@ int copy_file_fd_full( copy_progress_bytes_t progress_bytes, void *userdata) { - _cleanup_close_ int fdf = -1; + _cleanup_close_ int fdf = -EBADF; struct stat st; int r; @@ -1339,7 +1339,7 @@ int copy_file_full( 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; @@ -1428,7 +1428,7 @@ int copy_file_atomic_full( void *userdata) { _cleanup_(unlink_and_freep) char *t = NULL; - _cleanup_close_ int fdt = -1; + _cleanup_close_ int fdt = -EBADF; int r; assert(from); diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index f6811ce9aa7..9f4d0832abf 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -167,7 +167,7 @@ static int make_credential_host_secret( 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); @@ -251,7 +251,7 @@ finish: 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; @@ -298,7 +298,7 @@ int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t * 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; diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c index 58ee1845afd..15d31ac20ce 100644 --- a/src/shared/data-fd-util.c +++ b/src/shared/data-fd-util.c @@ -28,7 +28,7 @@ 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; @@ -163,7 +163,7 @@ try_dev_shm_without_o_tmpfile: } 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; @@ -376,7 +376,7 @@ int memfd_clone_fd(int fd, const char *name, int mode) { return r; if (ro) { - _cleanup_close_ int rfd = -1; + _cleanup_close_ int rfd = -EBADF; r = memfd_set_sealed(mfd); if (r < 0) diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index eb4d23f0e8a..1f0f7ca7da0 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -247,7 +247,7 @@ static int image_make( (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; @@ -367,7 +367,7 @@ static int image_make( 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 */ @@ -984,7 +984,7 @@ int image_read_only(Image *i, bool b) { } case IMAGE_BLOCK: { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct stat st; int state = b; @@ -1152,7 +1152,7 @@ int image_read_metadata(Image *i) { 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) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index b3d35e9fbf3..c9acc2e3063 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -88,7 +88,7 @@ int probe_filesystem_full( #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; @@ -313,7 +313,7 @@ static int make_partition_devname( 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; @@ -477,7 +477,7 @@ static int dissect_image( 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)) { @@ -872,7 +872,7 @@ static int dissect_image( 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) { @@ -958,7 +958,7 @@ static int dissect_image( 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; @@ -1043,7 +1043,7 @@ static int dissect_image( /* 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; @@ -1152,7 +1152,7 @@ int dissect_image_file( #if HAVE_BLKID _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(path); @@ -1282,7 +1282,7 @@ static int run_fsck(int node_fd, const char *fstype) { } 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; @@ -1736,7 +1736,7 @@ static int decrypt_partition( _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); @@ -2026,7 +2026,7 @@ static int verity_partition( _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); @@ -2088,7 +2088,7 @@ static int verity_partition( * 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); @@ -2712,7 +2712,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_ 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; } diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 059b9aecbb9..37a41e050a9 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -40,7 +40,7 @@ struct DissectedPartition { ((DissectedPartition) { \ .partno = -1, \ .architecture = _ARCHITECTURE_INVALID, \ - .mount_node_fd = -1, \ + .mount_node_fd = -EBADF, \ }) #define TAKE_PARTITION(p) \ ({ \ diff --git a/src/shared/dm-util.c b/src/shared/dm-util.c index b48b9b5cbcf..66c1e134397 100644 --- a/src/shared/dm-util.c +++ b/src/shared/dm-util.c @@ -9,7 +9,7 @@ #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; diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index e39b2f754bb..e2b2ca23529 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -349,7 +349,7 @@ int ethtool_get_link_info( } 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]; diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index cd57016964e..cd922b84d4d 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -123,7 +123,7 @@ static int do_execute( 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); @@ -158,7 +158,7 @@ static int do_execute( 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); } @@ -199,7 +199,7 @@ int execute_directories( ExecDirFlags flags) { char **dirs = (char**) directories; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; char *name; int r; pid_t executor_pid; @@ -245,7 +245,7 @@ int execute_directories( 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; diff --git a/src/shared/fdset.c b/src/shared/fdset.c index 183fa239b6d..cfa12a509e3 100644 --- a/src/shared/fdset.c +++ b/src/shared/fdset.c @@ -131,7 +131,7 @@ int fdset_new_fill(FDSet **_s) { } FOREACH_DIRENT(de, d, return -errno) { - int fd = -1; + int fd = -EBADF; r = safe_atoi(de->d_name, &fd); if (r < 0) diff --git a/src/shared/find-esp.c b/src/shared/find-esp.c index e019b816205..084dd1c1e2a 100644 --- a/src/shared/find-esp.c +++ b/src/shared/find-esp.c @@ -243,7 +243,7 @@ static int verify_fsroot_dir( 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; @@ -328,7 +328,7 @@ success: 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. */ diff --git a/src/shared/install-file.c b/src/shared/install-file.c index 5187d71beca..ffcf86e057d 100644 --- a/src/shared/install-file.c +++ b/src/shared/install-file.c @@ -98,7 +98,7 @@ int install_file(int source_atfd, const char *source_name, 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: @@ -118,7 +118,7 @@ int install_file(int source_atfd, const char *source_name, * 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. */ @@ -133,7 +133,7 @@ int install_file(int source_atfd, const char *source_name, 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) @@ -158,7 +158,7 @@ int install_file(int source_atfd, const char *source_name, } 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) @@ -203,7 +203,7 @@ int install_file(int source_atfd, const char *source_name, 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; diff --git a/src/shared/install.c b/src/shared/install.c index c38ba1bd7aa..db150247fc9 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -739,7 +739,7 @@ static int remove_marked_symlinks( InstallChange **changes, size_t *n_changes) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; bool restart; int r = 0; @@ -1330,7 +1330,7 @@ static int unit_file_load( UnitType type; _cleanup_fclose_ FILE *f = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct stat st; int r; diff --git a/src/shared/local-addresses.c b/src/shared/local-addresses.c index 2876f72d16f..a1577de0df2 100644 --- a/src/shared/local-addresses.c +++ b/src/shared/local-addresses.c @@ -390,7 +390,7 @@ int local_outbounds( } 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; diff --git a/src/shared/lockfile-util.c b/src/shared/lockfile-util.c index 6f059abfffa..b920f3fe9be 100644 --- a/src/shared/lockfile-util.c +++ b/src/shared/lockfile-util.c @@ -16,7 +16,7 @@ #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; @@ -76,7 +76,7 @@ int make_lock_file(const char *p, int operation, LockFile *ret) { ret->fd = fd; ret->operation = operation; - fd = -1; + fd = -EBADF; t = NULL; return r; diff --git a/src/shared/lockfile-util.h b/src/shared/lockfile-util.h index 36063270dd2..20e19c01d4d 100644 --- a/src/shared/lockfile-util.h +++ b/src/shared/lockfile-util.h @@ -11,4 +11,4 @@ int make_lock_file(const char *p, int operation, LockFile *ret); 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 } diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 7972fc009e5..535b6170448 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1625,7 +1625,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) { 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; diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index ed31454e313..eb1a5bb59fd 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -73,7 +73,7 @@ static int get_current_uevent_seqnum(uint64_t *ret) { } 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)); @@ -238,8 +238,8 @@ static int loop_configure( 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; @@ -409,7 +409,7 @@ static int loop_device_make_internal( 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; @@ -588,7 +588,7 @@ int loop_device_make_by_path( 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); @@ -776,7 +776,7 @@ int loop_device_open( 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; @@ -896,7 +896,7 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) { 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; diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index 0bdaba00e64..4b4309037b4 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -28,7 +28,7 @@ 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); @@ -83,7 +83,7 @@ static int generate_machine_id(const char *root, sd_id128_t *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; @@ -195,7 +195,7 @@ finish: } 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; diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index 59d851ba0f8..9e240d41f43 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -130,7 +130,7 @@ static int setup_userns(uid_t uid, gid_t gid) { 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; diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 8fce74297bd..6e4fa4a4869 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -807,7 +807,7 @@ static int mount_in_namespace( 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, @@ -1067,7 +1067,7 @@ int make_mount_point(const char *path) { } 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 @@ -1118,7 +1118,7 @@ int remount_idmap( 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); diff --git a/src/shared/nscd-flush.c b/src/shared/nscd-flush.c index 9b0ba2d67a0..dfc7db6964d 100644 --- a/src/shared/nscd-flush.c +++ b/src/shared/nscd-flush.c @@ -23,7 +23,7 @@ struct nscdInvalidateRequest { 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; diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index 6ffe86ef7f0..195e6032243 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -412,9 +412,9 @@ int pty_forward_new( *f = (struct PTYForward) { .flags = flags, - .master = -1, - .input_fd = -1, - .output_fd = -1, + .master = -EBADF, + .input_fd = -EBADF, + .output_fd = -EBADF, }; if (event) diff --git a/src/shared/reboot-util.c b/src/shared/reboot-util.c index b1104055683..a010bf6e7f2 100644 --- a/src/shared/reboot-util.c +++ b/src/shared/reboot-util.c @@ -122,7 +122,7 @@ int shall_restore_state(void) { 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; diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index e240cdc2c32..a74883ab81e 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -297,7 +297,7 @@ int mac_selinux_fix_full( 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; diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 0b1470ca013..9c5602d617d 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -718,7 +718,7 @@ static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) { * 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; diff --git a/src/shared/smack-util.c b/src/shared/smack-util.c index 9ffee5a5eb6..b3b5c905ad8 100644 --- a/src/shared/smack-util.c +++ b/src/shared/smack-util.c @@ -188,7 +188,7 @@ int mac_smack_fix_full( 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; diff --git a/src/shared/socket-label.c b/src/shared/socket-label.c index 5195ca410c9..b86a6adbb96 100644 --- a/src/shared/socket-label.c +++ b/src/shared/socket-label.c @@ -32,7 +32,7 @@ int socket_address_listen( mode_t socket_mode, const char *label) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *p; int r; diff --git a/src/shared/specifier.c b/src/shared/specifier.c index cd651768bd8..05f5b28bb64 100644 --- a/src/shared/specifier.c +++ b/src/shared/specifier.c @@ -188,7 +188,7 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con 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) diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 8d4c07150e2..2aa30bd9f02 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -31,7 +31,7 @@ int switch_root(const char *new_root, 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); diff --git a/src/shared/tests.c b/src/shared/tests.c index ad6f978f98b..54e80decd1b 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -137,7 +137,7 @@ int log_tests_skipped_errno(int r, const char *message) { } int write_tmpfile(char *pattern, const char *contents) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(pattern); assert(contents); diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 7d953534520..a4b17be0979 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -570,7 +570,7 @@ int udev_queue_is_empty(void) { } int udev_queue_init(void) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = inotify_init1(IN_CLOEXEC); if (fd < 0) diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 37a5bf79904..3a68cf80169 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -284,7 +284,7 @@ int utmp_put_runlevel(int runlevel, int previous) { #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; diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 7ff81973e1c..80820fcad21 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -258,7 +258,7 @@ static int varlink_new(Varlink **ret) { *v = (Varlink) { .n_ref = 1, - .fd = -1, + .fd = -EBADF, .state = _VARLINK_STATE_INVALID, @@ -2194,7 +2194,7 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret) 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; } @@ -2218,7 +2218,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free); 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; @@ -2306,7 +2306,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t _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); @@ -2619,7 +2619,7 @@ int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *f _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; diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index cb44e96dae9..4445efb125f 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -17,7 +17,7 @@ #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 */ diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c index c6fa64c344b..3ccd7173e3c 100644 --- a/src/shutdown/umount.c +++ b/src/shutdown/umount.c @@ -401,7 +401,7 @@ static int md_list_get(MountPoint **head) { } static int delete_loopback(const char *device) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct loop_info64 info; assert(device); @@ -476,7 +476,7 @@ static int delete_loopback(const char *device) { } static int delete_dm(MountPoint *m) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(m); @@ -503,7 +503,7 @@ static int delete_dm(MountPoint *m) { } static int delete_md(MountPoint *m) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(m); assert(major(m->devnum) != 0); diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 9b69a2a10d1..20d3a947044 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -273,7 +273,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) { 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; diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index fb262842d88..c3bb293520a 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -486,7 +486,7 @@ static int add_connection_socket(Context *context, int fd) { *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}, }; @@ -504,7 +504,7 @@ static int add_connection_socket(Context *context, int fd) { 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); diff --git a/src/systemctl/fuzz-systemctl-parse-argv.c b/src/systemctl/fuzz-systemctl-parse-argv.c index 606f602c3ac..a97db68d2dc 100644 --- a/src/systemctl/fuzz-systemctl-parse-argv.c +++ b/src/systemctl/fuzz-systemctl-parse-argv.c @@ -16,7 +16,7 @@ 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) diff --git a/src/systemctl/systemctl-sysv-compat.c b/src/systemctl/systemctl-sysv-compat.c index 0412b0c6266..fc73830a075 100644 --- a/src/systemctl/systemctl-sysv-compat.c +++ b/src/systemctl/systemctl-sysv-compat.c @@ -18,7 +18,7 @@ int talk_initctl(char rl) { #if HAVE_SYSV_COMPAT - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *path; int r; diff --git a/src/sysupdate/sysupdate-resource.c b/src/sysupdate/sysupdate-resource.c index 2814fdb6fa3..56ce9b31cf5 100644 --- a/src/sysupdate/sysupdate-resource.c +++ b/src/sysupdate/sysupdate-resource.c @@ -563,7 +563,7 @@ int resource_resolve_path( 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; diff --git a/src/test/test-acl-util.c b/src/test/test-acl-util.c index cdce5ccef14..2c406893df8 100644 --- a/src/test/test-acl-util.c +++ b/src/test/test-acl-util.c @@ -16,7 +16,7 @@ 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; diff --git a/src/test/test-chase-symlinks.c b/src/test/test-chase-symlinks.c index 9e50c5c7490..d94173f27be 100644 --- a/src/test/test-chase-symlinks.c +++ b/src/test/test-chase-symlinks.c @@ -92,7 +92,7 @@ static int run(int argc, char **argv) { 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); @@ -105,7 +105,7 @@ static int run(int argc, char **argv) { if (arg_open) assert_se(fd >= 0); else - assert_se(fd == -1); + assert_se(fd == -EBADF); } } diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 8177f6e33b8..2568b9b384e 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -110,7 +110,7 @@ TEST(copy_tree_replace_dirs) { 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] = {}; @@ -258,7 +258,7 @@ TEST(copy_tree) { 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]; @@ -295,7 +295,7 @@ TEST(copy_bytes) { 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; diff --git a/src/test/test-data-fd-util.c b/src/test/test-data-fd-util.c index 432ba14825f..d466ba93150 100644 --- a/src/test/test-data-fd-util.c +++ b/src/test/test-data-fd-util.c @@ -80,7 +80,7 @@ static void assert_equal_fd(int fd1, int fd2) { } 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; diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c index df6ca13785f..b546933ea45 100644 --- a/src/test/test-fd-util.c +++ b/src/test/test-fd-util.c @@ -59,7 +59,7 @@ TEST(close_nointr) { 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); @@ -92,7 +92,7 @@ TEST(same_fd) { } TEST(open_serialization_fd) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = open_serialization_fd("test"); assert_se(fd >= 0); @@ -389,7 +389,7 @@ TEST(format_proc_fd_path) { } TEST(fd_reopen) { - _cleanup_close_ int fd1 = -1, fd2 = -1; + _cleanup_close_ int fd1 = -EBADF, fd2 = -EBADF; struct stat st1, st2; int fl; @@ -480,11 +480,11 @@ TEST(fd_reopen) { /* 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 */ @@ -531,42 +531,42 @@ TEST(fd_reopen_condition) { } 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); diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c index b6ad290eef9..67c99d85012 100644 --- a/src/test/test-fdset.c +++ b/src/test/test-fdset.c @@ -10,7 +10,7 @@ #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"; @@ -23,8 +23,8 @@ TEST(fdset_new_fill) { } 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"; @@ -42,7 +42,7 @@ TEST(fdset_put_dup) { } 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"; @@ -68,8 +68,8 @@ TEST(fdset_cloexec) { } 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"; @@ -92,7 +92,7 @@ TEST(fdset_close_others) { } TEST(fdset_remove) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; FDSet *fdset = NULL; char name[] = "/tmp/test-fdset_remove.XXXXXX"; @@ -112,7 +112,7 @@ TEST(fdset_remove) { } TEST(fdset_iterate) { - int fd = -1; + int fd = -EBADF; FDSet *fdset = NULL; char name[] = "/tmp/test-fdset_iterate.XXXXXX"; int c = 0; diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 6f27cd43d67..2009c0f972b 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -525,7 +525,7 @@ TEST(search_and_fopen) { 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; @@ -573,7 +573,7 @@ TEST(search_and_fopen_nulstr) { _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; @@ -610,7 +610,7 @@ TEST(writing_tmpfile) { _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[] = { @@ -909,7 +909,7 @@ TEST(read_full_file_socket) { 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); diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 69f63039902..38299ce7298 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -28,7 +28,7 @@ static const char *arg_test_dir = NULL; 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; @@ -316,7 +316,7 @@ TEST(chase_symlinks) { 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); @@ -553,7 +553,7 @@ TEST(dot_or_dot_dot) { 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"); @@ -679,7 +679,7 @@ TEST(touch_file) { 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); @@ -704,7 +704,7 @@ TEST(unlinkat_deallocate) { } 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); @@ -821,7 +821,7 @@ TEST(chmod_and_chown) { } 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); @@ -961,7 +961,7 @@ TEST(parse_cifs_service) { } 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); @@ -1005,7 +1005,7 @@ TEST(open_mkdir_at) { 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); diff --git a/src/test/test-glob-util.c b/src/test/test-glob-util.c index 566b68b5892..9b3e73cce01 100644 --- a/src/test/test-glob-util.c +++ b/src/test/test-glob-util.c @@ -15,7 +15,7 @@ TEST(glob_first) { char *first, name[] = "/tmp/test-glob_first.XXXXXX"; - int fd = -1; + int fd = -EBADF; int r; fd = mkostemp_safe(name); @@ -36,7 +36,7 @@ TEST(glob_first) { TEST(glob_exists) { char name[] = "/tmp/test-glob_exists.XXXXXX"; - int fd = -1; + int fd = -EBADF; int r; fd = mkostemp_safe(name); diff --git a/src/test/test-id128.c b/src/test/test-id128.c index afdbf1e4b90..0a97366b6da 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -23,7 +23,7 @@ TEST(id128) { 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)); diff --git a/src/test/test-io-util.c b/src/test/test-io-util.c index 38ca3d858cc..fd41a2a4d10 100644 --- a/src/test/test-io-util.c +++ b/src/test/test-io-util.c @@ -32,7 +32,7 @@ TEST(sparse_write) { 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); diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c index 6e15e1accbf..bfc32726436 100644 --- a/src/test/test-loop-block.c +++ b/src/test/test-loop-block.c @@ -145,7 +145,7 @@ static int run(int argc, char *argv[]) { _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); diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index c4a87d253e9..ea47c3a5b3a 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -276,7 +276,7 @@ TEST(path_is_mount_point) { } 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); diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index e4d763ecd57..74f3c9c7c82 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -170,7 +170,7 @@ TEST(protect_kernel_logs) { 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); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 06b9793fe31..3669dcbb123 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -195,7 +195,7 @@ TEST(path_equal_root) { 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); @@ -278,7 +278,7 @@ TEST(find_executable) { 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; diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 7e4b5d82557..1864f8a750b 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -240,7 +240,7 @@ TEST(personality) { 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; diff --git a/src/test/test-psi-util.c b/src/test/test-psi-util.c index 111671c5a9f..4ce0811a8d9 100644 --- a/src/test/test-psi-util.c +++ b/src/test/test-psi-util.c @@ -11,7 +11,7 @@ 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) diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c index ae311c56868..2d06098dddf 100644 --- a/src/test/test-seccomp.c +++ b/src/test/test-seccomp.c @@ -1020,7 +1020,7 @@ TEST(restrict_suid_sgid) { 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); diff --git a/src/test/test-selinux.c b/src/test/test-selinux.c index 717cb0db16d..04b5ba146d9 100644 --- a/src/test/test-selinux.c +++ b/src/test/test-selinux.c @@ -56,7 +56,7 @@ static void test_cleanup(void) { 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__); diff --git a/src/test/test-sigbus.c b/src/test/test-sigbus.c index 5262947c087..299463c2435 100644 --- a/src/test/test-sigbus.c +++ b/src/test/test-sigbus.c @@ -15,7 +15,7 @@ #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; diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index de64f920d17..abaae43e724 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -43,7 +43,7 @@ TEST(parse_sleep_config) { 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__); diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index cd1e374ec82..6456316aae6 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -249,7 +249,7 @@ TEST(passfd_read) { /* 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]); @@ -293,7 +293,7 @@ TEST(passfd_contents_read) { /* 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]); @@ -344,7 +344,7 @@ TEST(receive_nopassfd) { 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) { @@ -418,7 +418,7 @@ TEST(send_emptydata) { } 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; @@ -488,7 +488,7 @@ TEST(sockaddr_un_set_path) { _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); diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index 04d52d364fd..6b0f2d80337 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -43,7 +43,7 @@ TEST(null_or_empty_path_with_root) { } 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"; @@ -63,7 +63,7 @@ TEST(files_same) { 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); @@ -125,7 +125,7 @@ TEST(path_is_read_only_fs) { } 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); diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c index c58ac933bbf..83d11f5cf65 100644 --- a/src/test/test-tmpfiles.c +++ b/src/test/test-tmpfiles.c @@ -18,7 +18,7 @@ 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; diff --git a/src/test/test-varlink.c b/src/test/test-varlink.c index 634baf1ae85..7515da52ba9 100644 --- a/src/test/test-varlink.c +++ b/src/test/test-varlink.c @@ -21,7 +21,7 @@ #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; diff --git a/src/test/test-xattr-util.c b/src/test/test-xattr-util.c index 02fba3d6ff3..04d23ef09b2 100644 --- a/src/test/test-xattr-util.c +++ b/src/test/test-xattr-util.c @@ -18,7 +18,7 @@ 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; @@ -60,7 +60,7 @@ cleanup: } TEST(getcrtime) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *vt; usec_t usec, k; int r; diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 999d1d38523..887b323d96a 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -23,7 +23,7 @@ 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 diff --git a/src/timesync/wait-sync.c b/src/timesync/wait-sync.c index 44de4932fd7..832e1170960 100644 --- a/src/timesync/wait-sync.c +++ b/src/timesync/wait-sync.c @@ -177,8 +177,8 @@ static int clock_state_update( 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, }; diff --git a/src/tmpfiles/offline-passwd.c b/src/tmpfiles/offline-passwd.c index c847266ed4a..f7d3978c935 100644 --- a/src/tmpfiles/offline-passwd.c +++ b/src/tmpfiles/offline-passwd.c @@ -10,7 +10,7 @@ DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(uid_gid_hash_ops, char, string_hash_ 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) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index efe0e107b14..538d5273cff 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1021,7 +1021,7 @@ static int path_set_perms( const char *path, CreationMode creation) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(i); assert(path); @@ -1094,7 +1094,7 @@ static int path_set_xattrs( const char *path, CreationMode creation) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(i); assert(path); @@ -1240,7 +1240,7 @@ static int fd_set_acls( 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); @@ -1345,7 +1345,7 @@ static int fd_set_attribute( 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; @@ -1395,7 +1395,7 @@ static int fd_set_attribute( } 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; @@ -1429,7 +1429,7 @@ static int write_argument_data(Item *i, int fd, const char *path) { } 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; @@ -1475,7 +1475,7 @@ static int write_one_file(Item *i, const char *path, CreationMode creation) { } 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; @@ -1540,7 +1540,7 @@ static int create_file(Item *i, const char *path) { } 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; @@ -1629,7 +1629,7 @@ static int truncate_file(Item *i, const char *path) { } 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; @@ -1684,7 +1684,7 @@ static int create_directory_or_subvolume( 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; @@ -1761,7 +1761,7 @@ static int create_directory_or_subvolume( } static int create_directory(Item *i, const char *path) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; CreationMode creation; struct stat st; @@ -1778,7 +1778,7 @@ static int create_directory(Item *i, const char *path) { } 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; @@ -1817,7 +1817,7 @@ static int create_subvolume(Item *i, const char *path) { } 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; @@ -1847,7 +1847,7 @@ static int empty_directory(Item *i, const char *path, CreationMode creation) { } 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; @@ -1952,7 +1952,7 @@ handle_privilege: } 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; @@ -2037,7 +2037,7 @@ static int create_fifo(Item *i) { } 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; @@ -2223,7 +2223,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) { 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 @@ -2243,7 +2243,7 @@ static int glob_item_recursively(Item *i, fdaction_t action) { r = k; /* we passed fd ownership to the previous call */ - fd = -1; + fd = -EBADF; } return r; @@ -2306,7 +2306,7 @@ static int rm_if_wrong_type_safe( "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) @@ -2329,7 +2329,7 @@ static int rm_if_wrong_type_safe( /* 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; @@ -2357,7 +2357,7 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) { /* 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; diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index c7609d7d79d..9166e1f9ecd 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -56,7 +56,7 @@ static const char *arg_device = NULL; 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; @@ -97,7 +97,7 @@ static int send_passwords(const char *socket_name, char **passwords) { 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)); @@ -142,7 +142,7 @@ static int agent_ask_password_tty( 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) { @@ -337,8 +337,8 @@ static int process_and_watch_password_files(bool watch) { _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; diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index bae4d03b4f4..6a631e515cd 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -399,7 +399,7 @@ int main(int argc, char *argv[]) { 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[] = { diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 5945dcbbaec..ea420a96171 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -103,7 +103,7 @@ typedef struct Context { } Context; #define CONTEXT_EMPTY { \ - .fd = -1, \ + .fd = -EBADF, \ .media_feature = _FEATURE_INVALID, \ .media_state = _MEDIA_STATE_INVALID, \ } diff --git a/src/udev/fido_id/fido_id.c b/src/udev/fido_id/fido_id.c index 58a28278180..f2fbc38003a 100644 --- a/src/udev/fido_id/fido_id.c +++ b/src/udev/fido_id/fido_id.c @@ -28,7 +28,7 @@ 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; diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c index d5fb64f1948..a7210a05e3c 100644 --- a/src/udev/mtd_probe/mtd_probe.c +++ b/src/udev/mtd_probe/mtd_probe.c @@ -33,7 +33,7 @@ #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) { diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 25edb49d28a..5f18ba35fc3 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -97,7 +97,7 @@ int link_config_ctx_new(LinkConfigContext **ret) { return -ENOMEM; *ctx = (LinkConfigContext) { - .ethtool_fd = -1, + .ethtool_fd = -EBADF, }; *ret = TAKE_PTR(ctx); diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index f1ce8601bd8..c619506877c 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -786,7 +786,7 @@ out: 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; diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 9b5dfbe33be..d2de03d5f9b 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -238,7 +238,7 @@ static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv 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; diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index faaafb23f66..79f91ea2ae5 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -14,7 +14,7 @@ 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")) diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 465913ce31f..33184b024f4 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -47,7 +47,7 @@ static int abs_size_mm(const struct input_absinfo *absinfo) { 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) diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index e67a02aee6e..80cfdee0c18 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -162,7 +162,7 @@ static int set_trackpoint_sensitivity(sd_device *dev, const char *value) { 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; diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 847c2b8316b..91deb64292e 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -134,7 +134,7 @@ static void set_scsi_type(char *to, const char *from, size_t len) { #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; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 9e34ea6b01f..1990282c754 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -281,7 +281,7 @@ static int stack_directory_update(sd_device *dev, int fd, bool add) { } static int stack_directory_open(const char *dirname) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(dirname); @@ -298,7 +298,7 @@ static int stack_directory_open(const char *dirname) { } static int stack_directory_lock(int dirfd) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(dirfd >= 0); @@ -387,7 +387,7 @@ static int stack_directory_get_name(const char *slink, char **ret) { 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); @@ -624,7 +624,7 @@ int udev_node_apply_permissions( OrderedHashmap *seclabel_list) { const char *devnode; - _cleanup_close_ int node_fd = -1; + _cleanup_close_ int node_fd = -EBADF; int r; assert(dev); @@ -654,7 +654,7 @@ int static_node_apply_permissions( 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; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 6bb013c094f..d00226cd7a4 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -174,7 +174,7 @@ finalize: 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; @@ -229,7 +229,7 @@ on_failure: } 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); diff --git a/src/udev/udevadm-lock.c b/src/udev/udevadm-lock.c index 35e9999c015..d19e7561f81 100644 --- a/src/udev/udevadm-lock.c +++ b/src/udev/udevadm-lock.c @@ -176,7 +176,7 @@ static int lock_device( dev_t devno, usec_t deadline) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct stat st; int r; @@ -328,7 +328,7 @@ int lock_main(int argc, char *argv[], void *userdata) { 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) diff --git a/src/udev/udevd.c b/src/udev/udevd.c index eb15b250d56..0de5b4ec643 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -513,7 +513,7 @@ irrelevant: } 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; @@ -550,12 +550,12 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) { 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; @@ -600,7 +600,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) { 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); @@ -1561,7 +1561,7 @@ static int on_post(sd_event_source *s, void *userdata) { } 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); @@ -1847,7 +1847,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent) { return log_oom(); *manager = (Manager) { - .inotify_fd = -1, + .inotify_fd = -EBADF, .worker_watch = { -1, -1 }, .cgroup = TAKE_PTR(cgroup), }; @@ -1993,7 +1993,7 @@ static int main_loop(Manager *manager) { 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); diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index 13b4839989f..4f163c43509 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, {} }; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; char *device; struct v4l2_capability v2cap; int c; diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 675526f3ace..7449a2321c5 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -39,7 +39,7 @@ static void context_clear(Context *c) { #if HAVE_AUDIT if (c->audit_fd >= 0) audit_close(c->audit_fd); - c->audit_fd = -1; + c->audit_fd = -EBADF; #endif } @@ -221,7 +221,7 @@ static int on_runlevel(Context *c) { static int run(int argc, char *argv[]) { _cleanup_(context_clear) Context c = { #if HAVE_AUDIT - .audit_fd = -1, + .audit_fd = -EBADF, #endif }; int r; diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index 49bdaf666f6..b728cdc1c36 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -931,7 +931,7 @@ static int display_services(int argc, char *argv[], void *userdata) { 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) diff --git a/src/userdb/userdbd-manager.c b/src/userdb/userdbd-manager.c index 81d3f6407c9..7890d047c49 100644 --- a/src/userdb/userdbd-manager.c +++ b/src/userdb/userdbd-manager.c @@ -83,7 +83,7 @@ int manager_new(Manager **ret) { return -ENOMEM; *m = (Manager) { - .listen_fd = -1, + .listen_fd = -EBADF, .worker_ratelimit = { .interval = 5 * USEC_PER_SEC, .burst = 50, diff --git a/src/userdb/userwork.c b/src/userdb/userwork.c index 21a869df1b5..9fccadc9501 100644 --- a/src/userdb/userwork.c +++ b/src/userdb/userwork.c @@ -503,7 +503,7 @@ static int run(int argc, char *argv[]) { 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 */ diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 98f978df0af..ecc859a2c35 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -278,7 +278,7 @@ static void setup_remaining_vcs(int src_fd, unsigned src_idx, bool utf8) { 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; @@ -350,7 +350,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) { 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) { @@ -383,7 +383,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) { } 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; @@ -416,7 +416,7 @@ int main(int argc, char **argv) { *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; diff --git a/src/xdg-autostart-generator/fuzz-xdg-desktop.c b/src/xdg-autostart-generator/fuzz-xdg-desktop.c index 084c9073070..b1b035d94e7 100644 --- a/src/xdg-autostart-generator/fuzz-xdg-desktop.c +++ b/src/xdg-autostart-generator/fuzz-xdg-desktop.c @@ -13,7 +13,7 @@ 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;