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:
@@ -360,7 +360,7 @@ static int verb_status(int argc, char *argv[], void *userdata) {
|
||||
left, done);
|
||||
|
||||
STRV_FOREACH(p, arg_path) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
|
||||
if (fd < 0) {
|
||||
@@ -439,7 +439,7 @@ static int verb_set(int argc, char *argv[], void *userdata) {
|
||||
}
|
||||
|
||||
STRV_FOREACH(p, arg_path) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
fd = open(*p, O_DIRECTORY|O_CLOEXEC|O_RDONLY);
|
||||
if (fd < 0)
|
||||
|
||||
@@ -299,7 +299,7 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
|
||||
}
|
||||
|
||||
static int copy_file_with_version_check(const char *from, const char *to, bool force) {
|
||||
_cleanup_close_ int fd_from = -1, fd_to = -1;
|
||||
_cleanup_close_ int fd_from = -EBADF, fd_to = -EBADF;
|
||||
_cleanup_free_ char *t = NULL;
|
||||
int r;
|
||||
|
||||
@@ -899,7 +899,7 @@ static int remove_boot_efi(const char *esp_path) {
|
||||
return log_error_errno(r, "Failed to open directory \"%s/EFI/BOOT\": %m", esp_path);
|
||||
|
||||
FOREACH_DIRENT(de, d, break) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
_cleanup_free_ char *v = NULL;
|
||||
|
||||
if (!endswith_no_case(de->d_name, ".efi"))
|
||||
|
||||
@@ -19,7 +19,7 @@ int install_random_seed(const char *esp) {
|
||||
_cleanup_(unlink_and_freep) char *tmp = NULL;
|
||||
uint8_t buffer[RANDOM_EFI_SEED_SIZE];
|
||||
_cleanup_free_ char *path = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
size_t token_size;
|
||||
ssize_t n;
|
||||
int r;
|
||||
|
||||
@@ -205,7 +205,7 @@ static int enumerate_binaries(
|
||||
|
||||
FOREACH_DIRENT(de, d, break) {
|
||||
_cleanup_free_ char *v = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
if (!endswith_no_case(de->d_name, ".efi"))
|
||||
continue;
|
||||
|
||||
+1
-1
@@ -427,7 +427,7 @@ static int measure_kernel(PcrState *pcr_states, size_t n) {
|
||||
|
||||
for (UnifiedSection c = 0; c < _UNIFIED_SECTION_MAX; c++) {
|
||||
_cleanup_(evp_md_ctx_free_all) EVP_MD_CTX **mdctx = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
uint64_t m = 0;
|
||||
|
||||
if (!arg_sections[c])
|
||||
|
||||
Reference in New Issue
Block a user