Paolo Bonzini wrote: > No, gethostname does not require sockets &c, it just requires sys/socket.h.
And gethostname() does not open user-visible sockets. > IIRC, something like this: > > diff --git a/lib/unistd.in.h b/lib/unistd.in.h > index 93edb48..733c8b6 100644 > --- a/lib/unistd.in.h > +++ b/lib/unistd.in.h > @@ -137,7 +137,7 @@ > # define close rpl_close > extern int close (int); > # endif > -#elif @UNISTD_H_HAVE_WINSOCK2_H@ > +#elif @UNISTD_H_HAVE_WINSOCK2_H@ &&(@GNULIB_SOCKET@ || @GNULIB_ACCEPT@) > # undef close > # define close close_used_without_requesting_gnulib_module_close > #elif defined GNULIB_POSIXCHECK > > was not considered safe (?), but I would like to have something like > this indeed. The 'accept' function does not need to be used as a trigger, since it turns an already open socket into a usable socket. Only the 'socket' function is the trigger. I'm applying these two patches. The first one adds a comment about why close() deals with sockets even when the gnulib module 'socket' is not used. The second one should fix Sam's problem. 2009-08-10 Bruno Haible <br...@clisp.org> * m4/close.m4 (gl_FUNC_CLOSE): Add comment. * modules/ioctl (configure.ac): Likewise. --- m4/close.m4.orig 2009-08-10 22:52:34.000000000 +0200 +++ m4/close.m4 2009-08-10 22:50:45.000000000 +0200 @@ -1,4 +1,4 @@ -# close.m4 serial 3 +# close.m4 serial 4 dnl Copyright (C) 2008-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,6 +9,9 @@ m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [ gl_PREREQ_SYS_H_WINSOCK2 if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then + dnl Even if the 'socket' module is not used here, another part of the + dnl application may use it and pass file descriptors that refer to + dnl sockets to the close() function. So enable the support for sockets. gl_REPLACE_CLOSE fi ]) --- modules/ioctl.orig 2009-08-10 22:52:34.000000000 +0200 +++ modules/ioctl 2009-08-10 22:50:34.000000000 +0200 @@ -13,6 +13,9 @@ configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) if test "$ac_cv_header_winsock2_h" = yes; then + dnl Even if the 'socket' module is not used here, another part of the + dnl application may use it and pass file descriptors that refer to + dnl sockets to the ioctl() function. So enable the support for sockets. AC_LIBOBJ([ioctl]) gl_REPLACE_SYS_IOCTL_H fi 2009-08-10 Bruno Haible <br...@clisp.org> Make it possible to use module 'gethostname' without module 'close'. * lib/unistd.in.h (close): Evoke a link error only if UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS is set. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS. * modules/unistd (Makefile.am): Substitute UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS. * lib/sys_ioctl.in.h (ioctl): Evoke a link error only if SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS is set. * m4/sys_ioctl_h.m4 (gl_SYS_IOCTL_H_DEFAULTS): Initialize SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS. * modules/sys_ioctl (Makefile.am): Substitute SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS. * modules/socket (configure.ac): On native Windows, set UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS and SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS. Reported by Sam Steingold <s...@gnu.org>. --- lib/sys_ioctl.in.h.orig 2009-08-10 22:54:30.000000000 +0200 +++ lib/sys_ioctl.in.h 2009-08-10 22:29:27.000000000 +0200 @@ -1,5 +1,5 @@ /* Substitute for and wrapper around <sys/ioctl.h>. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,7 +49,7 @@ # define ioctl rpl_ioctl extern int ioctl (int fd, int request, ... /* {void *,char *} arg */); # endif -#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H@ +#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ # undef ioctl # define ioctl ioctl_used_without_requesting_gnulib_module_ioctl #elif defined GNULIB_POSIXCHECK --- lib/unistd.in.h.orig 2009-08-10 22:54:30.000000000 +0200 +++ lib/unistd.in.h 2009-08-10 22:24:30.000000000 +0200 @@ -137,7 +137,7 @@ # define close rpl_close extern int close (int); # endif -#elif @UNISTD_H_HAVE_WINSOCK2_H@ +#elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ # undef close # define close close_used_without_requesting_gnulib_module_close #elif defined GNULIB_POSIXCHECK --- m4/sys_ioctl_h.m4.orig 2009-08-10 22:54:30.000000000 +0200 +++ m4/sys_ioctl_h.m4 2009-08-10 22:40:43.000000000 +0200 @@ -1,5 +1,5 @@ -# sys_ioctl_h.m4 serial 2 -dnl Copyright (C) 2008 Free Software Foundation, Inc. +# sys_ioctl_h.m4 serial 3 +dnl Copyright (C) 2008-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -59,5 +59,7 @@ GNULIB_IOCTL=0; AC_SUBST([GNULIB_IOCTL]) dnl Assume proper GNU behavior unless another module says otherwise. SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H]) + SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0; + AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS]) SYS_IOCTL_H=''; AC_SUBST([SYS_IOCTL_H]) ]) --- m4/unistd_h.m4.orig 2009-08-10 22:54:30.000000000 +0200 +++ m4/unistd_h.m4 2009-08-10 22:25:22.000000000 +0200 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 18 +# unistd_h.m4 serial 19 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -81,4 +81,6 @@ REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE]) UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H]) + UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0; + AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS]) ]) --- modules/socket.orig 2009-08-10 22:54:30.000000000 +0200 +++ modules/socket 2009-08-10 22:35:05.000000000 +0200 @@ -15,6 +15,15 @@ if test "$ac_cv_header_winsock2_h" = yes; then AC_LIBOBJ([socket]) fi +# When this module is used, sockets may actually occur as file descriptors, +# hence it is worth warning if the modules 'close' and 'ioctl' are not used. +m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])]) +m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])]) +AC_REQUIRE([gl_PREREQ_SYS_H_WINSOCK2]) +if test "$ac_cv_header_winsock2_h" = yes; then + UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1 + SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1 +fi gl_SYS_SOCKET_MODULE_INDICATOR([socket]) Makefile.am: --- modules/sys_ioctl.orig 2009-08-10 22:54:30.000000000 +0200 +++ modules/sys_ioctl 2009-08-10 22:39:49.000000000 +0200 @@ -29,6 +29,7 @@ -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \ -e 's|@''GNULIB_IOCTL''@|$(GNULIB_IOCTL)|g' \ -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \ + -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/sys_ioctl.in.h; \ } > $...@-t --- modules/unistd.orig 2009-08-10 22:54:30.000000000 +0200 +++ modules/unistd 2009-08-10 22:25:46.000000000 +0200 @@ -72,6 +72,7 @@ -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ + -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/unistd.in.h; \ } > $...@-t