diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 13:07:42 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-12-19 15:00:57 +0100 |
commit | 254d1313ae5a69c08c9b93032aaaf3d6083cfc07 (patch) | |
tree | 067102a36abe6bf597c26a42d79018a1060c9007 /src/udev | |
parent | sd-event: never pass negative errnos as signalfd to signalfd (diff) | |
download | systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.tar.xz systemd-254d1313ae5a69c08c9b93032aaaf3d6083cfc07.zip |
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/udev')
-rw-r--r-- | src/udev/ata_id/ata_id.c | 2 | ||||
-rw-r--r-- | src/udev/cdrom_id/cdrom_id.c | 2 | ||||
-rw-r--r-- | src/udev/fido_id/fido_id.c | 2 | ||||
-rw-r--r-- | src/udev/mtd_probe/mtd_probe.c | 2 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 2 | ||||
-rw-r--r-- | src/udev/scsi_id/scsi_serial.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-blkid.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-btrfs.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-input_id.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-keyboard.c | 2 | ||||
-rw-r--r-- | src/udev/udev-builtin-usb_id.c | 2 | ||||
-rw-r--r-- | src/udev/udev-node.c | 10 | ||||
-rw-r--r-- | src/udev/udev-watch.c | 4 | ||||
-rw-r--r-- | src/udev/udevadm-lock.c | 4 | ||||
-rw-r--r-- | src/udev/udevd.c | 14 | ||||
-rw-r--r-- | src/udev/v4l_id/v4l_id.c | 2 |
16 files changed, 28 insertions, 28 deletions
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index bae4d03b4f..6a631e515c 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -399,7 +399,7 @@ int main(int argc, char *argv[]) { char revision[9]; const char *node = NULL; int export = 0; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; uint16_t word; int is_packet_device = 0; static const struct option options[] = { diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 5945dcbbae..ea420a9617 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -103,7 +103,7 @@ typedef struct Context { } Context; #define CONTEXT_EMPTY { \ - .fd = -1, \ + .fd = -EBADF, \ .media_feature = _FEATURE_INVALID, \ .media_state = _MEDIA_STATE_INVALID, \ } diff --git a/src/udev/fido_id/fido_id.c b/src/udev/fido_id/fido_id.c index 58a2827818..f2fbc38003 100644 --- a/src/udev/fido_id/fido_id.c +++ b/src/udev/fido_id/fido_id.c @@ -28,7 +28,7 @@ static int run(int argc, char **argv) { _cleanup_(sd_device_unrefp) struct sd_device *device = NULL; _cleanup_free_ char *desc_path = NULL; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct sd_device *hid_device; const char *sys_path; diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c index d5fb64f194..a7210a05e3 100644 --- a/src/udev/mtd_probe/mtd_probe.c +++ b/src/udev/mtd_probe/mtd_probe.c @@ -33,7 +33,7 @@ #include "mtd_probe.h" int main(int argc, char** argv) { - _cleanup_close_ int mtd_fd = -1; + _cleanup_close_ int mtd_fd = -EBADF; mtd_info_t mtd_info; if (argc != 2) { diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 25edb49d28..5f18ba35fc 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -97,7 +97,7 @@ int link_config_ctx_new(LinkConfigContext **ret) { return -ENOMEM; *ctx = (LinkConfigContext) { - .ethtool_fd = -1, + .ethtool_fd = -EBADF, }; *ret = TAKE_PTR(ctx); diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index f1ce8601bd..c619506877 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -786,7 +786,7 @@ out: int scsi_get_serial(struct scsi_id_device *dev_scsi, const char *devname, int page_code, int len) { unsigned char page0[SCSI_INQ_BUFF_LEN]; - int fd = -1; + int fd = -EBADF; int cnt; int ind; int retval; diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 9b5dfbe33b..d2de03d5f9 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -238,7 +238,7 @@ static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv const char *devnode, *root_partition = NULL, *data, *name; _cleanup_(blkid_free_probep) blkid_probe pr = NULL; bool noraid = false, is_gpt = false; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int64_t offset = 0; int r; diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index faaafb23f6..79f91ea2ae 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -14,7 +14,7 @@ static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) { struct btrfs_ioctl_vol_args args = {}; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; if (argc != 3 || !streq(argv[1], "ready")) diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 465913ce31..33184b024f 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -47,7 +47,7 @@ static int abs_size_mm(const struct input_absinfo *absinfo) { static void extract_info(sd_device *dev, bool test) { char width[DECIMAL_STR_MAX(int)], height[DECIMAL_STR_MAX(int)]; struct input_absinfo xabsinfo = {}, yabsinfo = {}; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); if (fd < 0) diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index e67a02aee6..80cfdee0c1 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -162,7 +162,7 @@ static int set_trackpoint_sensitivity(sd_device *dev, const char *value) { static int builtin_keyboard(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) { unsigned release[1024]; unsigned release_count = 0; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *node, *key, *value; int has_abs = -1, r; diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 847c2b8316..91deb64292 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -134,7 +134,7 @@ static void set_scsi_type(char *to, const char *from, size_t len) { #define USB_DT_INTERFACE 0x04 static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; ssize_t size; unsigned char buf[18 + 65535]; size_t pos = 0; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 9e34ea6b01..1990282c75 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -281,7 +281,7 @@ static int stack_directory_update(sd_device *dev, int fd, bool add) { } static int stack_directory_open(const char *dirname) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; int r; assert(dirname); @@ -298,7 +298,7 @@ static int stack_directory_open(const char *dirname) { } static int stack_directory_lock(int dirfd) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; assert(dirfd >= 0); @@ -387,7 +387,7 @@ static int stack_directory_get_name(const char *slink, char **ret) { static int link_update(sd_device *dev, const char *slink, bool add) { _cleanup_free_ char *dirname = NULL, *devnode = NULL; - _cleanup_close_ int dirfd = -1, lockfd = -1; + _cleanup_close_ int dirfd = -EBADF, lockfd = -EBADF; int r; assert(dev); @@ -624,7 +624,7 @@ int udev_node_apply_permissions( OrderedHashmap *seclabel_list) { const char *devnode; - _cleanup_close_ int node_fd = -1; + _cleanup_close_ int node_fd = -EBADF; int r; assert(dev); @@ -654,7 +654,7 @@ int static_node_apply_permissions( char **tags) { _cleanup_free_ char *unescaped_filename = NULL; - _cleanup_close_ int node_fd = -1; + _cleanup_close_ int node_fd = -EBADF; const char *devnode; struct stat stats; int r; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 6bb013c094..d00226cd7a 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -174,7 +174,7 @@ finalize: int udev_watch_begin(int inotify_fd, sd_device *dev) { char wd_str[DECIMAL_STR_MAX(int)]; - _cleanup_close_ int dirfd = -1; + _cleanup_close_ int dirfd = -EBADF; const char *devnode, *id; int wd, r; @@ -229,7 +229,7 @@ on_failure: } int udev_watch_end(int inotify_fd, sd_device *dev) { - _cleanup_close_ int dirfd = -1; + _cleanup_close_ int dirfd = -EBADF; int wd, r; assert(dev); diff --git a/src/udev/udevadm-lock.c b/src/udev/udevadm-lock.c index 35e9999c01..d19e7561f8 100644 --- a/src/udev/udevadm-lock.c +++ b/src/udev/udevadm-lock.c @@ -176,7 +176,7 @@ static int lock_device( dev_t devno, usec_t deadline) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; struct stat st; int r; @@ -328,7 +328,7 @@ int lock_main(int argc, char *argv[], void *userdata) { if (arg_print) printf("%s\n", node); else { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; fd = lock_device(node, devnos[i], deadline); if (fd < 0) diff --git a/src/udev/udevd.c b/src/udev/udevd.c index eb15b250d5..0de5b4ec64 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -513,7 +513,7 @@ irrelevant: } static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; sd_device *dev_whole_disk; const char *val; int r; @@ -550,12 +550,12 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) { return 1; nolock: - *ret_fd = -1; + *ret_fd = -EBADF; return 0; } static int worker_mark_block_device_read_only(sd_device *dev) { - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; const char *val; int state = 1, r; @@ -600,7 +600,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) { static int worker_process_device(Manager *manager, sd_device *dev) { _cleanup_(udev_event_freep) UdevEvent *udev_event = NULL; - _cleanup_close_ int fd_lock = -1; + _cleanup_close_ int fd_lock = -EBADF; int r; assert(manager); @@ -1561,7 +1561,7 @@ static int on_post(sd_event_source *s, void *userdata) { } static int listen_fds(int *ret_ctrl, int *ret_netlink) { - int ctrl_fd = -1, netlink_fd = -1; + int ctrl_fd = -EBADF, netlink_fd = -EBADF; int fd, n; assert(ret_ctrl); @@ -1847,7 +1847,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent) { return log_oom(); *manager = (Manager) { - .inotify_fd = -1, + .inotify_fd = -EBADF, .worker_watch = { -1, -1 }, .cgroup = TAKE_PTR(cgroup), }; @@ -1993,7 +1993,7 @@ static int main_loop(Manager *manager) { int run_udevd(int argc, char *argv[]) { _cleanup_(manager_freep) Manager *manager = NULL; - int fd_ctrl = -1, fd_uevent = -1; + int fd_ctrl = -EBADF, fd_uevent = -EBADF; int r; log_set_target(LOG_TARGET_AUTO); diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index 13b4839989..4f163c4350 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, {} }; - _cleanup_close_ int fd = -1; + _cleanup_close_ int fd = -EBADF; char *device; struct v4l2_capability v2cap; int c; |