]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Handle d_type == DT_UNKNOWN correctly
authorMichael Olbrich <m.olbrich@pengutronix.de>
Sun, 29 Sep 2019 11:43:00 +0000 (13:43 +0200)
committerChris Down <chris@chrisdown.name>
Mon, 30 Sep 2019 12:29:59 +0000 (13:29 +0100)
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

src/core/smack-setup.c
src/login/logind-dbus.c
src/login/logind.c
src/shared/bootspec.c
src/shared/unit-file.c

index b95e6239d4b217c1302f02c611505fc419a88ab7..e2d4c0d6e1726ab3d6f73b0d2f576e98e3d0c8ca 100644 (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;
 
index 30b9a66334fa7914e4f6984da46c49dd678e12aa..679eb6a62ec0c2068f91aabb9681e46cfb755306 100644 (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;
 
index 3a16e6c8712a89740a1ae1e173e74f39d8180975..d889d7b9bec953851354a57a7f89810868261843 100644 (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;
 
index 355b1bebf610ac09ad38cfc356656a64543ca041..22736098421982eacfa8efebc59b027af006a479 100644 (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;
 
index 4a5f23e6c1bcbb0e76ffe9a508d661022fc98189..c7a6d6717244d63994e917db09a36442bff83ccd 100644 (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. */