about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/pathconf.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2013-04-03 10:56:45 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2013-04-03 10:56:45 +0530
commitd755bba40f880c01ced8740a26fecc85534454b9 (patch)
treeb295c8cadaf81d7fedd5394f5aa358c25cf51dcb /sysdeps/unix/sysv/linux/pathconf.c
parent52ce486045074d0af0298082f94e385e6b2fe443 (diff)
downloadglibc-d755bba40f880c01ced8740a26fecc85534454b9.tar.gz
glibc-d755bba40f880c01ced8740a26fecc85534454b9.tar.xz
glibc-d755bba40f880c01ced8740a26fecc85534454b9.zip
Preserve errno across _PC_CHOWN_RESTRICTED call on XFS
Fix BZ #15305.

On kernel versions earlier than 2.6.29, the Linux kernel exported a
sysctl called restrict_chown for xfs, which could be used to allow
chown to users other than the owner.  2.6.29 removed this support,
causing the open_not_cancel_2 to fail and thus modify errno.  The fix
is to save and restore errno so that the caller sees it as unmodified.

Additionally, since the code to check the sysctl is not useful on
newer kernels, we add an ifdef so that in future the code block gets
rmeoved completely.
Diffstat (limited to 'sysdeps/unix/sysv/linux/pathconf.c')
-rw-r--r--sysdeps/unix/sysv/linux/pathconf.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/pathconf.c b/sysdeps/unix/sysv/linux/pathconf.c
index de91a4541b..723d234538 100644
--- a/sysdeps/unix/sysv/linux/pathconf.c
+++ b/sysdeps/unix/sysv/linux/pathconf.c
@@ -289,11 +289,16 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
       return -1;
     }
 
+#if __ASSUME_XFS_RESTRICTED_CHOWN
+  return 1;
+#else
   int fd;
+  int save_errno;
   long int retval = 1;
   switch (fsbuf->f_type)
     {
     case XFS_SUPER_MAGIC:
+      save_errno = errno;
       /* Read the value from /proc/sys/fs/xfs/restrict_chown.  If we cannot
 	 read it default to assume the restriction is in place.  */
       fd = open_not_cancel_2 ("/proc/sys/fs/xfs/restrict_chown", O_RDONLY);
@@ -306,6 +311,7 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
 
 	  close_not_cancel_no_status (fd);
 	}
+      __set_errno (save_errno);
       break;
 
     default:
@@ -313,4 +319,5 @@ __statfs_chown_restricted (int result, const struct statfs *fsbuf)
     }
 
   return retval;
+#endif
 }