ce426f
commit d755bba40f880c01ced8740a26fecc85534454b9
ce426f
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
ce426f
Date:   Wed Apr 3 10:56:45 2013 +0530
ce426f
ce426f
    Preserve errno across _PC_CHOWN_RESTRICTED call on XFS
ce426f
    
ce426f
    Fix BZ #15305.
ce426f
    
ce426f
    On kernel versions earlier than 2.6.29, the Linux kernel exported a
ce426f
    sysctl called restrict_chown for xfs, which could be used to allow
ce426f
    chown to users other than the owner.  2.6.29 removed this support,
ce426f
    causing the open_not_cancel_2 to fail and thus modify errno.  The fix
ce426f
    is to save and restore errno so that the caller sees it as unmodified.
ce426f
    
ce426f
    Additionally, since the code to check the sysctl is not useful on
ce426f
    newer kernels, we add an ifdef so that in future the code block gets
ce426f
    rmeoved completely.
ce426f
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/kernel-features.h glibc-2.17-c758a686/sysdeps/unix/sysv/linux/kernel-features.h
ce426f
index 8fdff7e..ccd4c59 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/kernel-features.h
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/kernel-features.h
ce426f
@@ -221,3 +221,9 @@
ce426f
 #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
ce426f
 # define __ASSUME_GETCPU_SYSCALL	1
ce426f
 #endif
ce426f
+
ce426f
+/* 2.6.29 removed the XFS restricted_chown sysctl, so it is pointless looking
ce426f
+   for it in newer kernels.  */
ce426f
+#if __LINUX_KERNEL_VERSION >= 0x02061d
ce426f
+# define __ASSUME_XFS_RESTRICTED_CHOWN 1
ce426f
+#endif
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
index de91a45..723d234 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/pathconf.c
ce426f
@@ -289,11 +289,16 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
ce426f
       return -1;
ce426f
     }
ce426f
 
ce426f
+#if __ASSUME_XFS_RESTRICTED_CHOWN
ce426f
+  return 1;
ce426f
+#else
ce426f
   int fd;
ce426f
+  int save_errno;
ce426f
   long int retval = 1;
ce426f
   switch (fsbuf->f_type)
ce426f
     {
ce426f
     case XFS_SUPER_MAGIC:
ce426f
+      save_errno = errno;
ce426f
       /* Read the value from /proc/sys/fs/xfs/restrict_chown.  If we cannot
ce426f
 	 read it default to assume the restriction is in place.  */
ce426f
       fd = open_not_cancel_2 ("/proc/sys/fs/xfs/restrict_chown", O_RDONLY);
ce426f
@@ -306,6 +311,7 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
ce426f
 
ce426f
 	  close_not_cancel_no_status (fd);
ce426f
 	}
ce426f
+      __set_errno (save_errno);
ce426f
       break;
ce426f
 
ce426f
     default:
ce426f
@@ -313,4 +319,5 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
ce426f
     }
ce426f
 
ce426f
   return retval;
ce426f
+#endif
ce426f
 }