summaryrefslogtreecommitdiffstats
path: root/src/udev
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-12-07 15:02:55 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-12-15 16:19:13 +0100
commitc7f0d9e5acef3f62db3640d5ab7446241c022b35 (patch)
treed8312bdb6ba90d0277306ba8f3b08dc391759e5a /src/udev
parentwait-online: also use address state even when operational state is below degr... (diff)
downloadsystemd-c7f0d9e5acef3f62db3640d5ab7446241c022b35.tar.xz
systemd-c7f0d9e5acef3f62db3640d5ab7446241c022b35.zip
tree-wide: make FOREACH_DIRENT_ALL define the iterator variable
The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-builtin-net_id.c17
-rw-r--r--src/udev/udev-builtin-path_id.c11
-rw-r--r--src/udev/udev-node.c11
-rw-r--r--src/udev/udev-rules.c7
-rw-r--r--src/udev/udev-watch.c1
-rw-r--r--src/udev/udevadm-info.c2
6 files changed, 20 insertions, 29 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 4d16591750..c1f9f232ae 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -97,7 +97,6 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
const char *physfn_syspath, *syspath;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
int r;
assert(pcidev);
@@ -123,15 +122,15 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha
if (!dir)
return -errno;
- FOREACH_DIRENT_ALL(dent, dir, break) {
+ FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *virtfn_link_file = NULL, *virtfn_pci_syspath = NULL;
const char *n;
- n = startswith(dent->d_name, "virtfn");
+ n = startswith(de->d_name, "virtfn");
if (!n)
continue;
- virtfn_link_file = path_join(physfn_syspath, dent->d_name);
+ virtfn_link_file = path_join(physfn_syspath, de->d_name);
if (!virtfn_link_file)
return -ENOMEM;
@@ -390,8 +389,6 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
hotplug_slot_dev = names->pcidev;
while (hotplug_slot_dev) {
- struct dirent *dent;
-
r = parse_hotplug_slot_from_function_id(hotplug_slot_dev, slots, &hotplug_slot);
if (r < 0)
return 0;
@@ -404,20 +401,20 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
if (r < 0)
return log_device_debug_errno(hotplug_slot_dev, r, "Failed to get sysname: %m");
- FOREACH_DIRENT_ALL(dent, dir, break) {
+ FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *address = NULL;
char str[PATH_MAX];
uint32_t i;
- if (dot_or_dot_dot(dent->d_name))
+ if (dot_or_dot_dot(de->d_name))
continue;
- r = safe_atou32(dent->d_name, &i);
+ r = safe_atou32(de->d_name, &i);
if (r < 0 || i <= 0)
continue;
/* match slot address with device by stripping the function */
- if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) &&
+ if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, de->d_name) &&
read_one_line_file(str, &address) >= 0 &&
startswith(sysname, address)) {
hotplug_slot = i;
diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c
index 6fdd3eceea..ae92e45205 100644
--- a/src/udev/udev-builtin-path_id.c
+++ b/src/udev/udev-builtin-path_id.c
@@ -309,7 +309,6 @@ static sd_device *handle_scsi_default(sd_device *parent, char **path) {
int host, bus, target, lun;
const char *name, *base, *pos;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
int basenum = -1;
assert(parent);
@@ -352,16 +351,16 @@ static sd_device *handle_scsi_default(sd_device *parent, char **path) {
if (!dir)
return NULL;
- FOREACH_DIRENT_ALL(dent, dir, break) {
+ FOREACH_DIRENT_ALL(de, dir, break) {
unsigned i;
- if (dent->d_name[0] == '.')
+ if (de->d_name[0] == '.')
continue;
- if (!IN_SET(dent->d_type, DT_DIR, DT_LNK))
+ if (!IN_SET(de->d_type, DT_DIR, DT_LNK))
continue;
- if (!startswith(dent->d_name, "host"))
+ if (!startswith(de->d_name, "host"))
continue;
- if (safe_atou_full(&dent->d_name[4], 10, &i) < 0)
+ if (safe_atou_full(&de->d_name[4], 10, &i) < 0)
continue;
/*
* find the smallest number; the host really needs to export its
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
index 760c3a4448..1824ccef6a 100644
--- a/src/udev/udev-node.c
+++ b/src/udev/udev-node.c
@@ -111,7 +111,6 @@ static int node_symlink(sd_device *dev, const char *node, const char *slink) {
static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, char **ret) {
_cleanup_closedir_ DIR *dir = NULL;
_cleanup_free_ char *target = NULL;
- struct dirent *dent;
int r, priority = 0;
const char *id;
@@ -153,18 +152,18 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
if (r < 0)
return r;
- FOREACH_DIRENT_ALL(dent, dir, break) {
+ FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *path = NULL, *buf = NULL;
int tmp_prio;
- if (dent->d_name[0] == '.')
+ if (de->d_name[0] == '.')
continue;
/* skip ourself */
- if (streq(dent->d_name, id))
+ if (streq(de->d_name, id))
continue;
- path = path_join(stackdir, dent->d_name);
+ path = path_join(stackdir, de->d_name);
if (!path)
return -ENOMEM;
@@ -197,7 +196,7 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
/* Old format. The devnode and priority must be obtained from uevent and
* udev database files. */
- if (sd_device_new_from_device_id(&tmp_dev, dent->d_name) < 0)
+ if (sd_device_new_from_device_id(&tmp_dev, de->d_name) < 0)
continue;
if (device_get_devlink_priority(tmp_dev, &tmp_prio) < 0)
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 693c743c57..1a384d6b38 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1494,7 +1494,6 @@ static int import_parent_into_properties(sd_device *dev, const char *filter) {
static int attr_subst_subdir(char attr[static UDEV_PATH_SIZE]) {
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
char buf[UDEV_PATH_SIZE], *p;
const char *tail;
size_t len, size;
@@ -1516,11 +1515,11 @@ static int attr_subst_subdir(char attr[static UDEV_PATH_SIZE]) {
if (!dir)
return -errno;
- FOREACH_DIRENT_ALL(dent, dir, break) {
- if (dent->d_name[0] == '.')
+ FOREACH_DIRENT_ALL(de, dir, break) {
+ if (de->d_name[0] == '.')
continue;
- strscpyl(p, size, dent->d_name, tail, NULL);
+ strscpyl(p, size, de->d_name, tail, NULL);
if (faccessat(dirfd(dir), p, F_OK, 0) < 0)
continue;
diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c
index 87c4f09928..a8b7d2d2d1 100644
--- a/src/udev/udev-watch.c
+++ b/src/udev/udev-watch.c
@@ -20,7 +20,6 @@
#define MIN_RANDOM_DELAY ( 10 * USEC_PER_MSEC)
int udev_watch_restore(int inotify_fd) {
- struct dirent *ent;
DIR *dir;
int r;
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 84f7794e86..133be80b70 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -224,8 +224,6 @@ static int export_devices(void) {
}
static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
- struct dirent *dent;
-
if (depth <= 0)
return;