summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 13:07:42 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-12-19 15:00:57 +0100
commit254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch)
tree067102a36abe6bf597c26a42d79018a1060c9007 /src/basic
parentcbff793ffb280d9d11e5d7b1dc3964276491bee8 (diff)
downloadsystemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.gz
tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/chase-symlinks.c16
-rw-r--r--src/basic/chattr-util.c4
-rw-r--r--src/basic/efivars.c4
-rw-r--r--src/basic/fd-util.c36
-rw-r--r--src/basic/fd-util.h2
-rw-r--r--src/basic/fileio.c10
-rw-r--r--src/basic/fs-util.c10
-rw-r--r--src/basic/locale-util.c2
-rw-r--r--src/basic/log.c8
-rw-r--r--src/basic/memfd-util.c2
-rw-r--r--src/basic/mkdir.c4
-rw-r--r--src/basic/mountpoint-util.c6
-rw-r--r--src/basic/namespace-util.c8
-rw-r--r--src/basic/os-util.c2
-rw-r--r--src/basic/path-util.c4
-rw-r--r--src/basic/random-util.c8
-rw-r--r--src/basic/recurse-dir.c4
-rw-r--r--src/basic/socket-util.c4
-rw-r--r--src/basic/stat-util.c2
-rw-r--r--src/basic/sync-util.c10
-rw-r--r--src/basic/terminal-util.c20
-rw-r--r--src/basic/time-util.c4
-rw-r--r--src/basic/tmpfile-util.c6
-rw-r--r--src/basic/xattr-util.c4
24 files changed, 90 insertions, 90 deletions
diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c
index 385d0aed69..a9de17b476 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 eddde132aa..3c66a3e0c8 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 17e0fb895e..e7ece805d4 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 b97039284c..4ab972b13e 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 fbaa458613..530270a73f 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 5078cae2df..a901597962 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 fbc7492b15..ed020b1b08 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 40c6e46ab8..d94fbcff4b 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 173643196e..282130345f 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 f05fb1524e..fb86ac2b5b 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 6796d4aeda..7ad19ee33b 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 1136454b7d..bc74fbef8f 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 a87a875943..f5c0e04cec 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 8f8bb0881e..9c21dc3bdc 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 bf93990fde..cc45cb311e 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 d8734cc7d0..28ace92f19 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 fe18b98d5b..5e98b7a5d8 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 f39be19a59..54f5f1cc5b 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 0974f6178a..693e1f7eb6 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 e2d4a3d895..52c8c417de 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 7bc2f71bcf..da03a884f8 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 71b2f67350..d5c10571c9 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 dbbd54027e..95adf9d374 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 0b661d9325..5b6131b56a 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;