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:
Zbigniew Jędrzejewski-Szmek
2022-12-19 15:00:57 +01:00
parent cbff793ffb
commit 254d1313ae
284 changed files with 792 additions and 793 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ int acpi_get_boot_usec(usec_t *ret_loader_start, usec_t *ret_loader_exit) {
struct acpi_fpdt_header *rec;
int r;
uint64_t ptr = 0;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct acpi_fpdt_boot_header hbrec;
struct acpi_fpdt_boot brec;
+4 -4
View File
@@ -213,7 +213,7 @@ int ask_password_plymouth(
char ***ret) {
static const union sockaddr_union sa = PLYMOUTH_SOCKET;
_cleanup_close_ int fd = -1, notify = -1;
_cleanup_close_ int fd = -EBADF, notify = -EBADF;
_cleanup_free_ char *packet = NULL;
ssize_t k;
int r, n;
@@ -394,7 +394,7 @@ int ask_password_tty(
};
bool reset_tty = false, dirty = false, use_color = false, press_tab_visible = false;
_cleanup_close_ int cttyfd = -1, notify = -1;
_cleanup_close_ int cttyfd = -EBADF, notify = -EBADF;
struct termios old_termios, new_termios;
char passphrase[LINE_MAX + 1] = {}, *x;
_cleanup_strv_free_erase_ char **l = NULL;
@@ -670,7 +670,7 @@ static int create_socket(char **ret) {
_cleanup_free_ char *path = NULL;
union sockaddr_union sa;
socklen_t sa_len;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(ret);
@@ -715,7 +715,7 @@ int ask_password_agent(
_FD_MAX
};
_cleanup_close_ int socket_fd = -1, signal_fd = -1, notify = -1, fd = -1;
_cleanup_close_ int socket_fd = -EBADF, signal_fd = -EBADF, notify = -EBADF, fd = -EBADF;
char temp[] = "/run/systemd/ask-password/tmp.XXXXXX";
char final[sizeof(temp)] = "";
_cleanup_free_ char *socket_name = NULL;
+1 -1
View File
@@ -123,7 +123,7 @@ static const BaseFilesystem table[] = {
#endif
int base_filesystem_create(const char *root, uid_t uid, gid_t gid) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
+7 -7
View File
@@ -198,7 +198,7 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flags, sd_device **re
}
int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flags, sd_device **ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
@@ -283,7 +283,7 @@ int get_block_device_fd(int fd, dev_t *ret) {
}
int get_block_device(const char *path, dev_t *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
@@ -333,7 +333,7 @@ int get_block_device_harder_fd(int fd, dev_t *ret) {
}
int get_block_device_harder(const char *path, dev_t *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
assert(ret);
@@ -346,7 +346,7 @@ int get_block_device_harder(const char *path, dev_t *ret) {
}
int lock_whole_block_device(dev_t devt, int operation) {
_cleanup_close_ int lock_fd = -1;
_cleanup_close_ int lock_fd = -EBADF;
dev_t whole_devt;
int r;
@@ -519,7 +519,7 @@ int fd_get_whole_disk(int fd, bool backing, dev_t *ret) {
}
int path_get_whole_disk(const char *path, bool backing, dev_t *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_CLOEXEC|O_PATH);
if (fd < 0)
@@ -662,7 +662,7 @@ int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) {
int block_device_remove_all_partitions(sd_device *dev, int fd) {
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
_cleanup_(sd_device_unrefp) sd_device *dev_unref = NULL;
_cleanup_close_ int fd_close = -1;
_cleanup_close_ int fd_close = -EBADF;
bool has_partitions = false;
sd_device *part;
int r, k = 0;
@@ -740,7 +740,7 @@ int block_device_has_partitions(sd_device *dev) {
}
int blockdev_reread_partition_table(sd_device *dev) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(dev);
+2 -2
View File
@@ -585,7 +585,7 @@ static int boot_entries_find_type1(
_cleanup_free_ DirectoryEntries *dentries = NULL;
_cleanup_free_ char *full = NULL;
_cleanup_close_ int dir_fd = -1;
_cleanup_close_ int dir_fd = -EBADF;
int r;
assert(config);
@@ -860,7 +860,7 @@ static int boot_entries_find_unified(
FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read %s: %m", full)) {
_cleanup_free_ char *j = NULL, *osrelease = NULL, *cmdline = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
if (!dirent_is_file(de))
continue;
+5 -5
View File
@@ -98,7 +98,7 @@ int bpf_program_new(uint32_t prog_type, const char *prog_name, BPFProgram **ret)
*p = (BPFProgram) {
.prog_type = prog_type,
.kernel_fd = -1,
.kernel_fd = -EBADF,
.prog_name = TAKE_PTR(name),
};
@@ -121,7 +121,7 @@ int bpf_program_new_from_bpffs_path(const char *path, BPFProgram **ret) {
*p = (BPFProgram) {
.prog_type = BPF_PROG_TYPE_UNSPEC,
.kernel_fd = -1,
.kernel_fd = -EBADF,
};
r = bpf_program_load_from_bpf_fs(p, path);
@@ -207,7 +207,7 @@ int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path) {
int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags) {
_cleanup_free_ char *copy = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
union bpf_attr attr;
int r;
@@ -268,7 +268,7 @@ int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_
}
int bpf_program_cgroup_detach(BPFProgram *p) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(p);
@@ -420,7 +420,7 @@ int bpf_program_serialize_attachment_set(FILE *f, FDSet *fds, const char *key, S
int bpf_program_deserialize_attachment(const char *v, FDSet *fds, BPFProgram **bpfp) {
_cleanup_free_ char *sfd = NULL, *sat = NULL, *unescaped = NULL;
_cleanup_(bpf_program_freep) BPFProgram *p = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
ssize_t l;
int ifd, at, r;
+22 -22
View File
@@ -85,7 +85,7 @@ int btrfs_is_subvol_fd(int fd) {
}
int btrfs_is_subvol(const char *path) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
@@ -98,7 +98,7 @@ int btrfs_is_subvol(const char *path) {
int btrfs_subvol_make_fd(int fd, const char *subvolume) {
struct btrfs_ioctl_vol_args args = {};
_cleanup_close_ int real_fd = -1;
_cleanup_close_ int real_fd = -EBADF;
int r;
assert(subvolume);
@@ -119,7 +119,7 @@ int btrfs_subvol_make_fd(int fd, const char *subvolume) {
}
int btrfs_subvol_make(const char *path) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
const char *subvolume;
int r;
@@ -184,7 +184,7 @@ int btrfs_subvol_set_read_only_fd(int fd, bool b) {
}
int btrfs_subvol_set_read_only(const char *path, bool b) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
@@ -247,7 +247,7 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int outfd, uint64_t out_offs
int btrfs_get_block_device_fd(int fd, dev_t *dev) {
struct btrfs_ioctl_fs_info_args fsi = {};
_cleanup_close_ int regfd = -1;
_cleanup_close_ int regfd = -EBADF;
uint64_t id;
int r;
@@ -312,7 +312,7 @@ int btrfs_get_block_device_fd(int fd, dev_t *dev) {
}
int btrfs_get_block_device(const char *path, dev_t *dev) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(path);
assert(dev);
@@ -347,7 +347,7 @@ int btrfs_subvol_get_id_fd(int fd, uint64_t *ret) {
}
int btrfs_subvol_get_id(int fd, const char *subvol, uint64_t *ret) {
_cleanup_close_ int subvol_fd = -1;
_cleanup_close_ int subvol_fd = -EBADF;
assert(fd >= 0);
assert(ret);
@@ -629,7 +629,7 @@ finish:
}
int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -722,7 +722,7 @@ int btrfs_subvol_get_subtree_quota_fd(int fd, uint64_t subvol_id, BtrfsQuotaInfo
}
int btrfs_subvol_get_subtree_quota(const char *path, uint64_t subvol_id, BtrfsQuotaInfo *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -744,7 +744,7 @@ int btrfs_defrag_fd(int fd) {
}
int btrfs_defrag(const char *p) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -771,7 +771,7 @@ int btrfs_quota_enable_fd(int fd, bool b) {
}
int btrfs_quota_enable(const char *path, bool b) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -822,7 +822,7 @@ int btrfs_qgroup_set_limit_fd(int fd, uint64_t qgroupid, uint64_t referenced_max
}
int btrfs_qgroup_set_limit(const char *path, uint64_t qgroupid, uint64_t referenced_max) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -845,7 +845,7 @@ int btrfs_subvol_set_subtree_quota_limit_fd(int fd, uint64_t subvol_id, uint64_t
}
int btrfs_subvol_set_subtree_quota_limit(const char *path, uint64_t subvol_id, uint64_t referenced_max) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd < 0)
@@ -1049,7 +1049,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
};
struct btrfs_ioctl_vol_args vol_args = {};
_cleanup_close_ int subvol_fd = -1;
_cleanup_close_ int subvol_fd = -EBADF;
struct stat st;
bool made_writable = false;
int r;
@@ -1149,7 +1149,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
* directory of the subvolume. */
r = subvol_remove_children(subvol_fd, p, sh->objectid, flags);
else {
_cleanup_close_ int child_fd = -1;
_cleanup_close_ int child_fd = -EBADF;
/* Subvolume is somewhere further down,
* hence we need to open the
@@ -1180,7 +1180,7 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
}
int btrfs_subvol_remove(const char *path, BtrfsRemoveFlags flags) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
const char *subvolume;
int r;
@@ -1414,7 +1414,7 @@ static int subvol_snapshot_children(
.flags = flags & BTRFS_SNAPSHOT_READ_ONLY ? BTRFS_SUBVOL_RDONLY : 0,
.fd = old_fd,
};
_cleanup_close_ int subvolume_fd = -1;
_cleanup_close_ int subvolume_fd = -EBADF;
uint64_t new_subvol_id;
int r;
@@ -1468,7 +1468,7 @@ static int subvol_snapshot_children(
FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
_cleanup_free_ char *p = NULL, *c = NULL, *np = NULL;
const struct btrfs_root_ref *ref;
_cleanup_close_ int old_child_fd = -1, new_child_fd = -1;
_cleanup_close_ int old_child_fd = -EBADF, new_child_fd = -EBADF;
btrfs_ioctl_search_args_set(&args, sh);
@@ -1578,7 +1578,7 @@ int btrfs_subvol_snapshot_fd_full(
copy_progress_bytes_t progress_bytes,
void *userdata) {
_cleanup_close_ int new_fd = -1;
_cleanup_close_ int new_fd = -EBADF;
const char *subvolume;
int r;
@@ -1661,7 +1661,7 @@ int btrfs_subvol_snapshot_full(
copy_progress_bytes_t progress_bytes,
void *userdata) {
_cleanup_close_ int old_fd = -1;
_cleanup_close_ int old_fd = -EBADF;
assert(old_path);
assert(new_path);
@@ -1762,7 +1762,7 @@ int btrfs_qgroup_find_parents(int fd, uint64_t qgroupid, uint64_t **ret) {
int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermediary_qgroup) {
_cleanup_free_ uint64_t *qgroups = NULL;
_cleanup_close_ int real_fd = -1;
_cleanup_close_ int real_fd = -EBADF;
uint64_t parent_subvol;
bool changed = false;
int n = 0, r;
@@ -1914,7 +1914,7 @@ int btrfs_subvol_auto_qgroup_fd(int fd, uint64_t subvol_id, bool insert_intermed
}
int btrfs_subvol_auto_qgroup(const char *path, uint64_t subvol_id, bool create_intermediary_qgroup) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_NOCTTY|O_CLOEXEC|O_DIRECTORY);
if (fd < 0)
+1 -1
View File
@@ -161,7 +161,7 @@ static int show_cgroup_name(
uint64_t cgroupid = UINT64_MAX;
_cleanup_free_ char *b = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
bool delegate;
int r;
+3 -3
View File
@@ -63,7 +63,7 @@ static int chown_recursive_internal(
}
FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_close_ int path_fd = -1;
_cleanup_close_ int path_fd = -EBADF;
struct stat fst;
if (dot_or_dot_dot(de->d_name))
@@ -113,7 +113,7 @@ int path_chown_recursive(
gid_t gid,
mode_t mask) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct stat st;
fd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
@@ -142,7 +142,7 @@ int fd_chown_recursive(
gid_t gid,
mode_t mask) {
int duplicated_fd = -1;
int duplicated_fd = -EBADF;
struct stat st;
/* Note that the slightly different order of fstat() and the checks here and in
+2 -2
View File
@@ -19,7 +19,7 @@
#include "string-util.h"
int clock_get_hwclock(struct tm *tm) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(tm);
@@ -40,7 +40,7 @@ int clock_get_hwclock(struct tm *tm) {
}
int clock_set_hwclock(const struct tm *tm) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(tm);
+7 -7
View File
@@ -713,7 +713,7 @@ static int fd_copy_regular(
copy_progress_bytes_t progress,
void *userdata) {
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
int r, q;
assert(from);
@@ -904,11 +904,11 @@ static int fd_copy_directory(
void *userdata) {
_cleanup_(hardlink_context_destroy) HardlinkContext our_hardlink_context = {
.dir_fd = -1,
.parent_fd = -1,
.dir_fd = -EBADF,
.parent_fd = -EBADF,
};
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
_cleanup_closedir_ DIR *d = NULL;
bool exists, created;
int r;
@@ -1286,7 +1286,7 @@ int copy_file_fd_full(
copy_progress_bytes_t progress_bytes,
void *userdata) {
_cleanup_close_ int fdf = -1;
_cleanup_close_ int fdf = -EBADF;
struct stat st;
int r;
@@ -1339,7 +1339,7 @@ int copy_file_full(
copy_progress_bytes_t progress_bytes,
void *userdata) {
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
struct stat st;
int r;
@@ -1428,7 +1428,7 @@ int copy_file_atomic_full(
void *userdata) {
_cleanup_(unlink_and_freep) char *t = NULL;
_cleanup_close_ int fdt = -1;
_cleanup_close_ int fdt = -EBADF;
int r;
assert(from);
+3 -3
View File
@@ -167,7 +167,7 @@ static int make_credential_host_secret(
struct credential_host_secret_format buf;
_cleanup_free_ char *t = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(dfd >= 0);
@@ -251,7 +251,7 @@ finish:
int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *ret_size) {
_cleanup_free_ char *_dirname = NULL, *_filename = NULL;
_cleanup_close_ int dfd = -1;
_cleanup_close_ int dfd = -EBADF;
sd_id128_t machine_id;
const char *dirname, *filename;
int r;
@@ -298,7 +298,7 @@ int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *
for (unsigned attempt = 0;; attempt++) {
_cleanup_(erase_and_freep) struct credential_host_secret_format *f = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
size_t l = 0;
ssize_t n = 0;
struct stat st;
+3 -3
View File
@@ -28,7 +28,7 @@
int acquire_data_fd(const void *data, size_t size, unsigned flags) {
_cleanup_close_pair_ int pipefds[2] = { -1, -1 };
char pattern[] = "/dev/shm/data-fd-XXXXXX";
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int isz = 0, r;
ssize_t n;
off_t f;
@@ -163,7 +163,7 @@ try_dev_shm_without_o_tmpfile:
}
int copy_data_fd(int fd) {
_cleanup_close_ int copy_fd = -1, tmp_fd = -1;
_cleanup_close_ int copy_fd = -EBADF, tmp_fd = -EBADF;
_cleanup_free_ void *remains = NULL;
size_t remains_size = 0;
const char *td;
@@ -376,7 +376,7 @@ int memfd_clone_fd(int fd, const char *name, int mode) {
return r;
if (ro) {
_cleanup_close_ int rfd = -1;
_cleanup_close_ int rfd = -EBADF;
r = memfd_set_sealed(mfd);
if (r < 0)
+4 -4
View File
@@ -247,7 +247,7 @@ static int image_make(
(faccessat(dfd, filename, W_OK, AT_EACCESS) < 0 && errno == EROFS);
if (S_ISDIR(st->st_mode)) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
unsigned file_attr = 0;
usec_t crtime = 0;
@@ -367,7 +367,7 @@ static int image_make(
return 0;
} else if (S_ISBLK(st->st_mode)) {
_cleanup_close_ int block_fd = -1;
_cleanup_close_ int block_fd = -EBADF;
uint64_t size = UINT64_MAX;
/* A block device */
@@ -984,7 +984,7 @@ int image_read_only(Image *i, bool b) {
}
case IMAGE_BLOCK: {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct stat st;
int state = b;
@@ -1152,7 +1152,7 @@ int image_read_metadata(Image *i) {
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to chase /etc/machine-id in image %s: %m", i->name);
else if (r >= 0) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
+12 -12
View File
@@ -88,7 +88,7 @@ int probe_filesystem_full(
#if HAVE_BLKID
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
_cleanup_free_ char *path_by_fd = NULL;
_cleanup_close_ int fd_close = -1;
_cleanup_close_ int fd_close = -EBADF;
const char *fstype;
int r;
@@ -313,7 +313,7 @@ static int make_partition_devname(
static int open_partition(const char *node, bool is_partition, const LoopDevice *loop) {
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
dev_t devnum;
int r;
@@ -477,7 +477,7 @@ static int dissect_image(
if (STRPTR_IN_SET(usage, "filesystem", "crypto")) {
_cleanup_free_ char *t = NULL, *n = NULL, *o = NULL;
const char *fstype = NULL, *options = NULL, *suuid = NULL;
_cleanup_close_ int mount_node_fd = -1;
_cleanup_close_ int mount_node_fd = -EBADF;
sd_id128_t uuid = SD_ID128_NULL;
if (FLAGS_SET(flags, DISSECT_IMAGE_PIN_PARTITION_DEVICES)) {
@@ -872,7 +872,7 @@ static int dissect_image(
if (type.designator != _PARTITION_DESIGNATOR_INVALID) {
_cleanup_free_ char *t = NULL, *o = NULL, *l = NULL;
_cleanup_close_ int mount_node_fd = -1;
_cleanup_close_ int mount_node_fd = -EBADF;
const char *options = NULL;
if (m->partitions[type.designator].found) {
@@ -958,7 +958,7 @@ static int dissect_image(
break;
case 0xEA: { /* Boot Loader Spec extended $BOOT partition */
_cleanup_close_ int mount_node_fd = -1;
_cleanup_close_ int mount_node_fd = -EBADF;
_cleanup_free_ char *o = NULL;
sd_id128_t id = SD_ID128_NULL;
const char *options = NULL;
@@ -1043,7 +1043,7 @@ static int dissect_image(
/* If we didn't find a generic node, then we can't fix this up either */
if (generic_node) {
_cleanup_close_ int mount_node_fd = -1;
_cleanup_close_ int mount_node_fd = -EBADF;
_cleanup_free_ char *o = NULL;
const char *options;
@@ -1152,7 +1152,7 @@ int dissect_image_file(
#if HAVE_BLKID
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(path);
@@ -1282,7 +1282,7 @@ static int run_fsck(int node_fd, const char *fstype) {
}
static int fs_grow(const char *node_path, const char *mount_path) {
_cleanup_close_ int mount_fd = -1, node_fd = -1;
_cleanup_close_ int mount_fd = -EBADF, node_fd = -EBADF;
uint64_t size, newsize;
int r;
@@ -1736,7 +1736,7 @@ static int decrypt_partition(
_cleanup_free_ char *node = NULL, *name = NULL;
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(m);
@@ -2026,7 +2026,7 @@ static int verity_partition(
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_(dm_deferred_remove_cleanp) char *restore_deferred_remove = NULL;
_cleanup_free_ char *node = NULL, *name = NULL;
_cleanup_close_ int mount_node_fd = -1;
_cleanup_close_ int mount_node_fd = -EBADF;
int r;
assert(m);
@@ -2088,7 +2088,7 @@ static int verity_partition(
* retry a few times before giving up. */
for (unsigned i = 0; i < N_DEVICE_NODE_LIST_ATTEMPTS; i++) {
_cleanup_(sym_crypt_freep) struct crypt_device *existing_cd = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
/* First, check if the device already exists. */
fd = open(node, O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
@@ -2712,7 +2712,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
for (; n_meta_initialized < _META_MAX; n_meta_initialized ++) {
if (!paths[n_meta_initialized]) {
fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -1;
fds[2*n_meta_initialized] = fds[2*n_meta_initialized+1] = -EBADF;
continue;
}
+1 -1
View File
@@ -40,7 +40,7 @@ struct DissectedPartition {
((DissectedPartition) { \
.partno = -1, \
.architecture = _ARCHITECTURE_INVALID, \
.mount_node_fd = -1, \
.mount_node_fd = -EBADF, \
})
#define TAKE_PARTITION(p) \
({ \
+1 -1
View File
@@ -9,7 +9,7 @@
#include "string-util.h"
int dm_deferred_remove_cancel(const char *name) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct message {
struct dm_ioctl dm_ioctl;
struct dm_target_msg dm_target_msg;
+1 -1
View File
@@ -349,7 +349,7 @@ int ethtool_get_link_info(
}
int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct {
struct ethtool_perm_addr addr;
uint8_t space[HW_ADDR_MAX_SIZE];
+4 -4
View File
@@ -123,7 +123,7 @@ static int do_execute(
STRV_FOREACH(path, paths) {
_cleanup_free_ char *t = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
pid_t pid;
t = strdup(*path);
@@ -158,7 +158,7 @@ static int do_execute(
return log_error_errno(errno, "Failed to seek on serialization fd: %m");
r = callbacks[STDOUT_GENERATE](fd, callback_args[STDOUT_GENERATE]);
fd = -1;
fd = -EBADF;
if (r < 0)
return log_error_errno(r, "Failed to process output from %s: %m", *path);
}
@@ -199,7 +199,7 @@ int execute_directories(
ExecDirFlags flags) {
char **dirs = (char**) directories;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
char *name;
int r;
pid_t executor_pid;
@@ -245,7 +245,7 @@ int execute_directories(
return log_error_errno(errno, "Failed to rewind serialization fd: %m");
r = callbacks[STDOUT_CONSUME](fd, callback_args[STDOUT_CONSUME]);
fd = -1;
fd = -EBADF;
if (r < 0)
return log_error_errno(r, "Failed to parse returned data: %m");
return 0;
+1 -1
View File
@@ -131,7 +131,7 @@ int fdset_new_fill(FDSet **_s) {
}
FOREACH_DIRENT(de, d, return -errno) {
int fd = -1;
int fd = -EBADF;
r = safe_atoi(de->d_name, &fd);
if (r < 0)
+2 -2
View File
@@ -243,7 +243,7 @@ static int verify_fsroot_dir(
bool unprivileged_mode,
dev_t *ret_dev) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
STRUCT_NEW_STATX_DEFINE(sxa);
STRUCT_NEW_STATX_DEFINE(sxb);
int r;
@@ -328,7 +328,7 @@ success:
return 0;
if (sxa.sx.stx_dev_major == 0) { /* Hmm, maybe a btrfs device, and the caller asked for the backing device? Then let's try to get it. */
_cleanup_close_ int real_fd = -1;
_cleanup_close_ int real_fd = -EBADF;
/* The statx() above we can execute on an O_PATH fd. But the btrfs ioctl we cannot. Hence
* acquire a "real" fd first, without the O_PATH flag. */
+5 -5
View File
@@ -98,7 +98,7 @@ int install_file(int source_atfd, const char *source_name,
int target_atfd, const char *target_name,
InstallFileFlags flags) {
_cleanup_close_ int rofd = -1;
_cleanup_close_ int rofd = -EBADF;
int r;
/* Moves a file or directory tree into place, with some bells and whistles:
@@ -118,7 +118,7 @@ int install_file(int source_atfd, const char *source_name,
* target_name=NULL and flags=0 this call is a NOP */
if ((flags & (INSTALL_FSYNC|INSTALL_FSYNC_FULL|INSTALL_SYNCFS|INSTALL_READ_ONLY)) != 0) {
_cleanup_close_ int pfd = -1;
_cleanup_close_ int pfd = -EBADF;
struct stat st;
/* Open an O_PATH fd for the source if we need to sync things or mark things read only. */
@@ -133,7 +133,7 @@ int install_file(int source_atfd, const char *source_name,
switch (st.st_mode & S_IFMT) {
case S_IFREG: {
_cleanup_close_ int regfd = -1;
_cleanup_close_ int regfd = -EBADF;
regfd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
if (regfd < 0)
@@ -158,7 +158,7 @@ int install_file(int source_atfd, const char *source_name,
}
case S_IFDIR: {
_cleanup_close_ int dfd = -1;
_cleanup_close_ int dfd = -EBADF;
dfd = fd_reopen(pfd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
if (dfd < 0)
@@ -203,7 +203,7 @@ int install_file(int source_atfd, const char *source_name,
if (flags & INSTALL_REPLACE) {
/* First, try a simple renamat(), maybe that's enough */
if (renameat(source_atfd, source_name, target_atfd, target_name) < 0) {
_cleanup_close_ int dfd = -1;
_cleanup_close_ int dfd = -EBADF;
if (!IN_SET(errno, EEXIST, ENOTDIR, ENOTEMPTY, EISDIR, EBUSY))
return -errno;
+2 -2
View File
@@ -739,7 +739,7 @@ static int remove_marked_symlinks(
InstallChange **changes,
size_t *n_changes) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
bool restart;
int r = 0;
@@ -1330,7 +1330,7 @@ static int unit_file_load(
UnitType type;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
struct stat st;
int r;
+1 -1
View File
@@ -390,7 +390,7 @@ int local_outbounds(
}
for (int i = 0; i < n_gateways; i++) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
union sockaddr_union sa;
socklen_t salen;
+2 -2
View File
@@ -16,7 +16,7 @@
#include "path-util.h"
int make_lock_file(const char *p, int operation, LockFile *ret) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *t = NULL;
int r;
@@ -76,7 +76,7 @@ int make_lock_file(const char *p, int operation, LockFile *ret) {
ret->fd = fd;
ret->operation = operation;
fd = -1;
fd = -EBADF;
t = NULL;
return r;
+1 -1
View File
@@ -11,4 +11,4 @@ int make_lock_file(const char *p, int operation, LockFile *ret);
int make_lock_file_for(const char *p, int operation, LockFile *ret);
void release_lock_file(LockFile *f);
#define LOCK_FILE_INIT { .fd = -1, .path = NULL }
#define LOCK_FILE_INIT { .fd = -EBADF, .path = NULL }
+1 -1
View File
@@ -1625,7 +1625,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
_cleanup_close_pair_ int pair[2] = { -1, -1 };
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
_cleanup_close_ int pidnsfd = -EBADF, mntnsfd = -EBADF, rootfd = -EBADF;
char buf[SD_ID128_UUID_STRING_MAX];
pid_t pid, child;
ssize_t k;
+7 -7
View File
@@ -73,7 +73,7 @@ static int get_current_uevent_seqnum(uint64_t *ret) {
}
static int open_lock_fd(int primary_fd, int operation) {
_cleanup_close_ int lock_fd = -1;
_cleanup_close_ int lock_fd = -EBADF;
assert(primary_fd >= 0);
assert(IN_SET(operation & ~LOCK_NB, LOCK_SH, LOCK_EX));
@@ -238,8 +238,8 @@ static int loop_configure(
static bool loop_configure_broken = false;
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
_cleanup_(cleanup_clear_loop_close) int loop_with_fd = -1; /* This must be declared before lock_fd. */
_cleanup_close_ int fd = -1, lock_fd = -1;
_cleanup_(cleanup_clear_loop_close) int loop_with_fd = -EBADF; /* This must be declared before lock_fd. */
_cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
_cleanup_free_ char *node = NULL;
uint64_t diskseq = 0, seqnum = UINT64_MAX;
usec_t timestamp = USEC_INFINITY;
@@ -409,7 +409,7 @@ static int loop_device_make_internal(
LoopDevice **ret) {
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
_cleanup_close_ int direct_io_fd = -1, control = -1;
_cleanup_close_ int direct_io_fd = -EBADF, control = -EBADF;
_cleanup_free_ char *backing_file = NULL;
struct loop_config config;
int r, f_flags;
@@ -588,7 +588,7 @@ int loop_device_make_by_path(
LoopDevice **ret) {
int r, basic_flags, direct_flags, rdwr_flags;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
bool direct = false;
assert(path);
@@ -776,7 +776,7 @@ int loop_device_open(
int lock_op,
LoopDevice **ret) {
_cleanup_close_ int fd = -1, lock_fd = -1;
_cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
_cleanup_free_ char *node = NULL, *backing_file = NULL;
struct loop_info64 info;
uint64_t diskseq = 0;
@@ -896,7 +896,7 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) {
char sysfs[STRLEN("/sys/dev/block/:/partition") + 2*DECIMAL_STR_MAX(dev_t) + 1];
_cleanup_free_ char *buffer = NULL;
uint64_t current_offset, current_size, partno;
_cleanup_close_ int whole_fd = -1;
_cleanup_close_ int whole_fd = -EBADF;
struct stat st;
dev_t devno;
int r;
+3 -3
View File
@@ -28,7 +28,7 @@
static int generate_machine_id(const char *root, sd_id128_t *ret) {
const char *dbus_machine_id;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert(ret);
@@ -83,7 +83,7 @@ static int generate_machine_id(const char *root, sd_id128_t *ret) {
int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_id, sd_id128_t *ret) {
const char *etc_machine_id, *run_machine_id;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
bool writable;
int r;
@@ -195,7 +195,7 @@ finish:
}
int machine_id_commit(const char *root) {
_cleanup_close_ int fd = -1, initial_mntns_fd = -1;
_cleanup_close_ int fd = -EBADF, initial_mntns_fd = -EBADF;
const char *etc_machine_id;
sd_id128_t id;
int r;
+1 -1
View File
@@ -130,7 +130,7 @@ static int setup_userns(uid_t uid, gid_t gid) {
static int do_mcopy(const char *node, const char *root) {
_cleanup_free_ char *mcopy = NULL;
_cleanup_strv_free_ char **argv = NULL;
_cleanup_close_ int rfd = -1;
_cleanup_close_ int rfd = -EBADF;
_cleanup_free_ DirectoryEntries *de = NULL;
struct stat st;
int r;
+3 -3
View File
@@ -807,7 +807,7 @@ static int mount_in_namespace(
bool is_image) {
_cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
_cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1, chased_src_fd = -1;
_cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, chased_src_fd = -EBADF;
char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
bool mount_slave_created = false, mount_slave_mounted = false,
mount_tmp_created = false, mount_tmp_mounted = false,
@@ -1067,7 +1067,7 @@ int make_mount_point(const char *path) {
}
static int make_userns(uid_t uid_shift, uid_t uid_range, uid_t owner, RemountIdmapping idmapping) {
_cleanup_close_ int userns_fd = -1;
_cleanup_close_ int userns_fd = -EBADF;
_cleanup_free_ char *line = NULL;
/* Allocates a userns file descriptor with the mapping we need. For this we'll fork off a child
@@ -1118,7 +1118,7 @@ int remount_idmap(
uid_t owner,
RemountIdmapping idmapping) {
_cleanup_close_ int mount_fd = -1, userns_fd = -1;
_cleanup_close_ int mount_fd = -EBADF, userns_fd = -EBADF;
int r;
assert(p);
+1 -1
View File
@@ -23,7 +23,7 @@ struct nscdInvalidateRequest {
static int nscd_flush_cache_one(const char *database, usec_t end) {
size_t req_size, has_written = 0, has_read = 0, l;
struct nscdInvalidateRequest *req;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int32_t resp;
int events, r;
+3 -3
View File
@@ -412,9 +412,9 @@ int pty_forward_new(
*f = (struct PTYForward) {
.flags = flags,
.master = -1,
.input_fd = -1,
.output_fd = -1,
.master = -EBADF,
.input_fd = -EBADF,
.output_fd = -EBADF,
};
if (event)
+1 -1
View File
@@ -122,7 +122,7 @@ int shall_restore_state(void) {
static int xen_kexec_loaded(void) {
#if HAVE_XENCTRL
_cleanup_close_ int privcmd_fd = -1, buf_fd = -1;
_cleanup_close_ int privcmd_fd = -EBADF, buf_fd = -EBADF;
xen_kexec_status_t *buffer;
size_t size;
int r;
+1 -1
View File
@@ -297,7 +297,7 @@ int mac_selinux_fix_full(
assert(atfd >= 0 || inode_path);
#if HAVE_SELINUX
_cleanup_close_ int opened_fd = -1;
_cleanup_close_ int opened_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int inode_fd, r;
+1 -1
View File
@@ -718,7 +718,7 @@ static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) {
* filesystems, a debug message is logged and ret_offset is set to UINT64_MAX.
*/
static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offset) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
_cleanup_free_ struct fiemap *fiemap = NULL;
struct stat sb;
int r;
+1 -1
View File
@@ -188,7 +188,7 @@ int mac_smack_fix_full(
const char *label_path,
LabelFixFlags flags) {
_cleanup_close_ int opened_fd = -1;
_cleanup_close_ int opened_fd = -EBADF;
_cleanup_free_ char *p = NULL;
int r, inode_fd;
+1 -1
View File
@@ -32,7 +32,7 @@ int socket_address_listen(
mode_t socket_mode,
const char *label) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
const char *p;
int r;
+1 -1
View File
@@ -188,7 +188,7 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
assert(ret);
if (root) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd < 0)
+1 -1
View File
@@ -31,7 +31,7 @@ int switch_root(const char *new_root,
unsigned long mount_flags) { /* MS_MOVE or MS_BIND */
_cleanup_free_ char *resolved_old_root_after = NULL;
_cleanup_close_ int old_root_fd = -1;
_cleanup_close_ int old_root_fd = -EBADF;
int r;
assert(new_root);
+1 -1
View File
@@ -137,7 +137,7 @@ int log_tests_skipped_errno(int r, const char *message) {
}
int write_tmpfile(char *pattern, const char *contents) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
assert(pattern);
assert(contents);
+1 -1
View File
@@ -570,7 +570,7 @@ int udev_queue_is_empty(void) {
}
int udev_queue_init(void) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
fd = inotify_init1(IN_CLOEXEC);
if (fd < 0)
+1 -1
View File
@@ -284,7 +284,7 @@ int utmp_put_runlevel(int runlevel, int previous) {
#define TIMEOUT_USEC (50 * USEC_PER_MSEC)
static int write_to_terminal(const char *tty, const char *message) {
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
const char *p;
size_t left;
usec_t end;
+5 -5
View File
@@ -258,7 +258,7 @@ static int varlink_new(Varlink **ret) {
*v = (Varlink) {
.n_ref = 1,
.fd = -1,
.fd = -EBADF,
.state = _VARLINK_STATE_INVALID,
@@ -2194,7 +2194,7 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret)
r = varlink_attach_event(v, server->event, server->event_priority);
if (r < 0) {
varlink_log_errno(v, r, "Failed to attach new connection: %m");
v->fd = -1; /* take the fd out of the connection again */
v->fd = -EBADF; /* take the fd out of the connection again */
varlink_close(v);
return r;
}
@@ -2218,7 +2218,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free);
static int connect_callback(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
VarlinkServerSocket *ss = ASSERT_PTR(userdata);
_cleanup_close_ int cfd = -1;
_cleanup_close_ int cfd = -EBADF;
Varlink *v = NULL;
int r;
@@ -2306,7 +2306,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t
_cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
union sockaddr_union sockaddr;
socklen_t sockaddr_len;
_cleanup_close_ int fd = -1;
_cleanup_close_ int fd = -EBADF;
int r;
assert_return(s, -EINVAL);
@@ -2619,7 +2619,7 @@ int varlink_server_deserialize_one(VarlinkServer *s, const char *value, FDSet *f
_cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
_cleanup_free_ char *address = NULL;
const char *v = ASSERT_PTR(value);
int r, fd = -1;
int r, fd = -EBADF;
char *buf;
size_t n;
+1 -1
View File
@@ -17,7 +17,7 @@
#include "time-util.h"
#include "watchdog.h"
static int watchdog_fd = -1;
static int watchdog_fd = -EBADF;
static char *watchdog_device = NULL;
static usec_t watchdog_timeout = 0; /* 0 → close device and USEC_INFINITY → don't change timeout */
static usec_t watchdog_pretimeout = 0; /* 0 → disable pretimeout and USEC_INFINITY → don't change pretimeout */