~ruther/guix-local

def983628e14436998edc0bf7499a27013b5fe4b — Romain GARBAGE 6 months ago 13e8266
pack: Address DT_UNKNOWN case for exotic filesystems.

This is a followup of 4ce3a53ae5ee832aa92e0345f15780bc7da060d7.

In some filesystems, the d_type field in the dirent struct returned by
readdir(3) is not properly filled. According to readdir(3), "All applications
must properly handle a return of DT_UNKNOWN". This patch addresses the issue.

* gnu/packages/aux-files/run-in-namespace.c: Handle DT_UNKNOWN case.

Change-Id: Iae3554a01f19a3f30f323916a3426a4068b5df59
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Modified-by: Ludovic Courtès <ludo@gnu.org>
1 files changed, 14 insertions(+), 1 deletions(-)

M gnu/packages/aux-files/run-in-namespace.c
M gnu/packages/aux-files/run-in-namespace.c => gnu/packages/aux-files/run-in-namespace.c +14 -1
@@ 205,11 205,24 @@ mirror_directory (const char *source, const char *target,
	  /* Create the mount point.  */
	  int err = firmlink (abs_source, entry, new_entry);

	  int is_directory = 0;
	  if (entry->d_type == DT_UNKNOWN)
	    {
	      struct stat statbuf;
	      if (fstatat (dir_fd, entry->d_name, &statbuf,
			   AT_SYMLINK_NOFOLLOW) < 0)
		assert_perror (errno);
	      if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
		is_directory = 1;
	    }
	  else if (entry->d_type == DT_DIR)
	    is_directory = 1;

	  /* It used to be that only directories could be bind-mounted.  Thus,
	     keep going if we fail to bind-mount a non-directory entry.
	     That's OK because regular files in the root file system are
	     usually uninteresting.  */
	  if (err != 0 && entry->d_type != DT_DIR)
	  if (err != 0 && is_directory == 0)
	    assert_perror (errno);

	  free (new_entry);