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
+7 -7
View File
@@ -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);