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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-12-15 16:19:13 +01:00
parent 372e8592c6
commit c7f0d9e5ac
31 changed files with 71 additions and 116 deletions
-1
View File
@@ -103,7 +103,6 @@ int block_get_originating(dev_t dt, dev_t *ret) {
_cleanup_free_ char *t = NULL;
char p[SYS_BLOCK_PATH_MAX("/slaves")];
_cleanup_free_ char *first_found = NULL;
struct dirent *de;
const char *q;
dev_t devt;
int r;
-1
View File
@@ -52,7 +52,6 @@ static int chown_recursive_internal(
_cleanup_closedir_ DIR *d = NULL;
bool changed = false;
struct dirent *de;
int r;
assert(fd >= 0);
-2
View File
@@ -219,7 +219,6 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid, bool rm) {
}
static int clean_posix_shm_internal(const char *dirname, DIR *dir, uid_t uid, gid_t gid, bool rm) {
struct dirent *de;
int ret = 0, r;
assert(dir);
@@ -315,7 +314,6 @@ static int clean_posix_shm(uid_t uid, gid_t gid, bool rm) {
static int clean_posix_mq(uid_t uid, gid_t gid, bool rm) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
int ret = 0;
dir = opendir("/dev/mqueue");
-1
View File
@@ -789,7 +789,6 @@ static int fd_copy_directory(
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
bool exists, created;
int r;
-1
View File
@@ -543,7 +543,6 @@ int image_discover(
NULSTR_FOREACH(path, image_search_path[class]) {
_cleanup_free_ char *resolved = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
r = chase_symlinks_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
if (r == -ENOENT)
+3 -4
View File
@@ -188,7 +188,6 @@ static int wait_for_children(Set *pids, sigset_t *mask, usec_t timeout) {
static int killall(int sig, Set *pids, bool send_sighup) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *d;
int n_killed = 0;
/* Send the specified signal to all remaining processes, if not excluded by ignore_proc().
@@ -198,14 +197,14 @@ static int killall(int sig, Set *pids, bool send_sighup) {
if (!dir)
return log_warning_errno(errno, "opendir(/proc) failed: %m");
FOREACH_DIRENT_ALL(d, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
pid_t pid;
int r;
if (!IN_SET(d->d_type, DT_DIR, DT_UNKNOWN))
if (!IN_SET(de->d_type, DT_DIR, DT_UNKNOWN))
continue;
if (parse_pid(d->d_name, &pid) < 0)
if (parse_pid(de->d_name, &pid) < 0)
continue;
if (ignore_proc(pid, sig == SIGKILL && !in_initrd()))
-1
View File
@@ -203,7 +203,6 @@ int rm_rf_children(
const struct stat *root_dev) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int ret = 0, r;
assert(fd >= 0);