[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: unlink test failure on MacOS X
From: |
Bruno Haible |
Subject: |
Re: unlink test failure on MacOS X |
Date: |
Sat, 20 Mar 2010 17:48:09 +0100 |
User-agent: |
KMail/1.9.9 |
Jim Meyering wrote:
> > + (umask 077 && mkdir "$tmp")
> > + }; then
> > + mkdir "$tmp/subdir"
> > + export tmp
> > + AC_RUN_IFELSE(
> > + [AC_LANG_SOURCE([[
> > + #include <stdlib.h>
> > + #include <unistd.h>
> > + int main ()
> > + {
> > + if (chdir (getenv ("tmp")) != 0)
> > + return 1;
> > + return unlink ("..") == 0;
> > + }
>
> This all looks fine.
> The only question I had was why bother to create "$tmp/subdir".
> At first I though it was to ensure $tmp is not empty,
Oops, the test program was supposed to chdir into $tmp/subdir, not $tmp.
Then, the directory that is argument of unlink() is non-empty anyway.
The reason for the subdir is:
1) If the test is being run as root, possibly on a file system where
unlink() of a directory actually works, I find it preferable to remove
a directory that contains only an empty subdirectory, rather than
removing the entire /tmp with all its contents.
2) The MacOS X kernel code indicates that things work differently when
the VFS node is sticky. I don't know whether it's the same or a different
meaning of "sticky". But since /tmp always the sticky bit set, it's better
to avoid it.
3) /tmp is not owned by the current user, so unlinking it may fail for another
reason.
4) It's also imagineable that /tmp be a mount point (although on the machine
I use, it's not). Again, unlink() may behave differently on a mount point
than on a regular directory.
Thanks for the review!
Bruno
2010-03-20 Bruno Haible <address@hidden>
* m4/unlink.m4 (gl_FUNC_UNLINK): Fix last commit.
Reported by Jim Meyering.
--- m4/unlink.m4.orig Sat Mar 20 17:46:37 2010
+++ m4/unlink.m4 Sat Mar 20 17:45:52 2010
@@ -36,6 +36,11 @@
[gl_cv_func_unlink_parent_fails],
[case "$host_os" in
darwin*)
+ dnl Try to unlink a subdirectory of /tmp, because /tmp is usually on a
+ dnl HFS mount on MacOS X. Use a subdirectory, owned by the current
+ dnl user, because otherwise unlink() may fail due to permissions
+ dnl reasons, and because when running as root we don't want to risk
+ dnl destroying the entire /tmp.
if {
# Use the mktemp program if available. If not available, hide
the error
# message.
@@ -52,14 +57,15 @@
(umask 077 && mkdir "$tmp")
}; then
mkdir "$tmp/subdir"
- export tmp
+ GL_SUBDIR_FOR_UNLINK="$tmp/subdir"
+ export GL_SUBDIR_FOR_UNLINK
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdlib.h>
#include <unistd.h>
int main ()
{
- if (chdir (getenv ("tmp")) != 0)
+ if (chdir (getenv ("GL_SUBDIR_FOR_UNLINK")) != 0)
return 1;
return unlink ("..") == 0;
}
@@ -67,8 +73,8 @@
[gl_cv_func_unlink_parent_fails=yes],
[gl_cv_func_unlink_parent_fails=no],
[gl_cv_func_unlink_parent_fails="guessing no"])
+ unset GL_SUBDIR_FOR_UNLINK
rm -rf "$tmp"
- unset tmp
else
gl_cv_func_unlink_parent_fails="guessing no"
fi