This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #15305] Preserve errno across pathconf on XFS
On Mon, Apr 01, 2013 at 03:03:11PM +0200, Andreas Schwab wrote:
> Siddhesh Poyarekar <siddhesh@redhat.com> writes:
>
> > [__LINUX_KERNEL_VERSION >= 0x02061d]: Define
> > __ASSUME_RESTRICTED_CHOWN.
>
> Since this is XFS specific, the macro should probably contain XFS in its
> name.
>
How about this:
[BZ #15305]
* sysdeps/unix/sysv/linux/kernel-features.h
[__LINUX_KERNEL_VERSION >= 0x02061d]: Define
__ASSUME_XFS_RESTRICTED_CHOWN.
* sysdeps/unix/sysv/linux/pathconf.c
(__statfs_chown_restricted) [!__ASSUME_XFS_RESTRICTED_CHOWN]:
Save and restore errno.
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 8fdff7e..ccd4c59 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -221,3 +221,9 @@
#if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
# define __ASSUME_GETCPU_SYSCALL 1
#endif
+
+/* 2.6.29 removed the XFS restricted_chown sysctl, so it is pointless looking
+ for it in newer kernels. */
+#if __LINUX_KERNEL_VERSION >= 0x02061d
+# define __ASSUME_XFS_RESTRICTED_CHOWN 1
+#endif
diff --git a/sysdeps/unix/sysv/linux/pathconf.c b/sysdeps/unix/sysv/linux/pathconf.c
index de91a45..723d234 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
}