summaryrefslogtreecommitdiff
path: root/src/machine
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/machine
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/machine')
-rw-r--r--src/machine/image-dbus.c4
-rw-r--r--src/machine/machine-dbus.c16
-rw-r--r--src/machine/machinectl.c10
-rw-r--r--src/machine/machined-dbus.c10
-rw-r--r--src/machine/operation.c2
5 files changed, 21 insertions, 21 deletions
diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c
index 84dc95eca1..698052dd86 100644
--- a/src/machine/image-dbus.c
+++ b/src/machine/image-dbus.c
@@ -88,7 +88,7 @@ int bus_image_method_remove(
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
@@ -211,7 +211,7 @@ int bus_image_method_clone(
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 75f397dd6b..26ba5d4292 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -225,7 +225,7 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd
case MACHINE_CONTAINER: {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_free_ char *us = NULL, *them = NULL;
- _cleanup_close_ int netns_fd = -1;
+ _cleanup_close_ int netns_fd = -EBADF;
const char *p;
pid_t child;
@@ -370,7 +370,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
break;
case MACHINE_CONTAINER: {
- _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1;
+ _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_fclose_ FILE *f = NULL;
pid_t child;
@@ -388,7 +388,7 @@ int bus_machine_method_get_os_release(sd_bus_message *message, void *userdata, s
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
if (r == 0) {
- int fd = -1;
+ int fd = -EBADF;
pair[0] = safe_close(pair[0]);
@@ -890,7 +890,7 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro
const char *src, *dest, *host_path, *container_path;
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
CopyFlags copy_flags = COPY_REFLINK|COPY_MERGE|COPY_HARDLINKS;
- _cleanup_close_ int hostfd = -1;
+ _cleanup_close_ int hostfd = -EBADF;
Machine *m = ASSERT_PTR(userdata);
bool copy_from;
pid_t child;
@@ -1042,13 +1042,13 @@ int bus_machine_method_copy(sd_bus_message *message, void *userdata, sd_bus_erro
(void) sigkill_wait(child);
return r;
}
- errno_pipe_fd[0] = -1;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
int bus_machine_method_open_root_directory(sd_bus_message *message, void *userdata, sd_bus_error *error) {
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
Machine *m = ASSERT_PTR(userdata);
int r;
@@ -1084,7 +1084,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
break;
case MACHINE_CONTAINER: {
- _cleanup_close_ int mntns_fd = -1, root_fd = -1;
+ _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
_cleanup_close_pair_ int pair[2] = { -1, -1 };
pid_t child;
@@ -1100,7 +1100,7 @@ int bus_machine_method_open_root_directory(sd_bus_message *message, void *userda
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
if (r == 0) {
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
pair[0] = safe_close(pair[0]);
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 93761a1da9..149b5d8e60 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -1800,7 +1800,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
@@ -1861,7 +1861,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
@@ -1922,7 +1922,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
const char *local = NULL, *path = NULL;
_cleanup_free_ char *fn = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
@@ -1987,7 +1987,7 @@ static void determine_compression_from_filename(const char *p) {
static int export_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *local = NULL, *path = NULL;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
@@ -2027,7 +2027,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
static int export_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- _cleanup_close_ int fd = -1;
+ _cleanup_close_ int fd = -EBADF;
const char *local = NULL, *path = NULL;
sd_bus *bus = ASSERT_PTR(userdata);
int r;
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 3da639279d..aef3e90542 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -44,7 +44,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);
@@ -70,7 +70,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);
@@ -684,7 +684,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
} mode;
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
- _cleanup_close_ int result_fd = -1;
+ _cleanup_close_ int result_fd = -EBADF;
Manager *m = userdata;
Operation *operation;
const char *mm;
@@ -824,8 +824,8 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
operation->extra_fd = result_fd;
operation->done = clean_pool_done;
- result_fd = -1;
- errno_pipe_fd[0] = -1;
+ result_fd = -EBADF;
+ errno_pipe_fd[0] = -EBADF;
return 1;
}
diff --git a/src/machine/operation.c b/src/machine/operation.c
index c97b29aba8..49b6d31bdc 100644
--- a/src/machine/operation.c
+++ b/src/machine/operation.c
@@ -81,7 +81,7 @@ int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_messag
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) {