Bug 9369 - configure fails to detect dirfd on FreeBSD because it is a macro
Summary: configure fails to detect dirfd on FreeBSD because it is a macro
Status: NEW
Alias: None
Product: Samba 3.6
Classification: Unclassified
Component: Build environment (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: Björn Jacke
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-07 23:08 UTC by Richard Sharpe
Modified: 2012-11-09 14:44 UTC (History)
0 users

See Also:


Attachments
Patch in git format-patch format (1.77 KB, patch)
2012-11-08 20:10 UTC, Volker Lendecke
no flags Details
Patch for 3.6 (3.49 KB, patch)
2012-11-09 11:50 UTC, Volker Lendecke
no flags Details
Patch for 4.0 (3.35 KB, patch)
2012-11-09 11:50 UTC, Volker Lendecke
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Sharpe 2012-11-07 23:08:56 UTC
When we run configure on FreeBSD the test for dirfd fails:

configure:25451: checking for dirfd
configure:25507: gcc -o conftest -O0 -I/home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4/usr/include -DPANZURA_DEV -I/home/rsharpe/dev-src/buildroot/../pixel8/replock -I/home/rsharpe/dev-src/buildroot/build/cloudcc/build_x86_64/samba-3.6.6/lib/tdb/include -I/home/rsharpe/dev-src/buildroot/build/cloudcc/build_x86_64/root/usr/include -Iinclude -I./include  -I. -I. -I./../lib/replace -I./../lib/tevent -I./librpc -I./.. -I./../lib/popt --sysroot /home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4 -L/home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4/lib -L/home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4/usr/lib -L/home/rsharpe/dev-src/buildroot/build/cloudcc/build_x86_64/samba-3.6.6/source3 -L/home/rsharpe/dev-src/buildroot/build/cloudcc/build_x86_64/samba-3.6.6/source3/bin -L/home/rsharpe/dev-src/buildroot/build/cloudcc/build_x86_64/licd/build/FreeBSD/export/dist/lib -rpath /home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4/lib -rpath /home/rsharpe/dev-src/buildroot/tools/x86_gcc4.2.4/usr/lib conftest.c   >&5
/var/tmp//ccQXACBM.o(.text+0xa): In function `main':
: undefined reference to `dirfd'

This is because it is a macro and the testing code is:

| int
| main ()
| {
| return dirfd ();
|   ;
|   return 0;
| }

We need a more robust configure test.
Comment 1 Richard Sharpe 2012-11-07 23:31:03 UTC
I think we can do something like:

AC_CHECK_DECLS(dirfd, 
   [AC_DEFINE(HAVE_DIRFD,1,[Whether we have dirfd])],
   [AC_CHECK_FUNCS(dirfd)],
   #include <dirent.h>)
if test x"$ac_cv_func_dirfd" = x"yes" -o x"ac_cv_have_decl_diffd" = x"yes"; then
   ... current actions.
fi
Comment 2 Richard Sharpe 2012-11-08 11:51:56 UTC
Hmmm, my suggestion above is bogus. Here is something that promises to work (stolen from sudo):

dnl
dnl Check for the dirfd function/macro.  If not found, look for dd_fd in DIR.
dnl
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <$ac_header_dirent>]], [[DIR *d; (void)dirfd(d);]])], [AC_DEFINE(HAVE_DIRFD)], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <$ac_header_dirent>]], [[DIR d; memset(&d, 0, sizeof(d)); return(d.dd_fd);]])], [AC_DEFINE(HAVE_DD_FD)], [])])

Clearly, it will need a little changing to do what we want but it is close.
Comment 3 Richard Sharpe 2012-11-08 15:22:18 UTC
This looks like it should do something close to what is needed:

###########################################
# Check for the dirfd function/macro.
AC_CACHE_CHECK([for dirfd as func or macro], [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <$ac_header_dirent>], [DIR *d; (void)dirfd(d);], 
        [samba_ac_cv_func_dirfd=yes], [samba_ac_cv_func_dirfd=no])])

if test x"$samba_ac_cv_func_dirfd" = x"yes"; then
        AC_DEFINE(HAVE_DIRFD)]
        default_shared_modules="$default_shared_modules vfs_syncops vfs_dirsort"
fi

However, autogen.sh is generating some weird stuff so I don't know what is going wrong.
Comment 4 Richard Sharpe 2012-11-08 15:48:26 UTC
This is closer to correct, but it seems Linux has an automatic test for dirfd anyway:

###########################################
# Check for the dirfd function/macro.
AC_CACHE_CHECK([for dirfd as func or macro], samba_cv_have_dirfd, [
AC_TRY_COMPILE([
#include <sys/types.h>
#include <$ac_header_dirent>], [DIR *d; (void)dirfd(d);], 
        [samba_cv_have_dirfd=yes], [samba_cv_have_dirfd=no])])

if test x"$samba_cv_have_dirfd" = x"yes"; then
        AC_DEFINE(HAVE_DIRFD,1,[Whether we have dirfd as func or macro])
        default_shared_modules="$default_shared_modules vfs_syncops vfs_dirsort"
fi
Comment 5 Richard Sharpe 2012-11-08 17:34:22 UTC
The above entry seems to work for FreeBSD now.

However, it might be that on the FreeBSD system I am using we have an old version of autoconf, because there are checks for dirfd, they just do not detect the presence of dirfd.
Comment 6 Richard Sharpe 2012-11-08 17:47:22 UTC
The above fix also works on Linux (CentOS 6.3).
Comment 7 Volker Lendecke 2012-11-08 20:10:52 UTC
Created attachment 8168 [details]
Patch in git format-patch format
Comment 8 Richard Sharpe 2012-11-08 20:46:58 UTC
Comment on attachment 8168 [details]
Patch in git format-patch format

This looks good to me.
Comment 9 Richard Sharpe 2012-11-08 20:48:14 UTC
For reasons I can not understand, bugzilla does not present me with any review button or check box I can review.

The change looks good to me ...
Comment 10 Jeremy Allison 2012-11-09 04:16:02 UTC
Do we also need this for 4.0.x (and in that case a waf fix also) ?

Jeremy.
Comment 11 Björn Jacke 2012-11-09 08:38:24 UTC
(In reply to comment #9)
> For reasons I can not understand, bugzilla does not present me with any review
> button or check box I can review.

the question is why you created a second bugzilla account. Your previous and still existing account has the rights to do that.
Comment 12 Volker Lendecke 2012-11-09 11:50:14 UTC
Created attachment 8174 [details]
Patch for 3.6
Comment 13 Volker Lendecke 2012-11-09 11:50:37 UTC
Created attachment 8175 [details]
Patch for 4.0
Comment 14 Richard Sharpe 2012-11-09 14:44:29 UTC
(In reply to comment #11)
> (In reply to comment #9)
> > For reasons I can not understand, bugzilla does not present me with any review
> > button or check box I can review.
> 
> the question is why you created a second bugzilla account. Your previous and
> still existing account has the rights to do that.

Probably because I forgot about the previous account, or could not remember the password.