1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

Handle d_type == DT_UNKNOWN correctly

As documented in the man-page, readdir() may return a directory entry with
d_type == DT_UNKNOWN. This must be handled for regular filesystems.

dirent_ensure_type() is available to set d_type if necessary. Use it in
some more places.

Without this systemd will fail to boot correctly with nfsroot and some
other filesystems.

Closes #13609
This commit is contained in:
Michael Olbrich 2019-09-29 13:43:00 +02:00 committed by Chris Down
parent 501deda1ce
commit 28e68bb235
5 changed files with 6 additions and 0 deletions

View File

@ -84,6 +84,7 @@ static int write_access2_rules(const char *srcdir) {
FOREACH_DIRENT(entry, dir, return 0) {
_cleanup_fclose_ FILE *policy = NULL;
dirent_ensure_type(dir, entry);
if (!dirent_is_file(entry))
continue;
@ -150,6 +151,7 @@ static int write_cipso2_rules(const char *srcdir) {
FOREACH_DIRENT(entry, dir, return 0) {
_cleanup_fclose_ FILE *policy = NULL;
dirent_ensure_type(dir, entry);
if (!dirent_is_file(entry))
continue;

View File

@ -1378,6 +1378,7 @@ static int flush_devices(Manager *m) {
struct dirent *de;
FOREACH_DIRENT_ALL(de, d, break) {
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
continue;

View File

@ -291,6 +291,7 @@ static int manager_enumerate_linger_users(Manager *m) {
FOREACH_DIRENT(de, d, return -errno) {
int k;
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
continue;

View File

@ -475,6 +475,7 @@ static int boot_entries_find_unified(
_cleanup_free_ char *j = NULL, *osrelease = NULL, *cmdline = NULL;
_cleanup_close_ int fd = -1;
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
continue;

View File

@ -279,6 +279,7 @@ int unit_file_build_name_map(
if (hashmap_contains(ids, de->d_name))
continue;
dirent_ensure_type(d, de);
if (de->d_type == DT_LNK) {
/* We don't explicitly check for alias loops here. unit_ids_map_get() which
* limits the number of hops should be used to access the map. */