]> git.eshelyaron.com Git - emacs.git/commitdiff
process.c: Use socklen_t, not int, for socket lengths.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 18 Mar 2011 03:30:24 +0000 (20:30 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 18 Mar 2011 03:30:24 +0000 (20:30 -0700)
12 files changed:
ChangeLog
Makefile.in
aclocal.m4
configure
configure.in
lib/Makefile.in
lib/gnulib.mk
m4/gl-comp.m4
m4/socklen.m4 [new file with mode: 0644]
src/ChangeLog
src/config.in
src/process.c

index fdde50669b5def138191c03915ba2fda02dbc58c..8928b2aceeb37ac24e02cf1ed849f66d7eb129cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-03-17  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * Makefile.in (GNULIB_MODULES): Add socklen.
+       * configure.in: Do not check for sys/socket.h, since socklen does that.
+       * m4/socklen.m4: New automatically-generated file, from gnulib.
+
 2011-03-13  Paul Eggert  <eggert@cs.ucla.edu>
 
        Update for gnulib.
index 19267f821219ae175a801fd3cab79faa4bbe8503..bc8ae5a958952e7cbcc9a76d7717c3bd107fe02e 100644 (file)
@@ -332,7 +332,7 @@ DOS_gnulib_comp.m4 = gl-comp.m4
 # as per $(gnulib_srcdir)/DEPENDENCIES.
 GNULIB_MODULES = \
   crypto/md5 dtoastr filemode getloadavg getopt-gnu \
-  ignore-value intprops lstat mktime readlink strftime symlink sys_stat
+  ignore-value intprops lstat mktime readlink socklen strftime symlink sys_stat
 GNULIB_TOOL_FLAGS = \
  --import --no-changelog --no-vc-files --makefile-name=gnulib.mk
 sync-from-gnulib: $(gnulib_srcdir)
index 1536f3b48b5a202122bfb6d727bcc51d280b5945..9bd85a88bbead08242b340dfaf708caad16c0305 100644 (file)
@@ -999,6 +999,7 @@ m4_include([m4/md5.m4])
 m4_include([m4/mktime.m4])
 m4_include([m4/multiarch.m4])
 m4_include([m4/readlink.m4])
+m4_include([m4/socklen.m4])
 m4_include([m4/st_dm_mode.m4])
 m4_include([m4/stat.m4])
 m4_include([m4/stdbool.m4])
index 57ecd9d52eb171fbffef96250faba0b9e6ee8150..eed1c70599e716156dda0c023ebf0b792b0f597d 100755 (executable)
--- a/configure
+++ b/configure
@@ -2960,6 +2960,7 @@ as_fn_append ac_header_list " getopt.h"
 as_fn_append ac_func_list " lstat"
 as_fn_append ac_func_list " alarm"
 as_fn_append ac_func_list " readlink"
+as_fn_append ac_header_list " sys/socket.h"
 as_fn_append ac_header_list " wchar.h"
 as_fn_append ac_header_list " stdint.h"
 as_fn_append ac_func_list " tzset"
@@ -6141,6 +6142,7 @@ $as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
   # Code from module mktime:
   # Code from module multiarch:
   # Code from module readlink:
+  # Code from module socklen:
   # Code from module stat:
   # Code from module stdbool:
   # Code from module stddef:
@@ -7966,18 +7968,6 @@ $as_echo "#define NO_MATHERR 1" >>confdefs.h
 
 fi
 
-for ac_header in sys/socket.h
-do :
-  ac_fn_c_check_header_mongrel "$LINENO" "sys/socket.h" "ac_cv_header_sys_socket_h" "$ac_includes_default"
-if test "x$ac_cv_header_sys_socket_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_SYS_SOCKET_H 1
-_ACEOF
-
-fi
-
-done
-
 for ac_header in net/if.h
 do :
   ac_fn_c_check_header_compile "$LINENO" "net/if.h" "ac_cv_header_net_if_h" "$ac_includes_default
@@ -14784,6 +14774,10 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 
 
+
+
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdbool.h that conforms to C99" >&5
 $as_echo_n "checking for stdbool.h that conforms to C99... " >&6; }
 if ${ac_cv_header_stdbool_h+:} false; then :
@@ -16356,6 +16350,63 @@ $as_echo "#define READLINK_TRAILING_SLASH_BUG 1" >>confdefs.h
 
 
 
+  # Code from module socklen:
+     ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "#include <sys/types.h>
+      #if HAVE_SYS_SOCKET_H
+      # include <sys/socket.h>
+      #endif
+"
+if test "x$ac_cv_type_socklen_t" = xyes; then :
+
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socklen_t equivalent" >&5
+$as_echo_n "checking for socklen_t equivalent... " >&6; }
+      if ${gl_cv_socklen_t_equiv+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  # Systems have either "struct sockaddr *" or
+         # "void *" as the second argument to getpeername
+         gl_cv_socklen_t_equiv=
+         for arg2 in "struct sockaddr" void; do
+           for t in int size_t "unsigned int" "long int" "unsigned long int"; do
+             cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+                   #include <sys/socket.h>
+
+                   int getpeername (int, $arg2 *, $t *);
+int
+main ()
+{
+$t len;
+                  getpeername (0, 0, &len);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_socklen_t_equiv="$t"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+             test "$gl_cv_socklen_t_equiv" != "" && break
+           done
+           test "$gl_cv_socklen_t_equiv" != "" && break
+         done
+
+fi
+
+      if test "$gl_cv_socklen_t_equiv" = ""; then
+        as_fn_error $? "Cannot find a type to use in place of socklen_t" "$LINENO" 5
+      fi
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_socklen_t_equiv" >&5
+$as_echo "$gl_cv_socklen_t_equiv" >&6; }
+
+cat >>confdefs.h <<_ACEOF
+#define socklen_t $gl_cv_socklen_t_equiv
+_ACEOF
+
+fi
+
   # Code from module stat:
 
 
index 086a7e12d67b8e303785a24d7310019e13dc607e..11b7ad4db05bdd896ca333b9d5504e6849a00320 100644 (file)
@@ -1265,7 +1265,6 @@ if test $emacs_cv_struct_exception != yes; then
   AC_DEFINE(NO_MATHERR, 1, [Define to 1 if you don't have struct exception in math.h.])
 fi
 
-AC_CHECK_HEADERS(sys/socket.h)
 AC_CHECK_HEADERS(net/if.h, , , [AC_INCLUDES_DEFAULT
 #if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
index 502b3dbb92757b622c611601bd431be3cbb4f4f4..8be57520014cf8695b2c999cd6d57135db5418c2 100644 (file)
@@ -24,7 +24,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink strftime symlink sys_stat
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink socklen strftime symlink sys_stat
 
 VPATH = @srcdir@
 pkgdatadir = $(datadir)/@PACKAGE@
@@ -57,14 +57,15 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \
        $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/longlong.m4 \
        $(top_srcdir)/m4/lstat.m4 $(top_srcdir)/m4/md5.m4 \
        $(top_srcdir)/m4/mktime.m4 $(top_srcdir)/m4/multiarch.m4 \
-       $(top_srcdir)/m4/readlink.m4 $(top_srcdir)/m4/st_dm_mode.m4 \
-       $(top_srcdir)/m4/stat.m4 $(top_srcdir)/m4/stdbool.m4 \
-       $(top_srcdir)/m4/stddef_h.m4 $(top_srcdir)/m4/stdint.m4 \
-       $(top_srcdir)/m4/stdlib_h.m4 $(top_srcdir)/m4/strftime.m4 \
-       $(top_srcdir)/m4/symlink.m4 $(top_srcdir)/m4/sys_stat_h.m4 \
-       $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \
-       $(top_srcdir)/m4/tm_gmtoff.m4 $(top_srcdir)/m4/unistd_h.m4 \
-       $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/configure.in
+       $(top_srcdir)/m4/readlink.m4 $(top_srcdir)/m4/socklen.m4 \
+       $(top_srcdir)/m4/st_dm_mode.m4 $(top_srcdir)/m4/stat.m4 \
+       $(top_srcdir)/m4/stdbool.m4 $(top_srcdir)/m4/stddef_h.m4 \
+       $(top_srcdir)/m4/stdint.m4 $(top_srcdir)/m4/stdlib_h.m4 \
+       $(top_srcdir)/m4/strftime.m4 $(top_srcdir)/m4/symlink.m4 \
+       $(top_srcdir)/m4/sys_stat_h.m4 $(top_srcdir)/m4/time_h.m4 \
+       $(top_srcdir)/m4/time_r.m4 $(top_srcdir)/m4/tm_gmtoff.m4 \
+       $(top_srcdir)/m4/unistd_h.m4 $(top_srcdir)/m4/wchar_t.m4 \
+       $(top_srcdir)/configure.in
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
index cd6a1d00c15164feff311c2f0a8bcc3cd7f745c7..369b7a48732bfda9356f30ad009c1cbcea02cef7 100644 (file)
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink strftime symlink sys_stat
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files crypto/md5 dtoastr filemode getloadavg getopt-gnu ignore-value intprops lstat mktime readlink socklen strftime symlink sys_stat
 
 
 MOSTLYCLEANFILES += core *.stackdump
index 8bf5a64a5f98126d8f7a3f0822bf78ff1eec59e4..7f8b5a790701dd704082d395338af0e86db199b3 100644 (file)
@@ -45,6 +45,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module mktime:
   # Code from module multiarch:
   # Code from module readlink:
+  # Code from module socklen:
   # Code from module stat:
   # Code from module stdbool:
   # Code from module stddef:
@@ -111,6 +112,8 @@ AC_DEFUN([gl_INIT],
   # Code from module readlink:
   gl_FUNC_READLINK
   gl_UNISTD_MODULE_INDICATOR([readlink])
+  # Code from module socklen:
+  gl_TYPE_SOCKLEN_T
   # Code from module stat:
   gl_FUNC_STAT
   gl_SYS_STAT_MODULE_INDICATOR([stat])
@@ -327,6 +330,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/mktime.m4
   m4/multiarch.m4
   m4/readlink.m4
+  m4/socklen.m4
   m4/st_dm_mode.m4
   m4/stat.m4
   m4/stdbool.m4
diff --git a/m4/socklen.m4 b/m4/socklen.m4
new file mode 100644 (file)
index 0000000..28dcf07
--- /dev/null
@@ -0,0 +1,65 @@
+# socklen.m4 serial 9
+dnl Copyright (C) 2005-2007, 2009-2011 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.
+
+dnl From Albert Chin, Windows fixes from Simon Josefsson.
+
+dnl Check for socklen_t: historically on BSD it is an int, and in
+dnl POSIX 1g it is a type of its own, but some platforms use different
+dnl types for the argument to getsockopt, getpeername, etc.:
+dnl HP-UX 10.20, IRIX 6.5, Interix 3.5, BeOS.
+dnl So we have to test to find something that will work.
+
+dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
+dnl it there first.  That file is included by gnulib's sys_socket.in.h, which
+dnl all users of this module should include if they want to be portable to
+dnl mingw32.  Cygwin must not include ws2tcpip.h.
+AC_DEFUN([gl_TYPE_SOCKLEN_T],
+  [AC_REQUIRE([gl_PREREQ_TYPE_SOCKLEN_T])dnl
+   AC_CHECK_TYPE([socklen_t], ,
+     [AC_MSG_CHECKING([for socklen_t equivalent])
+      AC_CACHE_VAL([gl_cv_socklen_t_equiv],
+        [# Systems have either "struct sockaddr *" or
+         # "void *" as the second argument to getpeername
+         gl_cv_socklen_t_equiv=
+         for arg2 in "struct sockaddr" void; do
+           for t in int size_t "unsigned int" "long int" "unsigned long int"; do
+             AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+                 [[#include <sys/types.h>
+                   #include <sys/socket.h>
+
+                   int getpeername (int, $arg2 *, $t *);]],
+                 [[$t len;
+                  getpeername (0, 0, &len);]])],
+               [gl_cv_socklen_t_equiv="$t"])
+             test "$gl_cv_socklen_t_equiv" != "" && break
+           done
+           test "$gl_cv_socklen_t_equiv" != "" && break
+         done
+      ])
+      if test "$gl_cv_socklen_t_equiv" = ""; then
+        AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
+      fi
+      AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
+      AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
+        [type to use in place of socklen_t if not defined])],
+     [#include <sys/types.h>
+      #if HAVE_SYS_SOCKET_H
+      # include <sys/socket.h>
+      ]m4_ifdef([gl_SYS_SOCKET_H_DEFAULTS],
+         [#elif HAVE_WS2TCPIP_H
+          # include <ws2tcpip.h>]
+      )[#endif])])
+
+AC_DEFUN([gl_PREREQ_TYPE_SOCKLEN_T],
+  [AC_CHECK_HEADERS_ONCE([sys/socket.h])
+   m4_ifdef([gl_SYS_SOCKET_H_DEFAULTS],
+     [if test $ac_cv_header_sys_socket_h = no; then
+        dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
+        dnl the check for those headers unconditional; yet cygwin reports
+        dnl that the headers are present but cannot be compiled (since on
+        dnl cygwin, all socket information should come from sys/socket.h).
+        AC_CHECK_HEADERS([ws2tcpip.h])
+      fi])])
index d97969c24dbd26b18879f83062ef1a0ace3261fb..6eaa52ee28595f15ffd75441643500c95f9ef2de 100644 (file)
@@ -1,3 +1,13 @@
+2011-03-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * process.c (Fmake_network_process): Use socklen_t, not int,
+       where POSIX says socklen_t is required in portable programs.
+       This fixes a porting bug on hosts like 64-bit HP-UX, where
+       socklen_t is wider than int.
+       (Fmake_network_process, server_accept_connection):
+       (wait_reading_process_output, read_process_output):
+       Likewise.
+
 2011-03-17  Paul Eggert  <eggert@cs.ucla.edu>
 
        Fix more problems found by GCC 4.5.2's static checks.
index fbd3ee9338d8b9b5bc44b0109b07120a5842f6e6..8b7312faaaab9d235727240d830126f7ec3519a3 100644 (file)
@@ -1209,6 +1209,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Define to `unsigned int' if <sys/types.h> does not define. */
 #undef size_t
 
+/* type to use in place of socklen_t if not defined */
+#undef socklen_t
+
 /* Define to any substitute for sys_siglist. */
 #undef sys_siglist
 
index c9b420ab2ae67ddd0d44637a3b42910851573cb1..5a410c1e924306b5757308e07bb0ad56f1ef0c0c 100644 (file)
@@ -3467,7 +3467,7 @@ usage: (make-network-process &rest ARGS)  */)
          if (EQ (service, Qt))
            {
              struct sockaddr_in sa1;
-             int len1 = sizeof (sa1);
+             socklen_t len1 = sizeof (sa1);
              if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
                {
                  ((struct sockaddr_in *)(lres->ai_addr))->sin_port = sa1.sin_port;
@@ -3514,7 +3514,8 @@ usage: (make-network-process &rest ARGS)  */)
          /* Unlike most other syscalls connect() cannot be called
             again.  (That would return EALREADY.)  The proper way to
             wait for completion is select(). */
-         int sc, len;
+         int sc;
+         socklen_t len;
          SELECT_TYPE fdset;
        retry_select:
          FD_ZERO (&fdset);
@@ -3587,7 +3588,7 @@ usage: (make-network-process &rest ARGS)  */)
       if (!is_server)
        {
          struct sockaddr_in sa1;
-         int len1 = sizeof (sa1);
+         socklen_t len1 = sizeof (sa1);
          if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
            contact = Fplist_put (contact, QClocal,
                                  conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
@@ -4192,7 +4193,7 @@ server_accept_connection (Lisp_Object server, int channel)
     struct sockaddr_un un;
 #endif
   } saddr;
-  int len = sizeof saddr;
+  socklen_t len = sizeof saddr;
 
   s = accept (channel, &saddr.sa, &len);
 
@@ -5059,7 +5060,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
              /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
                 So only use it on systems where it is known to work.  */
              {
-               int xlen = sizeof (xerrno);
+               socklen_t xlen = sizeof (xerrno);
                if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen))
                  xerrno = errno;
              }
@@ -5171,7 +5172,7 @@ read_process_output (Lisp_Object proc, register int channel)
   /* We have a working select, so proc_buffered_char is always -1.  */
   if (DATAGRAM_CHAN_P (channel))
     {
-      int len = datagram_address[channel].len;
+      socklen_t len = datagram_address[channel].len;
       nbytes = recvfrom (channel, chars + carryover, readmax,
                         0, datagram_address[channel].sa, &len);
     }