summaryrefslogtreecommitdiff
path: root/src/portable
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/portable
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/portable')
-rw-r--r--src/portable/portable.c20
-rw-r--r--src/portable/portabled-bus.c4
-rw-r--r--src/portable/portabled-image-bus.c2
-rw-r--r--src/portable/portabled-operation.c2
4 files changed, 14 insertions, 14 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 0909e14aab..45dd70b13d 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 be321b8f03..768964231a 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 b108fd34af..704b51d81d 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 26adb9091a..6897ed0b28 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) {