diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-08-04 20:42:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-08-04 20:42:45 -0700 |
commit | 75c6845ef1fc840afe995a84f3cd1c94f5257d7d (patch) | |
tree | 031fe9d75394737620dc678cd7ba0878ccee2fb2 | |
parent | 70a9ef01f022982241f80fe1eac19930aa597507 (diff) | |
download | txr-75c6845ef1fc840afe995a84f3cd1c94f5257d7d.tar.gz txr-75c6845ef1fc840afe995a84f3cd1c94f5257d7d.tar.bz2 txr-75c6845ef1fc840afe995a84f3cd1c94f5257d7d.zip |
musl: fix missing <sys/time.h>.
Issue peported by Ethan Hawk. Our socket.c module is using struct
timeval without including <sys/time.h>, which breaks on musl.
* configure: in the select test, let's include <sys/time.h>, and
if the test passes, let's set have_sys_time, so that HAVE_SELECT
implies HAVE_SYS_TIME. This way code wrapped with HAVE_SELECT doesn't
separately have to test for HAVE_SYS_TIME.
* socket.c: If HAVE_SYS_TIME is true, then we include <sys/time.h>,
independently of HAVE_SELECT.
(sock_timeout, sock_load_init): Like the select-based code, code using
SO_SNDTIMEO or SO_RCVTIMO also uses timeval, so needs to be wrapped with
HAVE_SYS_TIME.
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | socket.c | 7 |
2 files changed, 7 insertions, 2 deletions
@@ -3480,6 +3480,7 @@ if [ $have_sockets ] ; then cat > conftest.c <<! #include <sys/select.h> +#include <sys/time.h> int main(int argc, char **argv) { @@ -3494,6 +3495,7 @@ int main(int argc, char **argv) if conftest; then printf "yes\n" printf "#define HAVE_SELECT 1\n" >> config.h + have_sys_time=y else printf "no\n" fi @@ -45,6 +45,9 @@ #elif HAVE_SELECT #include <sys/select.h> #endif +#if HAVE_SYS_TIME +#include <sys/time.h> +#endif #include <netinet/in.h> #include "lib.h" #include "stream.h" @@ -1045,7 +1048,7 @@ static val sock_shutdown(val sock, val how) return t; } -#if defined SO_SNDTIMEO && defined SO_RCVTIMEO +#if HAVE_SYS_TIME && defined SO_SNDTIMEO && defined SO_RCVTIMEO static val sock_timeout(val sock, val usec, val name, int which, val self) { cnum fd = c_num(stream_fd(sock), self); @@ -1180,7 +1183,7 @@ void sock_load_init(void) reg_fun(intern(lit("sock-shutdown"), user_package), func_n2o(sock_shutdown, 1)); reg_fun(intern(lit("open-socket"), user_package), func_n3o(open_socket, 2)); reg_fun(intern(lit("open-socket-pair"), user_package), func_n3o(socketpair_wrap, 2)); -#if defined SO_SNDTIMEO && defined SO_RCVTIMEO +#if HAVE_SYS_TIME && defined SO_SNDTIMEO && defined SO_RCVTIMEO reg_fun(intern(lit("sock-send-timeout"), user_package), func_n2(sock_send_timeout)); reg_fun(intern(lit("sock-recv-timeout"), user_package), func_n2(sock_recv_timeout)); #endif |