summaryrefslogtreecommitdiff
path: root/src/dissect
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/dissect
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/dissect')
-rw-r--r--src/dissect/dissect.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index b7bcf731f7..ed923c2c86 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