From: Paul Eggert Date: Fri, 18 Mar 2011 03:30:24 +0000 (-0700) Subject: process.c: Use socklen_t, not int, for socket lengths. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~513^2~24^2~2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=401bf9b4708c19d3c86c888ce482014ca559a5b8;p=emacs.git process.c: Use socklen_t, not int, for socket lengths. --- diff --git a/ChangeLog b/ChangeLog index fdde50669b5..8928b2aceeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-17 Paul Eggert + + * 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 Update for gnulib. diff --git a/Makefile.in b/Makefile.in index 19267f82121..bc8ae5a9589 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/aclocal.m4 b/aclocal.m4 index 1536f3b48b5..9bd85a88bbe 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -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]) diff --git a/configure b/configure index 57ecd9d52eb..eed1c70599e 100755 --- 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 + #if HAVE_SYS_SOCKET_H + # include + #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 + #include + + 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: diff --git a/configure.in b/configure.in index 086a7e12d67..11b7ad4db05 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/lib/Makefile.in b/lib/Makefile.in index 502b3dbb927..8be57520014 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -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 diff --git a/lib/gnulib.mk b/lib/gnulib.mk index cd6a1d00c15..369b7a48732 100644 --- a/lib/gnulib.mk +++ b/lib/gnulib.mk @@ -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 diff --git a/m4/gl-comp.m4 b/m4/gl-comp.m4 index 8bf5a64a5f9..7f8b5a79070 100644 --- a/m4/gl-comp.m4 +++ b/m4/gl-comp.m4 @@ -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 index 00000000000..28dcf070463 --- /dev/null +++ b/m4/socklen.m4 @@ -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 + #include + + 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 + #if HAVE_SYS_SOCKET_H + # include + ]m4_ifdef([gl_SYS_SOCKET_H_DEFAULTS], + [#elif HAVE_WS2TCPIP_H + # include ] + )[#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])]) diff --git a/src/ChangeLog b/src/ChangeLog index d97969c24db..6eaa52ee285 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2011-03-18 Paul Eggert + + * 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 Fix more problems found by GCC 4.5.2's static checks. diff --git a/src/config.in b/src/config.in index fbd3ee9338d..8b7312faaaa 100644 --- a/src/config.in +++ b/src/config.in @@ -1209,6 +1209,9 @@ along with GNU Emacs. If not, see . */ /* Define to `unsigned int' if 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 diff --git a/src/process.c b/src/process.c index c9b420ab2ae..5a410c1e924 100644 --- a/src/process.c +++ b/src/process.c @@ -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); }