public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] gnulib: import chown
@ 2021-05-29 17:25 Mike Frysinger
  2021-05-29 17:25 ` [PATCH 2/4] sim: v850: assume chown is available Mike Frysinger
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Mike Frysinger @ 2021-05-29 17:25 UTC (permalink / raw)
  To: gdb-patches

A few sims use this to emulate chown syscalls.
---
 gnulib/Makefile.in               |   1 +
 gnulib/aclocal.m4                |   1 +
 gnulib/config.in                 |  22 ++
 gnulib/configure                 | 482 ++++++++++++++++++++++++++-----
 gnulib/import/Makefile.am        |  10 +
 gnulib/import/Makefile.in        |  31 +-
 gnulib/import/chown.c            | 151 ++++++++++
 gnulib/import/fchown-stub.c      |  34 +++
 gnulib/import/m4/chown.m4        | 218 ++++++++++++++
 gnulib/import/m4/gnulib-cache.m4 |   2 +
 gnulib/import/m4/gnulib-comp.m4  |  12 +
 gnulib/update-gnulib.sh          |   1 +
 12 files changed, 884 insertions(+), 81 deletions(-)
 create mode 100644 gnulib/import/chown.c
 create mode 100644 gnulib/import/fchown-stub.c
 create mode 100644 gnulib/import/m4/chown.m4

diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in
index 4c46e0a99e72..04dc454701e1 100644
--- a/gnulib/Makefile.in
+++ b/gnulib/Makefile.in
@@ -121,6 +121,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
 	$(top_srcdir)/import/m4/chdir-long.m4 \
+	$(top_srcdir)/import/m4/chown.m4 \
 	$(top_srcdir)/import/m4/clock_time.m4 \
 	$(top_srcdir)/import/m4/close.m4 \
 	$(top_srcdir)/import/m4/closedir.m4 \
diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4
index 00a0c9c0d95f..d466a2666cac 100644
--- a/gnulib/aclocal.m4
+++ b/gnulib/aclocal.m4
@@ -1193,6 +1193,7 @@ m4_include([import/m4/btowc.m4])
 m4_include([import/m4/builtin-expect.m4])
 m4_include([import/m4/canonicalize.m4])
 m4_include([import/m4/chdir-long.m4])
+m4_include([import/m4/chown.m4])
 m4_include([import/m4/clock_time.m4])
 m4_include([import/m4/close.m4])
 m4_include([import/m4/closedir.m4])
diff --git a/gnulib/config.in b/gnulib/config.in
index e3f581423f9f..15abb17cb445 100644
--- a/gnulib/config.in
+++ b/gnulib/config.in
@@ -18,6 +18,19 @@
 /* Define to the number of bits in type 'wint_t'. */
 #undef BITSIZEOF_WINT_T
 
+/* Define to 1 if chown fails to change ctime when at least one argument was
+   not -1. */
+#undef CHOWN_CHANGE_TIME_BUG
+
+/* Define if chown is not POSIX compliant regarding IDs of -1. */
+#undef CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE
+
+/* Define if chown modifies symlinks. */
+#undef CHOWN_MODIFIES_SYMLINK
+
+/* Define to 1 if chown mishandles trailing slash. */
+#undef CHOWN_TRAILING_SLASH_BUG
+
 /* Define to 1 if using 'alloca.c'. */
 #undef C_ALLOCA
 
@@ -140,6 +153,9 @@
 /* Define to 1 when the gnulib module chdir should be tested. */
 #undef GNULIB_TEST_CHDIR
 
+/* Define to 1 when the gnulib module chown should be tested. */
+#undef GNULIB_TEST_CHOWN
+
 /* Define to 1 when the gnulib module cloexec should be tested. */
 #undef GNULIB_TEST_CLOEXEC
 
@@ -355,6 +371,9 @@
 /* Define to 1 if you have the `catgets' function. */
 #undef HAVE_CATGETS
 
+/* Define to 1 if you have the `chown' function. */
+#undef HAVE_CHOWN
+
 /* Define to 1 if you have the `clock_gettime' function. */
 #undef HAVE_CLOCK_GETTIME
 
@@ -521,6 +540,9 @@
 /* Define to 1 if you have the `fchdir' function. */
 #undef HAVE_FCHDIR
 
+/* Define to 1 if you have the `fchown' function. */
+#undef HAVE_FCHOWN
+
 /* Define to 1 if you have the `fcntl' function. */
 #undef HAVE_FCNTL
 
diff --git a/gnulib/configure b/gnulib/configure
index 2ddb1d7cbb07..827393a6d254 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -3725,6 +3725,8 @@ as_fn_append ac_func_list " faccessat"
 as_fn_append ac_func_list " realpath"
 as_fn_append ac_header_list " sys/param.h"
 as_fn_append ac_header_list " unistd.h"
+as_fn_append ac_func_list " chown"
+as_fn_append ac_func_list " fchown"
 as_fn_append ac_func_list " _set_invalid_parameter_handler"
 as_fn_append ac_func_list " fchdir"
 as_fn_append ac_header_list " dirent.h"
@@ -6685,6 +6687,7 @@ fi
   # Code from module canonicalize-lgpl:
   # Code from module chdir:
   # Code from module chdir-long:
+  # Code from module chown:
   # Code from module clock-time:
   # Code from module cloexec:
   # Code from module close:
@@ -8281,50 +8284,35 @@ done
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5
+$as_echo_n "checking for uid_t in sys/types.h... " >&6; }
+if ${ac_cv_type_uid_t+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
 
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "uid_t" >/dev/null 2>&1; then :
+  ac_cv_type_uid_t=yes
+else
+  ac_cv_type_uid_t=no
+fi
+rm -f conftest*
 
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
+$as_echo "$ac_cv_type_uid_t" >&6; }
+if test $ac_cv_type_uid_t = no; then
 
+$as_echo "#define uid_t int" >>confdefs.h
 
-  if test $ac_cv_func__set_invalid_parameter_handler = yes; then
-    HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
-
-$as_echo "#define HAVE_MSVC_INVALID_PARAMETER_HANDLER 1" >>confdefs.h
-
-  else
-    HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
-  fi
-
-
-
-
-
-     GNULIB_OPENDIR=0;
-  GNULIB_READDIR=0;
-  GNULIB_REWINDDIR=0;
-  GNULIB_CLOSEDIR=0;
-  GNULIB_DIRFD=0;
-  GNULIB_FDOPENDIR=0;
-  GNULIB_SCANDIR=0;
-  GNULIB_ALPHASORT=0;
-    HAVE_OPENDIR=1;
-  HAVE_READDIR=1;
-  HAVE_REWINDDIR=1;
-  HAVE_CLOSEDIR=1;
-  HAVE_DECL_DIRFD=1;
-  HAVE_DECL_FDOPENDIR=1;
-  HAVE_FDOPENDIR=1;
-  HAVE_SCANDIR=1;
-  HAVE_ALPHASORT=1;
-  REPLACE_OPENDIR=0;
-  REPLACE_CLOSEDIR=0;
-  REPLACE_DIRFD=0;
-  REPLACE_FDOPENDIR=0;
-
-
-  GNULIB_ISBLANK=0;
-    HAVE_ISBLANK=1;
 
+$as_echo "#define gid_t int" >>confdefs.h
 
+fi
 
 gl_mda_defines='
 #if defined _WIN32 && !defined __CYGWIN__
@@ -8382,6 +8370,354 @@ gl_mda_defines='
 '
 
 
+      for ac_header in unistd.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default"
+if test "x$ac_cv_header_unistd_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_UNISTD_H 1
+_ACEOF
+
+fi
+
+done
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working chown" >&5
+$as_echo_n "checking for working chown... " >&6; }
+if ${ac_cv_func_chown_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  case "$host_os" in # ((
+                           # Guess yes on Linux systems.
+          linux-* | linux) ac_cv_func_chown_works="guessing yes" ;;
+                           # Guess yes on glibc systems.
+          *-gnu* | gnu*)   ac_cv_func_chown_works="guessing yes" ;;
+                           # Guess no on native Windows.
+          mingw*)          ac_cv_func_chown_works="guessing no" ;;
+                           # If we don't know, obey --enable-cross-guesses.
+          *)               ac_cv_func_chown_works="$gl_cross_guess_normal" ;;
+        esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+           #include <fcntl.h>
+
+
+$gl_mda_defines
+
+int
+main ()
+{
+
+            char *f = "conftest.chown";
+            struct stat before, after;
+
+            if (creat (f, 0600) < 0)
+              return 1;
+            if (stat (f, &before) < 0)
+              return 1;
+            if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
+              return 1;
+            if (stat (f, &after) < 0)
+              return 1;
+            return ! (before.st_uid == after.st_uid && before.st_gid == after.st_gid);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_func_chown_works=yes
+else
+  ac_cv_func_chown_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+     rm -f conftest.chown
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_chown_works" >&5
+$as_echo "$ac_cv_func_chown_works" >&6; }
+  case "$ac_cv_func_chown_works" in
+    *yes)
+
+$as_echo "#define HAVE_CHOWN 1" >>confdefs.h
+
+      ;;
+  esac
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether chown dereferences symlinks" >&5
+$as_echo_n "checking whether chown dereferences symlinks... " >&6; }
+if ${gl_cv_func_chown_follows_symlink+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+      if test "$cross_compiling" = yes; then :
+  gl_cv_func_chown_follows_symlink="guessing yes"
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+
+$gl_mda_defines
+
+        int
+        main ()
+        {
+          int result = 0;
+          char const *dangling_symlink = "conftest.dangle";
+
+          unlink (dangling_symlink);
+          if (symlink ("conftest.no-such", dangling_symlink))
+            abort ();
+
+          /* Exit successfully on a conforming system,
+             i.e., where chown must fail with ENOENT.  */
+          if (chown (dangling_symlink, getuid (), getgid ()) == 0)
+            result |= 1;
+          if (errno != ENOENT)
+            result |= 2;
+          return result;
+        }
+
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_chown_follows_symlink=yes
+else
+  gl_cv_func_chown_follows_symlink=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_chown_follows_symlink" >&5
+$as_echo "$gl_cv_func_chown_follows_symlink" >&6; }
+
+  case "$gl_cv_func_chown_follows_symlink" in
+    *yes) ;;
+    *)
+
+$as_echo "#define CHOWN_MODIFIES_SYMLINK 1" >>confdefs.h
+
+      ;;
+  esac
+
+
+
+
+
+
+
+
+
+
+
+
+    if test $ac_cv_func_chown = no; then
+    HAVE_CHOWN=0
+  else
+        case "$gl_cv_func_chown_follows_symlink" in
+      *yes) ;;
+      *) REPLACE_CHOWN=1 ;;
+    esac
+
+        case "$ac_cv_func_chown_works" in
+      *no)
+
+$as_echo "#define CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE 1" >>confdefs.h
+
+        REPLACE_CHOWN=1
+        ;;
+    esac
+
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether chown honors trailing slash" >&5
+$as_echo_n "checking whether chown honors trailing slash... " >&6; }
+if ${gl_cv_func_chown_slash_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  touch conftest.file && rm -f conftest.link
+       if test "$cross_compiling" = yes; then :
+  case "$host_os" in
+                    # Guess yes on glibc systems.
+           *-gnu*)  gl_cv_func_chown_slash_works="guessing yes" ;;
+                    # Guess yes on musl systems.
+           *-musl*) gl_cv_func_chown_slash_works="guessing yes" ;;
+                    # If we don't know, obey --enable-cross-guesses.
+           *)       gl_cv_func_chown_slash_works="$gl_cross_guess_normal" ;;
+         esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+
+$gl_mda_defines
+
+int
+main ()
+{
+if (symlink ("conftest.file", "conftest.link")) return 1;
+          if (chown ("conftest.link/", getuid (), getgid ()) == 0) return 2;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_chown_slash_works=yes
+else
+  gl_cv_func_chown_slash_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+      rm -f conftest.link conftest.file
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_chown_slash_works" >&5
+$as_echo "$gl_cv_func_chown_slash_works" >&6; }
+    case "$gl_cv_func_chown_slash_works" in
+      *yes) ;;
+      *)
+
+$as_echo "#define CHOWN_TRAILING_SLASH_BUG 1" >>confdefs.h
+
+        REPLACE_CHOWN=1
+        ;;
+    esac
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether chown always updates ctime" >&5
+$as_echo_n "checking whether chown always updates ctime... " >&6; }
+if ${gl_cv_func_chown_ctime_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "$cross_compiling" = yes; then :
+  case "$host_os" in
+                    # Guess yes on glibc systems.
+           *-gnu*)  gl_cv_func_chown_ctime_works="guessing yes" ;;
+                    # Guess yes on musl systems.
+           *-musl*) gl_cv_func_chown_ctime_works="guessing yes" ;;
+                    # If we don't know, obey --enable-cross-guesses.
+           *)       gl_cv_func_chown_ctime_works="$gl_cross_guess_normal" ;;
+         esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+
+$gl_mda_defines
+
+int
+main ()
+{
+struct stat st1, st2;
+          if (close (creat ("conftest.file", 0600))) return 1;
+          if (stat ("conftest.file", &st1)) return 2;
+          sleep (1);
+          if (chown ("conftest.file", st1.st_uid, st1.st_gid)) return 3;
+          if (stat ("conftest.file", &st2)) return 4;
+          if (st2.st_ctime <= st1.st_ctime) return 5;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_chown_ctime_works=yes
+else
+  gl_cv_func_chown_ctime_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+      rm -f conftest.file
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_chown_ctime_works" >&5
+$as_echo "$gl_cv_func_chown_ctime_works" >&6; }
+    case "$gl_cv_func_chown_ctime_works" in
+      *yes) ;;
+      *)
+
+$as_echo "#define CHOWN_CHANGE_TIME_BUG 1" >>confdefs.h
+
+        REPLACE_CHOWN=1
+        ;;
+    esac
+  fi
+
+
+
+
+
+  if test $ac_cv_func__set_invalid_parameter_handler = yes; then
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=1
+
+$as_echo "#define HAVE_MSVC_INVALID_PARAMETER_HANDLER 1" >>confdefs.h
+
+  else
+    HAVE_MSVC_INVALID_PARAMETER_HANDLER=0
+  fi
+
+
+
+
+
+     GNULIB_OPENDIR=0;
+  GNULIB_READDIR=0;
+  GNULIB_REWINDDIR=0;
+  GNULIB_CLOSEDIR=0;
+  GNULIB_DIRFD=0;
+  GNULIB_FDOPENDIR=0;
+  GNULIB_SCANDIR=0;
+  GNULIB_ALPHASORT=0;
+    HAVE_OPENDIR=1;
+  HAVE_READDIR=1;
+  HAVE_REWINDDIR=1;
+  HAVE_CLOSEDIR=1;
+  HAVE_DECL_DIRFD=1;
+  HAVE_DECL_FDOPENDIR=1;
+  HAVE_FDOPENDIR=1;
+  HAVE_SCANDIR=1;
+  HAVE_ALPHASORT=1;
+  REPLACE_OPENDIR=0;
+  REPLACE_CLOSEDIR=0;
+  REPLACE_DIRFD=0;
+  REPLACE_FDOPENDIR=0;
+
+
+  GNULIB_ISBLANK=0;
+    HAVE_ISBLANK=1;
+
+
+
+
 
 
 
@@ -16208,36 +16544,6 @@ fi
     HAVE_SIGSET_T=0
   fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5
-$as_echo_n "checking for uid_t in sys/types.h... " >&6; }
-if ${ac_cv_type_uid_t+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/types.h>
-
-_ACEOF
-if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "uid_t" >/dev/null 2>&1; then :
-  ac_cv_type_uid_t=yes
-else
-  ac_cv_type_uid_t=no
-fi
-rm -f conftest*
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
-$as_echo "$ac_cv_type_uid_t" >&6; }
-if test $ac_cv_type_uid_t = no; then
-
-$as_echo "#define uid_t int" >>confdefs.h
-
-
-$as_echo "#define gid_t int" >>confdefs.h
-
-fi
-
 { $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 :
@@ -17891,6 +18197,46 @@ $as_echo "$gl_cv_have_unlimited_file_name_length" >&6; }
     :
   fi
 
+  if test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS chown.$ac_objext"
+
+  fi
+  if test $REPLACE_CHOWN = 1 && test $ac_cv_func_fchown = no; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS fchown-stub.$ac_objext"
+
+  fi
+
+
+
+
+
+          GNULIB_CHOWN=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_CHOWN 1" >>confdefs.h
+
+
+
+
 
 
   # Solaris 2.5.1 needs -lposix4 to get the clock_gettime function.
diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am
index e99adab7a22c..30b8afd28463 100644
--- a/gnulib/import/Makefile.am
+++ b/gnulib/import/Makefile.am
@@ -35,6 +35,7 @@
 #  --no-vc-files \
 #  alloca \
 #  canonicalize-lgpl \
+#  chown \
 #  count-one-bits \
 #  dirent \
 #  dirfd \
@@ -237,6 +238,15 @@ EXTRA_libgnu_a_SOURCES += chdir-long.c
 
 ## end   gnulib module chdir-long
 
+## begin gnulib module chown
+
+
+EXTRA_DIST += chown.c fchown-stub.c
+
+EXTRA_libgnu_a_SOURCES += chown.c fchown-stub.c
+
+## end   gnulib module chown
+
 ## begin gnulib module cloexec
 
 libgnu_a_SOURCES += cloexec.c
diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in
index e02adc633ea6..d8a31f83de46 100644
--- a/gnulib/import/Makefile.in
+++ b/gnulib/import/Makefile.in
@@ -49,6 +49,7 @@
 #  --no-vc-files \
 #  alloca \
 #  canonicalize-lgpl \
+#  chown \
 #  count-one-bits \
 #  dirent \
 #  dirfd \
@@ -182,6 +183,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/builtin-expect.m4 \
 	$(top_srcdir)/import/m4/canonicalize.m4 \
 	$(top_srcdir)/import/m4/chdir-long.m4 \
+	$(top_srcdir)/import/m4/chown.m4 \
 	$(top_srcdir)/import/m4/clock_time.m4 \
 	$(top_srcdir)/import/m4/close.m4 \
 	$(top_srcdir)/import/m4/closedir.m4 \
@@ -1787,12 +1789,12 @@ noinst_LTLIBRARIES =
 # No GNU Make output.
 EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
 	assure.h attribute.h basename-lgpl.h btowc.c \
-	canonicalize-lgpl.c chdir-long.c chdir-long.h cloexec.h \
-	close.c closedir.c dirent-private.h count-one-bits.h \
-	ctype.in.h dirent.in.h dirfd.c dirname.h dup.c dup2.c \
-	eloop-threshold.h errno.in.h error.c error.h exitfail.h \
-	fchdir.c fcntl.c fcntl.in.h fd-hook.h fdopendir.c ffs.c \
-	filename.h filenamecat.h flexmember.h float.c float.in.h \
+	canonicalize-lgpl.c chdir-long.c chdir-long.h chown.c \
+	fchown-stub.c cloexec.h close.c closedir.c dirent-private.h \
+	count-one-bits.h ctype.in.h dirent.in.h dirfd.c dirname.h \
+	dup.c dup2.c eloop-threshold.h errno.in.h error.c error.h \
+	exitfail.h fchdir.c fcntl.c fcntl.in.h fd-hook.h fdopendir.c \
+	ffs.c filename.h filenamecat.h flexmember.h float.c float.in.h \
 	itold.c fnmatch.c fnmatch_loop.c fnmatch.c fnmatch.in.h \
 	fpucw.h free.c frexp.c frexp.c frexpl.c fstat.c stat-w32.c \
 	stat-w32.h at-func.c fstatat.c \
@@ -1876,13 +1878,14 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.c \
 libgnu_a_LIBADD = $(gl_LIBOBJS) @ALLOCA@
 libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) @ALLOCA@
 EXTRA_libgnu_a_SOURCES = alloca.c btowc.c canonicalize-lgpl.c \
-	chdir-long.c close.c closedir.c dirfd.c dup.c dup2.c error.c \
-	fchdir.c fcntl.c fdopendir.c ffs.c float.c itold.c fnmatch.c \
-	fnmatch_loop.c fnmatch.c free.c frexp.c frexp.c frexpl.c \
-	fstat.c stat-w32.c at-func.c fstatat.c getcwd.c getcwd-lgpl.c \
-	getdelim.c getdtablesize.c getline.c getlogin_r.c getrandom.c \
-	gettimeofday.c glob.c glob_pattern_p.c globfree.c inet_ntop.c \
-	isblank.c isnan.c isnand.c isnan.c isnanl.c lstat.c malloc.c \
+	chdir-long.c chown.c fchown-stub.c close.c closedir.c dirfd.c \
+	dup.c dup2.c error.c fchdir.c fcntl.c fdopendir.c ffs.c \
+	float.c itold.c fnmatch.c fnmatch_loop.c fnmatch.c free.c \
+	frexp.c frexp.c frexpl.c fstat.c stat-w32.c at-func.c \
+	fstatat.c getcwd.c getcwd-lgpl.c getdelim.c getdtablesize.c \
+	getline.c getlogin_r.c getrandom.c gettimeofday.c glob.c \
+	glob_pattern_p.c globfree.c inet_ntop.c isblank.c isnan.c \
+	isnand.c isnan.c isnanl.c lstat.c malloc.c \
 	lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c mbsinit.c \
 	mbsrtowcs-state.c mbsrtowcs.c mbtowc.c memchr.c memmem.c \
 	memmem.c mempcpy.c memrchr.c mkdir.c mkdtemp.c mkostemp.c \
@@ -2010,6 +2013,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/btowc.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/canonicalize-lgpl.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chdir-long.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chown.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cloexec.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/closedir.Po@am__quote@
@@ -2023,6 +2027,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exitfail.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fchdir.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fchown-stub.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fcntl.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fd-hook.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fd-safer-flag.Po@am__quote@
diff --git a/gnulib/import/chown.c b/gnulib/import/chown.c
new file mode 100644
index 000000000000..9b8b36192c95
--- /dev/null
+++ b/gnulib/import/chown.c
@@ -0,0 +1,151 @@
+/* provide consistent interface to chown for systems that don't interpret
+   an ID of -1 as meaning "don't change the corresponding ID".
+
+   Copyright (C) 1997, 2004-2007, 2009-2021 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* written by Jim Meyering */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#if !HAVE_CHOWN
+
+/* Simple stub that always fails with ENOSYS, for mingw.  */
+int
+chown (const char *file _GL_UNUSED, uid_t uid _GL_UNUSED,
+       gid_t gid _GL_UNUSED)
+{
+  errno = ENOSYS;
+  return -1;
+}
+
+#else /* HAVE_CHOWN */
+
+/* Below we refer to the system's chown().  */
+# undef chown
+
+/* Provide a more-closely POSIX-conforming version of chown on
+   systems with one or both of the following problems:
+   - chown doesn't treat an ID of -1 as meaning
+   "don't change the corresponding ID".
+   - chown doesn't dereference symlinks.  */
+
+int
+rpl_chown (const char *file, uid_t uid, gid_t gid)
+{
+  struct stat st;
+  bool stat_valid = false;
+  int result;
+
+# if CHOWN_CHANGE_TIME_BUG
+  if (gid != (gid_t) -1 || uid != (uid_t) -1)
+    {
+      if (stat (file, &st))
+        return -1;
+      stat_valid = true;
+    }
+# endif
+
+# if CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE
+  if (gid == (gid_t) -1 || uid == (uid_t) -1)
+    {
+      /* Stat file to get id(s) that should remain unchanged.  */
+      if (!stat_valid && stat (file, &st))
+        return -1;
+      if (gid == (gid_t) -1)
+        gid = st.st_gid;
+      if (uid == (uid_t) -1)
+        uid = st.st_uid;
+    }
+# endif
+
+# if CHOWN_MODIFIES_SYMLINK
+  {
+    /* Handle the case in which the system-supplied chown function
+       does *not* follow symlinks.  Instead, it changes permissions
+       on the symlink itself.  To work around that, we open the
+       file (but this can fail due to lack of read or write permission) and
+       use fchown on the resulting descriptor.  */
+    int open_flags = O_NONBLOCK | O_NOCTTY | O_CLOEXEC;
+    int fd = open (file, O_RDONLY | open_flags);
+    if (0 <= fd
+        || (errno == EACCES
+            && 0 <= (fd = open (file, O_WRONLY | open_flags))))
+      {
+        int saved_errno;
+        bool fchown_socket_failure;
+
+        result = fchown (fd, uid, gid);
+        saved_errno = errno;
+
+        /* POSIX says fchown can fail with errno == EINVAL on sockets
+           and pipes, so fall back on chown in that case.  */
+        fchown_socket_failure =
+          (result != 0 && saved_errno == EINVAL
+           && fstat (fd, &st) == 0
+           && (S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode)));
+
+        close (fd);
+
+        if (! fchown_socket_failure)
+          {
+            errno = saved_errno;
+            return result;
+          }
+      }
+    else if (errno != EACCES)
+      return -1;
+  }
+# endif
+
+# if CHOWN_TRAILING_SLASH_BUG
+  if (!stat_valid)
+    {
+      size_t len = strlen (file);
+      if (len && file[len - 1] == '/' && stat (file, &st))
+        return -1;
+    }
+# endif
+
+  result = chown (file, uid, gid);
+
+# if CHOWN_CHANGE_TIME_BUG
+  if (result == 0 && stat_valid
+      && (uid == st.st_uid || uid == (uid_t) -1)
+      && (gid == st.st_gid || gid == (gid_t) -1))
+    {
+      /* No change in ownership, but at least one argument was not -1,
+         so we are required to update ctime.  Since chown succeeded,
+         we assume that chmod will do likewise.  Fortunately, on all
+         known systems where a 'no-op' chown skips the ctime update, a
+         'no-op' chmod still does the trick.  */
+      result = chmod (file, st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO
+                                          | S_ISUID | S_ISGID | S_ISVTX));
+    }
+# endif
+
+  return result;
+}
+
+#endif /* HAVE_CHOWN */
diff --git a/gnulib/import/fchown-stub.c b/gnulib/import/fchown-stub.c
new file mode 100644
index 000000000000..f549ff300a48
--- /dev/null
+++ b/gnulib/import/fchown-stub.c
@@ -0,0 +1,34 @@
+/* Change ownership of a file.
+   Copyright (C) 2004-2021 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert, 2004.  */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <errno.h>
+
+/* A trivial substitute for 'fchown'.
+
+   DJGPP 2.03 and earlier (and perhaps later) don't have 'fchown',
+   so we pretend no-one has permission for this operation. */
+
+int
+fchown (int fd, uid_t uid, gid_t gid)
+{
+  errno = EPERM;
+  return -1;
+}
diff --git a/gnulib/import/m4/chown.m4 b/gnulib/import/m4/chown.m4
new file mode 100644
index 000000000000..d1c083175e6b
--- /dev/null
+++ b/gnulib/import/m4/chown.m4
@@ -0,0 +1,218 @@
+# serial 35
+# Determine whether we need the chown wrapper.
+
+dnl Copyright (C) 1997-2001, 2003-2005, 2007, 2009-2021 Free Software
+dnl 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.
+
+# chown should accept arguments of -1 for uid and gid, and it should
+# dereference symlinks.  If it doesn't, arrange to use the replacement
+# function.
+
+# From Jim Meyering.
+
+# This is taken from the following Autoconf patch:
+# https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=7fbb553727ed7e0e689a17594b58559ecf3ea6e9
+AC_DEFUN([AC_FUNC_CHOWN],
+[
+  AC_REQUIRE([AC_TYPE_UID_T])dnl
+  AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+  AC_CHECK_HEADERS([unistd.h])
+  AC_CACHE_CHECK([for working chown],
+    [ac_cv_func_chown_works],
+    [AC_RUN_IFELSE(
+       [AC_LANG_PROGRAM(
+          [AC_INCLUDES_DEFAULT
+           [#include <fcntl.h>
+          ]GL_MDA_DEFINES],
+          [[
+            char *f = "conftest.chown";
+            struct stat before, after;
+
+            if (creat (f, 0600) < 0)
+              return 1;
+            if (stat (f, &before) < 0)
+              return 1;
+            if (chown (f, (uid_t) -1, (gid_t) -1) == -1)
+              return 1;
+            if (stat (f, &after) < 0)
+              return 1;
+            return ! (before.st_uid == after.st_uid && before.st_gid == after.st_gid);
+          ]])
+       ],
+       [ac_cv_func_chown_works=yes],
+       [ac_cv_func_chown_works=no],
+       [case "$host_os" in # ((
+                           # Guess yes on Linux systems.
+          linux-* | linux) ac_cv_func_chown_works="guessing yes" ;;
+                           # Guess yes on glibc systems.
+          *-gnu* | gnu*)   ac_cv_func_chown_works="guessing yes" ;;
+                           # Guess no on native Windows.
+          mingw*)          ac_cv_func_chown_works="guessing no" ;;
+                           # If we don't know, obey --enable-cross-guesses.
+          *)               ac_cv_func_chown_works="$gl_cross_guess_normal" ;;
+        esac
+       ])
+     rm -f conftest.chown
+    ])
+  case "$ac_cv_func_chown_works" in
+    *yes)
+      AC_DEFINE([HAVE_CHOWN], [1],
+        [Define to 1 if your system has a working `chown' function.])
+      ;;
+  esac
+])# AC_FUNC_CHOWN
+
+AC_DEFUN_ONCE([gl_FUNC_CHOWN],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_TYPE_UID_T])
+  AC_REQUIRE([AC_FUNC_CHOWN])
+  AC_REQUIRE([gl_FUNC_CHOWN_FOLLOWS_SYMLINK])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CHECK_FUNCS_ONCE([chown fchown])
+
+  dnl mingw lacks chown altogether.
+  if test $ac_cv_func_chown = no; then
+    HAVE_CHOWN=0
+  else
+    dnl Some old systems treated chown like lchown.
+    case "$gl_cv_func_chown_follows_symlink" in
+      *yes) ;;
+      *) REPLACE_CHOWN=1 ;;
+    esac
+
+    dnl Some old systems tried to use uid/gid -1 literally.
+    case "$ac_cv_func_chown_works" in
+      *no)
+        AC_DEFINE([CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE], [1],
+          [Define if chown is not POSIX compliant regarding IDs of -1.])
+        REPLACE_CHOWN=1
+        ;;
+    esac
+
+    dnl Solaris 9 ignores trailing slash.
+    dnl FreeBSD 7.2 mishandles trailing slash on symlinks.
+    dnl Likewise for AIX 7.1.
+    AC_CACHE_CHECK([whether chown honors trailing slash],
+      [gl_cv_func_chown_slash_works],
+      [touch conftest.file && rm -f conftest.link
+       AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+]GL_MDA_DEFINES],
+        [[if (symlink ("conftest.file", "conftest.link")) return 1;
+          if (chown ("conftest.link/", getuid (), getgid ()) == 0) return 2;
+        ]])],
+        [gl_cv_func_chown_slash_works=yes],
+        [gl_cv_func_chown_slash_works=no],
+        [case "$host_os" in
+                    # Guess yes on glibc systems.
+           *-gnu*)  gl_cv_func_chown_slash_works="guessing yes" ;;
+                    # Guess yes on musl systems.
+           *-musl*) gl_cv_func_chown_slash_works="guessing yes" ;;
+                    # If we don't know, obey --enable-cross-guesses.
+           *)       gl_cv_func_chown_slash_works="$gl_cross_guess_normal" ;;
+         esac
+        ])
+      rm -f conftest.link conftest.file])
+    case "$gl_cv_func_chown_slash_works" in
+      *yes) ;;
+      *)
+        AC_DEFINE([CHOWN_TRAILING_SLASH_BUG], [1],
+          [Define to 1 if chown mishandles trailing slash.])
+        REPLACE_CHOWN=1
+        ;;
+    esac
+
+    dnl OpenBSD fails to update ctime if ownership does not change.
+    AC_CACHE_CHECK([whether chown always updates ctime],
+      [gl_cv_func_chown_ctime_works],
+      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+]GL_MDA_DEFINES],
+        [[struct stat st1, st2;
+          if (close (creat ("conftest.file", 0600))) return 1;
+          if (stat ("conftest.file", &st1)) return 2;
+          sleep (1);
+          if (chown ("conftest.file", st1.st_uid, st1.st_gid)) return 3;
+          if (stat ("conftest.file", &st2)) return 4;
+          if (st2.st_ctime <= st1.st_ctime) return 5;
+        ]])],
+        [gl_cv_func_chown_ctime_works=yes],
+        [gl_cv_func_chown_ctime_works=no],
+        [case "$host_os" in
+                    # Guess yes on glibc systems.
+           *-gnu*)  gl_cv_func_chown_ctime_works="guessing yes" ;;
+                    # Guess yes on musl systems.
+           *-musl*) gl_cv_func_chown_ctime_works="guessing yes" ;;
+                    # If we don't know, obey --enable-cross-guesses.
+           *)       gl_cv_func_chown_ctime_works="$gl_cross_guess_normal" ;;
+         esac
+        ])
+      rm -f conftest.file])
+    case "$gl_cv_func_chown_ctime_works" in
+      *yes) ;;
+      *)
+        AC_DEFINE([CHOWN_CHANGE_TIME_BUG], [1], [Define to 1 if chown fails
+          to change ctime when at least one argument was not -1.])
+        REPLACE_CHOWN=1
+        ;;
+    esac
+  fi
+])
+
+# Determine whether chown follows symlinks (it should).
+AC_DEFUN_ONCE([gl_FUNC_CHOWN_FOLLOWS_SYMLINK],
+[
+  AC_CACHE_CHECK(
+    [whether chown dereferences symlinks],
+    [gl_cv_func_chown_follows_symlink],
+    [
+      AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+]GL_MDA_DEFINES[
+        int
+        main ()
+        {
+          int result = 0;
+          char const *dangling_symlink = "conftest.dangle";
+
+          unlink (dangling_symlink);
+          if (symlink ("conftest.no-such", dangling_symlink))
+            abort ();
+
+          /* Exit successfully on a conforming system,
+             i.e., where chown must fail with ENOENT.  */
+          if (chown (dangling_symlink, getuid (), getgid ()) == 0)
+            result |= 1;
+          if (errno != ENOENT)
+            result |= 2;
+          return result;
+        }
+        ]])],
+        [gl_cv_func_chown_follows_symlink=yes],
+        [gl_cv_func_chown_follows_symlink=no],
+        [gl_cv_func_chown_follows_symlink="guessing yes"]
+      )
+    ]
+  )
+
+  case "$gl_cv_func_chown_follows_symlink" in
+    *yes) ;;
+    *)
+      AC_DEFINE([CHOWN_MODIFIES_SYMLINK], [1],
+        [Define if chown modifies symlinks.])
+      ;;
+  esac
+])
diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4
index ad7db9a694ec..d21f54296d62 100644
--- a/gnulib/import/m4/gnulib-cache.m4
+++ b/gnulib/import/m4/gnulib-cache.m4
@@ -40,6 +40,7 @@
 #  --no-vc-files \
 #  alloca \
 #  canonicalize-lgpl \
+#  chown \
 #  count-one-bits \
 #  dirent \
 #  dirfd \
@@ -85,6 +86,7 @@ gl_LOCAL_DIR([])
 gl_MODULES([
   alloca
   canonicalize-lgpl
+  chown
   count-one-bits
   dirent
   dirfd
diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4
index 75fe076f74ec..d4734854fbc1 100644
--- a/gnulib/import/m4/gnulib-comp.m4
+++ b/gnulib/import/m4/gnulib-comp.m4
@@ -57,6 +57,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module canonicalize-lgpl:
   # Code from module chdir:
   # Code from module chdir-long:
+  # Code from module chown:
   # Code from module clock-time:
   # Code from module cloexec:
   # Code from module close:
@@ -268,6 +269,14 @@ AC_DEFUN([gl_INIT],
     AC_LIBOBJ([chdir-long])
     gl_PREREQ_CHDIR_LONG
   fi
+  gl_FUNC_CHOWN
+  if test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1; then
+    AC_LIBOBJ([chown])
+  fi
+  if test $REPLACE_CHOWN = 1 && test $ac_cv_func_fchown = no; then
+    AC_LIBOBJ([fchown-stub])
+  fi
+  gl_UNISTD_MODULE_INDICATOR([chown])
   gl_CLOCK_TIME
   gl_MODULE_INDICATOR_FOR_TESTS([cloexec])
   gl_FUNC_CLOSE
@@ -968,6 +977,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/cdefs.h
   lib/chdir-long.c
   lib/chdir-long.h
+  lib/chown.c
   lib/cloexec.c
   lib/cloexec.h
   lib/close.c
@@ -991,6 +1001,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/exitfail.c
   lib/exitfail.h
   lib/fchdir.c
+  lib/fchown-stub.c
   lib/fcntl.c
   lib/fcntl.in.h
   lib/fd-hook.c
@@ -1189,6 +1200,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/builtin-expect.m4
   m4/canonicalize.m4
   m4/chdir-long.m4
+  m4/chown.m4
   m4/clock_time.m4
   m4/close.m4
   m4/closedir.m4
diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh
index e8bb59652696..44e8db47e2ba 100755
--- a/gnulib/update-gnulib.sh
+++ b/gnulib/update-gnulib.sh
@@ -32,6 +32,7 @@
 IMPORTED_GNULIB_MODULES="\
     alloca \
     canonicalize-lgpl \
+    chown \
     count-one-bits \
     dirent \
     dirfd \
-- 
2.31.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/4] sim: v850: assume chown is available
  2021-05-29 17:25 [PATCH 1/4] gnulib: import chown Mike Frysinger
@ 2021-05-29 17:25 ` Mike Frysinger
  2021-05-29 17:25 ` [PATCH 3/4] gnulib: import netdb Mike Frysinger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2021-05-29 17:25 UTC (permalink / raw)
  To: gdb-patches

Now that gnulib provides a wrapper, assume it always exists.
---
 sim/v850/config.in    | 3 ---
 sim/v850/configure    | 7 ++-----
 sim/v850/configure.ac | 2 +-
 sim/v850/simops.c     | 2 --
 4 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/sim/v850/config.in b/sim/v850/config.in
index 74af5e5087e0..b6a4255b404b 100644
--- a/sim/v850/config.in
+++ b/sim/v850/config.in
@@ -13,9 +13,6 @@
 /* Define to 1 if you have the `chmod' function. */
 #undef HAVE_CHMOD
 
-/* Define to 1 if you have the `chown' function. */
-#undef HAVE_CHOWN
-
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
diff --git a/sim/v850/configure b/sim/v850/configure
index bc49f306a27f..29999bde7019 100755
--- a/sim/v850/configure
+++ b/sim/v850/configure
@@ -2321,7 +2321,6 @@ as_fn_append ac_func_list " utime"
 as_fn_append ac_func_list " fork"
 as_fn_append ac_func_list " execve"
 as_fn_append ac_func_list " execv"
-as_fn_append ac_func_list " chown"
 as_fn_append ac_header_list " utime.h"
 # Check that the precious variables saved in the cache have kept the same
 # value.
@@ -11220,7 +11219,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11223 "configure"
+#line 11222 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11326,7 +11325,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11329 "configure"
+#line 11328 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12057,8 +12056,6 @@ fi
 
 
 
-
-
 # Check whether --enable-werror was given.
 if test "${enable_werror+set}" = set; then :
   enableval=$enable_werror; case "${enableval}" in
diff --git a/sim/v850/configure.ac b/sim/v850/configure.ac
index f2edf1f7c480..892e78b90ff3 100644
--- a/sim/v850/configure.ac
+++ b/sim/v850/configure.ac
@@ -9,7 +9,7 @@ SIM_AC_OPTION_ALIGNMENT(,NONSTRICT_ALIGNMENT)
 SIM_AC_OPTION_RESERVED_BITS
 SIM_AC_OPTION_BITSIZE(32,31)
 
-AC_CHECK_FUNCS_ONCE(chmod utime fork execve execv chown)
+AC_CHECK_FUNCS_ONCE(chmod utime fork execve execv)
 AC_CHECK_HEADERS_ONCE(utime.h)
 
 SIM_AC_OUTPUT
diff --git a/sim/v850/simops.c b/sim/v850/simops.c
index 62a2bbcbb615..689dfe1d0313 100644
--- a/sim/v850/simops.c
+++ b/sim/v850/simops.c
@@ -1859,7 +1859,6 @@ OP_10007E0 (void)
 	  break;
 #endif
 
-#ifdef HAVE_CHOWN
 #ifdef TARGET_SYS_chown
 	case TARGET_SYS_chown:
 	  {
@@ -1870,7 +1869,6 @@ OP_10007E0 (void)
 	  }
 	  break;
 #endif
-#endif
 
 #if HAVE_CHMOD
 #ifdef TARGET_SYS_chmod
-- 
2.31.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 3/4] gnulib: import netdb
  2021-05-29 17:25 [PATCH 1/4] gnulib: import chown Mike Frysinger
  2021-05-29 17:25 ` [PATCH 2/4] sim: v850: assume chown is available Mike Frysinger
@ 2021-05-29 17:25 ` Mike Frysinger
  2021-06-07 14:27   ` Tom Tromey
  2021-05-29 17:25 ` [PATCH 4/4] gnulib: import select Mike Frysinger
  2021-06-07 14:23 ` [PATCH 1/4] gnulib: import chown Tom Tromey
  3 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-05-29 17:25 UTC (permalink / raw)
  To: gdb-patches

A few sims use this to provide network functionality.
---
 gnulib/Makefile.in               |  12 ++
 gnulib/aclocal.m4                |   1 +
 gnulib/configure                 | 113 ++++++++++++
 gnulib/import/Makefile.am        |  36 ++++
 gnulib/import/Makefile.in        |  69 ++++++--
 gnulib/import/m4/gnulib-cache.m4 |   2 +
 gnulib/import/m4/gnulib-comp.m4  |   4 +
 gnulib/import/m4/netdb_h.m4      |  44 +++++
 gnulib/import/netdb.in.h         | 295 +++++++++++++++++++++++++++++++
 gnulib/update-gnulib.sh          |   1 +
 10 files changed, 562 insertions(+), 15 deletions(-)
 create mode 100644 gnulib/import/m4/netdb_h.m4
 create mode 100644 gnulib/import/netdb.in.h

diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in
index 04dc454701e1..be154720295d 100644
--- a/gnulib/Makefile.in
+++ b/gnulib/Makefile.in
@@ -210,6 +210,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/msvc-inval.m4 \
 	$(top_srcdir)/import/m4/msvc-nothrow.m4 \
 	$(top_srcdir)/import/m4/multiarch.m4 \
+	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
@@ -495,6 +496,7 @@ GNULIB_FTELLO = @GNULIB_FTELLO@
 GNULIB_FTRUNCATE = @GNULIB_FTRUNCATE@
 GNULIB_FUTIMENS = @GNULIB_FUTIMENS@
 GNULIB_FWRITE = @GNULIB_FWRITE@
+GNULIB_GETADDRINFO = @GNULIB_GETADDRINFO@
 GNULIB_GETC = @GNULIB_GETC@
 GNULIB_GETCHAR = @GNULIB_GETCHAR@
 GNULIB_GETCWD = @GNULIB_GETCWD@
@@ -900,16 +902,20 @@ HAVE_DECL_FDOPENDIR = @HAVE_DECL_FDOPENDIR@
 HAVE_DECL_FLOORF = @HAVE_DECL_FLOORF@
 HAVE_DECL_FLOORL = @HAVE_DECL_FLOORL@
 HAVE_DECL_FPURGE = @HAVE_DECL_FPURGE@
+HAVE_DECL_FREEADDRINFO = @HAVE_DECL_FREEADDRINFO@
 HAVE_DECL_FREXPL = @HAVE_DECL_FREXPL@
 HAVE_DECL_FSEEKO = @HAVE_DECL_FSEEKO@
 HAVE_DECL_FTELLO = @HAVE_DECL_FTELLO@
+HAVE_DECL_GAI_STRERROR = @HAVE_DECL_GAI_STRERROR@
 HAVE_DECL_GCVT = @HAVE_DECL_GCVT@
+HAVE_DECL_GETADDRINFO = @HAVE_DECL_GETADDRINFO@
 HAVE_DECL_GETDELIM = @HAVE_DECL_GETDELIM@
 HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@
 HAVE_DECL_GETLINE = @HAVE_DECL_GETLINE@
 HAVE_DECL_GETLOADAVG = @HAVE_DECL_GETLOADAVG@
 HAVE_DECL_GETLOGIN = @HAVE_DECL_GETLOGIN@
 HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@
+HAVE_DECL_GETNAMEINFO = @HAVE_DECL_GETNAMEINFO@
 HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@
 HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@
 HAVE_DECL_IMAXABS = @HAVE_DECL_IMAXABS@
@@ -1067,6 +1073,7 @@ HAVE_MODFF = @HAVE_MODFF@
 HAVE_MODFL = @HAVE_MODFL@
 HAVE_MSVC_INVALID_PARAMETER_HANDLER = @HAVE_MSVC_INVALID_PARAMETER_HANDLER@
 HAVE_NANOSLEEP = @HAVE_NANOSLEEP@
+HAVE_NETDB_H = @HAVE_NETDB_H@
 HAVE_NETINET_IN_H = @HAVE_NETINET_IN_H@
 HAVE_NEWLOCALE = @HAVE_NEWLOCALE@
 HAVE_OPENAT = @HAVE_OPENAT@
@@ -1140,6 +1147,7 @@ HAVE_STRTOD = @HAVE_STRTOD@
 HAVE_STRTOLD = @HAVE_STRTOLD@
 HAVE_STRTOLL = @HAVE_STRTOLL@
 HAVE_STRTOULL = @HAVE_STRTOULL@
+HAVE_STRUCT_ADDRINFO = @HAVE_STRUCT_ADDRINFO@
 HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@
 HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@
 HAVE_STRUCT_SOCKADDR_STORAGE = @HAVE_STRUCT_SOCKADDR_STORAGE@
@@ -1273,6 +1281,7 @@ NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@
 NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@
 NEXT_AS_FIRST_DIRECTIVE_LOCALE_H = @NEXT_AS_FIRST_DIRECTIVE_LOCALE_H@
 NEXT_AS_FIRST_DIRECTIVE_MATH_H = @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
+NEXT_AS_FIRST_DIRECTIVE_NETDB_H = @NEXT_AS_FIRST_DIRECTIVE_NETDB_H@
 NEXT_AS_FIRST_DIRECTIVE_NETINET_IN_H = @NEXT_AS_FIRST_DIRECTIVE_NETINET_IN_H@
 NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@
 NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
@@ -1302,6 +1311,7 @@ NEXT_INTTYPES_H = @NEXT_INTTYPES_H@
 NEXT_LIMITS_H = @NEXT_LIMITS_H@
 NEXT_LOCALE_H = @NEXT_LOCALE_H@
 NEXT_MATH_H = @NEXT_MATH_H@
+NEXT_NETDB_H = @NEXT_NETDB_H@
 NEXT_NETINET_IN_H = @NEXT_NETINET_IN_H@
 NEXT_SIGNAL_H = @NEXT_SIGNAL_H@
 NEXT_STDDEF_H = @NEXT_STDDEF_H@
@@ -1412,6 +1422,8 @@ REPLACE_FTELL = @REPLACE_FTELL@
 REPLACE_FTELLO = @REPLACE_FTELLO@
 REPLACE_FTRUNCATE = @REPLACE_FTRUNCATE@
 REPLACE_FUTIMENS = @REPLACE_FUTIMENS@
+REPLACE_GAI_STRERROR = @REPLACE_GAI_STRERROR@
+REPLACE_GETADDRINFO = @REPLACE_GETADDRINFO@
 REPLACE_GETCWD = @REPLACE_GETCWD@
 REPLACE_GETDELIM = @REPLACE_GETDELIM@
 REPLACE_GETDOMAINNAME = @REPLACE_GETDOMAINNAME@
diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4
index d466a2666cac..96f7dc60af7f 100644
--- a/gnulib/aclocal.m4
+++ b/gnulib/aclocal.m4
@@ -1283,6 +1283,7 @@ m4_include([import/m4/mode_t.m4])
 m4_include([import/m4/msvc-inval.m4])
 m4_include([import/m4/msvc-nothrow.m4])
 m4_include([import/m4/multiarch.m4])
+m4_include([import/m4/netdb_h.m4])
 m4_include([import/m4/netinet_in_h.m4])
 m4_include([import/m4/nocrash.m4])
 m4_include([import/m4/off_t.m4])
diff --git a/gnulib/configure b/gnulib/configure
index 827393a6d254..d447121f4f16 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -782,6 +782,17 @@ NETINET_IN_H
 HAVE_NETINET_IN_H
 NEXT_AS_FIRST_DIRECTIVE_NETINET_IN_H
 NEXT_NETINET_IN_H
+HAVE_NETDB_H
+NEXT_AS_FIRST_DIRECTIVE_NETDB_H
+NEXT_NETDB_H
+REPLACE_GETADDRINFO
+REPLACE_GAI_STRERROR
+HAVE_DECL_GETNAMEINFO
+HAVE_DECL_GETADDRINFO
+HAVE_DECL_GAI_STRERROR
+HAVE_DECL_FREEADDRINFO
+HAVE_STRUCT_ADDRINFO
+GNULIB_GETADDRINFO
 UNDEFINE_STRTOK_R
 REPLACE_STRSIGNAL
 REPLACE_STRERRORNAME_NP
@@ -6782,6 +6793,7 @@ fi
   # Code from module msvc-inval:
   # Code from module msvc-nothrow:
   # Code from module multiarch:
+  # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
   # Code from module open:
@@ -16380,6 +16392,16 @@ $as_echo "#define HAVE_MINMAX_IN_SYS_PARAM_H 1" >>confdefs.h
 
 
 
+  GNULIB_GETADDRINFO=0;
+    HAVE_STRUCT_ADDRINFO=1;
+  HAVE_DECL_FREEADDRINFO=1;
+  HAVE_DECL_GAI_STRERROR=1;
+  HAVE_DECL_GETADDRINFO=1;
+  HAVE_DECL_GETNAMEINFO=1;
+  REPLACE_GAI_STRERROR=0;
+  REPLACE_GETADDRINFO=0;
+
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for O_CLOEXEC" >&5
 $as_echo_n "checking for O_CLOEXEC... " >&6; }
 if ${gl_cv_macro_O_CLOEXEC+:} false; then :
@@ -26252,6 +26274,97 @@ _ACEOF
 
 
 
+
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_netdb_h='<'netdb.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <netdb.h>" >&5
+$as_echo_n "checking absolute name of <netdb.h>... " >&6; }
+if ${gl_cv_next_netdb_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+             if test $ac_cv_header_netdb_h = yes; then
+
+
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <netdb.h>
+_ACEOF
+                case "$host_os" in
+    aix*) gl_absname_cpp="$ac_cpp -C" ;;
+    *)    gl_absname_cpp="$ac_cpp" ;;
+  esac
+
+  case "$host_os" in
+    mingw*)
+                                          gl_dirsep_regex='[/\\]'
+      ;;
+    *)
+      gl_dirsep_regex='\/'
+      ;;
+  esac
+      gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+  gl_header_literal_regex=`echo 'netdb.h' \
+                           | sed -e "$gl_make_literal_regex_sed"`
+  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+      s|^/[^/]|//&|
+      p
+      q
+    }'
+
+        gl_cv_absolute_netdb_h=`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+  sed -n "$gl_absolute_header_sed"`
+
+           gl_header=$gl_cv_absolute_netdb_h
+           gl_cv_next_netdb_h='"'$gl_header'"'
+          else
+               gl_cv_next_netdb_h='<'netdb.h'>'
+             fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_netdb_h" >&5
+$as_echo "$gl_cv_next_netdb_h" >&6; }
+     fi
+     NEXT_NETDB_H=$gl_cv_next_netdb_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'netdb.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_netdb_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_NETDB_H=$gl_next_as_first_directive
+
+
+
+
+  if test $ac_cv_header_netdb_h = yes; then
+    HAVE_NETDB_H=1
+  else
+    HAVE_NETDB_H=0
+  fi
+
+
+
+
+
+
+
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <netinet/in.h> is self-contained" >&5
 $as_echo_n "checking whether <netinet/in.h> is self-contained... " >&6; }
 if ${gl_cv_header_netinet_in_h_selfcontained+:} false; then :
diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am
index 30b8afd28463..2a11accc8d61 100644
--- a/gnulib/import/Makefile.am
+++ b/gnulib/import/Makefile.am
@@ -58,6 +58,7 @@
 #  mkdir \
 #  mkdtemp \
 #  mkostemp \
+#  netdb \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -1492,6 +1493,41 @@ EXTRA_libgnu_a_SOURCES += msvc-nothrow.c
 
 ## end   gnulib module msvc-nothrow
 
+## begin gnulib module netdb
+
+BUILT_SOURCES += netdb.h
+
+# We need the following in order to create <netdb.h> when the system
+# doesn't have one that works with the given compiler.
+netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
+	      -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
+	      -e 's/@''GNULIB_GETADDRINFO''@/$(GNULIB_GETADDRINFO)/g' \
+	      -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
+	      -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
+	      -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \
+	      -e 's|@''REPLACE_GETADDRINFO''@|$(REPLACE_GETADDRINFO)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/netdb.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += netdb.h netdb.h-t
+
+EXTRA_DIST += netdb.in.h
+
+## end   gnulib module netdb
+
 ## begin gnulib module netinet_in
 
 BUILT_SOURCES += $(NETINET_IN_H)
diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in
index d8a31f83de46..96606cf73f31 100644
--- a/gnulib/import/Makefile.in
+++ b/gnulib/import/Makefile.in
@@ -72,6 +72,7 @@
 #  mkdir \
 #  mkdtemp \
 #  mkostemp \
+#  netdb \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -272,6 +273,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/msvc-inval.m4 \
 	$(top_srcdir)/import/m4/msvc-nothrow.m4 \
 	$(top_srcdir)/import/m4/multiarch.m4 \
+	$(top_srcdir)/import/m4/netdb_h.m4 \
 	$(top_srcdir)/import/m4/netinet_in_h.m4 \
 	$(top_srcdir)/import/m4/nocrash.m4 \
 	$(top_srcdir)/import/m4/off_t.m4 \
@@ -595,6 +597,7 @@ GNULIB_FTELLO = @GNULIB_FTELLO@
 GNULIB_FTRUNCATE = @GNULIB_FTRUNCATE@
 GNULIB_FUTIMENS = @GNULIB_FUTIMENS@
 GNULIB_FWRITE = @GNULIB_FWRITE@
+GNULIB_GETADDRINFO = @GNULIB_GETADDRINFO@
 GNULIB_GETC = @GNULIB_GETC@
 GNULIB_GETCHAR = @GNULIB_GETCHAR@
 GNULIB_GETCWD = @GNULIB_GETCWD@
@@ -1000,16 +1003,20 @@ HAVE_DECL_FDOPENDIR = @HAVE_DECL_FDOPENDIR@
 HAVE_DECL_FLOORF = @HAVE_DECL_FLOORF@
 HAVE_DECL_FLOORL = @HAVE_DECL_FLOORL@
 HAVE_DECL_FPURGE = @HAVE_DECL_FPURGE@
+HAVE_DECL_FREEADDRINFO = @HAVE_DECL_FREEADDRINFO@
 HAVE_DECL_FREXPL = @HAVE_DECL_FREXPL@
 HAVE_DECL_FSEEKO = @HAVE_DECL_FSEEKO@
 HAVE_DECL_FTELLO = @HAVE_DECL_FTELLO@
+HAVE_DECL_GAI_STRERROR = @HAVE_DECL_GAI_STRERROR@
 HAVE_DECL_GCVT = @HAVE_DECL_GCVT@
+HAVE_DECL_GETADDRINFO = @HAVE_DECL_GETADDRINFO@
 HAVE_DECL_GETDELIM = @HAVE_DECL_GETDELIM@
 HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@
 HAVE_DECL_GETLINE = @HAVE_DECL_GETLINE@
 HAVE_DECL_GETLOADAVG = @HAVE_DECL_GETLOADAVG@
 HAVE_DECL_GETLOGIN = @HAVE_DECL_GETLOGIN@
 HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@
+HAVE_DECL_GETNAMEINFO = @HAVE_DECL_GETNAMEINFO@
 HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@
 HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@
 HAVE_DECL_IMAXABS = @HAVE_DECL_IMAXABS@
@@ -1167,6 +1174,7 @@ HAVE_MODFF = @HAVE_MODFF@
 HAVE_MODFL = @HAVE_MODFL@
 HAVE_MSVC_INVALID_PARAMETER_HANDLER = @HAVE_MSVC_INVALID_PARAMETER_HANDLER@
 HAVE_NANOSLEEP = @HAVE_NANOSLEEP@
+HAVE_NETDB_H = @HAVE_NETDB_H@
 HAVE_NETINET_IN_H = @HAVE_NETINET_IN_H@
 HAVE_NEWLOCALE = @HAVE_NEWLOCALE@
 HAVE_OPENAT = @HAVE_OPENAT@
@@ -1240,6 +1248,7 @@ HAVE_STRTOD = @HAVE_STRTOD@
 HAVE_STRTOLD = @HAVE_STRTOLD@
 HAVE_STRTOLL = @HAVE_STRTOLL@
 HAVE_STRTOULL = @HAVE_STRTOULL@
+HAVE_STRUCT_ADDRINFO = @HAVE_STRUCT_ADDRINFO@
 HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@
 HAVE_STRUCT_SIGACTION_SA_SIGACTION = @HAVE_STRUCT_SIGACTION_SA_SIGACTION@
 HAVE_STRUCT_SOCKADDR_STORAGE = @HAVE_STRUCT_SOCKADDR_STORAGE@
@@ -1373,6 +1382,7 @@ NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H = @NEXT_AS_FIRST_DIRECTIVE_INTTYPES_H@
 NEXT_AS_FIRST_DIRECTIVE_LIMITS_H = @NEXT_AS_FIRST_DIRECTIVE_LIMITS_H@
 NEXT_AS_FIRST_DIRECTIVE_LOCALE_H = @NEXT_AS_FIRST_DIRECTIVE_LOCALE_H@
 NEXT_AS_FIRST_DIRECTIVE_MATH_H = @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
+NEXT_AS_FIRST_DIRECTIVE_NETDB_H = @NEXT_AS_FIRST_DIRECTIVE_NETDB_H@
 NEXT_AS_FIRST_DIRECTIVE_NETINET_IN_H = @NEXT_AS_FIRST_DIRECTIVE_NETINET_IN_H@
 NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H = @NEXT_AS_FIRST_DIRECTIVE_SIGNAL_H@
 NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
@@ -1402,6 +1412,7 @@ NEXT_INTTYPES_H = @NEXT_INTTYPES_H@
 NEXT_LIMITS_H = @NEXT_LIMITS_H@
 NEXT_LOCALE_H = @NEXT_LOCALE_H@
 NEXT_MATH_H = @NEXT_MATH_H@
+NEXT_NETDB_H = @NEXT_NETDB_H@
 NEXT_NETINET_IN_H = @NEXT_NETINET_IN_H@
 NEXT_SIGNAL_H = @NEXT_SIGNAL_H@
 NEXT_STDDEF_H = @NEXT_STDDEF_H@
@@ -1512,6 +1523,8 @@ REPLACE_FTELL = @REPLACE_FTELL@
 REPLACE_FTELLO = @REPLACE_FTELLO@
 REPLACE_FTRUNCATE = @REPLACE_FTRUNCATE@
 REPLACE_FUTIMENS = @REPLACE_FUTIMENS@
+REPLACE_GAI_STRERROR = @REPLACE_GAI_STRERROR@
+REPLACE_GETADDRINFO = @REPLACE_GETADDRINFO@
 REPLACE_GETCWD = @REPLACE_GETCWD@
 REPLACE_GETDELIM = @REPLACE_GETDELIM@
 REPLACE_GETDOMAINNAME = @REPLACE_GETDOMAINNAME@
@@ -1813,11 +1826,11 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
 	mbtowc-impl.h mbtowc.c memchr.c memchr.valgrind memmem.c \
 	memmem.c str-two-way.h mempcpy.c memrchr.c mkdir.c mkdtemp.c \
 	mkostemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
-	msvc-nothrow.h netinet_in.in.h open.c openat.c openat.h \
-	dirent-private.h opendir.c pathmax.h pipe.c rawmemchr.c \
-	rawmemchr.valgrind dirent-private.h readdir.c readlink.c \
-	realloc.c rename.c dirent-private.h rewinddir.c rmdir.c \
-	same-inode.h save-cwd.h malloc/scratch_buffer.h \
+	msvc-nothrow.h netdb.in.h netinet_in.in.h open.c openat.c \
+	openat.h dirent-private.h opendir.c pathmax.h pipe.c \
+	rawmemchr.c rawmemchr.valgrind dirent-private.h readdir.c \
+	readlink.c realloc.c rename.c dirent-private.h rewinddir.c \
+	rmdir.c same-inode.h save-cwd.h malloc/scratch_buffer.h \
 	scratch_buffer.h setenv.c setlocale-lock.c setlocale_null.h \
 	windows-initguard.h signal.in.h _Noreturn.h arg-nonnull.h \
 	c++defs.h warn-on-use.h stat-w32.c stat-w32.h stat.c \
@@ -1837,7 +1850,7 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
 	wmemchr-impl.h wmemchr.c wmempcpy.c xalloc-oversized.h
 BUILT_SOURCES = $(ALLOCA_H) arpa/inet.h ctype.h dirent.h $(ERRNO_H) \
 	fcntl.h $(FLOAT_H) $(FNMATCH_H) $(GLOB_H) inttypes.h \
-	$(LIMITS_H) locale.h math.h $(NETINET_IN_H) signal.h \
+	$(LIMITS_H) locale.h math.h netdb.h $(NETINET_IN_H) signal.h \
 	$(STDALIGN_H) $(STDBOOL_H) $(STDDEF_H) $(STDINT_H) stdio.h \
 	stdlib.h string.h strings.h sys/random.h sys/socket.h \
 	sys/stat.h sys/time.h sys/types.h sys/uio.h time.h unistd.h \
@@ -1847,15 +1860,15 @@ MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	arpa/inet.h-t ctype.h ctype.h-t dirent.h dirent.h-t errno.h \
 	errno.h-t fcntl.h fcntl.h-t float.h float.h-t fnmatch.h \
 	fnmatch.h-t glob.h glob.h-t inttypes.h inttypes.h-t limits.h \
-	limits.h-t locale.h locale.h-t math.h math.h-t netinet/in.h \
-	netinet/in.h-t signal.h signal.h-t stdalign.h stdalign.h-t \
-	stdbool.h stdbool.h-t stddef.h stddef.h-t stdint.h stdint.h-t \
-	stdio.h stdio.h-t stdlib.h stdlib.h-t string.h string.h-t \
-	strings.h strings.h-t sys/random.h sys/random.h-t sys/socket.h \
-	sys/socket.h-t sys/stat.h sys/stat.h-t sys/time.h sys/time.h-t \
-	sys/types.h sys/types.h-t sys/uio.h sys/uio.h-t time.h \
-	time.h-t unistd.h unistd.h-t wchar.h wchar.h-t wctype.h \
-	wctype.h-t
+	limits.h-t locale.h locale.h-t math.h math.h-t netdb.h \
+	netdb.h-t netinet/in.h netinet/in.h-t signal.h signal.h-t \
+	stdalign.h stdalign.h-t stdbool.h stdbool.h-t stddef.h \
+	stddef.h-t stdint.h stdint.h-t stdio.h stdio.h-t stdlib.h \
+	stdlib.h-t string.h string.h-t strings.h strings.h-t \
+	sys/random.h sys/random.h-t sys/socket.h sys/socket.h-t \
+	sys/stat.h sys/stat.h-t sys/time.h sys/time.h-t sys/types.h \
+	sys/types.h-t sys/uio.h sys/uio.h-t time.h time.h-t unistd.h \
+	unistd.h-t wchar.h wchar.h-t wctype.h wctype.h-t
 MOSTLYCLEANDIRS = arpa netinet sys sys sys sys
 CLEANFILES = 
 DISTCLEANFILES = 
@@ -2972,6 +2985,32 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
 	} > $@-t && \
 	mv $@-t $@
 
+# We need the following in order to create <netdb.h> when the system
+# doesn't have one that works with the given compiler.
+netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
+	      -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
+	      -e 's/@''GNULIB_GETADDRINFO''@/$(GNULIB_GETADDRINFO)/g' \
+	      -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
+	      -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
+	      -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
+	      -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \
+	      -e 's|@''REPLACE_GETADDRINFO''@|$(REPLACE_GETADDRINFO)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/netdb.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <netinet/in.h> when the system
 # doesn't have one.
 @GL_GENERATE_NETINET_IN_H_TRUE@netinet/in.h: netinet_in.in.h $(top_builddir)/config.status
diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4
index d21f54296d62..54ee8ca68bb9 100644
--- a/gnulib/import/m4/gnulib-cache.m4
+++ b/gnulib/import/m4/gnulib-cache.m4
@@ -63,6 +63,7 @@
 #  mkdir \
 #  mkdtemp \
 #  mkostemp \
+#  netdb \
 #  pathmax \
 #  rawmemchr \
 #  readlink \
@@ -109,6 +110,7 @@ gl_MODULES([
   mkdir
   mkdtemp
   mkostemp
+  netdb
   pathmax
   rawmemchr
   readlink
diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4
index d4734854fbc1..0bf0d171ee49 100644
--- a/gnulib/import/m4/gnulib-comp.m4
+++ b/gnulib/import/m4/gnulib-comp.m4
@@ -152,6 +152,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module msvc-inval:
   # Code from module msvc-nothrow:
   # Code from module multiarch:
+  # Code from module netdb:
   # Code from module netinet_in:
   # Code from module nocrash:
   # Code from module open:
@@ -598,6 +599,7 @@ AC_DEFUN([gl_INIT],
   fi
   gl_MODULE_INDICATOR([msvc-nothrow])
   gl_MULTIARCH
+  gl_HEADER_NETDB
   gl_HEADER_NETINET_IN
   AC_PROG_MKDIR_P
   gl_FUNC_OPEN
@@ -1101,6 +1103,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/msvc-inval.h
   lib/msvc-nothrow.c
   lib/msvc-nothrow.h
+  lib/netdb.in.h
   lib/netinet_in.in.h
   lib/open.c
   lib/openat-die.c
@@ -1289,6 +1292,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/msvc-inval.m4
   m4/msvc-nothrow.m4
   m4/multiarch.m4
+  m4/netdb_h.m4
   m4/netinet_in_h.m4
   m4/nocrash.m4
   m4/off_t.m4
diff --git a/gnulib/import/m4/netdb_h.m4 b/gnulib/import/m4/netdb_h.m4
new file mode 100644
index 000000000000..db84c787e989
--- /dev/null
+++ b/gnulib/import/m4/netdb_h.m4
@@ -0,0 +1,44 @@
+# netdb_h.m4 serial 12
+dnl Copyright (C) 2008-2021 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.
+
+AC_DEFUN([gl_HEADER_NETDB],
+[
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  gl_CHECK_NEXT_HEADERS([netdb.h])
+  if test $ac_cv_header_netdb_h = yes; then
+    HAVE_NETDB_H=1
+  else
+    HAVE_NETDB_H=0
+  fi
+  AC_SUBST([HAVE_NETDB_H])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <netdb.h>]],
+    [getaddrinfo freeaddrinfo gai_strerror getnameinfo])
+])
+
+AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_NETDB_H_DEFAULTS],
+[
+  GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_STRUCT_ADDRINFO=1;   AC_SUBST([HAVE_STRUCT_ADDRINFO])
+  HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO])
+  HAVE_DECL_GAI_STRERROR=1; AC_SUBST([HAVE_DECL_GAI_STRERROR])
+  HAVE_DECL_GETADDRINFO=1;  AC_SUBST([HAVE_DECL_GETADDRINFO])
+  HAVE_DECL_GETNAMEINFO=1;  AC_SUBST([HAVE_DECL_GETNAMEINFO])
+  REPLACE_GAI_STRERROR=0;   AC_SUBST([REPLACE_GAI_STRERROR])
+  REPLACE_GETADDRINFO=0;    AC_SUBST([REPLACE_GETADDRINFO])
+])
diff --git a/gnulib/import/netdb.in.h b/gnulib/import/netdb.in.h
new file mode 100644
index 000000000000..4b1cab14b2e3
--- /dev/null
+++ b/gnulib/import/netdb.in.h
@@ -0,0 +1,295 @@
+/* Provide a netdb.h header file for systems lacking it (read: MinGW).
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   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
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+/* This file is supposed to be used on platforms that lack <netdb.h>.
+   It is intended to provide definitions and prototypes needed by an
+   application.  */
+
+#ifndef _@GUARD_PREFIX@_NETDB_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+#if @HAVE_NETDB_H@
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_NETDB_H@
+
+#endif
+
+#ifndef _@GUARD_PREFIX@_NETDB_H
+#define _@GUARD_PREFIX@_NETDB_H
+
+/* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
+   'struct hostent' on MinGW.  */
+#include <sys/socket.h>
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+/* Declarations for a platform that lacks <netdb.h>, or where it is
+   incomplete.  */
+
+#if @GNULIB_GETADDRINFO@
+
+# if !@HAVE_STRUCT_ADDRINFO@
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif
+
+#  if !GNULIB_defined_struct_addrinfo
+/* Structure to contain information about address of a service provider.  */
+struct addrinfo
+{
+  int ai_flags;                 /* Input flags.  */
+  int ai_family;                /* Protocol family for socket.  */
+  int ai_socktype;              /* Socket type.  */
+  int ai_protocol;              /* Protocol for socket.  */
+  socklen_t ai_addrlen;         /* Length of socket address.  */
+  struct sockaddr *ai_addr;     /* Socket address for socket.  */
+  char *ai_canonname;           /* Canonical name for service location.  */
+  struct addrinfo *ai_next;     /* Pointer to next in list.  */
+};
+#   define GNULIB_defined_struct_addrinfo 1
+#  endif
+
+#  ifdef __cplusplus
+}
+#  endif
+
+# endif
+
+/* Possible values for 'ai_flags' field in 'addrinfo' structure.  */
+# ifndef AI_PASSIVE
+#  define AI_PASSIVE    0x0001  /* Socket address is intended for 'bind'.  */
+# endif
+# ifndef AI_CANONNAME
+#  define AI_CANONNAME  0x0002  /* Request for canonical name.  */
+# endif
+# ifndef AI_NUMERICSERV
+#  define AI_NUMERICSERV        0x0400  /* Don't use name resolution.  */
+# endif
+
+# if 0
+#  define AI_NUMERICHOST        0x0004  /* Don't use name resolution.  */
+# endif
+
+/* These symbolic constants are required to be present by POSIX, but
+   our getaddrinfo replacement doesn't use them (yet).  Setting them
+   to 0 on systems that doesn't have them avoids causing problems for
+   system getaddrinfo implementations that would be confused by
+   unknown values.  */
+# ifndef AI_V4MAPPED
+#  define AI_V4MAPPED    0 /* 0x0008: IPv4 mapped addresses are acceptable.  */
+# endif
+# ifndef AI_ALL
+#  define AI_ALL         0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
+# endif
+# ifndef AI_ADDRCONFIG
+#  define AI_ADDRCONFIG  0 /* 0x0020: Use configuration of this host to choose
+                                      returned address type.  */
+# endif
+
+/* Error values for 'getaddrinfo' function.  */
+# ifndef EAI_BADFLAGS
+#  define EAI_BADFLAGS    -1    /* Invalid value for 'ai_flags' field.  */
+#  define EAI_NONAME      -2    /* NAME or SERVICE is unknown.  */
+#  define EAI_AGAIN       -3    /* Temporary failure in name resolution.  */
+#  define EAI_FAIL        -4    /* Non-recoverable failure in name res.  */
+#  define EAI_NODATA      -5    /* No address associated with NAME.  */
+#  define EAI_FAMILY      -6    /* 'ai_family' not supported.  */
+#  define EAI_SOCKTYPE    -7    /* 'ai_socktype' not supported.  */
+#  define EAI_SERVICE     -8    /* SERVICE not supported for 'ai_socktype'.  */
+#  define EAI_MEMORY      -10   /* Memory allocation failure.  */
+# endif
+
+/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
+   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
+   in favor of EAI_NONAME.  */
+# if !defined EAI_NODATA && defined EAI_NONAME
+#  define EAI_NODATA EAI_NONAME
+# endif
+
+# ifndef EAI_OVERFLOW
+/* Not defined on mingw32 and Haiku. */
+#  define EAI_OVERFLOW    -12   /* Argument buffer overflow.  */
+# endif
+# ifndef EAI_ADDRFAMILY
+/* Not defined on mingw32. */
+#  define EAI_ADDRFAMILY  -9    /* Address family for NAME not supported.  */
+# endif
+# ifndef EAI_SYSTEM
+/* Not defined on mingw32. */
+#  define EAI_SYSTEM      -11   /* System error returned in 'errno'.  */
+# endif
+
+# if 0
+/* The commented out definitions below are not yet implemented in the
+   GNULIB getaddrinfo() replacement, so are not yet needed.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  ifndef EAI_INPROGRESS
+#   define EAI_INPROGRESS       -100    /* Processing request in progress.  */
+#   define EAI_CANCELED         -101    /* Request canceled.  */
+#   define EAI_NOTCANCELED      -102    /* Request not canceled.  */
+#   define EAI_ALLDONE          -103    /* All requests done.  */
+#   define EAI_INTR             -104    /* Interrupted by a signal.  */
+#   define EAI_IDN_ENCODE       -105    /* IDN encoding failed.  */
+#  endif
+# endif
+
+/* Translate name of a service location and/or a service name to set of
+   socket addresses.
+   For more details, see the POSIX:2008 specification
+   <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>.  */
+# if @REPLACE_GETADDRINFO@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef getaddrinfo
+#   define getaddrinfo rpl_getaddrinfo
+#  endif
+_GL_FUNCDECL_RPL (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res)
+                  _GL_ARG_NONNULL ((4)));
+_GL_CXXALIAS_RPL (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res));
+# else
+#  if !@HAVE_DECL_GETADDRINFO@
+_GL_FUNCDECL_SYS (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res)
+                  _GL_ARG_NONNULL ((4)));
+#  endif
+_GL_CXXALIAS_SYS (getaddrinfo, int,
+                  (const char *restrict nodename,
+                   const char *restrict servname,
+                   const struct addrinfo *restrict hints,
+                   struct addrinfo **restrict res));
+# endif
+_GL_CXXALIASWARN (getaddrinfo);
+
+/* Free 'addrinfo' structure AI including associated storage.
+   For more details, see the POSIX:2008 specification
+   <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>.  */
+# if @REPLACE_GETADDRINFO@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef freeaddrinfo
+#   define freeaddrinfo rpl_freeaddrinfo
+#  endif
+_GL_FUNCDECL_RPL (freeaddrinfo, void, (struct addrinfo *ai)
+                                      _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (freeaddrinfo, void, (struct addrinfo *ai));
+# else
+#  if !@HAVE_DECL_FREEADDRINFO@
+_GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
+                                      _GL_ARG_NONNULL ((1)));
+#  endif
+_GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
+# endif
+_GL_CXXALIASWARN (freeaddrinfo);
+
+# if @REPLACE_GAI_STRERROR@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gai_strerror
+#   define gai_strerror rpl_gai_strerror
+#  endif
+_GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode));
+_GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
+# else
+#  if !@HAVE_DECL_GAI_STRERROR@
+/* Convert error return from getaddrinfo() to a string.
+   For more details, see the POSIX:2008 specification
+   <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>.  */
+_GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
+#  endif
+_GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (gai_strerror);
+# endif
+
+# if !@HAVE_DECL_GETNAMEINFO@
+/* Convert socket address to printable node and service names.
+   For more details, see the POSIX:2008 specification
+   <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>.  */
+_GL_FUNCDECL_SYS (getnameinfo, int,
+                  (const struct sockaddr *restrict sa, socklen_t salen,
+                   char *restrict node, socklen_t nodelen,
+                   char *restrict service, socklen_t servicelen,
+                   int flags)
+                  _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on glibc systems, the seventh parameter is
+                        unsigned int flags.  */
+_GL_CXXALIAS_SYS_CAST (getnameinfo, int,
+                       (const struct sockaddr *restrict sa, socklen_t salen,
+                        char *restrict node, socklen_t nodelen,
+                        char *restrict service, socklen_t servicelen,
+                        int flags));
+_GL_CXXALIASWARN (getnameinfo);
+
+/* Possible flags for getnameinfo.  */
+# ifndef NI_NUMERICHOST
+#  define NI_NUMERICHOST 1
+# endif
+# ifndef NI_NUMERICSERV
+#  define NI_NUMERICSERV 2
+# endif
+
+#elif defined GNULIB_POSIXCHECK
+
+# undef getaddrinfo
+# if HAVE_RAW_DECL_GETADDRINFO
+_GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
+                 "use gnulib module getaddrinfo for portability");
+# endif
+
+# undef freeaddrinfo
+# if HAVE_RAW_DECL_FREEADDRINFO
+_GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
+                 "use gnulib module getaddrinfo for portability");
+# endif
+
+# undef gai_strerror
+# if HAVE_RAW_DECL_GAI_STRERROR
+_GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
+                 "use gnulib module getaddrinfo for portability");
+# endif
+
+# undef getnameinfo
+# if HAVE_RAW_DECL_GETNAMEINFO
+_GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
+                 "use gnulib module getaddrinfo for portability");
+# endif
+
+#endif
+
+#endif /* _@GUARD_PREFIX@_NETDB_H */
+#endif /* _@GUARD_PREFIX@_NETDB_H */
diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh
index 44e8db47e2ba..252f163bf2ed 100755
--- a/gnulib/update-gnulib.sh
+++ b/gnulib/update-gnulib.sh
@@ -55,6 +55,7 @@ IMPORTED_GNULIB_MODULES="\
     mkdir \
     mkdtemp \
     mkostemp \
+    netdb \
     pathmax \
     rawmemchr \
     readlink \
-- 
2.31.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 4/4] gnulib: import select
  2021-05-29 17:25 [PATCH 1/4] gnulib: import chown Mike Frysinger
  2021-05-29 17:25 ` [PATCH 2/4] sim: v850: assume chown is available Mike Frysinger
  2021-05-29 17:25 ` [PATCH 3/4] gnulib: import netdb Mike Frysinger
@ 2021-05-29 17:25 ` Mike Frysinger
  2021-06-07 14:29   ` Tom Tromey
  2021-06-07 14:23 ` [PATCH 1/4] gnulib: import chown Tom Tromey
  3 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-05-29 17:25 UTC (permalink / raw)
  To: gdb-patches

A few sims use this to emulate the syscall & provide network
functionality.
---
 gnulib/Makefile.gnulib.inc.in    |   2 +-
 gnulib/Makefile.in               |  14 +
 gnulib/aclocal.m4                |   4 +
 gnulib/config.in                 |   9 +
 gnulib/configure                 | 604 +++++++++++++++++++++++++++++++
 gnulib/import/Makefile.am        |  52 +++
 gnulib/import/Makefile.in        |  93 +++--
 gnulib/import/m4/gnulib-cache.m4 |   2 +
 gnulib/import/m4/gnulib-comp.m4  |  22 ++
 gnulib/import/m4/select.m4       | 117 ++++++
 gnulib/import/m4/socketlib.m4    |  96 +++++
 gnulib/import/m4/sockets.m4      |  17 +
 gnulib/import/m4/sys_select_h.m4 |  95 +++++
 gnulib/import/select.c           | 597 ++++++++++++++++++++++++++++++
 gnulib/import/sockets.c          | 161 ++++++++
 gnulib/import/sockets.h          |  66 ++++
 gnulib/import/sys_select.in.h    | 326 +++++++++++++++++
 gnulib/import/w32sock.h          | 140 +++++++
 gnulib/update-gnulib.sh          |   1 +
 19 files changed, 2392 insertions(+), 26 deletions(-)
 create mode 100644 gnulib/import/m4/select.m4
 create mode 100644 gnulib/import/m4/socketlib.m4
 create mode 100644 gnulib/import/m4/sockets.m4
 create mode 100644 gnulib/import/m4/sys_select_h.m4
 create mode 100644 gnulib/import/select.c
 create mode 100644 gnulib/import/sockets.c
 create mode 100644 gnulib/import/sockets.h
 create mode 100644 gnulib/import/sys_select.in.h
 create mode 100644 gnulib/import/w32sock.h

diff --git a/gnulib/Makefile.gnulib.inc.in b/gnulib/Makefile.gnulib.inc.in
index 8cac19fca0d1..822f892a189a 100644
--- a/gnulib/Makefile.gnulib.inc.in
+++ b/gnulib/Makefile.gnulib.inc.in
@@ -40,5 +40,5 @@ LIBGNU = $(GNULIB_BUILDDIR)/import/libgnu.a
 LIBGNU_EXTRA_LIBS = @FREXPL_LIBM@ @FREXP_LIBM@ @INET_NTOP_LIB@ \
                     @LIBTHREAD@ @LIB_GETLOGIN@ @LIB_GETRANDOM@ \
                     @LIB_HARD_LOCALE@ @LIB_MBRTOWC@ \
-                    @LIB_SETLOCALE_NULL@ @LIBINTL@
+                    @LIB_SETLOCALE_NULL@ @LIBINTL@ @LIB_SELECT@ @LIBSOCKET@
 INCGNU = -I$(srcdir)/../gnulib/import -I$(GNULIB_BUILDDIR)/import
diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in
index be154720295d..e1b9b34a794e 100644
--- a/gnulib/Makefile.in
+++ b/gnulib/Makefile.in
@@ -231,9 +231,12 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/rewinddir.m4 \
 	$(top_srcdir)/import/m4/rmdir.m4 \
 	$(top_srcdir)/import/m4/save-cwd.m4 \
+	$(top_srcdir)/import/m4/select.m4 \
 	$(top_srcdir)/import/m4/setenv.m4 \
 	$(top_srcdir)/import/m4/setlocale_null.m4 \
 	$(top_srcdir)/import/m4/signal_h.m4 \
+	$(top_srcdir)/import/m4/socketlib.m4 \
+	$(top_srcdir)/import/m4/sockets.m4 \
 	$(top_srcdir)/import/m4/socklen.m4 \
 	$(top_srcdir)/import/m4/sockpfaf.m4 \
 	$(top_srcdir)/import/m4/ssize_t.m4 \
@@ -256,6 +259,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
+	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
 	$(top_srcdir)/import/m4/sys_stat_h.m4 \
 	$(top_srcdir)/import/m4/sys_time_h.m4 \
@@ -680,6 +684,7 @@ GNULIB_POWF = @GNULIB_POWF@
 GNULIB_PREAD = @GNULIB_PREAD@
 GNULIB_PRINTF = @GNULIB_PRINTF@
 GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@
+GNULIB_PSELECT = @GNULIB_PSELECT@
 GNULIB_PTHREAD_SIGMASK = @GNULIB_PTHREAD_SIGMASK@
 GNULIB_PTSNAME = @GNULIB_PTSNAME@
 GNULIB_PTSNAME_R = @GNULIB_PTSNAME_R@
@@ -720,6 +725,7 @@ GNULIB_RPMATCH = @GNULIB_RPMATCH@
 GNULIB_SCANDIR = @GNULIB_SCANDIR@
 GNULIB_SCANF = @GNULIB_SCANF@
 GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@
+GNULIB_SELECT = @GNULIB_SELECT@
 GNULIB_SEND = @GNULIB_SEND@
 GNULIB_SENDTO = @GNULIB_SENDTO@
 GNULIB_SETENV = @GNULIB_SETENV@
@@ -1088,6 +1094,7 @@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@
 HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@
 HAVE_POWF = @HAVE_POWF@
 HAVE_PREAD = @HAVE_PREAD@
+HAVE_PSELECT = @HAVE_PSELECT@
 HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@
 HAVE_PTSNAME = @HAVE_PTSNAME@
 HAVE_PTSNAME_R = @HAVE_PTSNAME_R@
@@ -1161,6 +1168,7 @@ HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
+HAVE_SYS_SELECT_H = @HAVE_SYS_SELECT_H@
 HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@
 HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@
 HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
@@ -1244,6 +1252,7 @@ LIBOBJS = @LIBOBJS@
 LIBPMULTITHREAD = @LIBPMULTITHREAD@
 LIBPTHREAD = @LIBPTHREAD@
 LIBS = @LIBS@
+LIBSOCKET = @LIBSOCKET@
 LIBSTDTHREAD = @LIBSTDTHREAD@
 LIBTHREAD = @LIBTHREAD@
 LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
@@ -1252,6 +1261,7 @@ LIB_GETRANDOM = @LIB_GETRANDOM@
 LIB_HARD_LOCALE = @LIB_HARD_LOCALE@
 LIB_MBRTOWC = @LIB_MBRTOWC@
 LIB_SCHED_YIELD = @LIB_SCHED_YIELD@
+LIB_SELECT = @LIB_SELECT@
 LIB_SETLOCALE_NULL = @LIB_SETLOCALE_NULL@
 LIMITS_H = @LIMITS_H@
 LN_S = @LN_S@
@@ -1291,6 +1301,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H@
@@ -1321,6 +1332,7 @@ NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
+NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
 NEXT_SYS_STAT_H = @NEXT_SYS_STAT_H@
 NEXT_SYS_TIME_H = @NEXT_SYS_TIME_H@
@@ -1514,6 +1526,7 @@ REPLACE_POPEN = @REPLACE_POPEN@
 REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@
 REPLACE_PREAD = @REPLACE_PREAD@
 REPLACE_PRINTF = @REPLACE_PRINTF@
+REPLACE_PSELECT = @REPLACE_PSELECT@
 REPLACE_PTHREAD_SIGMASK = @REPLACE_PTHREAD_SIGMASK@
 REPLACE_PTSNAME = @REPLACE_PTSNAME@
 REPLACE_PTSNAME_R = @REPLACE_PTSNAME_R@
@@ -1539,6 +1552,7 @@ REPLACE_RMDIR = @REPLACE_RMDIR@
 REPLACE_ROUND = @REPLACE_ROUND@
 REPLACE_ROUNDF = @REPLACE_ROUNDF@
 REPLACE_ROUNDL = @REPLACE_ROUNDL@
+REPLACE_SELECT = @REPLACE_SELECT@
 REPLACE_SETENV = @REPLACE_SETENV@
 REPLACE_SETLOCALE = @REPLACE_SETLOCALE@
 REPLACE_SETSTATE = @REPLACE_SETSTATE@
diff --git a/gnulib/aclocal.m4 b/gnulib/aclocal.m4
index 96f7dc60af7f..83780b641ac4 100644
--- a/gnulib/aclocal.m4
+++ b/gnulib/aclocal.m4
@@ -1304,9 +1304,12 @@ m4_include([import/m4/rename.m4])
 m4_include([import/m4/rewinddir.m4])
 m4_include([import/m4/rmdir.m4])
 m4_include([import/m4/save-cwd.m4])
+m4_include([import/m4/select.m4])
 m4_include([import/m4/setenv.m4])
 m4_include([import/m4/setlocale_null.m4])
 m4_include([import/m4/signal_h.m4])
+m4_include([import/m4/socketlib.m4])
+m4_include([import/m4/sockets.m4])
 m4_include([import/m4/socklen.m4])
 m4_include([import/m4/sockpfaf.m4])
 m4_include([import/m4/ssize_t.m4])
@@ -1329,6 +1332,7 @@ m4_include([import/m4/strnlen.m4])
 m4_include([import/m4/strstr.m4])
 m4_include([import/m4/strtok_r.m4])
 m4_include([import/m4/sys_random_h.m4])
+m4_include([import/m4/sys_select_h.m4])
 m4_include([import/m4/sys_socket_h.m4])
 m4_include([import/m4/sys_stat_h.m4])
 m4_include([import/m4/sys_time_h.m4])
diff --git a/gnulib/config.in b/gnulib/config.in
index 15abb17cb445..a90ddd611823 100644
--- a/gnulib/config.in
+++ b/gnulib/config.in
@@ -303,6 +303,9 @@
 /* Define to 1 when the gnulib module rmdir should be tested. */
 #undef GNULIB_TEST_RMDIR
 
+/* Define to 1 when the gnulib module select should be tested. */
+#undef GNULIB_TEST_SELECT
+
 /* Define to 1 when the gnulib module setenv should be tested. */
 #undef GNULIB_TEST_SETENV
 
@@ -880,6 +883,9 @@
 /* Define to 1 if you have the <sys/random.h> header file. */
 #undef HAVE_SYS_RANDOM_H
 
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
 /* Define to 1 if you have the <sys/socket.h> header file. */
 #undef HAVE_SYS_SOCKET_H
 
@@ -1252,6 +1258,9 @@
    'wchar_t'. */
 #undef WCHAR_T_SUFFIX
 
+/* Define if WSAStartup is needed. */
+#undef WINDOWS_SOCKETS
+
 /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
    'wint_t'. */
 #undef WINT_T_SUFFIX
diff --git a/gnulib/configure b/gnulib/configure
index d447121f4f16..73a38082960a 100644
--- a/gnulib/configure
+++ b/gnulib/configure
@@ -776,6 +776,16 @@ GNULIB_SIGPROCMASK
 GNULIB_SIGNAL_H_SIGPIPE
 GNULIB_RAISE
 GNULIB_PTHREAD_SIGMASK
+LIB_SELECT
+LIBSOCKET
+HAVE_SYS_SELECT_H
+NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H
+NEXT_SYS_SELECT_H
+REPLACE_SELECT
+REPLACE_PSELECT
+HAVE_PSELECT
+GNULIB_SELECT
+GNULIB_PSELECT
 GL_GENERATE_NETINET_IN_H_FALSE
 GL_GENERATE_NETINET_IN_H_TRUE
 NETINET_IN_H
@@ -3783,6 +3793,7 @@ as_fn_append ac_func_list " openat"
 as_fn_append ac_func_list " pipe"
 as_fn_append ac_func_list " readlink"
 as_fn_append ac_func_list " link"
+as_fn_append ac_header_list " sys/select.h"
 as_fn_append ac_func_list " setenv"
 as_fn_append ac_func_list " strerror_r"
 as_fn_append ac_func_list " __xpg_strerror_r"
@@ -6813,6 +6824,7 @@ fi
   # Code from module same-inode:
   # Code from module save-cwd:
   # Code from module scratch_buffer:
+  # Code from module select:
   # Code from module setenv:
   # Code from module setlocale-null:
   # Code from module signal-h:
@@ -6820,6 +6832,8 @@ fi
   # Code from module snippet/arg-nonnull:
   # Code from module snippet/c++defs:
   # Code from module snippet/warn-on-use:
+  # Code from module socketlib:
+  # Code from module sockets:
   # Code from module socklen:
   # Code from module ssize_t:
   # Code from module stat:
@@ -6845,6 +6859,7 @@ fi
   # Code from module strstr-simple:
   # Code from module strtok_r:
   # Code from module sys_random:
+  # Code from module sys_select:
   # Code from module sys_socket:
   # Code from module sys_stat:
   # Code from module sys_time:
@@ -16475,6 +16490,409 @@ _ACEOF
 
 
 
+
+  GNULIB_PSELECT=0;
+  GNULIB_SELECT=0;
+    HAVE_PSELECT=1;
+  REPLACE_PSELECT=0;
+  REPLACE_SELECT=0;
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <sys/select.h> is self-contained" >&5
+$as_echo_n "checking whether <sys/select.h> is self-contained... " >&6; }
+if ${gl_cv_header_sys_select_h_selfcontained+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+                                    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/select.h>
+int
+main ()
+{
+struct timeval b;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gl_cv_header_sys_select_h_selfcontained=yes
+else
+  gl_cv_header_sys_select_h_selfcontained=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+                        if test $gl_cv_header_sys_select_h_selfcontained = yes; then
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/select.h>
+int
+main ()
+{
+int memset; int bzero;
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/select.h>
+int
+main ()
+{
+
+                  #undef memset
+                  #define memset nonexistent_memset
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void *memset (void *, int, unsigned long);
+                  #undef bzero
+                  #define bzero nonexistent_bzero
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void bzero (void *, unsigned long);
+                  fd_set fds;
+                  FD_ZERO (&fds);
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  gl_cv_header_sys_select_h_selfcontained=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+      fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_header_sys_select_h_selfcontained" >&5
+$as_echo "$gl_cv_header_sys_select_h_selfcontained" >&6; }
+
+
+
+
+
+
+
+
+
+     if test $gl_cv_have_include_next = yes; then
+       gl_cv_next_sys_select_h='<'sys/select.h'>'
+     else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking absolute name of <sys/select.h>" >&5
+$as_echo_n "checking absolute name of <sys/select.h>... " >&6; }
+if ${gl_cv_next_sys_select_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+             if test $ac_cv_header_sys_select_h = yes; then
+
+
+
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/select.h>
+_ACEOF
+                case "$host_os" in
+    aix*) gl_absname_cpp="$ac_cpp -C" ;;
+    *)    gl_absname_cpp="$ac_cpp" ;;
+  esac
+
+  case "$host_os" in
+    mingw*)
+                                          gl_dirsep_regex='[/\\]'
+      ;;
+    *)
+      gl_dirsep_regex='\/'
+      ;;
+  esac
+      gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
+  gl_header_literal_regex=`echo 'sys/select.h' \
+                           | sed -e "$gl_make_literal_regex_sed"`
+  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
+      s|^/[^/]|//&|
+      p
+      q
+    }'
+
+        gl_cv_absolute_sys_select_h=`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&5 |
+  sed -n "$gl_absolute_header_sed"`
+
+           gl_header=$gl_cv_absolute_sys_select_h
+           gl_cv_next_sys_select_h='"'$gl_header'"'
+          else
+               gl_cv_next_sys_select_h='<'sys/select.h'>'
+             fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_next_sys_select_h" >&5
+$as_echo "$gl_cv_next_sys_select_h" >&6; }
+     fi
+     NEXT_SYS_SELECT_H=$gl_cv_next_sys_select_h
+
+     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
+       gl_next_as_first_directive='<'sys/select.h'>'
+     else
+       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
+       gl_next_as_first_directive=$gl_cv_next_sys_select_h
+     fi
+     NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H=$gl_next_as_first_directive
+
+
+
+
+  if test $ac_cv_header_sys_select_h = yes; then
+    HAVE_SYS_SELECT_H=1
+  else
+    HAVE_SYS_SELECT_H=0
+  fi
+
+
+
+
+
+  if test $ac_cv_header_sys_socket_h != yes; then
+                    for ac_header in winsock2.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default"
+if test "x$ac_cv_header_winsock2_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_WINSOCK2_H 1
+_ACEOF
+
+fi
+
+done
+
+  fi
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    HAVE_WINSOCK2_H=1
+    UNISTD_H_HAVE_WINSOCK2_H=1
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
+  else
+    HAVE_WINSOCK2_H=0
+  fi
+
+
+
+
+
+
+
+
+
+
+
+
+  if test $ac_cv_header_sys_socket_h != yes; then
+                    for ac_header in winsock2.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "winsock2.h" "ac_cv_header_winsock2_h" "$ac_includes_default"
+if test "x$ac_cv_header_winsock2_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_WINSOCK2_H 1
+_ACEOF
+
+fi
+
+done
+
+  fi
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    HAVE_WINSOCK2_H=1
+    UNISTD_H_HAVE_WINSOCK2_H=1
+    SYS_IOCTL_H_HAVE_WINSOCK2_H=1
+  else
+    HAVE_WINSOCK2_H=0
+  fi
+
+   LIBSOCKET=
+  if test $HAVE_WINSOCK2_H = 1; then
+                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for WSAStartup" >&5
+$as_echo_n "checking for WSAStartup... " >&6; }
+if ${gl_cv_func_wsastartup+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+       gl_save_LIBS="$LIBS"
+       LIBS="$LIBS -lws2_32"
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif
+int
+main ()
+{
+
+            WORD wVersionRequested = MAKEWORD(1, 1);
+            WSADATA wsaData;
+            int err = WSAStartup(wVersionRequested, &wsaData);
+            WSACleanup ();
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gl_cv_func_wsastartup=yes
+else
+  gl_cv_func_wsastartup=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+       LIBS="$gl_save_LIBS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_wsastartup" >&5
+$as_echo "$gl_cv_func_wsastartup" >&6; }
+    if test "$gl_cv_func_wsastartup" = "yes"; then
+
+$as_echo "#define WINDOWS_SOCKETS 1" >>confdefs.h
+
+      LIBSOCKET='-lws2_32'
+    fi
+  else
+                                    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing setsockopt" >&5
+$as_echo_n "checking for library containing setsockopt... " >&6; }
+if ${gl_cv_lib_socket+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+      gl_cv_lib_socket=
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();
+int
+main ()
+{
+setsockopt();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  gl_save_LIBS="$LIBS"
+         LIBS="$gl_save_LIBS -lsocket"
+         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();
+int
+main ()
+{
+setsockopt();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gl_cv_lib_socket="-lsocket"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+         if test -z "$gl_cv_lib_socket"; then
+           LIBS="$gl_save_LIBS -lnetwork"
+           cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();
+int
+main ()
+{
+setsockopt();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gl_cv_lib_socket="-lnetwork"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+           if test -z "$gl_cv_lib_socket"; then
+             LIBS="$gl_save_LIBS -lnet"
+             cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();
+int
+main ()
+{
+setsockopt();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  gl_cv_lib_socket="-lnet"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+           fi
+         fi
+         LIBS="$gl_save_LIBS"
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+      if test -z "$gl_cv_lib_socket"; then
+        gl_cv_lib_socket="none needed"
+      fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_lib_socket" >&5
+$as_echo "$gl_cv_lib_socket" >&6; }
+    if test "$gl_cv_lib_socket" != "none needed"; then
+      LIBSOCKET="$gl_cv_lib_socket"
+    fi
+  fi
+
+
+
+
+
+
+  :
+
+
 ac_fn_c_check_decl "$LINENO" "setenv" "ac_cv_have_decl_setenv" "$ac_includes_default"
 if test "x$ac_cv_have_decl_setenv" = xyes; then :
   ac_have_decl=1
@@ -27598,6 +28016,188 @@ $as_echo "#define GNULIB_TEST_RMDIR 1" >>confdefs.h
 
 
 
+
+
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    REPLACE_SELECT=1
+  else
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether select supports a 0 argument" >&5
+$as_echo_n "checking whether select supports a 0 argument... " >&6; }
+if ${gl_cv_func_select_supports0+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+        if test "$cross_compiling" = yes; then :
+
+           case "$host_os" in
+                       # Guess no on Interix.
+             interix*) gl_cv_func_select_supports0="guessing no";;
+                       # Guess yes otherwise.
+             *)        gl_cv_func_select_supports0="guessing yes";;
+           esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+int main ()
+{
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 5;
+  return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_select_supports0=yes
+else
+  gl_cv_func_select_supports0=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_select_supports0" >&5
+$as_echo "$gl_cv_func_select_supports0" >&6; }
+    case "$gl_cv_func_select_supports0" in
+      *yes) ;;
+      *) REPLACE_SELECT=1 ;;
+    esac
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether select detects invalid fds" >&5
+$as_echo_n "checking whether select detects invalid fds... " >&6; }
+if ${gl_cv_func_select_detects_ebadf+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+        if test "$cross_compiling" = yes; then :
+
+           case "$host_os" in
+                             # Guess yes on Linux systems.
+            linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;;
+                             # Guess yes on glibc systems.
+            *-gnu* | gnu*)   gl_cv_func_select_detects_ebadf="guessing yes" ;;
+                             # If we don't know, obey --enable-cross-guesses.
+            *)               gl_cv_func_select_detects_ebadf="$gl_cross_guess_normal" ;;
+           esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#include <unistd.h>
+#include <errno.h>
+
+
+$gl_mda_defines
+
+int
+main ()
+{
+
+  fd_set set;
+  dup2(0, 16);
+  FD_ZERO(&set);
+  FD_SET(16, &set);
+  close(16);
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 5;
+  return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_select_detects_ebadf=yes
+else
+  gl_cv_func_select_detects_ebadf=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_select_detects_ebadf" >&5
+$as_echo "$gl_cv_func_select_detects_ebadf" >&6; }
+    case $gl_cv_func_select_detects_ebadf in
+      *yes) ;;
+      *) REPLACE_SELECT=1 ;;
+    esac
+  fi
+
+    LIB_SELECT="$LIBSOCKET"
+  if test $REPLACE_SELECT = 1; then
+    case "$host_os" in
+      mingw*)
+                                cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+int
+main ()
+{
+  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+else
+  LIB_SELECT="$LIB_SELECT -luser32"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+        ;;
+    esac
+  fi
+
+
+  if test $REPLACE_SELECT = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS select.$ac_objext"
+
+  fi
+
+
+
+
+
+          GNULIB_SELECT=1
+
+
+
+
+
+$as_echo "#define GNULIB_TEST_SELECT 1" >>confdefs.h
+
+
+
+
+
      if test $ac_cv_func_setenv = no; then
     HAVE_SETENV=0
   else
@@ -28113,6 +28713,8 @@ fi
 
 
 
+
+
      ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "
 /* <sys/types.h> is not needed according to POSIX, but the
    <sys/socket.h> in i386-unknown-freebsd4.10 and
@@ -29918,6 +30520,8 @@ $as_echo "$gl_cv_next_sys_random_h" >&6; }
 
 
 
+
+
 
 
 
diff --git a/gnulib/import/Makefile.am b/gnulib/import/Makefile.am
index 2a11accc8d61..1ae25ac28050 100644
--- a/gnulib/import/Makefile.am
+++ b/gnulib/import/Makefile.am
@@ -63,6 +63,7 @@
 #  rawmemchr \
 #  readlink \
 #  rename \
+#  select \
 #  setenv \
 #  signal-h \
 #  strchrnul \
@@ -1701,6 +1702,15 @@ EXTRA_DIST += malloc/scratch_buffer.h scratch_buffer.h
 
 ## end   gnulib module scratch_buffer
 
+## begin gnulib module select
+
+
+EXTRA_DIST += select.c
+
+EXTRA_libgnu_a_SOURCES += select.c
+
+## end   gnulib module select
+
 ## begin gnulib module setenv
 
 
@@ -1810,6 +1820,14 @@ EXTRA_DIST += warn-on-use.h
 
 ## end   gnulib module snippet/warn-on-use
 
+## begin gnulib module sockets
+
+libgnu_a_SOURCES += sockets.h sockets.c
+
+EXTRA_DIST += w32sock.h
+
+## end   gnulib module sockets
+
 ## begin gnulib module stat
 
 
@@ -2492,6 +2510,40 @@ EXTRA_DIST += sys_random.in.h
 
 ## end   gnulib module sys_random
 
+## begin gnulib module sys_select
+
+BUILT_SOURCES += sys/select.h
+
+# We need the following in order to create <sys/select.h> when the system
+# doesn't have one that works with the given compiler.
+sys/select.h: sys_select.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \
+	      -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \
+	      -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \
+	      -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \
+	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \
+	      -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \
+	      -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_select.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/select.h sys/select.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_select.in.h
+
+## end   gnulib module sys_select
+
 ## begin gnulib module sys_socket
 
 BUILT_SOURCES += sys/socket.h
diff --git a/gnulib/import/Makefile.in b/gnulib/import/Makefile.in
index 96606cf73f31..e9b52a7d4fc3 100644
--- a/gnulib/import/Makefile.in
+++ b/gnulib/import/Makefile.in
@@ -77,6 +77,7 @@
 #  rawmemchr \
 #  readlink \
 #  rename \
+#  select \
 #  setenv \
 #  signal-h \
 #  strchrnul \
@@ -294,9 +295,12 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/rewinddir.m4 \
 	$(top_srcdir)/import/m4/rmdir.m4 \
 	$(top_srcdir)/import/m4/save-cwd.m4 \
+	$(top_srcdir)/import/m4/select.m4 \
 	$(top_srcdir)/import/m4/setenv.m4 \
 	$(top_srcdir)/import/m4/setlocale_null.m4 \
 	$(top_srcdir)/import/m4/signal_h.m4 \
+	$(top_srcdir)/import/m4/socketlib.m4 \
+	$(top_srcdir)/import/m4/sockets.m4 \
 	$(top_srcdir)/import/m4/socklen.m4 \
 	$(top_srcdir)/import/m4/sockpfaf.m4 \
 	$(top_srcdir)/import/m4/ssize_t.m4 \
@@ -319,6 +323,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
 	$(top_srcdir)/import/m4/strstr.m4 \
 	$(top_srcdir)/import/m4/strtok_r.m4 \
 	$(top_srcdir)/import/m4/sys_random_h.m4 \
+	$(top_srcdir)/import/m4/sys_select_h.m4 \
 	$(top_srcdir)/import/m4/sys_socket_h.m4 \
 	$(top_srcdir)/import/m4/sys_stat_h.m4 \
 	$(top_srcdir)/import/m4/sys_time_h.m4 \
@@ -366,7 +371,7 @@ am_libgnu_a_OBJECTS = openat-proc.$(OBJEXT) basename-lgpl.$(OBJEXT) \
 	malloc/scratch_buffer_grow.$(OBJEXT) \
 	malloc/scratch_buffer_grow_preserve.$(OBJEXT) \
 	malloc/scratch_buffer_set_array_size.$(OBJEXT) \
-	setlocale_null.$(OBJEXT) stat-time.$(OBJEXT) \
+	setlocale_null.$(OBJEXT) sockets.$(OBJEXT) stat-time.$(OBJEXT) \
 	strnlen1.$(OBJEXT) sys_socket.$(OBJEXT) tempname.$(OBJEXT) \
 	glthread/threadlib.$(OBJEXT) unistd.$(OBJEXT) \
 	dup-safer.$(OBJEXT) fd-safer.$(OBJEXT) pipe-safer.$(OBJEXT) \
@@ -781,6 +786,7 @@ GNULIB_POWF = @GNULIB_POWF@
 GNULIB_PREAD = @GNULIB_PREAD@
 GNULIB_PRINTF = @GNULIB_PRINTF@
 GNULIB_PRINTF_POSIX = @GNULIB_PRINTF_POSIX@
+GNULIB_PSELECT = @GNULIB_PSELECT@
 GNULIB_PTHREAD_SIGMASK = @GNULIB_PTHREAD_SIGMASK@
 GNULIB_PTSNAME = @GNULIB_PTSNAME@
 GNULIB_PTSNAME_R = @GNULIB_PTSNAME_R@
@@ -821,6 +827,7 @@ GNULIB_RPMATCH = @GNULIB_RPMATCH@
 GNULIB_SCANDIR = @GNULIB_SCANDIR@
 GNULIB_SCANF = @GNULIB_SCANF@
 GNULIB_SECURE_GETENV = @GNULIB_SECURE_GETENV@
+GNULIB_SELECT = @GNULIB_SELECT@
 GNULIB_SEND = @GNULIB_SEND@
 GNULIB_SENDTO = @GNULIB_SENDTO@
 GNULIB_SETENV = @GNULIB_SETENV@
@@ -1189,6 +1196,7 @@ HAVE_POSIX_OPENPT = @HAVE_POSIX_OPENPT@
 HAVE_POSIX_SIGNALBLOCKING = @HAVE_POSIX_SIGNALBLOCKING@
 HAVE_POWF = @HAVE_POWF@
 HAVE_PREAD = @HAVE_PREAD@
+HAVE_PSELECT = @HAVE_PSELECT@
 HAVE_PTHREAD_SIGMASK = @HAVE_PTHREAD_SIGMASK@
 HAVE_PTSNAME = @HAVE_PTSNAME@
 HAVE_PTSNAME_R = @HAVE_PTSNAME_R@
@@ -1262,6 +1270,7 @@ HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@
 HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@
 HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
 HAVE_SYS_RANDOM_H = @HAVE_SYS_RANDOM_H@
+HAVE_SYS_SELECT_H = @HAVE_SYS_SELECT_H@
 HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@
 HAVE_SYS_TIME_H = @HAVE_SYS_TIME_H@
 HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
@@ -1345,6 +1354,7 @@ LIBOBJS = @LIBOBJS@
 LIBPMULTITHREAD = @LIBPMULTITHREAD@
 LIBPTHREAD = @LIBPTHREAD@
 LIBS = @LIBS@
+LIBSOCKET = @LIBSOCKET@
 LIBSTDTHREAD = @LIBSTDTHREAD@
 LIBTHREAD = @LIBTHREAD@
 LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
@@ -1353,6 +1363,7 @@ LIB_GETRANDOM = @LIB_GETRANDOM@
 LIB_HARD_LOCALE = @LIB_HARD_LOCALE@
 LIB_MBRTOWC = @LIB_MBRTOWC@
 LIB_SCHED_YIELD = @LIB_SCHED_YIELD@
+LIB_SELECT = @LIB_SELECT@
 LIB_SETLOCALE_NULL = @LIB_SETLOCALE_NULL@
 LIMITS_H = @LIMITS_H@
 LN_S = @LN_S@
@@ -1392,6 +1403,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
 NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
 NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_RANDOM_H@
+NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SELECT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_STAT_H@
 NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TIME_H@
@@ -1422,6 +1434,7 @@ NEXT_STDLIB_H = @NEXT_STDLIB_H@
 NEXT_STRINGS_H = @NEXT_STRINGS_H@
 NEXT_STRING_H = @NEXT_STRING_H@
 NEXT_SYS_RANDOM_H = @NEXT_SYS_RANDOM_H@
+NEXT_SYS_SELECT_H = @NEXT_SYS_SELECT_H@
 NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
 NEXT_SYS_STAT_H = @NEXT_SYS_STAT_H@
 NEXT_SYS_TIME_H = @NEXT_SYS_TIME_H@
@@ -1615,6 +1628,7 @@ REPLACE_POPEN = @REPLACE_POPEN@
 REPLACE_POSIX_MEMALIGN = @REPLACE_POSIX_MEMALIGN@
 REPLACE_PREAD = @REPLACE_PREAD@
 REPLACE_PRINTF = @REPLACE_PRINTF@
+REPLACE_PSELECT = @REPLACE_PSELECT@
 REPLACE_PTHREAD_SIGMASK = @REPLACE_PTHREAD_SIGMASK@
 REPLACE_PTSNAME = @REPLACE_PTSNAME@
 REPLACE_PTSNAME_R = @REPLACE_PTSNAME_R@
@@ -1640,6 +1654,7 @@ REPLACE_RMDIR = @REPLACE_RMDIR@
 REPLACE_ROUND = @REPLACE_ROUND@
 REPLACE_ROUNDF = @REPLACE_ROUNDF@
 REPLACE_ROUNDL = @REPLACE_ROUNDL@
+REPLACE_SELECT = @REPLACE_SELECT@
 REPLACE_SETENV = @REPLACE_SETENV@
 REPLACE_SETLOCALE = @REPLACE_SETLOCALE@
 REPLACE_SETSTATE = @REPLACE_SETSTATE@
@@ -1831,14 +1846,15 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
 	rawmemchr.c rawmemchr.valgrind dirent-private.h readdir.c \
 	readlink.c realloc.c rename.c dirent-private.h rewinddir.c \
 	rmdir.c same-inode.h save-cwd.h malloc/scratch_buffer.h \
-	scratch_buffer.h setenv.c setlocale-lock.c setlocale_null.h \
-	windows-initguard.h signal.in.h _Noreturn.h arg-nonnull.h \
-	c++defs.h warn-on-use.h stat-w32.c stat-w32.h stat.c \
-	stat-time.h stdalign.in.h stdbool.in.h stddef.in.h stdint.in.h \
-	stdio.in.h stdlib.in.h strchrnul.c strchrnul.valgrind strdup.c \
-	streq.h strerror.c strerror-override.c strerror-override.h \
-	strerror_r.c string.in.h strings.in.h strnlen.c strstr.c \
-	str-two-way.h strstr.c strtok_r.c sys_random.in.h \
+	scratch_buffer.h select.c setenv.c setlocale-lock.c \
+	setlocale_null.h windows-initguard.h signal.in.h _Noreturn.h \
+	arg-nonnull.h c++defs.h warn-on-use.h w32sock.h stat-w32.c \
+	stat-w32.h stat.c stat-time.h stdalign.in.h stdbool.in.h \
+	stddef.in.h stdint.in.h stdio.in.h stdlib.in.h strchrnul.c \
+	strchrnul.valgrind strdup.c streq.h strerror.c \
+	strerror-override.c strerror-override.h strerror_r.c \
+	string.in.h strings.in.h strnlen.c strstr.c str-two-way.h \
+	strstr.c strtok_r.c sys_random.in.h sys_select.in.h \
 	sys_socket.in.h sys_stat.in.h sys_time.in.h sys_types.in.h \
 	sys_uio.in.h tempname.h time.in.h time_r.c unistd.in.h \
 	unistd--.h unistd-safer.h unsetenv.c \
@@ -1852,9 +1868,9 @@ BUILT_SOURCES = $(ALLOCA_H) arpa/inet.h ctype.h dirent.h $(ERRNO_H) \
 	fcntl.h $(FLOAT_H) $(FNMATCH_H) $(GLOB_H) inttypes.h \
 	$(LIMITS_H) locale.h math.h netdb.h $(NETINET_IN_H) signal.h \
 	$(STDALIGN_H) $(STDBOOL_H) $(STDDEF_H) $(STDINT_H) stdio.h \
-	stdlib.h string.h strings.h sys/random.h sys/socket.h \
-	sys/stat.h sys/time.h sys/types.h sys/uio.h time.h unistd.h \
-	wchar.h wctype.h
+	stdlib.h string.h strings.h sys/random.h sys/select.h \
+	sys/socket.h sys/stat.h sys/time.h sys/types.h sys/uio.h \
+	time.h unistd.h wchar.h wctype.h
 SUFFIXES = 
 MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	arpa/inet.h-t ctype.h ctype.h-t dirent.h dirent.h-t errno.h \
@@ -1865,11 +1881,12 @@ MOSTLYCLEANFILES = core *.stackdump alloca.h alloca.h-t arpa/inet.h \
 	stdalign.h stdalign.h-t stdbool.h stdbool.h-t stddef.h \
 	stddef.h-t stdint.h stdint.h-t stdio.h stdio.h-t stdlib.h \
 	stdlib.h-t string.h string.h-t strings.h strings.h-t \
-	sys/random.h sys/random.h-t sys/socket.h sys/socket.h-t \
-	sys/stat.h sys/stat.h-t sys/time.h sys/time.h-t sys/types.h \
-	sys/types.h-t sys/uio.h sys/uio.h-t time.h time.h-t unistd.h \
-	unistd.h-t wchar.h wchar.h-t wctype.h wctype.h-t
-MOSTLYCLEANDIRS = arpa netinet sys sys sys sys
+	sys/random.h sys/random.h-t sys/select.h sys/select.h-t \
+	sys/socket.h sys/socket.h-t sys/stat.h sys/stat.h-t sys/time.h \
+	sys/time.h-t sys/types.h sys/types.h-t sys/uio.h sys/uio.h-t \
+	time.h time.h-t unistd.h unistd.h-t wchar.h wchar.h-t wctype.h \
+	wctype.h-t
+MOSTLYCLEANDIRS = arpa netinet sys sys sys sys sys
 CLEANFILES = 
 DISTCLEANFILES = 
 MAINTAINERCLEANFILES = 
@@ -1885,9 +1902,9 @@ libgnu_a_SOURCES = openat-priv.h openat-proc.c basename-lgpl.c \
 	malloc/scratch_buffer_grow.c \
 	malloc/scratch_buffer_grow_preserve.c \
 	malloc/scratch_buffer_set_array_size.c setlocale_null.c \
-	stat-time.c strnlen1.h strnlen1.c sys_socket.c tempname.c \
-	glthread/threadlib.c unistd.c dup-safer.c fd-safer.c \
-	pipe-safer.c wctype-h.c
+	sockets.h sockets.c stat-time.c strnlen1.h strnlen1.c \
+	sys_socket.c tempname.c glthread/threadlib.c unistd.c \
+	dup-safer.c fd-safer.c pipe-safer.c wctype-h.c
 libgnu_a_LIBADD = $(gl_LIBOBJS) @ALLOCA@
 libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) @ALLOCA@
 EXTRA_libgnu_a_SOURCES = alloca.c btowc.c canonicalize-lgpl.c \
@@ -1904,11 +1921,11 @@ EXTRA_libgnu_a_SOURCES = alloca.c btowc.c canonicalize-lgpl.c \
 	memmem.c mempcpy.c memrchr.c mkdir.c mkdtemp.c mkostemp.c \
 	msvc-inval.c msvc-nothrow.c open.c openat.c opendir.c pipe.c \
 	rawmemchr.c readdir.c readlink.c realloc.c rename.c \
-	rewinddir.c rmdir.c setenv.c setlocale-lock.c stat-w32.c \
-	stat.c strchrnul.c strdup.c strerror.c strerror-override.c \
-	strerror_r.c strnlen.c strstr.c strstr.c strtok_r.c time_r.c \
-	unsetenv.c windows-mutex.c windows-once.c windows-recmutex.c \
-	windows-rwlock.c wmemchr.c wmempcpy.c
+	rewinddir.c rmdir.c select.c setenv.c setlocale-lock.c \
+	stat-w32.c stat.c strchrnul.c strdup.c strerror.c \
+	strerror-override.c strerror_r.c strnlen.c strstr.c strstr.c \
+	strtok_r.c time_r.c unsetenv.c windows-mutex.c windows-once.c \
+	windows-recmutex.c windows-rwlock.c wmemchr.c wmempcpy.c
 
 # Use this preprocessor expression to decide whether #include_next works.
 # Do not rely on a 'configure'-time test for this, since the expression
@@ -2111,9 +2128,11 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewinddir.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rmdir.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/save-cwd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/select.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setenv.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setlocale-lock.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setlocale_null.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockets.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-time.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat-w32.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@
@@ -3539,6 +3558,30 @@ sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_N
 	} > $@-t && \
 	mv -f $@-t $@
 
+# We need the following in order to create <sys/select.h> when the system
+# doesn't have one that works with the given compiler.
+sys/select.h: sys_select.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_SYS_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \
+	      -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \
+	      -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \
+	      -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \
+	      -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \
+	      -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \
+	      -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_select.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+
 # We need the following in order to create <sys/socket.h> when the system
 # doesn't have one that works with the given compiler.
 sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
diff --git a/gnulib/import/m4/gnulib-cache.m4 b/gnulib/import/m4/gnulib-cache.m4
index 54ee8ca68bb9..689ebd3e5ba9 100644
--- a/gnulib/import/m4/gnulib-cache.m4
+++ b/gnulib/import/m4/gnulib-cache.m4
@@ -68,6 +68,7 @@
 #  rawmemchr \
 #  readlink \
 #  rename \
+#  select \
 #  setenv \
 #  signal-h \
 #  strchrnul \
@@ -115,6 +116,7 @@ gl_MODULES([
   rawmemchr
   readlink
   rename
+  select
   setenv
   signal-h
   strchrnul
diff --git a/gnulib/import/m4/gnulib-comp.m4 b/gnulib/import/m4/gnulib-comp.m4
index 0bf0d171ee49..03eff90b6b2d 100644
--- a/gnulib/import/m4/gnulib-comp.m4
+++ b/gnulib/import/m4/gnulib-comp.m4
@@ -172,6 +172,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module same-inode:
   # Code from module save-cwd:
   # Code from module scratch_buffer:
+  # Code from module select:
   # Code from module setenv:
   # Code from module setlocale-null:
   # Code from module signal-h:
@@ -179,6 +180,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module snippet/arg-nonnull:
   # Code from module snippet/c++defs:
   # Code from module snippet/warn-on-use:
+  # Code from module socketlib:
+  # Code from module sockets:
   # Code from module socklen:
   # Code from module ssize_t:
   # Code from module stat:
@@ -204,6 +207,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module strstr-simple:
   # Code from module strtok_r:
   # Code from module sys_random:
+  # Code from module sys_select:
   # Code from module sys_socket:
   # Code from module sys_stat:
   # Code from module sys_time:
@@ -664,6 +668,11 @@ AC_DEFUN([gl_INIT],
   fi
   gl_UNISTD_MODULE_INDICATOR([rmdir])
   gl_SAVE_CWD
+  gl_FUNC_SELECT
+  if test $REPLACE_SELECT = 1; then
+    AC_LIBOBJ([select])
+  fi
+  gl_SYS_SELECT_MODULE_INDICATOR([select])
   gl_FUNC_SETENV
   if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then
     AC_LIBOBJ([setenv])
@@ -676,6 +685,8 @@ AC_DEFUN([gl_INIT],
   fi
   gl_LOCALE_MODULE_INDICATOR([setlocale_null])
   gl_SIGNAL_H
+  AC_REQUIRE([gl_SOCKETLIB])
+  AC_REQUIRE([gl_SOCKETS])
   gl_TYPE_SOCKLEN_T
   gt_TYPE_SSIZE_T
   gl_FUNC_STAT
@@ -754,6 +765,8 @@ AC_DEFUN([gl_INIT],
   gl_STRING_MODULE_INDICATOR([strtok_r])
   gl_HEADER_SYS_RANDOM
   AC_PROG_MKDIR_P
+  AC_REQUIRE([gl_HEADER_SYS_SELECT])
+  AC_PROG_MKDIR_P
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_STAT_H
@@ -1127,11 +1140,14 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/save-cwd.c
   lib/save-cwd.h
   lib/scratch_buffer.h
+  lib/select.c
   lib/setenv.c
   lib/setlocale-lock.c
   lib/setlocale_null.c
   lib/setlocale_null.h
   lib/signal.in.h
+  lib/sockets.c
+  lib/sockets.h
   lib/stat-time.c
   lib/stat-time.h
   lib/stat-w32.c
@@ -1161,6 +1177,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strstr.c
   lib/strtok_r.c
   lib/sys_random.in.h
+  lib/sys_select.in.h
   lib/sys_socket.c
   lib/sys_socket.in.h
   lib/sys_stat.in.h
@@ -1177,6 +1194,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/unistd.in.h
   lib/unsetenv.c
   lib/verify.h
+  lib/w32sock.h
   lib/warn-on-use.h
   lib/wchar.in.h
   lib/wctype-h.c
@@ -1313,9 +1331,12 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/rewinddir.m4
   m4/rmdir.m4
   m4/save-cwd.m4
+  m4/select.m4
   m4/setenv.m4
   m4/setlocale_null.m4
   m4/signal_h.m4
+  m4/socketlib.m4
+  m4/sockets.m4
   m4/socklen.m4
   m4/sockpfaf.m4
   m4/ssize_t.m4
@@ -1338,6 +1359,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/strstr.m4
   m4/strtok_r.m4
   m4/sys_random_h.m4
+  m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
   m4/sys_time_h.m4
diff --git a/gnulib/import/m4/select.m4 b/gnulib/import/m4/select.m4
new file mode 100644
index 000000000000..c7409d2041d1
--- /dev/null
+++ b/gnulib/import/m4/select.m4
@@ -0,0 +1,117 @@
+# select.m4 serial 12
+dnl Copyright (C) 2009-2021 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.
+
+AC_DEFUN([gl_FUNC_SELECT],
+[
+  AC_REQUIRE([gl_HEADER_SYS_SELECT])
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SOCKETS])
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    REPLACE_SELECT=1
+  else
+    dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
+    dnl EFAULT.
+    AC_CHECK_HEADERS_ONCE([sys/select.h])
+    AC_CACHE_CHECK([whether select supports a 0 argument],
+      [gl_cv_func_select_supports0],
+      [
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#include <sys/time.h>
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+int main ()
+{
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 5;
+  return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
+}]])], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no],
+          [
+changequote(,)dnl
+           case "$host_os" in
+                       # Guess no on Interix.
+             interix*) gl_cv_func_select_supports0="guessing no";;
+                       # Guess yes otherwise.
+             *)        gl_cv_func_select_supports0="guessing yes";;
+           esac
+changequote([,])dnl
+          ])
+      ])
+    case "$gl_cv_func_select_supports0" in
+      *yes) ;;
+      *) REPLACE_SELECT=1 ;;
+    esac
+
+    dnl On FreeBSD 8.2, select() doesn't always reject bad fds.
+    AC_CACHE_CHECK([whether select detects invalid fds],
+      [gl_cv_func_select_detects_ebadf],
+      [
+        AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <sys/types.h>
+#include <sys/time.h>
+#if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#include <unistd.h>
+#include <errno.h>
+]GL_MDA_DEFINES],
+[[
+  fd_set set;
+  dup2(0, 16);
+  FD_ZERO(&set);
+  FD_SET(16, &set);
+  close(16);
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 5;
+  return select (17, &set, NULL, NULL, &timeout) != -1 || errno != EBADF;
+]])], [gl_cv_func_select_detects_ebadf=yes],
+      [gl_cv_func_select_detects_ebadf=no],
+          [
+           case "$host_os" in
+                             # Guess yes on Linux systems.
+            linux-* | linux) gl_cv_func_select_detects_ebadf="guessing yes" ;;
+                             # Guess yes on glibc systems.
+            *-gnu* | gnu*)   gl_cv_func_select_detects_ebadf="guessing yes" ;;
+                             # If we don't know, obey --enable-cross-guesses.
+            *)               gl_cv_func_select_detects_ebadf="$gl_cross_guess_normal" ;;
+           esac
+          ])
+      ])
+    case $gl_cv_func_select_detects_ebadf in
+      *yes) ;;
+      *) REPLACE_SELECT=1 ;;
+    esac
+  fi
+
+  dnl Determine the needed libraries.
+  LIB_SELECT="$LIBSOCKET"
+  if test $REPLACE_SELECT = 1; then
+    case "$host_os" in
+      mingw*)
+        dnl On the MSVC platform, the function MsgWaitForMultipleObjects
+        dnl (used in lib/select.c) requires linking with -luser32. On mingw,
+        dnl it is implicit.
+        AC_LINK_IFELSE(
+          [AC_LANG_SOURCE([[
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+int
+main ()
+{
+  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
+  return 0;
+}]])],
+          [],
+          [LIB_SELECT="$LIB_SELECT -luser32"])
+        ;;
+    esac
+  fi
+  AC_SUBST([LIB_SELECT])
+])
diff --git a/gnulib/import/m4/socketlib.m4 b/gnulib/import/m4/socketlib.m4
new file mode 100644
index 000000000000..0f8a0829c7ba
--- /dev/null
+++ b/gnulib/import/m4/socketlib.m4
@@ -0,0 +1,96 @@
+# socketlib.m4 serial 3
+dnl Copyright (C) 2008-2021 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 gl_SOCKETLIB
+dnl Determines the library to use for socket functions.
+dnl Sets and AC_SUBSTs LIBSOCKET.
+
+AC_DEFUN([gl_SOCKETLIB],
+[
+  gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
+  LIBSOCKET=
+  if test $HAVE_WINSOCK2_H = 1; then
+    dnl Native Windows API (not Cygwin).
+    dnl If the function WSAStartup exists (declared in <winsock2.h> and
+    dnl defined through -lws2_32), we need to call it.
+    AC_CACHE_CHECK([for WSAStartup],
+      [gl_cv_func_wsastartup], [
+       gl_save_LIBS="$LIBS"
+       LIBS="$LIBS -lws2_32"
+       AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM([[
+#ifdef HAVE_WINSOCK2_H
+# include <winsock2.h>
+#endif]], [[
+            WORD wVersionRequested = MAKEWORD(1, 1);
+            WSADATA wsaData;
+            int err = WSAStartup(wVersionRequested, &wsaData);
+            WSACleanup ();
+            ]])
+         ],
+         [gl_cv_func_wsastartup=yes],
+         [gl_cv_func_wsastartup=no])
+       LIBS="$gl_save_LIBS"
+      ])
+    if test "$gl_cv_func_wsastartup" = "yes"; then
+      AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
+      LIBSOCKET='-lws2_32'
+    fi
+  else
+    dnl Unix API.
+    dnl Solaris has most socket functions in libsocket.
+    dnl Haiku has most socket functions in libnetwork.
+    dnl BeOS has most socket functions in libnet.
+    dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would
+    dnl break code (e.g. in libraries) that invokes accept(), getpeername(),
+    dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See
+    dnl "man xopen_networking" for details.
+    AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
+      gl_cv_lib_socket=
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();]], [[setsockopt();]])],
+        [],
+        [gl_save_LIBS="$LIBS"
+         LIBS="$gl_save_LIBS -lsocket"
+         AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();]], [[setsockopt();]])],
+           [gl_cv_lib_socket="-lsocket"])
+         if test -z "$gl_cv_lib_socket"; then
+           LIBS="$gl_save_LIBS -lnetwork"
+           AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();]], [[setsockopt();]])],
+             [gl_cv_lib_socket="-lnetwork"])
+           if test -z "$gl_cv_lib_socket"; then
+             LIBS="$gl_save_LIBS -lnet"
+             AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
+#ifdef __cplusplus
+"C"
+#endif
+char setsockopt();]], [[setsockopt();]])],
+               [gl_cv_lib_socket="-lnet"])
+           fi
+         fi
+         LIBS="$gl_save_LIBS"
+        ])
+      if test -z "$gl_cv_lib_socket"; then
+        gl_cv_lib_socket="none needed"
+      fi
+    ])
+    if test "$gl_cv_lib_socket" != "none needed"; then
+      LIBSOCKET="$gl_cv_lib_socket"
+    fi
+  fi
+  AC_SUBST([LIBSOCKET])
+])
diff --git a/gnulib/import/m4/sockets.m4 b/gnulib/import/m4/sockets.m4
new file mode 100644
index 000000000000..02b43b6e7fe5
--- /dev/null
+++ b/gnulib/import/m4/sockets.m4
@@ -0,0 +1,17 @@
+# sockets.m4 serial 7
+dnl Copyright (C) 2008-2021 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.
+
+AC_DEFUN([gl_SOCKETS],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_REQUIRE([gl_SOCKETLIB])
+  gl_PREREQ_SOCKETS
+])
+
+# Prerequisites of lib/sockets.c.
+AC_DEFUN([gl_PREREQ_SOCKETS], [
+  :
+])
diff --git a/gnulib/import/m4/sys_select_h.m4 b/gnulib/import/m4/sys_select_h.m4
new file mode 100644
index 000000000000..4b33d312e55d
--- /dev/null
+++ b/gnulib/import/m4/sys_select_h.m4
@@ -0,0 +1,95 @@
+# sys_select_h.m4 serial 20
+dnl Copyright (C) 2006-2021 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.
+
+AC_DEFUN([gl_HEADER_SYS_SELECT],
+[
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
+  AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
+    [gl_cv_header_sys_select_h_selfcontained],
+    [
+      dnl Test against two bugs:
+      dnl 1. On many platforms, <sys/select.h> assumes prior inclusion of
+      dnl    <sys/types.h>.
+      dnl 2. On OSF/1 4.0, <sys/select.h> provides only a forward declaration
+      dnl    of 'struct timeval', and no definition of this type.
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
+                                         [[struct timeval b;]])],
+        [gl_cv_header_sys_select_h_selfcontained=yes],
+        [gl_cv_header_sys_select_h_selfcontained=no])
+      dnl Test against another bug:
+      dnl 3. On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
+      dnl    that relies on memset(), but without including <string.h>.
+      if test $gl_cv_header_sys_select_h_selfcontained = yes; then
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM([[#include <sys/select.h>]],
+                           [[int memset; int bzero;]])
+          ],
+          [AC_LINK_IFELSE(
+             [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
+                  #undef memset
+                  #define memset nonexistent_memset
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void *memset (void *, int, unsigned long);
+                  #undef bzero
+                  #define bzero nonexistent_bzero
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void bzero (void *, unsigned long);
+                  fd_set fds;
+                  FD_ZERO (&fds);
+                ]])
+             ],
+             [],
+             [gl_cv_header_sys_select_h_selfcontained=no])
+          ])
+      fi
+    ])
+  dnl <sys/select.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/select.h])
+  if test $ac_cv_header_sys_select_h = yes; then
+    HAVE_SYS_SELECT_H=1
+  else
+    HAVE_SYS_SELECT_H=0
+  fi
+  AC_SUBST([HAVE_SYS_SELECT_H])
+  gl_PREREQ_SYS_H_WINSOCK2
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+/* Some systems require prerequisite headers.  */
+#include <sys/types.h>
+#if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <sys/select.h>
+    ]], [pselect select])
+])
+
+AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
+[
+  GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT])
+  GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
+  REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
+  REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
+])
diff --git a/gnulib/import/select.c b/gnulib/import/select.c
new file mode 100644
index 000000000000..56ac8bb7b586
--- /dev/null
+++ b/gnulib/import/select.c
@@ -0,0 +1,597 @@
+/* Emulation for select(2)
+   Contributed by Paolo Bonzini.
+
+   Copyright 2008-2021 Free Software Foundation, Inc.
+
+   This file is part of gnulib.
+
+   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
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <sys/select.h>
+
+#if defined _WIN32 && ! defined __CYGWIN__
+/* Native Windows.  */
+
+#include <alloca.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <winsock2.h>
+#include <windows.h>
+#include <io.h>
+#include <stdio.h>
+#include <conio.h>
+#include <time.h>
+
+/* Get the overridden 'struct timeval'.  */
+#include <sys/time.h>
+
+#if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+#else
+# include <io.h>
+#endif
+
+#undef select
+
+/* Don't assume that UNICODE is not defined.  */
+#undef GetModuleHandle
+#define GetModuleHandle GetModuleHandleA
+#undef PeekConsoleInput
+#define PeekConsoleInput PeekConsoleInputA
+#undef CreateEvent
+#define CreateEvent CreateEventA
+#undef PeekMessage
+#define PeekMessage PeekMessageA
+#undef DispatchMessage
+#define DispatchMessage DispatchMessageA
+
+/* Avoid warnings from gcc -Wcast-function-type.  */
+#define GetProcAddress \
+  (void *) GetProcAddress
+
+struct bitset {
+  unsigned char in[FD_SETSIZE / CHAR_BIT];
+  unsigned char out[FD_SETSIZE / CHAR_BIT];
+};
+
+/* Declare data structures for ntdll functions.  */
+typedef struct _FILE_PIPE_LOCAL_INFORMATION {
+  ULONG NamedPipeType;
+  ULONG NamedPipeConfiguration;
+  ULONG MaximumInstances;
+  ULONG CurrentInstances;
+  ULONG InboundQuota;
+  ULONG ReadDataAvailable;
+  ULONG OutboundQuota;
+  ULONG WriteQuotaAvailable;
+  ULONG NamedPipeState;
+  ULONG NamedPipeEnd;
+} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
+
+typedef struct _IO_STATUS_BLOCK
+{
+  union {
+    DWORD Status;
+    PVOID Pointer;
+  } u;
+  ULONG_PTR Information;
+} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
+
+typedef enum _FILE_INFORMATION_CLASS {
+  FilePipeLocalInformation = 24
+} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
+
+typedef DWORD (WINAPI *PNtQueryInformationFile)
+         (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS);
+
+#ifndef PIPE_BUF
+#define PIPE_BUF        512
+#endif
+
+static BOOL IsConsoleHandle (HANDLE h)
+{
+  DWORD mode;
+  return GetConsoleMode (h, &mode) != 0;
+}
+
+static BOOL
+IsSocketHandle (HANDLE h)
+{
+  WSANETWORKEVENTS ev;
+
+  if (IsConsoleHandle (h))
+    return FALSE;
+
+  /* Under Wine, it seems that getsockopt returns 0 for pipes too.
+     WSAEnumNetworkEvents instead distinguishes the two correctly.  */
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
+  return ev.lNetworkEvents != 0xDEADBEEF;
+}
+
+/* Compute output fd_sets for libc descriptor FD (whose Windows handle is
+   H).  */
+
+static int
+windows_poll_handle (HANDLE h, int fd,
+                     struct bitset *rbits,
+                     struct bitset *wbits,
+                     struct bitset *xbits)
+{
+  BOOL read, write, except;
+  int i, ret;
+  INPUT_RECORD *irbuffer;
+  DWORD avail, nbuffer;
+  BOOL bRet;
+  IO_STATUS_BLOCK iosb;
+  FILE_PIPE_LOCAL_INFORMATION fpli;
+  static PNtQueryInformationFile NtQueryInformationFile;
+  static BOOL once_only;
+
+  read = write = except = FALSE;
+  switch (GetFileType (h))
+    {
+    case FILE_TYPE_DISK:
+      read = TRUE;
+      write = TRUE;
+      break;
+
+    case FILE_TYPE_PIPE:
+      if (!once_only)
+        {
+          NtQueryInformationFile = (PNtQueryInformationFile)
+            GetProcAddress (GetModuleHandle ("ntdll.dll"),
+                            "NtQueryInformationFile");
+          once_only = TRUE;
+        }
+
+      if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
+        {
+          if (avail)
+            read = TRUE;
+        }
+      else if (GetLastError () == ERROR_BROKEN_PIPE)
+        ;
+
+      else
+        {
+          /* It was the write-end of the pipe.  Check if it is writable.
+             If NtQueryInformationFile fails, optimistically assume the pipe is
+             writable.  This could happen on Windows 9x, where
+             NtQueryInformationFile is not available, or if we inherit a pipe
+             that doesn't permit FILE_READ_ATTRIBUTES access on the write end
+             (I think this should not happen since Windows XP SP2; WINE seems
+             fine too).  Otherwise, ensure that enough space is available for
+             atomic writes.  */
+          memset (&iosb, 0, sizeof (iosb));
+          memset (&fpli, 0, sizeof (fpli));
+
+          if (!NtQueryInformationFile
+              || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
+                                         FilePipeLocalInformation)
+              || fpli.WriteQuotaAvailable >= PIPE_BUF
+              || (fpli.OutboundQuota < PIPE_BUF &&
+                  fpli.WriteQuotaAvailable == fpli.OutboundQuota))
+            write = TRUE;
+        }
+      break;
+
+    case FILE_TYPE_CHAR:
+      write = TRUE;
+      if (!(rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+        break;
+
+      ret = WaitForSingleObject (h, 0);
+      if (ret == WAIT_OBJECT_0)
+        {
+          if (!IsConsoleHandle (h))
+            {
+              read = TRUE;
+              break;
+            }
+
+          nbuffer = avail = 0;
+          bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
+
+          /* Screen buffers handles are filtered earlier.  */
+          assert (bRet);
+          if (nbuffer == 0)
+            {
+              except = TRUE;
+              break;
+            }
+
+          irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
+          bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail);
+          if (!bRet || avail == 0)
+            {
+              except = TRUE;
+              break;
+            }
+
+          for (i = 0; i < avail; i++)
+            if (irbuffer[i].EventType == KEY_EVENT)
+              read = TRUE;
+        }
+      break;
+
+    default:
+      ret = WaitForSingleObject (h, 0);
+      write = TRUE;
+      if (ret == WAIT_OBJECT_0)
+        read = TRUE;
+
+      break;
+    }
+
+  ret = 0;
+  if (read && (rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      rbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  if (write && (wbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      wbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  if (except && (xbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      xbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  return ret;
+}
+
+int
+rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
+            struct timeval *timeout)
+#undef timeval
+{
+  static struct timeval tv0;
+  static HANDLE hEvent;
+  HANDLE h, handle_array[FD_SETSIZE + 2];
+  fd_set handle_rfds, handle_wfds, handle_xfds;
+  struct bitset rbits, wbits, xbits;
+  unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT];
+  DWORD ret, wait_timeout, nhandles, nsock, nbuffer;
+  MSG msg;
+  int i, fd, rc;
+  clock_t tend;
+
+  if (nfds > FD_SETSIZE)
+    nfds = FD_SETSIZE;
+
+  if (!timeout)
+    wait_timeout = INFINITE;
+  else
+    {
+      wait_timeout = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
+
+      /* select is also used as a portable usleep.  */
+      if (!rfds && !wfds && !xfds)
+        {
+          Sleep (wait_timeout);
+          return 0;
+        }
+    }
+
+  if (!hEvent)
+    hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
+
+  handle_array[0] = hEvent;
+  nhandles = 1;
+  nsock = 0;
+
+  /* Copy descriptors to bitsets.  At the same time, eliminate
+     bits in the "wrong" direction for console input buffers
+     and screen buffers, because screen buffers are waitable
+     and they will block until a character is available.  */
+  memset (&rbits, 0, sizeof (rbits));
+  memset (&wbits, 0, sizeof (wbits));
+  memset (&xbits, 0, sizeof (xbits));
+  memset (anyfds_in, 0, sizeof (anyfds_in));
+  if (rfds)
+    for (i = 0; i < rfds->fd_count; i++)
+      {
+        fd = rfds->fd_array[i];
+        h = (HANDLE) _get_osfhandle (fd);
+        if (IsConsoleHandle (h)
+            && !GetNumberOfConsoleInputEvents (h, &nbuffer))
+          continue;
+
+        rbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    rfds = (fd_set *) alloca (sizeof (fd_set));
+
+  if (wfds)
+    for (i = 0; i < wfds->fd_count; i++)
+      {
+        fd = wfds->fd_array[i];
+        h = (HANDLE) _get_osfhandle (fd);
+        if (IsConsoleHandle (h)
+            && GetNumberOfConsoleInputEvents (h, &nbuffer))
+          continue;
+
+        wbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    wfds = (fd_set *) alloca (sizeof (fd_set));
+
+  if (xfds)
+    for (i = 0; i < xfds->fd_count; i++)
+      {
+        fd = xfds->fd_array[i];
+        xbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    xfds = (fd_set *) alloca (sizeof (fd_set));
+
+  /* Zero all the fd_sets, including the application's.  */
+  FD_ZERO (rfds);
+  FD_ZERO (wfds);
+  FD_ZERO (xfds);
+  FD_ZERO (&handle_rfds);
+  FD_ZERO (&handle_wfds);
+  FD_ZERO (&handle_xfds);
+
+  /* Classify handles.  Create fd sets for sockets, poll the others. */
+  for (i = 0; i < nfds; i++)
+    {
+      if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
+        continue;
+
+      h = (HANDLE) _get_osfhandle (i);
+      if (!h)
+        {
+          errno = EBADF;
+          return -1;
+        }
+
+      if (IsSocketHandle (h))
+        {
+          int requested = FD_CLOSE;
+
+          /* See above; socket handles are mapped onto select, but we
+             need to map descriptors to handles.  */
+          if (rbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_READ | FD_ACCEPT;
+              FD_SET ((SOCKET) h, rfds);
+              FD_SET ((SOCKET) h, &handle_rfds);
+            }
+          if (wbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_WRITE | FD_CONNECT;
+              FD_SET ((SOCKET) h, wfds);
+              FD_SET ((SOCKET) h, &handle_wfds);
+            }
+          if (xbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_OOB;
+              FD_SET ((SOCKET) h, xfds);
+              FD_SET ((SOCKET) h, &handle_xfds);
+            }
+
+          WSAEventSelect ((SOCKET) h, hEvent, requested);
+          nsock++;
+        }
+      else
+        {
+          handle_array[nhandles++] = h;
+
+          /* Poll now.  If we get an event, do not wait below.  */
+          if (wait_timeout != 0
+              && windows_poll_handle (h, i, &rbits, &wbits, &xbits))
+            wait_timeout = 0;
+        }
+    }
+
+  /* Place a sentinel at the end of the array.  */
+  handle_array[nhandles] = NULL;
+
+  /* When will the waiting period expire?  */
+  if (wait_timeout != INFINITE)
+    tend = clock () + wait_timeout;
+
+restart:
+  if (wait_timeout == 0 || nsock == 0)
+    rc = 0;
+  else
+    {
+      /* See if we need to wait in the loop below.  If any select is ready,
+         do MsgWaitForMultipleObjects anyway to dispatch messages, but
+         no need to call select again.  */
+      rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0);
+      if (rc == 0)
+        {
+          /* Restore the fd_sets for the other select we do below.  */
+          memcpy (&handle_rfds, rfds, sizeof (fd_set));
+          memcpy (&handle_wfds, wfds, sizeof (fd_set));
+          memcpy (&handle_xfds, xfds, sizeof (fd_set));
+        }
+      else
+        wait_timeout = 0;
+    }
+
+  /* How much is left to wait?  */
+  if (wait_timeout != INFINITE)
+    {
+      clock_t tnow = clock ();
+      if (tend >= tnow)
+        wait_timeout = tend - tnow;
+      else
+        wait_timeout = 0;
+    }
+
+  for (;;)
+    {
+      ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
+                                       wait_timeout, QS_ALLINPUT);
+
+      if (ret == WAIT_OBJECT_0 + nhandles)
+        {
+          /* new input of some other kind */
+          BOOL bRet;
+          while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
+            {
+              TranslateMessage (&msg);
+              DispatchMessage (&msg);
+            }
+        }
+      else
+        break;
+    }
+
+  /* If we haven't done it yet, check the status of the sockets.  */
+  if (rc == 0 && nsock > 0)
+    rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0);
+
+  if (nhandles > 1)
+    {
+      /* Count results that are not counted in the return value of select.  */
+      nhandles = 1;
+      for (i = 0; i < nfds; i++)
+        {
+          if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
+            continue;
+
+          h = (HANDLE) _get_osfhandle (i);
+          if (h == handle_array[nhandles])
+            {
+              /* Not a socket.  */
+              nhandles++;
+              windows_poll_handle (h, i, &rbits, &wbits, &xbits);
+              if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))
+                  || wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))
+                  || xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+                rc++;
+            }
+        }
+
+      if (rc == 0
+          && (wait_timeout == INFINITE
+              /* If NHANDLES > 1, but no bits are set, it means we've
+                 been told incorrectly that some handle was signaled.
+                 This happens with anonymous pipes, which always cause
+                 MsgWaitForMultipleObjects to exit immediately, but no
+                 data is found ready to be read by windows_poll_handle.
+                 To avoid a total failure (whereby we return zero and
+                 don't wait at all), let's poll in a more busy loop.  */
+              || (wait_timeout != 0 && nhandles > 1)))
+        {
+          /* Sleep 1 millisecond to avoid busy wait and retry with the
+             original fd_sets.  */
+          memcpy (&handle_rfds, rfds, sizeof (fd_set));
+          memcpy (&handle_wfds, wfds, sizeof (fd_set));
+          memcpy (&handle_xfds, xfds, sizeof (fd_set));
+          SleepEx (1, TRUE);
+          goto restart;
+        }
+      if (timeout && wait_timeout == 0 && rc == 0)
+        timeout->tv_sec = timeout->tv_usec = 0;
+    }
+
+  /* Now fill in the results.  */
+  FD_ZERO (rfds);
+  FD_ZERO (wfds);
+  FD_ZERO (xfds);
+  nhandles = 1;
+  for (i = 0; i < nfds; i++)
+    {
+      if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
+        continue;
+
+      h = (HANDLE) _get_osfhandle (i);
+      if (h != handle_array[nhandles])
+        {
+          /* Perform handle->descriptor mapping.  */
+          WSAEventSelect ((SOCKET) h, NULL, 0);
+          if (FD_ISSET (h, &handle_rfds))
+            FD_SET (i, rfds);
+          if (FD_ISSET (h, &handle_wfds))
+            FD_SET (i, wfds);
+          if (FD_ISSET (h, &handle_xfds))
+            FD_SET (i, xfds);
+        }
+      else
+        {
+          /* Not a socket.  */
+          nhandles++;
+          if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            FD_SET (i, rfds);
+          if (wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            FD_SET (i, wfds);
+          if (xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            FD_SET (i, xfds);
+        }
+    }
+
+  return rc;
+}
+
+#else /* ! Native Windows.  */
+
+#include <stddef.h> /* NULL */
+#include <errno.h>
+#include <unistd.h>
+
+#undef select
+
+int
+rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
+            struct timeval *timeout)
+{
+  int i;
+
+  /* FreeBSD 8.2 has a bug: it does not always detect invalid fds.  */
+  if (nfds < 0 || nfds > FD_SETSIZE)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  for (i = 0; i < nfds; i++)
+    {
+      if (((rfds && FD_ISSET (i, rfds))
+           || (wfds && FD_ISSET (i, wfds))
+           || (xfds && FD_ISSET (i, xfds)))
+          && dup2 (i, i) != i)
+        return -1;
+    }
+
+  /* Interix 3.5 has a bug: it does not support nfds == 0.  */
+  if (nfds == 0)
+    {
+      nfds = 1;
+      rfds = NULL;
+      wfds = NULL;
+      xfds = NULL;
+    }
+  return select (nfds, rfds, wfds, xfds, timeout);
+}
+
+#endif
diff --git a/gnulib/import/sockets.c b/gnulib/import/sockets.c
new file mode 100644
index 000000000000..2de48d25b312
--- /dev/null
+++ b/gnulib/import/sockets.c
@@ -0,0 +1,161 @@
+/* sockets.c --- wrappers for Windows socket functions
+
+   Copyright (C) 2008-2021 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Simon Josefsson */
+
+#include <config.h>
+
+/* Specification.  */
+#include "sockets.h"
+
+#if WINDOWS_SOCKETS
+
+/* This includes winsock2.h on MinGW. */
+# include <sys/socket.h>
+
+# include "fd-hook.h"
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+# include "w32sock.h"
+
+static int
+close_fd_maybe_socket (const struct fd_hook *remaining_list,
+                       gl_close_fn primary,
+                       int fd)
+{
+  /* Note about multithread-safety: There is a race condition where, between
+     our calls to closesocket() and the primary close(), some other thread
+     could make system calls that allocate precisely the same HANDLE value
+     as sock; then the primary close() would call CloseHandle() on it.  */
+  SOCKET sock;
+  WSANETWORKEVENTS ev;
+
+  /* Test whether fd refers to a socket.  */
+  sock = FD_TO_SOCKET (fd);
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* fd refers to a socket.  */
+      /* FIXME: other applications, like squid, use an undocumented
+         _free_osfhnd free function.  But this is not enough: The 'osfile'
+         flags for fd also needs to be cleared, but it is hard to access it.
+         Instead, here we just close twice the file descriptor.  */
+      if (closesocket (sock))
+        {
+          set_winsock_errno ();
+          return -1;
+        }
+      else
+        {
+          /* This call frees the file descriptor and does a
+             CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails.  */
+          _close (fd);
+          return 0;
+        }
+    }
+  else
+    /* Some other type of file descriptor.  */
+    return execute_close_hooks (remaining_list, primary, fd);
+}
+
+static int
+ioctl_fd_maybe_socket (const struct fd_hook *remaining_list,
+                       gl_ioctl_fn primary,
+                       int fd, int request, void *arg)
+{
+  SOCKET sock;
+  WSANETWORKEVENTS ev;
+
+  /* Test whether fd refers to a socket.  */
+  sock = FD_TO_SOCKET (fd);
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents (sock, NULL, &ev);
+  if (ev.lNetworkEvents != 0xDEADBEEF)
+    {
+      /* fd refers to a socket.  */
+      if (ioctlsocket (sock, request, arg) < 0)
+        {
+          set_winsock_errno ();
+          return -1;
+        }
+      else
+        return 0;
+    }
+  else
+    /* Some other type of file descriptor.  */
+    return execute_ioctl_hooks (remaining_list, primary, fd, request, arg);
+}
+
+static struct fd_hook fd_sockets_hook;
+
+static int initialized_sockets_version /* = 0 */;
+
+#endif /* WINDOWS_SOCKETS */
+
+int
+gl_sockets_startup (int version _GL_UNUSED)
+{
+#if WINDOWS_SOCKETS
+  if (version > initialized_sockets_version)
+    {
+      WSADATA data;
+      int err;
+
+      err = WSAStartup (version, &data);
+      if (err != 0)
+        return 1;
+
+      if (data.wVersion != version)
+        {
+          WSACleanup ();
+          return 2;
+        }
+
+      if (initialized_sockets_version == 0)
+        register_fd_hook (close_fd_maybe_socket, ioctl_fd_maybe_socket,
+                          &fd_sockets_hook);
+
+      initialized_sockets_version = version;
+    }
+#endif
+
+  return 0;
+}
+
+int
+gl_sockets_cleanup (void)
+{
+#if WINDOWS_SOCKETS
+  int err;
+
+  initialized_sockets_version = 0;
+
+  unregister_fd_hook (&fd_sockets_hook);
+
+  err = WSACleanup ();
+  if (err != 0)
+    return 1;
+#endif
+
+  return 0;
+}
diff --git a/gnulib/import/sockets.h b/gnulib/import/sockets.h
new file mode 100644
index 000000000000..e0729c241467
--- /dev/null
+++ b/gnulib/import/sockets.h
@@ -0,0 +1,66 @@
+/* sockets.h - wrappers for Windows socket functions
+
+   Copyright (C) 2008-2021 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Simon Josefsson */
+
+#ifndef SOCKETS_H
+#define SOCKETS_H 1
+
+#define SOCKETS_1_0 0x0001
+#define SOCKETS_1_1 0x0101
+#define SOCKETS_2_0 0x0002
+#define SOCKETS_2_1 0x0102
+#define SOCKETS_2_2 0x0202
+
+int gl_sockets_startup (int version)
+#ifndef WINDOWS_SOCKETS
+  _GL_ATTRIBUTE_CONST
+#endif
+  ;
+
+int gl_sockets_cleanup (void)
+#ifndef WINDOWS_SOCKETS
+  _GL_ATTRIBUTE_CONST
+#endif
+  ;
+
+/* This function is useful it you create a socket using gnulib's
+   Winsock wrappers but needs to pass on the socket handle to some
+   other library that only accepts sockets. */
+#ifdef WINDOWS_SOCKETS
+
+# include <sys/socket.h>
+
+# if GNULIB_MSVC_NOTHROW
+#  include "msvc-nothrow.h"
+# else
+#  include <io.h>
+# endif
+
+static inline SOCKET
+gl_fd_to_handle (int fd)
+{
+  return _get_osfhandle (fd);
+}
+
+#else
+
+# define gl_fd_to_handle(x) (x)
+
+#endif /* WINDOWS_SOCKETS */
+
+#endif /* SOCKETS_H */
diff --git a/gnulib/import/sys_select.in.h b/gnulib/import/sys_select.in.h
new file mode 100644
index 000000000000..1dacb21087db
--- /dev/null
+++ b/gnulib/import/sys_select.in.h
@@ -0,0 +1,326 @@
+/* Substitute for <sys/select.h>.
+   Copyright (C) 2007-2021 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
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+# if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+# endif
+@PRAGMA_COLUMNS@
+
+/* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h>
+   both include <sys/select.h>.
+   On Cygwin, <sys/time.h> includes <sys/select.h>.
+   Simply delegate to the system's header in this case.  */
+#if (@HAVE_SYS_SELECT_H@                                                \
+     && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H             \
+     && ((defined __osf__ && defined _SYS_TYPES_H_                      \
+          && defined _OSF_SOURCE)                                       \
+         || (defined __sun && defined _SYS_TYPES_H                      \
+             && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE)   \
+                 || defined __EXTENSIONS__))))
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#elif (@HAVE_SYS_SELECT_H@                                              \
+       && (defined _CYGWIN_SYS_TIME_H                                   \
+           || (!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H       \
+               && ((defined __osf__ && defined _SYS_TIME_H_             \
+                    && defined _OSF_SOURCE)                             \
+                   || (defined __sun && defined _SYS_TIME_H             \
+                       && (! (defined _XOPEN_SOURCE                     \
+                              || defined _POSIX_C_SOURCE)               \
+                           || defined __EXTENSIONS__))))))
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+/* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
+   <sys/bsd_types.h>, which includes <sys/select.h>.  At this point we cannot
+   include <signal.h>, because that includes <internal/signal_core.h>, which
+   gives a syntax error because <sys/timespec.h> has not been completely
+   processed.  Simply delegate to the system's header in this case.  */
+#elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+/* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
+   <sys/select.h>.  At this point we cannot include <signal.h>, because that
+   includes gnulib's pthread.h override, which gives a syntax error because
+   /usr/include/pthread.h has not been completely processed.  Simply delegate
+   to the system's header in this case.  */
+#elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER)
+
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#else
+
+#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
+
+/* On many platforms, <sys/select.h> assumes prior inclusion of
+   <sys/types.h>.  Also, mingw defines sigset_t there, instead of
+   in <signal.h> where it belongs.  */
+#include <sys/types.h>
+
+#if @HAVE_SYS_SELECT_H@
+
+/* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
+   of 'struct timeval', and no definition of this type.
+   Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
+   in <sys/time.h>.
+   But avoid namespace pollution on glibc systems and "unknown type
+   name" problems on Cygwin.  */
+# if !(defined __GLIBC__ || defined __CYGWIN__)
+#  include <sys/time.h>
+# endif
+
+/* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
+   that relies on memset(), but without including <string.h>.
+   But in any case avoid namespace pollution on glibc systems.  */
+# if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
+     && ! defined __GLIBC__
+#  include <string.h>
+# endif
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#endif
+
+/* Get definition of 'sigset_t'.
+   But avoid namespace pollution on glibc systems and "unknown type
+   name" problems on Cygwin.
+   On OS/2 kLIBC, sigset_t is defined in <sys/select.h>, too. In addition,
+   if <sys/param.h> is included, <types.h> -> <sys/types.h> -> <sys/select.h>
+   are included. Then <signal.h> -> <pthread.h> are included by GNULIB. By the
+   way, <pthread.h> requires PAGE_SIZE defined in <sys/param.h>. However,
+   <sys/param.h> has not been processed, yet. As a result, 'PAGE_SIZE'
+   undeclared error occurs in <pthread.h>.
+   Do this after the include_next (for the sake of OpenBSD 5.0) but before
+   the split double-inclusion guard (for the sake of Solaris).  */
+#if !((defined __GLIBC__ || defined __CYGWIN__ || defined __KLIBC__) \
+      && !defined __UCLIBC__)
+# include <signal.h>
+#endif
+
+#ifndef _@GUARD_PREFIX@_SYS_SELECT_H
+#define _@GUARD_PREFIX@_SYS_SELECT_H
+
+#if !@HAVE_SYS_SELECT_H@
+/* A platform that lacks <sys/select.h>.  */
+/* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
+   on most platforms.  */
+# include <sys/time.h>
+/* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
+   that relies on memset(), but without including <string.h>.  */
+# if defined __hpux
+#  include <string.h>
+# endif
+/* On native Windows platforms:
+   Get the 'fd_set' type.
+   Get the close() declaration before we override it.  */
+# if @HAVE_WINSOCK2_H@
+#  if !defined _GL_INCLUDING_WINSOCK2_H
+#   define _GL_INCLUDING_WINSOCK2_H
+#   include <winsock2.h>
+#   undef _GL_INCLUDING_WINSOCK2_H
+#  endif
+#  include <io.h>
+# endif
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Fix some definitions from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+
+# if !GNULIB_defined_rpl_fd_isset
+
+/* Re-define FD_ISSET to avoid a WSA call while we are not using
+   network sockets.  */
+static int
+rpl_fd_isset (SOCKET fd, fd_set * set)
+{
+  u_int i;
+  if (set == NULL)
+    return 0;
+
+  for (i = 0; i < set->fd_count; i++)
+    if (set->fd_array[i] == fd)
+      return 1;
+
+  return 0;
+}
+
+#  define GNULIB_defined_rpl_fd_isset 1
+# endif
+
+# undef FD_ISSET
+# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
+
+#endif
+
+/* Hide some function declarations from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+# if !defined _@GUARD_PREFIX@_UNISTD_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef close
+#   define close close_used_without_including_unistd_h
+#  elif !defined __clang__
+    _GL_WARN_ON_USE (close,
+                     "close() used without including <unistd.h>");
+#  endif
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gethostname
+#   define gethostname gethostname_used_without_including_unistd_h
+#  elif !defined __clang__
+    _GL_WARN_ON_USE (gethostname,
+                     "gethostname() used without including <unistd.h>");
+#  endif
+# endif
+# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef socket
+#   define socket              socket_used_without_including_sys_socket_h
+#   undef connect
+#   define connect             connect_used_without_including_sys_socket_h
+#   undef accept
+#   define accept              accept_used_without_including_sys_socket_h
+#   undef bind
+#   define bind                bind_used_without_including_sys_socket_h
+#   undef getpeername
+#   define getpeername         getpeername_used_without_including_sys_socket_h
+#   undef getsockname
+#   define getsockname         getsockname_used_without_including_sys_socket_h
+#   undef getsockopt
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
+#   undef listen
+#   define listen              listen_used_without_including_sys_socket_h
+#   undef recv
+#   define recv                recv_used_without_including_sys_socket_h
+#   undef send
+#   define send                send_used_without_including_sys_socket_h
+#   undef recvfrom
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
+#   undef sendto
+#   define sendto              sendto_used_without_including_sys_socket_h
+#   undef setsockopt
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
+#   undef shutdown
+#   define shutdown            shutdown_used_without_including_sys_socket_h
+#  elif !defined __clang__
+    _GL_WARN_ON_USE (socket,
+                     "socket() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (connect,
+                     "connect() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (accept,
+                     "accept() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (bind,
+                     "bind() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getpeername,
+                     "getpeername() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockname,
+                     "getsockname() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockopt,
+                     "getsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (listen,
+                     "listen() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recv,
+                     "recv() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (send,
+                     "send() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recvfrom,
+                     "recvfrom() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (sendto,
+                     "sendto() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (setsockopt,
+                     "setsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (shutdown,
+                     "shutdown() used without including <sys/socket.h>");
+#  endif
+# endif
+#endif
+
+
+#if @GNULIB_PSELECT@
+# if @REPLACE_PSELECT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pselect
+#   define pselect rpl_pselect
+#  endif
+_GL_FUNCDECL_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+_GL_CXXALIAS_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# else
+#  if !@HAVE_PSELECT@
+_GL_FUNCDECL_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+#  endif
+_GL_CXXALIAS_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# endif
+_GL_CXXALIASWARN (pselect);
+#elif defined GNULIB_POSIXCHECK
+# undef pselect
+# if HAVE_RAW_DECL_PSELECT
+_GL_WARN_ON_USE (pselect, "pselect is not portable - "
+                 "use gnulib module pselect for portability");
+# endif
+#endif
+
+#if @GNULIB_SELECT@
+# if @REPLACE_SELECT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef select
+#   define select rpl_select
+#  endif
+_GL_FUNCDECL_RPL (select, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timeval *restrict));
+_GL_CXXALIAS_RPL (select, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   timeval *restrict));
+# else
+_GL_CXXALIAS_SYS (select, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   timeval *restrict));
+# endif
+_GL_CXXALIASWARN (select);
+#elif @HAVE_WINSOCK2_H@
+# undef select
+# define select select_used_without_requesting_gnulib_module_select
+#elif defined GNULIB_POSIXCHECK
+# undef select
+# if HAVE_RAW_DECL_SELECT
+_GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
+                 "use gnulib module select for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
+#endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
+#endif /* OSF/1 */
diff --git a/gnulib/import/w32sock.h b/gnulib/import/w32sock.h
new file mode 100644
index 000000000000..f7311887b2c6
--- /dev/null
+++ b/gnulib/import/w32sock.h
@@ -0,0 +1,140 @@
+/* w32sock.h --- internal auxiliary functions for Windows socket functions
+
+   Copyright (C) 2008-2021 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <errno.h>
+
+/* Get O_RDWR and O_BINARY.  */
+#include <fcntl.h>
+
+/* Get _open_osfhandle().  */
+#include <io.h>
+
+/* Get _get_osfhandle().  */
+#if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+#else
+# include <io.h>
+#endif
+
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY))
+
+static inline void
+set_winsock_errno (void)
+{
+  int err = WSAGetLastError ();
+
+  /* Map some WSAE* errors to the runtime library's error codes.  */
+  switch (err)
+    {
+    case WSA_INVALID_HANDLE:
+      errno = EBADF;
+      break;
+    case WSA_NOT_ENOUGH_MEMORY:
+      errno = ENOMEM;
+      break;
+    case WSA_INVALID_PARAMETER:
+      errno = EINVAL;
+      break;
+    case WSAENAMETOOLONG:
+      errno = ENAMETOOLONG;
+      break;
+    case WSAENOTEMPTY:
+      errno = ENOTEMPTY;
+      break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAEINPROGRESS:
+      errno = EINPROGRESS;
+      break;
+    case WSAEALREADY:
+      errno = EALREADY;
+      break;
+    case WSAENOTSOCK:
+      errno = ENOTSOCK;
+      break;
+    case WSAEDESTADDRREQ:
+      errno = EDESTADDRREQ;
+      break;
+    case WSAEMSGSIZE:
+      errno = EMSGSIZE;
+      break;
+    case WSAEPROTOTYPE:
+      errno = EPROTOTYPE;
+      break;
+    case WSAENOPROTOOPT:
+      errno = ENOPROTOOPT;
+      break;
+    case WSAEPROTONOSUPPORT:
+      errno = EPROTONOSUPPORT;
+      break;
+    case WSAEOPNOTSUPP:
+      errno = EOPNOTSUPP;
+      break;
+    case WSAEAFNOSUPPORT:
+      errno = EAFNOSUPPORT;
+      break;
+    case WSAEADDRINUSE:
+      errno = EADDRINUSE;
+      break;
+    case WSAEADDRNOTAVAIL:
+      errno = EADDRNOTAVAIL;
+      break;
+    case WSAENETDOWN:
+      errno = ENETDOWN;
+      break;
+    case WSAENETUNREACH:
+      errno = ENETUNREACH;
+      break;
+    case WSAENETRESET:
+      errno = ENETRESET;
+      break;
+    case WSAECONNABORTED:
+      errno = ECONNABORTED;
+      break;
+    case WSAECONNRESET:
+      errno = ECONNRESET;
+      break;
+    case WSAENOBUFS:
+      errno = ENOBUFS;
+      break;
+    case WSAEISCONN:
+      errno = EISCONN;
+      break;
+    case WSAENOTCONN:
+      errno = ENOTCONN;
+      break;
+    case WSAETIMEDOUT:
+      errno = ETIMEDOUT;
+      break;
+    case WSAECONNREFUSED:
+      errno = ECONNREFUSED;
+      break;
+    case WSAELOOP:
+      errno = ELOOP;
+      break;
+    case WSAEHOSTUNREACH:
+      errno = EHOSTUNREACH;
+      break;
+    default:
+      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
+      break;
+    }
+}
diff --git a/gnulib/update-gnulib.sh b/gnulib/update-gnulib.sh
index 252f163bf2ed..08c43fcfc143 100755
--- a/gnulib/update-gnulib.sh
+++ b/gnulib/update-gnulib.sh
@@ -60,6 +60,7 @@ IMPORTED_GNULIB_MODULES="\
     rawmemchr \
     readlink \
     rename \
+    select \
     setenv \
     signal-h \
     strchrnul \
-- 
2.31.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/4] gnulib: import chown
  2021-05-29 17:25 [PATCH 1/4] gnulib: import chown Mike Frysinger
                   ` (2 preceding siblings ...)
  2021-05-29 17:25 ` [PATCH 4/4] gnulib: import select Mike Frysinger
@ 2021-06-07 14:23 ` Tom Tromey
  2021-06-07 14:31   ` Eli Zaretskii
  3 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2021-06-07 14:23 UTC (permalink / raw)
  To: Mike Frysinger via Gdb-patches

>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:

Mike> A few sims use this to emulate chown syscalls.

Looks good.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/4] gnulib: import netdb
  2021-05-29 17:25 ` [PATCH 3/4] gnulib: import netdb Mike Frysinger
@ 2021-06-07 14:27   ` Tom Tromey
  0 siblings, 0 replies; 20+ messages in thread
From: Tom Tromey @ 2021-06-07 14:27 UTC (permalink / raw)
  To: Mike Frysinger via Gdb-patches

>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:

Mike> A few sims use this to provide network functionality.

Thanks, this is ok.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-05-29 17:25 ` [PATCH 4/4] gnulib: import select Mike Frysinger
@ 2021-06-07 14:29   ` Tom Tromey
  2021-06-08  4:52     ` Mike Frysinger
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2021-06-07 14:29 UTC (permalink / raw)
  To: Mike Frysinger via Gdb-patches

>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:

Mike> A few sims use this to emulate the syscall & provide network
Mike> functionality.

Thank you, I think this is ok.

There are some gnulib modules that don't work well for gdb.
The only one I can really remember is 'stat'.  Hopefully select isn't
one of them :)

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/4] gnulib: import chown
  2021-06-07 14:23 ` [PATCH 1/4] gnulib: import chown Tom Tromey
@ 2021-06-07 14:31   ` Eli Zaretskii
  2021-06-08  1:15     ` Mike Frysinger
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-07 14:31 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Date: Mon, 07 Jun 2021 08:23:50 -0600
> 
> >>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Mike> A few sims use this to emulate chown syscalls.
> 
> Looks good.

AFAICT, the Gnulib emulation always returns a failure status in the
MinGW port, is that okay for the callers of chown?  Perhaps a better
alternative is to silently do nothing on MS-Windows?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/4] gnulib: import chown
  2021-06-07 14:31   ` Eli Zaretskii
@ 2021-06-08  1:15     ` Mike Frysinger
  2021-06-08  2:32       ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-06-08  1:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Tom Tromey, gdb-patches

On 07 Jun 2021 17:31, Eli Zaretskii via Gdb-patches wrote:
> > From: Tom Tromey <tom@tromey.com>
> > Date: Mon, 07 Jun 2021 08:23:50 -0600
> > 
> > >>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> > 
> > Mike> A few sims use this to emulate chown syscalls.
> > 
> > Looks good.
> 
> AFAICT, the Gnulib emulation always returns a failure status in the
> MinGW port, is that okay for the callers of chown?  Perhaps a better
> alternative is to silently do nothing on MS-Windows?

the calling code can decide how to handle this.  using gnulib is still better
so we don't have to put _WIN32/__MINGW32__/whatever ifdefs everywhere.
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/4] gnulib: import chown
  2021-06-08  1:15     ` Mike Frysinger
@ 2021-06-08  2:32       ` Eli Zaretskii
  2021-06-08  4:14         ` Mike Frysinger
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2021-06-08  2:32 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: tom, gdb-patches

> Date: Mon, 7 Jun 2021 21:15:36 -0400
> From: Mike Frysinger <vapier@gentoo.org>
> Cc: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
> 
> > AFAICT, the Gnulib emulation always returns a failure status in the
> > MinGW port, is that okay for the callers of chown?  Perhaps a better
> > alternative is to silently do nothing on MS-Windows?
> 
> the calling code can decide how to handle this.  using gnulib is still better
> so we don't have to put _WIN32/__MINGW32__/whatever ifdefs everywhere.

Sure, but won't the calling code need those same #ifdef's you want to
avoid?

My point is that chown on Windows is largely a no-op, so most callers
will want to silently do nothing rather than always fail.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/4] gnulib: import chown
  2021-06-08  2:32       ` Eli Zaretskii
@ 2021-06-08  4:14         ` Mike Frysinger
  0 siblings, 0 replies; 20+ messages in thread
From: Mike Frysinger @ 2021-06-08  4:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tom, gdb-patches

On 08 Jun 2021 05:32, Eli Zaretskii wrote:
> > Date: Mon, 7 Jun 2021 21:15:36 -0400
> > From: Mike Frysinger <vapier@gentoo.org>
> > Cc: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
> > 
> > > AFAICT, the Gnulib emulation always returns a failure status in the
> > > MinGW port, is that okay for the callers of chown?  Perhaps a better
> > > alternative is to silently do nothing on MS-Windows?
> > 
> > the calling code can decide how to handle this.  using gnulib is still better
> > so we don't have to put _WIN32/__MINGW32__/whatever ifdefs everywhere.
> 
> Sure, but won't the calling code need those same #ifdef's you want to
> avoid?

no, because chown will fail with ENOSYS, and the caller can choose to ignore
those instead.

> My point is that chown on Windows is largely a no-op, so most callers
> will want to silently do nothing rather than always fail.

i get that.  my point is that we suffer from #ifdef hell and gnulib is
providing a way out.  the answer isn't to dive right back in.
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-07 14:29   ` Tom Tromey
@ 2021-06-08  4:52     ` Mike Frysinger
  2021-06-08 12:37       ` Tom Tromey
  2021-06-09 12:27       ` Pedro Alves
  0 siblings, 2 replies; 20+ messages in thread
From: Mike Frysinger @ 2021-06-08  4:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Mike Frysinger via Gdb-patches

On 07 Jun 2021 08:29, Tom Tromey wrote:
> >>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Mike> A few sims use this to emulate the syscall & provide network
> Mike> functionality.
> 
> Thank you, I think this is ok.
> 
> There are some gnulib modules that don't work well for gdb.
> The only one I can really remember is 'stat'.  Hopefully select isn't
> one of them :)

that would be unfortunate, but i guess we'll find out.  i'm not sure how we
can balance these tensions short of each project starting to carve out their
own gnulib ports.
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-08  4:52     ` Mike Frysinger
@ 2021-06-08 12:37       ` Tom Tromey
  2021-06-09 12:27       ` Pedro Alves
  1 sibling, 0 replies; 20+ messages in thread
From: Tom Tromey @ 2021-06-08 12:37 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Mike Frysinger via Gdb-patches

>> There are some gnulib modules that don't work well for gdb.
>> The only one I can really remember is 'stat'.  Hopefully select isn't
>> one of them :)

Mike> that would be unfortunate, but i guess we'll find out.  i'm not sure how we
Mike> can balance these tensions short of each project starting to carve out their
Mike> own gnulib ports.

The stat one could be fixed in theory by changing BFD to use gnulib.
We can also possibly patch gnulib when needed, either upstream or locally.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-08  4:52     ` Mike Frysinger
  2021-06-08 12:37       ` Tom Tromey
@ 2021-06-09 12:27       ` Pedro Alves
  2021-06-09 16:52         ` Mike Frysinger
  1 sibling, 1 reply; 20+ messages in thread
From: Pedro Alves @ 2021-06-09 12:27 UTC (permalink / raw)
  To: Tom Tromey, Mike Frysinger via Gdb-patches

On 2021-06-08 5:52 a.m., Mike Frysinger via Gdb-patches wrote:
> On 07 Jun 2021 08:29, Tom Tromey wrote:
>>>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
>>
>> Mike> A few sims use this to emulate the syscall & provide network
>> Mike> functionality.
>>
>> Thank you, I think this is ok.
>>
>> There are some gnulib modules that don't work well for gdb.
>> The only one I can really remember is 'stat'.  Hopefully select isn't
>> one of them :)
> 
> that would be unfortunate, but i guess we'll find out.  i'm not sure how we
> can balance these tensions short of each project starting to carve out their
> own gnulib ports.

I think that on Windows, gnulib's select module does something very similar to 
what we do with ser-mingw.c's gdb_select:

~~~
/* On Windows, gdb_select is implemented using WaitForMulpleObjects.
   A "select thread" is created for each file descriptor.  These
   threads looks for activity on the corresponding descriptor, using
   whatever techniques are appropriate for the descriptor type.  When
   that activity occurs, the thread signals an appropriate event,
   which wakes up WaitForMultipleObjects.
~~~

I've always feared that gnulib's select module would conflict with that,
but I don't know for sure.  In theory, we should be able to replace all
that code by using gnulib's select instead, though I'm not sure gnulib
handles some particulars like Ctrl-C interruption.

I think we can avoid some pain of someone tests the import on Windows before
merging to master.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-09 12:27       ` Pedro Alves
@ 2021-06-09 16:52         ` Mike Frysinger
  2021-06-09 18:12           ` Pedro Alves
  0 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-06-09 16:52 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, Mike Frysinger via Gdb-patches

On 09 Jun 2021 13:27, Pedro Alves wrote:
> On 2021-06-08 5:52 a.m., Mike Frysinger via Gdb-patches wrote:
> > On 07 Jun 2021 08:29, Tom Tromey wrote:
> >>>>>>> "Mike" == Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org> writes:
> >>
> >> Mike> A few sims use this to emulate the syscall & provide network
> >> Mike> functionality.
> >>
> >> Thank you, I think this is ok.
> >>
> >> There are some gnulib modules that don't work well for gdb.
> >> The only one I can really remember is 'stat'.  Hopefully select isn't
> >> one of them :)
> > 
> > that would be unfortunate, but i guess we'll find out.  i'm not sure how we
> > can balance these tensions short of each project starting to carve out their
> > own gnulib ports.
> 
> I think that on Windows, gnulib's select module does something very similar to 
> what we do with ser-mingw.c's gdb_select:
> 
> ~~~
> /* On Windows, gdb_select is implemented using WaitForMulpleObjects.
>    A "select thread" is created for each file descriptor.  These
>    threads looks for activity on the corresponding descriptor, using
>    whatever techniques are appropriate for the descriptor type.  When
>    that activity occurs, the thread signals an appropriate event,
>    which wakes up WaitForMultipleObjects.
> ~~~
> 
> I've always feared that gnulib's select module would conflict with that,
> but I don't know for sure.  In theory, we should be able to replace all
> that code by using gnulib's select instead, though I'm not sure gnulib
> handles some particulars like Ctrl-C interruption.

why do you think it would conflict ?  the file doesn't seem to use select()
at all, and ser-mingw is always enabled for mingw targets.  seems like the
func would just be ignored.

> I think we can avoid some pain of someone tests the import on Windows before
> merging to master.

it's already merged ;)

gdb.exe links for me for i686-w64-mingw32, but i don't really have any way of
testing it runs, let alone run test suite.
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-09 16:52         ` Mike Frysinger
@ 2021-06-09 18:12           ` Pedro Alves
  2021-06-09 18:32             ` Mike Frysinger
  0 siblings, 1 reply; 20+ messages in thread
From: Pedro Alves @ 2021-06-09 18:12 UTC (permalink / raw)
  To: Tom Tromey, Mike Frysinger via Gdb-patches

On 2021-06-09 5:52 p.m., Mike Frysinger wrote:
> On 09 Jun 2021 13:27, Pedro Alves wrote:

>> I've always feared that gnulib's select module would conflict with that,
>> but I don't know for sure.  In theory, we should be able to replace all
>> that code by using gnulib's select instead, though I'm not sure gnulib
>> handles some particulars like Ctrl-C interruption.
> 
> why do you think it would conflict ?  the file doesn't seem to use select()
> at all, and ser-mingw is always enabled for mingw targets.  seems like the
> func would just be ignored.

gnulib also sometimes replaces headers with their own incompatible
definitions.

Thanks,
Pedro Alves

> 
>> I think we can avoid some pain of someone tests the import on Windows before
>> merging to master.
> 
> it's already merged ;)
> 
> gdb.exe links for me for i686-w64-mingw32, but i don't really have any way of
> testing it runs, let alone run test suite.
> -mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-09 18:12           ` Pedro Alves
@ 2021-06-09 18:32             ` Mike Frysinger
  2021-06-09 23:30               ` Pedro Alves
  0 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-06-09 18:32 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, Mike Frysinger via Gdb-patches

On 09 Jun 2021 19:12, Pedro Alves wrote:
> On 2021-06-09 5:52 p.m., Mike Frysinger wrote:
> > On 09 Jun 2021 13:27, Pedro Alves wrote:
> >> I've always feared that gnulib's select module would conflict with that,
> >> but I don't know for sure.  In theory, we should be able to replace all
> >> that code by using gnulib's select instead, though I'm not sure gnulib
> >> handles some particulars like Ctrl-C interruption.
> > 
> > why do you think it would conflict ?  the file doesn't seem to use select()
> > at all, and ser-mingw is always enabled for mingw targets.  seems like the
> > func would just be ignored.
> 
> gnulib also sometimes replaces headers with their own incompatible
> definitions.

good point, but i'm not sure how that matters to ser-mingw specifically.
it isn't including any select.h related headers, just Windows-specific ones.
i haven't gone through that list (and indirect includes) explicitly.  but i
would expect the build to at least warn or fail if that were the case.

did you have any specific concerns here ?  or just aiming for due diligence
with the testsuite to assuage general unease ?
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-09 18:32             ` Mike Frysinger
@ 2021-06-09 23:30               ` Pedro Alves
  2021-06-10  0:38                 ` Mike Frysinger
  0 siblings, 1 reply; 20+ messages in thread
From: Pedro Alves @ 2021-06-09 23:30 UTC (permalink / raw)
  To: Tom Tromey, Mike Frysinger via Gdb-patches

On 2021-06-09 7:32 p.m., Mike Frysinger wrote:
> On 09 Jun 2021 19:12, Pedro Alves wrote:
>> On 2021-06-09 5:52 p.m., Mike Frysinger wrote:
>>> On 09 Jun 2021 13:27, Pedro Alves wrote:
>>>> I've always feared that gnulib's select module would conflict with that,
>>>> but I don't know for sure.  In theory, we should be able to replace all
>>>> that code by using gnulib's select instead, though I'm not sure gnulib
>>>> handles some particulars like Ctrl-C interruption.
>>>
>>> why do you think it would conflict ?  the file doesn't seem to use select()
>>> at all, and ser-mingw is always enabled for mingw targets.  seems like the
>>> func would just be ignored.
>>
>> gnulib also sometimes replaces headers with their own incompatible
>> definitions.
> 
> good point, but i'm not sure how that matters to ser-mingw specifically.
> it isn't including any select.h related headers, just Windows-specific ones.

I meant to also point at mingw-hdep.c, which is where gdb_select implementation lives.
That of course, includes sys/select.h via gdb_select.h.
I misremembered that gdb_select itself was in ser-mingw.c too.  mingw's version
of gdb_select is built on top of the ser-mingw.c and struct serial, but lives
in mingw-hdep.c.

Also, the sockets module was pulled in as well as dependency, and I suppose that hides the SOCKET vs
int, close vs closesocket, _get_osfhandle, read/write vs send/recv etc. WinSock2 particularities,
and don't know whether that can cause issues in the code that we have that assumes native Windows
sockets on mingw, which you'll find a lot of if you look for USE_WIN32API, particularly in
gdbserver and gdbreplay.

If it does, it may not be noticeable with a build-only check.

Even if it doesn't, there's now a lot of USE_WIN32API code in gdb, gdbsupport
and gdbserver that is now ripe for cleansing.  In addition to close vs closesocket, read vs send
etc I mentioned above, there should be no need anymore to include the windows/winsock headers to
get access to sockets things, we should call gl_sockets_startup instead of WSAStartup, etc.

> i haven't gone through that list (and indirect includes) explicitly.  but i
> would expect the build to at least warn or fail if that were the case.
> 
> did you have any specific concerns here ?  or just aiming for due diligence
> with the testsuite to assuage general unease ?

The latter, but I wasn't thinking of a testsuite run, which is notoriously difficult
on Windows.  More like a smoke test, run GDB, to make sure you can still debug something.

Also, a quick check to make sure remote debugging against a Windows GDBserver built
from master still works would be good -- gdbserver also uses gnulib, and uses select
(not gdb_select) and sockets.

Interestingly, this module import may have put us closer to removing the Windows
gdbserver limitation that it only works with tcp/ip socket connections, particularly
interesting being pipes, for "target remote | gdbserver" support.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-09 23:30               ` Pedro Alves
@ 2021-06-10  0:38                 ` Mike Frysinger
  2021-06-10 18:11                   ` Tom Tromey
  0 siblings, 1 reply; 20+ messages in thread
From: Mike Frysinger @ 2021-06-10  0:38 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, Mike Frysinger via Gdb-patches

On 10 Jun 2021 00:30, Pedro Alves wrote:
> On 2021-06-09 7:32 p.m., Mike Frysinger wrote:
> > On 09 Jun 2021 19:12, Pedro Alves wrote:
> >> On 2021-06-09 5:52 p.m., Mike Frysinger wrote:
> >>> On 09 Jun 2021 13:27, Pedro Alves wrote:
> >>>> I've always feared that gnulib's select module would conflict with that,
> >>>> but I don't know for sure.  In theory, we should be able to replace all
> >>>> that code by using gnulib's select instead, though I'm not sure gnulib
> >>>> handles some particulars like Ctrl-C interruption.
> >>>
> >>> why do you think it would conflict ?  the file doesn't seem to use select()
> >>> at all, and ser-mingw is always enabled for mingw targets.  seems like the
> >>> func would just be ignored.
> >>
> >> gnulib also sometimes replaces headers with their own incompatible
> >> definitions.
> > 
> > good point, but i'm not sure how that matters to ser-mingw specifically.
> > it isn't including any select.h related headers, just Windows-specific ones.
> 
> I meant to also point at mingw-hdep.c, which is where gdb_select implementation lives.
> That of course, includes sys/select.h via gdb_select.h.
> I misremembered that gdb_select itself was in ser-mingw.c too.  mingw's version
> of gdb_select is built on top of the ser-mingw.c and struct serial, but lives
> in mingw-hdep.c.
> 
> Also, the sockets module was pulled in as well as dependency, and I suppose that hides the SOCKET vs
> int, close vs closesocket, _get_osfhandle, read/write vs send/recv etc. WinSock2 particularities,
> and don't know whether that can cause issues in the code that we have that assumes native Windows
> sockets on mingw, which you'll find a lot of if you look for USE_WIN32API, particularly in
> gdbserver and gdbreplay.
> 
> If it does, it may not be noticeable with a build-only check.
> 
> Even if it doesn't, there's now a lot of USE_WIN32API code in gdb, gdbsupport
> and gdbserver that is now ripe for cleansing.  In addition to close vs closesocket, read vs send
> etc I mentioned above, there should be no need anymore to include the windows/winsock headers to
> get access to sockets things, we should call gl_sockets_startup instead of WSAStartup, etc.

hmm, so how gnulib is integrated leads to "interesting" behavior.  we don't
run configure against it, we only compile+link against it.  so when gdb's
configure probes sys/select.h, it doesn't find it.  and then the mingw files
(and files it includes) that are protected by HAVE_SYS_SELECT_H are not used.

on the sim side, i dropped the configure tests entirely and changed them to
assume the headers/funcs exist.

> > i haven't gone through that list (and indirect includes) explicitly.  but i
> > would expect the build to at least warn or fail if that were the case.
> > 
> > did you have any specific concerns here ?  or just aiming for due diligence
> > with the testsuite to assuage general unease ?
> 
> The latter, but I wasn't thinking of a testsuite run, which is notoriously difficult
> on Windows.  More like a smoke test, run GDB, to make sure you can still debug something.
> 
> Also, a quick check to make sure remote debugging against a Windows GDBserver built
> from master still works would be good -- gdbserver also uses gnulib, and uses select
> (not gdb_select) and sockets.
> 
> Interestingly, this module import may have put us closer to removing the Windows
> gdbserver limitation that it only works with tcp/ip socket connections, particularly
> interesting being pipes, for "target remote | gdbserver" support.

i can provide gdb.exe's easily, but i imagine most of us can do that now too.
i think Debian includes a bunch of mingw toolchains.
-mike

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/4] gnulib: import select
  2021-06-10  0:38                 ` Mike Frysinger
@ 2021-06-10 18:11                   ` Tom Tromey
  0 siblings, 0 replies; 20+ messages in thread
From: Tom Tromey @ 2021-06-10 18:11 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, Mike Frysinger via Gdb-patches

Mike> hmm, so how gnulib is integrated leads to "interesting" behavior.  we don't
Mike> run configure against it, we only compile+link against it.  so when gdb's
Mike> configure probes sys/select.h, it doesn't find it.  and then the mingw files
Mike> (and files it includes) that are protected by HAVE_SYS_SELECT_H are not used.

If gnulib provides a header, and we definitely want to use it in gdb,
then I think the configury and the cpp checks can just be removed.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-06-10 18:11 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-29 17:25 [PATCH 1/4] gnulib: import chown Mike Frysinger
2021-05-29 17:25 ` [PATCH 2/4] sim: v850: assume chown is available Mike Frysinger
2021-05-29 17:25 ` [PATCH 3/4] gnulib: import netdb Mike Frysinger
2021-06-07 14:27   ` Tom Tromey
2021-05-29 17:25 ` [PATCH 4/4] gnulib: import select Mike Frysinger
2021-06-07 14:29   ` Tom Tromey
2021-06-08  4:52     ` Mike Frysinger
2021-06-08 12:37       ` Tom Tromey
2021-06-09 12:27       ` Pedro Alves
2021-06-09 16:52         ` Mike Frysinger
2021-06-09 18:12           ` Pedro Alves
2021-06-09 18:32             ` Mike Frysinger
2021-06-09 23:30               ` Pedro Alves
2021-06-10  0:38                 ` Mike Frysinger
2021-06-10 18:11                   ` Tom Tromey
2021-06-07 14:23 ` [PATCH 1/4] gnulib: import chown Tom Tromey
2021-06-07 14:31   ` Eli Zaretskii
2021-06-08  1:15     ` Mike Frysinger
2021-06-08  2:32       ` Eli Zaretskii
2021-06-08  4:14         ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).