}
int cg_read_subgroup(DIR *d, char **fn) {
- struct dirent *de;
-
assert(d);
assert(fn);
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; \
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);
STRV_FOREACH(dir, (char**) lp->search_path) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
d = opendir(*dir);
if (!d) {
static int have_ask_password(void) {
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *de;
dir = opendir("/run/systemd/ask-password");
if (!dir) {
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;
}
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;
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;
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);
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);
}
_cleanup_strv_free_ char **ans = NULL;
- struct dirent *de;
FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_free_ char *u = NULL;
uint64_t *ret_free) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
struct statvfs ss;
assert(s);
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);
/* 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) {
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);
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;
}
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);
/* 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 */
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;
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;
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;
if (!(statbuf.st_mode & S_IRUSR))
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;
}
_cleanup_closedir_ DIR *d = NULL;
struct vacuum_info *list = NULL;
usec_t retention_limit = 0;
- struct dirent *de;
int r;
assert(directory);
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);
}
return;
-
fail:
log_debug_errno(errno, "Failed to enumerate directory %s, ignoring: %m", m->path);
}
_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;
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;
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);
}
goto read_only;
if (S_ISDIR(st->st_mode)) {
- struct dirent *de;
-
if (!donate_fd) {
int copy;
void manager_cleanup_saved_user(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
assert(m);
_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;
_cleanup_closedir_ DIR *d = NULL;
bool changed = false;
- struct dirent *de;
int r;
assert(fd >= 0);
}
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);
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");
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
bool exists, created;
int r;
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)
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().
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()))
const struct stat *root_dev) {
_cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
int ret = 0, r;
assert(fd >= 0);
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
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);
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 {
* 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;
}
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;
}
}
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;
_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;
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);
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);
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")) {
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);
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. */
_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);
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;
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;
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;
int host, bus, target, lun;
const char *name, *base, *pos;
_cleanup_closedir_ DIR *dir = NULL;
- struct dirent *dent;
int basenum = -1;
assert(parent);
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
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;
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;
/* 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)
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;
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;
#define MIN_RANDOM_DELAY ( 10 * USEC_PER_MSEC)
int udev_watch_restore(int inotify_fd) {
- struct dirent *ent;
DIR *dir;
int r;
}
static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
- struct dirent *dent;
-
if (depth <= 0)
return;