tree-wide: use -EBADF for fd initialization

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

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

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

In some places, initialization is dropped if unnecessary.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-12-19 15:00:57 +01:00
parent cbff793ffb
commit 254d1313ae
284 changed files with 792 additions and 793 deletions
+5 -5
View File
@@ -195,7 +195,7 @@ int readlink_and_make_absolute(const char *p, char **r) {
}
int chmod_and_chown_at(int dir_fd, const char *path, mode_t mode, uid_t uid, gid_t gid) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
@@ -360,7 +360,7 @@ int fd_warn_permissions(const char *path, int fd) {
}
int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r, ret;
assert(path);
@@ -684,7 +684,7 @@ void unlink_tempfilep(char (*p)[]) {
}
int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
_cleanup_close_ int truncate_fd = -1;
_cleanup_close_ int truncate_fd = -EBADF;
struct stat st;
off_t l, bs;
@@ -815,7 +815,7 @@ int conservative_renameat(
int olddirfd, const char *oldpath,
int newdirfd, const char *newpath) {
_cleanup_close_ int old_fd = -1, new_fd = -1;
_cleanup_close_ int old_fd = -EBADF, new_fd = -EBADF;
struct stat old_stat, new_stat;
/* Renames the old path to thew new path, much like renameat() — except if both are regular files and
@@ -997,7 +997,7 @@ int parse_cifs_service(
}
int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode) {
_cleanup_close_ int fd = -1, parent_fd = -1;
_cleanup_close_ int fd = -EBADF, parent_fd = -EBADF;
_cleanup_free_ char *fname = NULL;
bool made;
int r;