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