Merge pull request #21786 from keszybz/dirent-work

Make FOREACH_DIRENT and FOREACH_DIRENT_ALL declare the iterator variables
This commit is contained in:
Yu Watanabe 2021-12-17 04:07:35 +09:00 committed by GitHub
commit d9338387d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 211 additions and 329 deletions

View file

@ -1836,11 +1836,15 @@ if conf.get('HAVE_LIBCRYPTSETUP_PLUGINS') == 1
if conf.get('HAVE_TPM2') == 1
cryptsetup_token_systemd_tpm2 = shared_library(
'cryptsetup-token-systemd-tpm2',
cryptsetup_token_systemd_tpm2_sources,
include_directories : includes,
link_args : ['-shared',
'-Wl,--version-script=' + cryptsetup_token_sym_path],
dependencies : libshared_deps + [libcryptsetup, versiondep],
link_with : [libshared],
link_whole : [cryptsetup_token_systemd_tpm2_static],
link_with : [lib_cryptsetup_token_common,
libshared],
dependencies : [libcryptsetup,
tpm2,
versiondep],
link_depends : cryptsetup_token_sym,
install_rpath : rootlibexecdir,
install : true,
@ -1850,11 +1854,15 @@ if conf.get('HAVE_LIBCRYPTSETUP_PLUGINS') == 1
if conf.get('HAVE_LIBFIDO2') == 1
cryptsetup_token_systemd_fido2 = shared_library(
'cryptsetup-token-systemd-fido2',
cryptsetup_token_systemd_fido2_sources,
include_directories : includes,
link_args : ['-shared',
'-Wl,--version-script=' + cryptsetup_token_sym_path],
dependencies : libshared_deps + [libcryptsetup, versiondep],
link_with : [libshared],
link_whole : [cryptsetup_token_systemd_fido2_static],
link_with : [lib_cryptsetup_token_common,
libshared],
dependencies : [libcryptsetup,
libfido2,
versiondep],
link_depends : cryptsetup_token_sym,
install_rpath : rootlibexecdir,
install : true,
@ -1864,11 +1872,15 @@ if conf.get('HAVE_LIBCRYPTSETUP_PLUGINS') == 1
if conf.get('HAVE_P11KIT') == 1
cryptsetup_token_systemd_pkcs11 = shared_library(
'cryptsetup-token-systemd-pkcs11',
cryptsetup_token_systemd_pkcs11_sources,
include_directories : includes,
link_args : ['-shared',
'-Wl,--version-script=' + cryptsetup_token_sym_path],
dependencies : libshared_deps + [libcryptsetup, versiondep],
link_with : [libshared],
link_whole : [cryptsetup_token_systemd_pkcs11_static],
link_with : [lib_cryptsetup_token_common,
libshared],
dependencies : [libcryptsetup,
libp11kit,
versiondep],
link_depends : cryptsetup_token_sym,
install_rpath : rootlibexecdir,
install : true,
@ -2764,7 +2776,8 @@ if conf.get('ENABLE_IMPORTD') == 1
'systemd-pull',
systemd_pull_sources,
include_directories : includes,
link_with : [libshared],
link_with : [libshared,
lib_import_common],
dependencies : [versiondep,
libcurl,
lib_openssl_or_gcrypt,
@ -2779,7 +2792,8 @@ if conf.get('ENABLE_IMPORTD') == 1
'systemd-import',
systemd_import_sources,
include_directories : includes,
link_with : [libshared],
link_with : [libshared,
lib_import_common],
dependencies : [libcurl,
libz,
libbzip2,
@ -2792,7 +2806,8 @@ if conf.get('ENABLE_IMPORTD') == 1
'systemd-import-fs',
systemd_import_fs_sources,
include_directories : includes,
link_with : [libshared],
link_with : [libshared,
lib_import_common],
install_rpath : rootlibexecdir,
install : true,
install_dir : rootlibexecdir)
@ -2801,7 +2816,8 @@ if conf.get('ENABLE_IMPORTD') == 1
'systemd-export',
systemd_export_sources,
include_directories : includes,
link_with : [libshared],
link_with : [libshared,
lib_import_common],
dependencies : [libcurl,
libz,
libbzip2,

View file

@ -199,8 +199,6 @@ int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
}
int cg_read_subgroup(DIR *d, char **fn) {
struct dirent *de;
assert(d);
assert(fn);

View file

@ -30,7 +30,6 @@ static int files_add(
_cleanup_closedir_ DIR *dir = NULL;
const char *dirpath;
struct dirent *de;
int r;
assert(h);

View file

@ -14,19 +14,8 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pu
struct dirent *readdir_ensure_type(DIR *d);
struct dirent *readdir_no_dot(DIR *dirp);
#define FOREACH_DIRENT(de, d, on_error) \
for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \
if (!de) { \
if (errno > 0) { \
on_error; \
} \
break; \
} else if (hidden_or_backup_file((de)->d_name)) \
continue; \
else
#define FOREACH_DIRENT_ALL(de, d, on_error) \
for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \
for (struct dirent *(de) = readdir_ensure_type(d);; (de) = readdir_ensure_type(d)) \
if (!de) { \
if (errno > 0) { \
on_error; \
@ -34,6 +23,12 @@ struct dirent *readdir_no_dot(DIR *dirp);
break; \
} else
#define FOREACH_DIRENT(de, d, on_error) \
FOREACH_DIRENT_ALL(de, d, on_error) \
if (hidden_or_backup_file((de)->d_name)) \
continue; \
else
/* Maximum space one dirent structure might require at most */
#define DIRENT_SIZE_MAX CONST_MAX(sizeof(struct dirent), offsetof(struct dirent, d_name) + NAME_MAX + 1)

View file

@ -300,7 +300,6 @@ int close_all_fds_without_malloc(const int except[], size_t n_except) {
int close_all_fds(const int except[], size_t n_except) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
assert(n_except == 0 || except);

View file

@ -533,7 +533,6 @@ int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) {
int get_files_in_directory(const char *path, char ***list) {
_cleanup_strv_free_ char **l = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
size_t n = 0;
assert(path);

View file

@ -158,20 +158,19 @@ static int add_locales_from_archive(Set *locales) {
static int add_locales_from_libdir (Set *locales) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
int r;
dir = opendir("/usr/lib/locale");
if (!dir)
return errno == ENOENT ? 0 : -errno;
FOREACH_DIRENT(entry, dir, return -errno) {
FOREACH_DIRENT(de, dir, return -errno) {
char *z;
if (entry->d_type != DT_DIR)
if (de->d_type != DT_DIR)
continue;
z = normalize_locale(entry->d_name);
z = normalize_locale(de->d_name);
if (!z)
return -ENOMEM;

View file

@ -428,7 +428,7 @@ libbasic = static_library(
libcap,
libm],
c_args : ['-fvisibility=default'],
install : false)
build_by_default : false)
############################################################
@ -443,4 +443,5 @@ libbasic_gcrypt = static_library(
basic_gcrypt_sources,
include_directories : basic_includes,
dependencies : [libgcrypt],
c_args : ['-fvisibility=default'])
c_args : ['-fvisibility=default'],
build_by_default : false)

View file

@ -89,7 +89,6 @@ int open_extension_release(const char *root, const char *extension, char **ret_p
return log_debug_errno(r, "Cannot open %s/usr/lib/extension-release.d/, ignoring: %m", root);
r = -ENOENT;
struct dirent *de;
FOREACH_DIRENT(de, extension_release_dir, return -errno) {
int k;

View file

@ -276,7 +276,6 @@ int unit_file_build_name_map(
STRV_FOREACH(dir, (char**) lp->search_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*dir);
if (!d) {

View file

@ -118,7 +118,6 @@ void in_initrd_force(bool value) {
int on_ac_power(void) {
bool found_offline = false, found_online = false;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r;
d = opendir("/sys/class/power_supply");

View file

@ -98,7 +98,6 @@ static int detect_vm_device_tree(void) {
r = read_one_line_file("/proc/device-tree/hypervisor/compatible", &hvtype);
if (r == -ENOENT) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
if (access("/proc/device-tree/ibm,partition-name", F_OK) == 0 &&
access("/proc/device-tree/hmc-managed?", F_OK) == 0 &&
@ -114,9 +113,9 @@ static int detect_vm_device_tree(void) {
return -errno;
}
FOREACH_DIRENT(dent, dir, return -errno)
if (strstr(dent->d_name, "fw-cfg")) {
log_debug("Virtualization QEMU: \"fw-cfg\" present in /proc/device-tree/%s", dent->d_name);
FOREACH_DIRENT(de, dir, return -errno)
if (strstr(de->d_name, "fw-cfg")) {
log_debug("Virtualization QEMU: \"fw-cfg\" present in /proc/device-tree/%s", de->d_name);
return VIRTUALIZATION_QEMU;
}

View file

@ -184,7 +184,6 @@ finish:
static int enumerate_binaries(const char *esp_path, const char *path, const char *prefix) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
const char *p;
int c = 0, r;
@ -658,7 +657,6 @@ static int copy_one_file(const char *esp_path, const char *name, bool force) {
}
static int install_binaries(const char *esp_path, bool force) {
struct dirent *de;
_cleanup_closedir_ DIR *d = NULL;
int r = 0;
@ -850,7 +848,6 @@ static int install_variables(const char *esp_path,
static int remove_boot_efi(const char *esp_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
const char *p;
int r, c = 0;

View file

@ -287,7 +287,6 @@ static void manager_print_jobs_in_progress(Manager *m) {
static int have_ask_password(void) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
dir = opendir("/run/systemd/ask-password");
if (!dir) {
@ -297,10 +296,9 @@ static int have_ask_password(void) {
return -errno;
}
FOREACH_DIRENT_ALL(de, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno)
if (startswith(de->d_name, "ask."))
return true;
}
return false;
}

View file

@ -184,7 +184,8 @@ libcore = static_library(
libapparmor,
libselinux,
libmount,
libacl])
libacl],
build_by_default : false)
core_includes = [includes, include_directories('.')]

View file

@ -51,7 +51,6 @@ static int fdopen_unlocked_at(int dfd, const char *dir, const char *name, int *s
static int write_access2_rules(const char *srcdir) {
_cleanup_close_ int load2_fd = -1, change_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
int dfd = -1, r = 0;
load2_fd = open("/sys/fs/smackfs/load2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
@ -124,7 +123,6 @@ static int write_access2_rules(const char *srcdir) {
static int write_cipso2_rules(const char *srcdir) {
_cleanup_close_ int cipso2_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
int dfd = -1, r = 0;
cipso2_fd = open("/sys/fs/smackfs/cipso2", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
@ -184,7 +182,6 @@ static int write_cipso2_rules(const char *srcdir) {
static int write_netlabel_rules(const char *srcdir) {
_cleanup_fclose_ FILE *dst = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
int dfd = -1, r = 0;
dst = fopen("/sys/fs/smackfs/netlabel", "we");

View file

@ -142,7 +142,6 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
for (;;) {
_cleanup_(vacuum_candidate_hashmap_freep) Hashmap *h = NULL;
VacuumCandidate *worst = NULL;
struct dirent *de;
uint64_t sum = 0;
rewinddir(d);

View file

@ -580,7 +580,6 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
_cleanup_free_ char *buffer = NULL;
_cleanup_fclose_ FILE *stream = NULL;
const char *fddelim = "", *path;
struct dirent *dent = NULL;
size_t size = 0;
int r;
@ -600,20 +599,20 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
if (!stream)
return -ENOMEM;
FOREACH_DIRENT(dent, proc_fd_dir, return -errno) {
FOREACH_DIRENT(de, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
_cleanup_close_ int fd = -1;
r = readlinkat_malloc(dirfd(proc_fd_dir), dent->d_name, &fdname);
r = readlinkat_malloc(dirfd(proc_fd_dir), de->d_name, &fdname);
if (r < 0)
return r;
fprintf(stream, "%s%s:%s\n", fddelim, dent->d_name, fdname);
fprintf(stream, "%s%s:%s\n", fddelim, de->d_name, fdname);
fddelim = "\n";
/* Use the directory entry from /proc/[pid]/fd with /proc/[pid]/fdinfo */
fd = openat(proc_fdinfo_fd, dent->d_name, O_NOFOLLOW|O_CLOEXEC|O_RDONLY);
fd = openat(proc_fdinfo_fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_RDONLY);
if (fd < 0)
continue;

View file

@ -1,64 +1,28 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
if conf.get('HAVE_LIBCRYPTSETUP_PLUGINS') == 1
cryptsetup_token_c_args = ['-fvisibility=hidden']
cryptsetup_token_sym = files('cryptsetup-token.sym')
cryptsetup_token_sym_path = meson.current_source_dir() / 'cryptsetup-token.sym'
if conf.get('HAVE_TPM2') == 1
cryptsetup_token_systemd_tpm2_sources = files('''
cryptsetup-token-systemd-tpm2.c
cryptsetup-token.h
cryptsetup-token-util.h
cryptsetup-token-util.c
luks2-tpm2.c
luks2-tpm2.h
'''.split())
lib_cryptsetup_token_common = static_library(
'cryptsetup-token-common',
'cryptsetup-token.h',
'cryptsetup-token-util.h',
'cryptsetup-token-util.c',
include_directories : includes,
link_with : libshared,
build_by_default : false)
cryptsetup_token_systemd_tpm2_static = static_library(
'cryptsetup-token-systemd-tpm2_static',
cryptsetup_token_systemd_tpm2_sources,
include_directories : includes,
dependencies : libshared_deps + [libcryptsetup, versiondep],
c_args : cryptsetup_token_c_args)
endif
cryptsetup_token_systemd_tpm2_sources = files(
'cryptsetup-token-systemd-tpm2.c',
'luks2-tpm2.c',
'luks2-tpm2.h')
if conf.get('HAVE_LIBFIDO2') == 1
cryptsetup_token_systemd_fido2_sources = files('''
cryptsetup-token-systemd-fido2.c
cryptsetup-token.h
cryptsetup-token-util.h
cryptsetup-token-util.c
luks2-fido2.c
luks2-fido2.h
'''.split())
cryptsetup_token_systemd_fido2_sources = files(
'cryptsetup-token-systemd-fido2.c',
'luks2-fido2.c',
'luks2-fido2.h')
cryptsetup_token_systemd_fido2_static = static_library(
'cryptsetup-token-systemd-fido2_static',
cryptsetup_token_systemd_fido2_sources,
include_directories : includes,
dependencies : libshared_deps + [libcryptsetup, versiondep],
c_args : cryptsetup_token_c_args)
endif
if conf.get('HAVE_P11KIT') == 1
cryptsetup_token_systemd_pkcs11_sources = files('''
cryptsetup-token-systemd-pkcs11.c
cryptsetup-token.h
cryptsetup-token-util.h
cryptsetup-token-util.c
luks2-pkcs11.c
luks2-pkcs11.h
'''.split())
cryptsetup_token_systemd_pkcs11_static = static_library(
'cryptsetup-token-systemd-pkcs11_static',
cryptsetup_token_systemd_pkcs11_sources,
include_directories : includes,
dependencies : libshared_deps + [libcryptsetup, versiondep],
c_args : cryptsetup_token_c_args)
endif
endif
cryptsetup_token_systemd_pkcs11_sources = files(
'cryptsetup-token-systemd-pkcs11.c',
'luks2-pkcs11.c',
'luks2-pkcs11.h')

View file

@ -290,7 +290,6 @@ static int enumerate_dir(
const char *path, bool dropins) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
size_t n_files = 0, n_dirs = 0;
char **t;

View file

@ -447,7 +447,6 @@ unlink_this_file:
static int manager_enumerate_records(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
assert(m);
@ -919,7 +918,6 @@ static int manager_assess_image(
int manager_enumerate_images(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
assert(m);

View file

@ -159,7 +159,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
int import_mangle_os_tree(const char *path) {
_cleanup_free_ char *child = NULL, *t = NULL, *joined = NULL;
_cleanup_closedir_ DIR *d = NULL, *cd = NULL;
struct dirent *de;
struct dirent *dent;
struct stat st;
int r;
@ -183,8 +183,8 @@ int import_mangle_os_tree(const char *path) {
return log_error_errno(r, "Failed to open directory '%s': %m", path);
errno = 0;
de = readdir_no_dot(d);
if (!de) {
dent = readdir_no_dot(d);
if (!dent) {
if (errno != 0)
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);
@ -192,13 +192,13 @@ int import_mangle_os_tree(const char *path) {
return 0;
}
child = strdup(de->d_name);
child = strdup(dent->d_name);
if (!child)
return log_oom();
errno = 0;
de = readdir_no_dot(d);
if (de) {
dent = readdir_no_dot(d);
if (dent) {
if (errno != 0)
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);

View file

@ -1,62 +1,53 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
systemd_importd_sources = files('''
importd.c
'''.split())
systemd_importd_sources = files(
'importd.c')
systemd_pull_sources = files('''
pull.c
pull-raw.c
pull-raw.h
pull-tar.c
pull-tar.h
pull-job.c
pull-job.h
pull-common.c
pull-common.h
import-common.c
import-common.h
import-compress.c
import-compress.h
curl-util.c
curl-util.h
qcow2-util.c
qcow2-util.h
'''.split())
systemd_pull_sources = files(
'pull.c',
'pull-raw.c',
'pull-raw.h',
'pull-tar.c',
'pull-tar.h',
'pull-job.c',
'pull-job.h',
'pull-common.c',
'pull-common.h',
'curl-util.c',
'curl-util.h')
systemd_import_sources = files('''
import.c
import-raw.c
import-raw.h
import-tar.c
import-tar.h
import-common.c
import-common.h
import-compress.c
import-compress.h
qcow2-util.c
qcow2-util.h
'''.split())
systemd_import_sources = files(
'import.c',
'import-raw.c',
'import-raw.h',
'import-tar.c',
'import-tar.h')
systemd_import_fs_sources = files('''
import-fs.c
import-common.c
import-common.h
'''.split())
systemd_import_fs_sources = files(
'import-fs.c')
systemd_export_sources = files('''
export.c
export-tar.c
export-tar.h
export-raw.c
export-raw.h
import-common.c
import-common.h
import-compress.c
import-compress.h
'''.split())
systemd_export_sources = files(
'export.c',
'export-tar.c',
'export-tar.h',
'export-raw.c',
'export-raw.h')
if conf.get('ENABLE_IMPORTD') == 1
lib_import_common = static_library(
'import-common',
'import-common.c',
'import-common.h',
'import-compress.c',
'import-compress.h',
'qcow2-util.c',
'qcow2-util.h',
include_directories : includes,
dependencies : [libbzip2,
libxz,
libz],
build_by_default : false)
install_data('org.freedesktop.import1.conf',
install_dir : dbuspolicydir)
install_data('org.freedesktop.import1.service',

View file

@ -59,7 +59,6 @@ int pull_find_old_etags(
}
_cleanup_strv_free_ char **ans = NULL;
struct dirent *de;
FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_free_ char *u = NULL;

View file

@ -31,7 +31,7 @@ libsystemd_journal_remote = static_library(
libgnutls,
libxz,
liblz4],
install : false)
build_by_default : false)
systemd_journal_remote_sources = files('''
journal-remote-main.c

View file

@ -90,7 +90,6 @@ static int determine_path_usage(
uint64_t *ret_free) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
struct statvfs ss;
assert(s);

View file

@ -848,7 +848,6 @@ static int stdout_stream_restore(Server *s, const char *fname, int fd) {
int server_restore_streams(Server *s, FDSet *fds) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
const char *path;
int r;

View file

@ -36,7 +36,7 @@ libjournal_core = static_library(
sources,
include_directories : includes,
dependencies: threads,
install : false)
build_by_default : false)
journal_includes = [includes, include_directories('.')]

View file

@ -49,7 +49,8 @@ sources = files('''
libsystemd_network = static_library(
'systemd-network',
sources,
include_directories : includes)
include_directories : includes,
build_by_default : false)
libsystemd_network_includes = [includes, include_directories('.')]

View file

@ -166,12 +166,12 @@ libsystemd_c_args = ['-fvisibility=default']
libsystemd_static = static_library(
'systemd_static',
libsystemd_sources,
install : false,
include_directories : libsystemd_includes,
c_args : libsystemd_c_args,
link_with : libbasic,
dependencies : [threads,
librt],
c_args : libsystemd_c_args)
build_by_default : false)
libsystemd_sym = files('libsystemd.sym')
libsystemd_sym_path = meson.current_source_dir() / 'libsystemd.sym'

View file

@ -350,7 +350,6 @@ static bool match_sysname(sd_device_enumerator *enumerator, const char *sysname)
static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator, const char *basedir, const char *subdir1, const char *subdir2) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
assert(enumerator);
@ -369,18 +368,18 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
/* this is necessarily racey, so ignore missing directories */
return (errno == ENOENT && (subdir1 || subdir2)) ? 0 : -errno;
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
char syspath[strlen(path) + 1 + strlen(de->d_name) + 1];
int initialized, k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (!match_sysname(enumerator, dent->d_name))
if (!match_sysname(enumerator, de->d_name))
continue;
(void) sprintf(syspath, "%s%s", path, dent->d_name);
(void) sprintf(syspath, "%s%s", path, de->d_name);
k = sd_device_new_from_syspath(&device, syspath);
if (k < 0) {
@ -461,7 +460,6 @@ static bool match_subsystem(sd_device_enumerator *enumerator, const char *subsys
static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *basedir, const char *subdir, const char *subsystem) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
path = strjoina("/sys/", basedir);
@ -472,16 +470,16 @@ static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *bas
log_debug("sd-device-enumerator: Scanning %s", path);
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (!match_subsystem(enumerator, subsystem ? : dent->d_name))
if (!match_subsystem(enumerator, subsystem ? : de->d_name))
continue;
k = enumerator_scan_dir_and_add_devices(enumerator, basedir, dent->d_name, subdir);
k = enumerator_scan_dir_and_add_devices(enumerator, basedir, de->d_name, subdir);
if (k < 0)
r = k;
}
@ -492,7 +490,6 @@ static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *bas
static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const char *tag) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
assert(enumerator);
@ -509,15 +506,15 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
/* TODO: filter away subsystems? */
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
const char *subsystem, *sysname;
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
k = sd_device_new_from_device_id(&device, dent->d_name);
k = sd_device_new_from_device_id(&device, de->d_name);
if (k < 0) {
if (k != -ENODEV)
/* this is necessarily racy, so ignore missing devices */
@ -625,24 +622,23 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path)
static int parent_crawl_children(sd_device_enumerator *enumerator, const char *path, unsigned maxdepth) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
int r = 0;
dir = opendir(path);
if (!dir)
return log_debug_errno(errno, "sd-device-enumerator: Failed to open parent directory %s: %m", path);
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_free_ char *child = NULL;
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (dent->d_type != DT_DIR)
if (de->d_type != DT_DIR)
continue;
child = path_join(path, dent->d_name);
child = path_join(path, de->d_name);
if (!child)
return -ENOMEM;

View file

@ -1747,7 +1747,6 @@ _public_ const char *sd_device_get_property_next(sd_device *device, const char *
static int device_sysattrs_read_all_internal(sd_device *device, const char *subdir) {
_cleanup_free_ char *path_dir = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
const char *syspath;
int r;
@ -1779,33 +1778,33 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
if (!dir)
return -errno;
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_free_ char *path = NULL, *p = NULL;
struct stat statbuf;
if (dot_or_dot_dot(dent->d_name))
if (dot_or_dot_dot(de->d_name))
continue;
/* only handle symlinks, regular files, and directories */
if (!IN_SET(dent->d_type, DT_LNK, DT_REG, DT_DIR))
if (!IN_SET(de->d_type, DT_LNK, DT_REG, DT_DIR))
continue;
if (subdir) {
p = path_join(subdir, dent->d_name);
p = path_join(subdir, de->d_name);
if (!p)
return -ENOMEM;
}
if (dent->d_type == DT_DIR) {
if (de->d_type == DT_DIR) {
/* read subdirectory */
r = device_sysattrs_read_all_internal(device, p ?: dent->d_name);
r = device_sysattrs_read_all_internal(device, p ?: de->d_name);
if (r < 0)
return r;
continue;
}
path = path_join(syspath, p ?: dent->d_name);
path = path_join(syspath, p ?: de->d_name);
if (!path)
return -ENOMEM;
@ -1815,7 +1814,7 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
if ((statbuf.st_mode & (S_IRUSR | S_IWUSR)) == 0)
continue;
r = set_put_strdup(&device->sysattrs, p ?: dent->d_name);
r = set_put_strdup(&device->sysattrs, p ?: de->d_name);
if (r < 0)
return r;
}

View file

@ -127,7 +127,6 @@ int journal_directory_vacuum(
_cleanup_closedir_ DIR *d = NULL;
struct vacuum_info *list = NULL;
usec_t retention_limit = 0;
struct dirent *de;
int r;
assert(directory);

View file

@ -1560,14 +1560,11 @@ static int directory_open(sd_journal *j, const char *path, DIR **ret) {
static int add_directory(sd_journal *j, const char *prefix, const char *dirname);
static void directory_enumerate(sd_journal *j, Directory *m, DIR *d) {
struct dirent *de;
assert(j);
assert(m);
assert(d);
FOREACH_DIRENT_ALL(de, d, goto fail) {
if (dirent_is_journal_file(de))
(void) add_file_by_name(j, m->path, de->d_name);
@ -1576,7 +1573,6 @@ static void directory_enumerate(sd_journal *j, Directory *m, DIR *d) {
}
return;
fail:
log_debug_errno(errno, "Failed to enumerate directory %s, ignoring: %m", m->path);
}

View file

@ -774,7 +774,6 @@ _public_ int sd_get_sessions(char ***sessions) {
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;

View file

@ -28,13 +28,8 @@ libudev_basic = static_library(
'udev-basic',
libudev_sources,
include_directories : includes,
c_args : ['-fvisibility=default'])
libudev_static = static_library(
'udev_static',
include_directories : includes,
link_with : udev_link_with,
link_whole : libudev_basic)
c_args : ['-fvisibility=default'],
build_by_default : false)
static_libudev = get_option('static-libudev')
static_libudev_pic = static_libudev == 'true' or static_libudev == 'pic'
@ -52,5 +47,5 @@ custom_target(
tests += [
[['src/libudev/test-libudev.c'],
[libshared,
libudev_static]],
libudev_basic]],
]

View file

@ -1370,9 +1370,7 @@ static int flush_devices(Manager *m) {
if (!d) {
if (errno != ENOENT)
log_warning_errno(errno, "Failed to open /etc/udev/rules.d: %m");
} else {
struct dirent *de;
} else
FOREACH_DIRENT_ALL(de, d, break) {
if (!dirent_is_file(de))
continue;
@ -1386,7 +1384,6 @@ static int flush_devices(Manager *m) {
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
log_warning_errno(errno, "Failed to unlink %s: %m", de->d_name);
}
}
return trigger_device(m, NULL);
}

View file

@ -244,7 +244,6 @@ static int manager_enumerate_buttons(Manager *m) {
static int manager_enumerate_seats(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
assert(m);
@ -286,7 +285,6 @@ static int manager_enumerate_seats(Manager *m) {
static int manager_enumerate_linger_users(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
assert(m);
@ -315,7 +313,6 @@ static int manager_enumerate_linger_users(Manager *m) {
static int manager_enumerate_users(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r, k;
assert(m);
@ -474,7 +471,6 @@ static int manager_attach_fds(Manager *m) {
static int manager_enumerate_sessions(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0, k;
assert(m);
@ -516,7 +512,6 @@ static int manager_enumerate_sessions(Manager *m) {
static int manager_enumerate_inhibitors(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
assert(m);

View file

@ -50,7 +50,8 @@ liblogind_core = static_library(
'logind-core',
liblogind_core_sources,
include_directories : includes,
dependencies : [libacl])
dependencies : libacl,
build_by_default : false)
loginctl_sources = files('''
loginctl.c

View file

@ -136,7 +136,6 @@ static int manager_add_host_machine(Manager *m) {
static int manager_enumerate_machines(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r;
assert(m);

View file

@ -24,7 +24,8 @@ libmachine_core = static_library(
'machine-core',
libmachine_core_sources,
include_directories : includes,
dependencies : [threads])
dependencies : threads,
build_by_default : false)
if conf.get('ENABLE_MACHINED') == 1
install_data('org.freedesktop.machine1.conf',

View file

@ -777,7 +777,6 @@ static int find_mount_points(const char *what, char ***list) {
static int find_loop_device(const char *backing_file, char **loop_dev) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
_cleanup_free_ char *l = NULL;
assert(backing_file);

View file

@ -235,7 +235,8 @@ libnetworkd_core = static_library(
'networkd-core',
sources,
include_directories : network_includes,
link_with : [networkd_link_with])
link_with : networkd_link_with,
build_by_default : false)
if conf.get('ENABLE_NETWORKD') == 1
install_data('org.freedesktop.network1.conf',

View file

@ -45,7 +45,8 @@ libnspawn_core = static_library(
include_directories : includes,
dependencies : [libacl,
libseccomp,
libselinux])
libselinux],
build_by_default : false)
systemd_nspawn_sources = files('nspawn.c')

View file

@ -313,8 +313,6 @@ static int recurse_fd(int fd, bool donate_fd, const struct stat *st, uid_t shift
goto read_only;
if (S_ISDIR(st->st_mode)) {
struct dirent *de;
if (!donate_fd) {
int copy;

View file

@ -244,7 +244,6 @@ static int extract_now(
STRV_FOREACH(i, paths.search_path) {
_cleanup_free_ char *resolved = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
r = chase_symlinks_and_opendir(*i, where, 0, &resolved, &d);
if (r < 0) {
@ -1492,7 +1491,6 @@ int portable_detach(
_cleanup_set_free_ Set *unit_files = NULL, *markers = NULL;
_cleanup_closedir_ DIR *d = NULL;
const char *where, *item;
struct dirent *de;
int ret = 0;
int r;
@ -1662,7 +1660,6 @@ static int portable_get_state_internal(
_cleanup_set_free_ Set *unit_files = NULL;
_cleanup_closedir_ DIR *d = NULL;
const char *where;
struct dirent *de;
int r;
assert(name_or_path);

View file

@ -323,7 +323,6 @@ static void process_dmesg_files(PStoreList *list) {
static int list_files(PStoreList *list, const char *sourcepath) {
_cleanup_(closedirp) DIR *dirp = NULL;
struct dirent *de;
int r;
dirp = opendir(sourcepath);

View file

@ -120,7 +120,8 @@ basic_dns_sources += custom_target(
libsystemd_resolve_core = static_library(
'systemd-resolve-core',
basic_dns_sources,
include_directories : includes)
include_directories : includes,
build_by_default : false)
systemd_resolved_sources += custom_target(
'resolved_gperf.c',

View file

@ -1536,7 +1536,6 @@ void manager_reset_server_features(Manager *m) {
void manager_cleanup_saved_user(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
assert(m);

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;

View file

@ -488,7 +488,6 @@ static int boot_entries_find_unified(
size_t *n_entries) {
_cleanup_(closedirp) DIR *d = NULL;
struct dirent *de;
int r;
assert(root);

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);

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");

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;

View file

@ -166,7 +166,6 @@ int devnode_acl_all(const char *seat,
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
_cleanup_set_free_free_ Set *nodes = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
sd_device *d;
char *n;
int r;
@ -218,11 +217,11 @@ int devnode_acl_all(const char *seat,
* these devices are not known to the kernel at this moment */
dir = opendir("/run/udev/static_node-tags/uaccess");
if (dir) {
FOREACH_DIRENT(dent, dir, return -errno) {
FOREACH_DIRENT(de, dir, return -errno) {
_cleanup_free_ char *unescaped_devname = NULL;
ssize_t l;
l = cunescape(dent->d_name, UNESCAPE_RELAX, &unescaped_devname);
l = cunescape(de->d_name, UNESCAPE_RELAX, &unescaped_devname);
if (l < 0)
return l;

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)

View file

@ -485,7 +485,6 @@ static int cmp_uint16(const uint16_t *a, const uint16_t *b) {
int efi_get_boot_options(uint16_t **options) {
_cleanup_closedir_ DIR *dir = NULL;
_cleanup_free_ uint16_t *list = NULL;
struct dirent *de;
int count = 0;
assert(options);

View file

@ -112,7 +112,6 @@ int fdset_remove(FDSet *s, int fd) {
int fdset_new_fill(FDSet **_s) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
FDSet *s;

View file

@ -549,7 +549,6 @@ static int remove_marked_symlinks_fd(
size_t *n_changes) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
assert(remove_symlinks_to);
@ -729,7 +728,6 @@ static int find_symlinks_in_directory(
const char *config_path,
bool *same_name_link) {
struct dirent *de;
int r = 0;
FOREACH_DIRENT(de, dir, return -errno) {
@ -814,7 +812,6 @@ static int find_symlinks(
bool *same_name_link) {
_cleanup_closedir_ DIR *config_dir = NULL;
struct dirent *de;
int r = 0;
assert(i);
@ -3369,7 +3366,6 @@ int unit_file_preset_all(
STRV_FOREACH(i, paths.search_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*i);
if (!d) {
@ -3434,7 +3430,6 @@ int unit_file_get_list(
STRV_FOREACH(dirname, paths.search_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*dirname);
if (!d) {

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()))

View file

@ -459,7 +459,8 @@ libshared_static = static_library(
shared_sources,
include_directories : includes,
dependencies : libshared_deps,
c_args : ['-fvisibility=default'])
c_args : ['-fvisibility=default'],
build_by_default : false)
libshared = shared_library(
libshared_name,

View file

@ -128,7 +128,6 @@ int numa_to_cpu_set(const NUMAPolicy *policy, CPUSet *ret) {
static int numa_max_node(void) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r, max_node = 0;
d = opendir("/sys/devices/system/node");

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);

View file

@ -405,7 +405,6 @@ static int userdb_start_query(
_cleanup_(strv_freep) char **except = NULL, **only = NULL;
_cleanup_(closedirp) DIR *d = NULL;
struct dirent *de;
const char *e;
int r, ret = 0;

View file

@ -718,7 +718,6 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
STRV_FOREACH(path, sysvinit_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*path);
if (!d) {
@ -805,7 +804,6 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
for (unsigned i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_free_ char *path = NULL;
struct dirent *de;
path = path_join(*p, rcnd_table[i].path);
if (!path) {

View file

@ -167,7 +167,6 @@ TEST(get_paths, .sd_booted = true) {
TEST(proc) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r;
d = opendir("/proc");

View file

@ -135,7 +135,6 @@ static void test_get_process_cmdline_one(pid_t pid) {
TEST(get_process_cmdline) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
assert_se(d = opendir("/proc"));

View file

@ -32,7 +32,8 @@ libtimesyncd_core = static_library(
'timesyncd-core',
sources,
include_directories : includes,
link_with : [timesyncd_link_with])
link_with : timesyncd_link_with,
build_by_default : false)
custom_target(
'timesyncd.conf',

View file

@ -590,14 +590,13 @@ static int dir_cleanup(
AgeBy age_by_dir) {
bool deleted = false;
struct dirent *dent;
int r = 0;
FOREACH_DIRENT_ALL(dent, d, break) {
FOREACH_DIRENT_ALL(de, d, break) {
_cleanup_free_ char *sub_path = NULL;
nsec_t atime_nsec, mtime_nsec, ctime_nsec, btime_nsec;
if (dot_or_dot_dot(dent->d_name))
if (dot_or_dot_dot(de->d_name))
continue;
/* If statx() is supported, use it. It's preferable over fstatat() since it tells us
@ -614,7 +613,7 @@ static int dir_cleanup(
STRUCT_STATX_DEFINE(sx);
r = statx_fallback(
dirfd(d), dent->d_name,
dirfd(d), de->d_name,
AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT,
STATX_TYPE|STATX_MODE|STATX_UID|STATX_ATIME|STATX_MTIME|STATX_CTIME|STATX_BTIME,
&sx);
@ -623,14 +622,14 @@ static int dir_cleanup(
if (r < 0) {
/* FUSE, NFS mounts, SELinux might return EACCES */
r = log_full_errno(errno == EACCES ? LOG_DEBUG : LOG_ERR, errno,
"statx(%s/%s) failed: %m", p, dent->d_name);
"statx(%s/%s) failed: %m", p, de->d_name);
continue;
}
if (FLAGS_SET(sx.stx_attributes_mask, STATX_ATTR_MOUNT_ROOT)) {
/* Yay, we have the mount point API, use it */
if (FLAGS_SET(sx.stx_attributes, STATX_ATTR_MOUNT_ROOT)) {
log_debug("Ignoring \"%s/%s\": different mount points.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different mount points.", p, de->d_name);
continue;
}
} else {
@ -638,7 +637,7 @@ static int dir_cleanup(
* back to traditional stx_dev checking. */
if (sx.stx_dev_major != rootdev_major ||
sx.stx_dev_minor != rootdev_minor) {
log_debug("Ignoring \"%s/%s\": different filesystem.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different filesystem.", p, de->d_name);
continue;
}
@ -648,11 +647,11 @@ static int dir_cleanup(
if (S_ISDIR(sx.stx_mode)) {
int q;
q = fd_is_mount_point(dirfd(d), dent->d_name, 0);
q = fd_is_mount_point(dirfd(d), de->d_name, 0);
if (q < 0)
log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, dent->d_name);
log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, de->d_name);
else if (q > 0) {
log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", p, de->d_name);
continue;
}
}
@ -663,7 +662,7 @@ static int dir_cleanup(
ctime_nsec = FLAGS_SET(sx.stx_mask, STATX_CTIME) ? load_statx_timestamp_nsec(&sx.stx_ctime) : 0;
btime_nsec = FLAGS_SET(sx.stx_mask, STATX_BTIME) ? load_statx_timestamp_nsec(&sx.stx_btime) : 0;
sub_path = path_join(p, dent->d_name);
sub_path = path_join(p, de->d_name);
if (!sub_path) {
r = log_oom();
goto finish;
@ -684,7 +683,7 @@ static int dir_cleanup(
_cleanup_closedir_ DIR *sub_dir = NULL;
if (mountpoint &&
streq(dent->d_name, "lost+found") &&
streq(de->d_name, "lost+found") &&
sx.stx_uid == 0) {
log_debug("Ignoring directory \"%s\".", sub_path);
continue;
@ -695,7 +694,7 @@ static int dir_cleanup(
else {
int q;
sub_dir = xopendirat_nomod(dirfd(d), dent->d_name);
sub_dir = xopendirat_nomod(dirfd(d), de->d_name);
if (!sub_dir) {
if (errno != ENOENT)
r = log_warning_errno(errno, "Opening directory \"%s\" failed, ignoring: %m", sub_path);
@ -737,7 +736,7 @@ static int dir_cleanup(
continue;
log_debug("Removing directory \"%s\".", sub_path);
if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0)
if (unlinkat(dirfd(d), de->d_name, AT_REMOVEDIR) < 0)
if (!IN_SET(errno, ENOENT, ENOTEMPTY))
r = log_warning_errno(errno, "Failed to remove directory \"%s\", ignoring: %m", sub_path);
@ -752,7 +751,7 @@ static int dir_cleanup(
if (mountpoint &&
S_ISREG(sx.stx_mode) &&
sx.stx_uid == 0 &&
STR_IN_SET(dent->d_name,
STR_IN_SET(de->d_name,
".journal",
"aquota.user",
"aquota.group")) {
@ -783,7 +782,7 @@ static int dir_cleanup(
continue;
log_debug("Removing \"%s\".", sub_path);
if (unlinkat(dirfd(d), dent->d_name, 0) < 0)
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
if (errno != ENOENT)
r = log_warning_errno(errno, "Failed to remove \"%s\", ignoring: %m", sub_path);
@ -1920,7 +1919,6 @@ static int item_do(Item *i, int fd, const char *path, fdaction_t action) {
if (S_ISDIR(st.st_mode)) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
/* The passed 'fd' was opened with O_PATH. We need to convert it into a 'regular' fd before
* reading the directory content. */

View file

@ -295,7 +295,6 @@ static int wall_tty_block(void) {
static int process_password_files(void) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
d = opendir("/run/systemd/ask-password");

View file

@ -115,7 +115,9 @@ libudevd_core = static_library(
keyboard_keys_from_name_h,
include_directories : udev_includes,
link_with : udev_link_with,
dependencies : [libblkid, libkmod])
dependencies : [libblkid,
libkmod],
build_by_default : false)
udev_progs = [['ata_id/ata_id.c'],
['cdrom_id/cdrom_id.c'],

View file

@ -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;

View file

@ -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

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -229,8 +229,6 @@ static int export_devices(void) {
}
static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
struct dirent *dent;
if (depth <= 0)
return;

View file

@ -518,7 +518,6 @@ static int display_memberships(int argc, char *argv[], void *userdata) {
static int display_services(int argc, char *argv[], void *userdata) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_(closedirp) DIR *d = NULL;
struct dirent *de;
int r;
d = opendir("/run/systemd/userdb/");

View file

@ -43,7 +43,6 @@ static int enumerate_xdg_autostart(Hashmap *all_services) {
STRV_FOREACH(path, autostart_dirs) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*path);
if (!d) {