Blame SOURCES/coreutils-8.22-xfsbuildfailure.patch

dd59ef
From eafaa2e88f7af16756142a31ab63d032b31395e3 Mon Sep 17 00:00:00 2001
dd59ef
From: Pádraig Brady <P@draigBrady.com>
dd59ef
Date: Fri, 06 Nov 2015 16:31:22 +0000
dd59ef
Subject: tests: fix dirent d_type support verification
dd59ef
dd59ef
* tests/d_type-check: Check also the d_type of files,
dd59ef
which excludes XFS appropriately.  Specify all argument
dd59ef
and return types to avoid truncated pointers being passed,
dd59ef
which skipped the test due to crashes on x86_64 at least.
dd59ef
Simplify the C library lookup by reusing the interpreter's.
dd59ef
dd59ef
chroot issue reported at https://bugzilla.redhat.com/1263341
dd59ef
---
dd59ef
diff --git a/tests/d_type-check b/tests/d_type-check
dd59ef
index ff1eb60..1a2f76f 100644
dd59ef
--- a/tests/d_type-check
dd59ef
+++ b/tests/d_type-check
dd59ef
@@ -1,13 +1,17 @@
dd59ef
 #!/usr/bin/python
dd59ef
-# Exit 0 if "." has useful d_type information, else 1.
dd59ef
+# Exit 0 if "." and "./tempfile" have useful d_type information, else 1.
dd59ef
 # Intended to exit 0 only on Linux/GNU systems.
dd59ef
+import os
dd59ef
 import sys
dd59ef
+import tempfile
dd59ef
 
dd59ef
 fail = 1
dd59ef
+fname = None
dd59ef
+
dd59ef
 try:
dd59ef
   import ctypes
dd59ef
 
dd59ef
-  (DT_UNKNOWN, DT_DIR,) = (0, 4,)
dd59ef
+  (DT_UNKNOWN, DT_DIR, DT_REG) = (0, 4, 8)
dd59ef
 
dd59ef
   class dirent(ctypes.Structure):
dd59ef
     _fields_ = [
dd59ef
@@ -17,20 +21,48 @@ try:
dd59ef
       ("d_type", ctypes.c_ubyte),
dd59ef
       ("d_name", ctypes.c_char*256)]
dd59ef
 
dd59ef
+  # Pass NULL to dlopen, assuming the python
dd59ef
+  # interpreter is linked with the C runtime
dd59ef
+  libc = ctypes.CDLL(None)
dd59ef
+
dd59ef
+  # Setup correct types for all args and returns
dd59ef
+  # even if only passing, to avoid truncation etc.
dd59ef
+  dirp = ctypes.c_void_p
dd59ef
   direntp = ctypes.POINTER(dirent)
dd59ef
 
dd59ef
-  # FIXME: find a way to avoid hard-coding libc's so-name.
dd59ef
-  libc = ctypes.cdll.LoadLibrary("libc.so.6")
dd59ef
+  libc.readdir.argtypes = [dirp]
dd59ef
   libc.readdir.restype = direntp
dd59ef
 
dd59ef
+  libc.opendir.restype = dirp
dd59ef
+
dd59ef
+  # Ensure a file is present
dd59ef
+  f, fname = tempfile.mkstemp(dir='.')
dd59ef
+  fname = os.path.basename(fname)
dd59ef
+
dd59ef
   dirp = libc.opendir(".")
dd59ef
   if dirp:
dd59ef
-    ep = libc.readdir(dirp)
dd59ef
-    if ep:
dd59ef
+    while True:
dd59ef
+      ep = libc.readdir(dirp)
dd59ef
+      if not ep: break
dd59ef
+      d_type = ep.contents.d_type
dd59ef
       name = ep.contents.d_name
dd59ef
-      if (name == "." or name == "..") and ep.contents.d_type == DT_DIR:
dd59ef
+      if name == "." or name == "..":
dd59ef
+        if d_type != DT_DIR: break
dd59ef
+      # Check files too since on XFS, only dirs have DT_DIR
dd59ef
+      # while everything else has DT_UNKNOWN
dd59ef
+      elif name == fname:
dd59ef
+        if d_type == DT_REG:
dd59ef
+          fail = 0
dd59ef
+        break
dd59ef
+      elif d_type != DT_DIR and d_type != DT_UNKNOWN:
dd59ef
         fail = 0
dd59ef
+        break
dd59ef
+except:
dd59ef
+  pass
dd59ef
 
dd59ef
+try:
dd59ef
+  if fname:
dd59ef
+    os.unlink(fname);
dd59ef
 except:
dd59ef
   pass
dd59ef
 
dd59ef
--
dd59ef
cgit v0.9.0.2