summaryrefslogtreecommitdiff
path: root/src/import
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/import
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/import')
-rw-r--r--src/import/export-raw.c6
-rw-r--r--src/import/export-tar.c6
-rw-r--r--src/import/export.c4
-rw-r--r--src/import/import-fs.c2
-rw-r--r--src/import/import-raw.c6
-rw-r--r--src/import/import-tar.c4
-rw-r--r--src/import/import.c6
-rw-r--r--src/import/importd.c6
-rw-r--r--src/import/pull-job.c4
-rw-r--r--src/import/pull-raw.c4
-rw-r--r--src/import/test-qcow2.c2
11 files changed, 25 insertions, 25 deletions
diff --git a/src/import/export-raw.c b/src/import/export-raw.c
index 6b15884e77..7c61aef3b6 100644
--- a/src/import/export-raw.c
+++ b/src/import/export-raw.c
@@ -84,8 +84,8 @@ int raw_export_new(
return -ENOMEM;
*e = (RawExport) {
- .output_fd = -1,
- .input_fd = -1,
+ .output_fd = -EBADF,
+ .input_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
@@ -267,7 +267,7 @@ static int reflink_snapshot(int fd, const char *path) {
}
int raw_export_start(RawExport *e, const char *path, int fd, ImportCompressType compress) {
- _cleanup_close_ int sfd = -1, tfd = -1;
+ _cleanup_close_ int sfd = -EBADF, tfd = -EBADF;
int r;
assert(e);
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index b9953a4bf3..4aa8204983 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -90,8 +90,8 @@ int tar_export_new(
return -ENOMEM;
*e = (TarExport) {
- .output_fd = -1,
- .tar_fd = -1,
+ .output_fd = -EBADF,
+ .tar_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.quota_referenced = UINT64_MAX,
@@ -250,7 +250,7 @@ static int tar_export_on_defer(sd_event_source *s, void *userdata) {
}
int tar_export_start(TarExport *e, const char *path, int fd, ImportCompressType compress) {
- _cleanup_close_ int sfd = -1;
+ _cleanup_close_ int sfd = -EBADF;
int r;
assert(e);
diff --git a/src/import/export.c b/src/import/export.c
index 690e194453..84609cbe12 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -63,7 +63,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(image_unrefp) Image *image = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (hostname_is_valid(argv[1], 0)) {
@@ -139,7 +139,7 @@ static int export_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(image_unrefp) Image *image = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (hostname_is_valid(argv[1], 0)) {
diff --git a/src/import/import-fs.c b/src/import/import-fs.c
index ca5d33c008..d81dd13ffd 100644
--- a/src/import/import-fs.c
+++ b/src/import/import-fs.c
@@ -100,7 +100,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
_cleanup_(progress_info_free) ProgressInfo progress = {};
_cleanup_free_ char *l = NULL, *final_path = NULL;
const char *path = NULL, *local = NULL, *dest = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index ee904bc4e0..5d4dedf66d 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -105,8 +105,8 @@ int raw_import_new(
return -ENOMEM;
*i = (RawImport) {
- .input_fd = -1,
- .output_fd = -1,
+ .input_fd = -EBADF,
+ .output_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
@@ -154,7 +154,7 @@ static void raw_import_report_progress(RawImport *i) {
}
static int raw_import_maybe_convert_qcow2(RawImport *i) {
- _cleanup_close_ int converted_fd = -1;
+ _cleanup_close_ int converted_fd = -EBADF;
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_free_ char *f = NULL;
int r;
diff --git a/src/import/import-tar.c b/src/import/import-tar.c
index 90b4e51d2c..dff6d3276a 100644
--- a/src/import/import-tar.c
+++ b/src/import/import-tar.c
@@ -107,8 +107,8 @@ int tar_import_new(
return -ENOMEM;
*i = (TarImport) {
- .input_fd = -1,
- .tar_fd = -1,
+ .input_fd = -EBADF,
+ .tar_fd = -EBADF,
.on_finished = on_finished,
.userdata = userdata,
.last_percent = UINT_MAX,
diff --git a/src/import/import.c b/src/import/import.c
index 13f34633d2..a81617d38e 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -83,7 +83,7 @@ static int normalize_local(const char *local, char **ret) {
}
static int open_source(const char *path, const char *local, int *ret_open_fd) {
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int retval;
assert(local);
@@ -132,7 +132,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *ll = NULL, *normalized = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
@@ -204,7 +204,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *ll = NULL, *normalized = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
const char *path = NULL, *local = NULL;
- _cleanup_close_ int open_fd = -1;
+ _cleanup_close_ int open_fd = -EBADF;
int r, fd;
if (argc >= 2)
diff --git a/src/import/importd.c b/src/import/importd.c
index 4f6be5f20c..b2d176b4e7 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -157,9 +157,9 @@ static int transfer_new(Manager *m, Transfer **ret) {
*t = (Transfer) {
.type = _TRANSFER_TYPE_INVALID,
- .log_fd = -1,
- .stdin_fd = -1,
- .stdout_fd = -1,
+ .log_fd = -EBADF,
+ .stdin_fd = -EBADF,
+ .stdout_fd = -EBADF,
.verify = _IMPORT_VERIFY_INVALID,
.progress_percent= UINT_MAX,
};
diff --git a/src/import/pull-job.c b/src/import/pull-job.c
index 1e105bc769..ce7642e897 100644
--- a/src/import/pull-job.c
+++ b/src/import/pull-job.c
@@ -27,7 +27,7 @@ void pull_job_close_disk_fd(PullJob *j) {
if (j->close_disk_fd)
safe_close(j->disk_fd);
- j->disk_fd = -1;
+ j->disk_fd = -EBADF;
}
PullJob* pull_job_unref(PullJob *j) {
@@ -692,7 +692,7 @@ int pull_job_new(
*j = (PullJob) {
.state = PULL_JOB_INIT,
- .disk_fd = -1,
+ .disk_fd = -EBADF,
.close_disk_fd = true,
.userdata = userdata,
.glue = glue,
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index d3d14af6d1..a4a844bf07 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -238,7 +238,7 @@ static void raw_pull_report_progress(RawPull *i, RawProgress p) {
static int raw_pull_maybe_convert_qcow2(RawPull *i) {
_cleanup_(unlink_and_freep) char *t = NULL;
- _cleanup_close_ int converted_fd = -1;
+ _cleanup_close_ int converted_fd = -EBADF;
_cleanup_free_ char *f = NULL;
int r;
@@ -346,7 +346,7 @@ static int raw_pull_copy_auxiliary_file(
static int raw_pull_make_local_copy(RawPull *i) {
_cleanup_(unlink_and_freep) char *tp = NULL;
_cleanup_free_ char *f = NULL;
- _cleanup_close_ int dfd = -1;
+ _cleanup_close_ int dfd = -EBADF;
const char *p;
int r;
diff --git a/src/import/test-qcow2.c b/src/import/test-qcow2.c
index 77fed01dd3..ca31fd678d 100644
--- a/src/import/test-qcow2.c
+++ b/src/import/test-qcow2.c
@@ -9,7 +9,7 @@
#include "qcow2-util.h"
int main(int argc, char *argv[]) {
- _cleanup_close_ int sfd = -1, dfd = -1;
+ _cleanup_close_ int sfd = -EBADF, dfd = -EBADF;
int r;
if (argc != 3) {