]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Don’t include sys/select.h from sys/types.h.
authorZack Weinberg <zackw@panix.com>
Sat, 16 Mar 2019 16:35:25 +0000 (12:35 -0400)
committerZack Weinberg <zackw@panix.com>
Wed, 8 Jan 2020 18:45:44 +0000 (13:45 -0500)
This is supposedly present for BSD compatibility, but the current
generation of BSDs is not consistent about it: FreeBSD does, OpenBSD
doesn’t, NetBSD exposes only fd_set and the FD_* macros.  Programs
that need to wait for any of multiple I/O events have several
alternatives to select nowadays, so I think it makes sense to expose
select only to programs that specifically want it.

Only a few places within our own code are affected.  A few test
programs need to include sys/select.h explicitly, as does rpc/svc.h.
sysdeps/nptl/thread_db.h needs to declare sigset_t, and
sysdeps/unix/sysv/linux/pselect.c was including sys/poll.h instead of
sys/select.h, which is probably a copy-and-paste error.  sys/socket.h
needs to forward-declare struct timespec under __USE_GNU, because
recvmmsg has a struct timespec * argument; I’m open to the possibility
of having it fully declare struct timespec.

I considered taking sys/select.h out of sys/time.h as well, but POSIX
not only explicitly allows this inclusion, it requires sys/time.h to
declare almost everything that sys/select.h declares.  It doesn’t seem
worth creating another bits header just to prevent sys/time.h from
declaring pselect, sigset_t, and struct timespec.

Not including sys/select.h from sys/types.h means that sys/types.h
also no longer defines anything from sys/time.h, and a couple of files
were relying on that.  (pthread_join_common.c should be using
clock_gettime instead of gettimeofday, but that's out of scope for
this patch series.)

* posix/sys/types.h: Don’t include sys/select.h.
* scripts/check-obsolete-constructs.py: Remove whitelist entry
for sys/types.h -> sys/select.h.  Adjust commentary re
sys/time.h -> sys/select.h.

* socket/sys/socket.h: When __USE_GNU, forward-declare struct timespec.
* misc/tst-fdset.c, nptl/tst-cancel4.c, scripts/check-c++-types.sh
* sunrpc/rpc/svc.h: Include sys/select.h.
* sysdeps/nptl/thread_db.h: Include bits/types/sigset_t.h.
* sysdeps/unix/sysv/linux/pselect.c: Include sys/select.h,
not sys/poll.h.
* nptl/pthread_join_common.c, sysdeps/unix/sysv/linux/dl-vdso.h:
Include sys/time.h.

misc/tst-fdset.c
nptl/pthread_join_common.c
nptl/tst-cancel4.c
posix/sys/types.h
scripts/check-c++-types.sh
scripts/check-obsolete-constructs.py
socket/sys/socket.h
sunrpc/rpc/svc.h
sysdeps/nptl/thread_db.h

index eace688767ee9e3486a25257e234e5fb67657d17..62ac4c240ec0ea29fd84ed944c0f638d29acd1e4 100644 (file)
@@ -18,7 +18,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
-#include <sys/types.h>
+#include <sys/select.h>
 
 static int
 do_test (void)
index a96ceafde457ced247399ebaa2319466560322fe..29af4d2780154561251597a742e7cc824d162810 100644 (file)
@@ -21,6 +21,8 @@
 #include <stap-probe.h>
 #include <time.h>
 
+#include <sys/time.h>
+
 static void
 cleanup (void *arg)
 {
index 652668537a51a7e0e2018566cd7baccf3e0c8e73..5ede8a0caa85ae259d1ecfbd69f5dae500742ef6 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/ipc.h>
index 64fa01011456d63d2498c46525f313673ec7b640..f7ce0c68a8741e21158f4a81c4885b98a3707bad 100644 (file)
@@ -93,9 +93,6 @@ __BEGIN_DECLS
 
 /* In BSD <sys/types.h> is expected to define BYTE_ORDER.  */
 # include <endian.h>
-
-/* It also defines `fd_set' and the FD_* macros for `select'.  */
-# include <sys/select.h>
 #endif /* Use misc.  */
 
 __END_DECLS
index d868204abe0ce2ab8774436d75bc01e4561d617b..ebf4fd18189abec44b832af88de0c1bcf507af20 100755 (executable)
@@ -46,6 +46,7 @@ while read t; do
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/resource.h>
+#include <sys/select.h>
 #include <unistd.h>
 void foo ($t) { }
 EOF
index dfe0d0fff5eab42e41ffd3405d9567b53a0d742f..77999d8c6f3aeca55420b88d52d29f328a73d086 100755 (executable)
@@ -530,13 +530,13 @@ HEADER_ALLOWED_INCLUDES = {
     # mandated: sys/msg.h -> sys/ipc.h
     #           sys/sem.h -> sys/ipc.h
     #           sys/shm.h -> sys/ipc.h
-    # allowed:  sys/time.h -> sys/select.h
-    #           sys/wait.h -> signal.h
+    #           sys/time.h -> sys/select.h (effectively)
+    # allowed:  sys/wait.h -> signal.h
     "sys/msg.h":                   [ "sys/ipc.h" ],
     "sys/sem.h":                   [ "sys/ipc.h" ],
     "sys/shm.h":                   [ "sys/ipc.h" ],
     "sys/time.h":                  [ "sys/select.h" ],
-    "sys/types.h":                 [ "endian.h", "sys/select.h" ],
+    "sys/types.h":                 [ "endian.h" ],
     "sys/uio.h":                   [ "sys/types.h" ],
     "sys/un.h":                    [ "string.h" ],
     "sys/wait.h":                  [ "signal.h" ],
index 0c158d1e931ec05c1b81311fe25d867e63fb8936..305e6201f9c1181a1a2d92332d5f07dc2c1e9d1c 100644 (file)
@@ -35,6 +35,10 @@ __BEGIN_DECLS
 # include <bits/types/struct_osockaddr.h>
 #endif
 
+#ifdef __USE_GNU
+struct timespec;
+#endif
+
 /* The following constants should be used for the second parameter of
    `shutdown'.  */
 enum
index ea2ba71906befd7c476c32acdbc73d1526b194ff..2dd9d878812271590a8dedb2423311957259301a 100644 (file)
@@ -53,6 +53,7 @@
 
 #include <features.h>
 #include <rpc/rpc_msg.h>
+#include <sys/select.h>
 
 __BEGIN_DECLS
 
index 7418344d8b359b3be863aac7ba7e3bb97d51f09c..bf073b7d862392dee3239e92e2b5392b888f9bd7 100644 (file)
@@ -26,7 +26,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/procfs.h>
-
+#include <bits/types/sigset_t.h>
 
 /* Error codes of the library.  */
 typedef enum