xref: /netbsd-src/external/gpl2/xcvs/dist/m4/sunos57-select.m4 (revision a7c918477dd5f12c1da816ba05caf44eab2d06d6)
1dnl From Mark D Baushke & Derek Price.
2dnl
3dnl See if select() on a /dev/null fd hangs when timeout is NULL.
4dnl Also check to see that /dev/null is in the readfds set returned.
5dnl
6dnl Observed on Solaris 7:
7dnl   If /dev/null is in the readfds set, it will never be marked as
8dnl   ready by the OS. In the case of a /dev/null fd being the only fd
9dnl   in the select set and timeout == NULL, the select will hang.
10dnl
11dnl If the test fails, then arrange to use select only via a wrapper
12dnl function that works around the problem.
13
14AC_DEFUN([ccvs_FUNC_SELECT],
15[
16 AC_CHECK_HEADERS([fcntl.h])
17 AC_CACHE_CHECK([whether select hangs on /dev/null fd when timeout is NULL],
18  ccvs_cv_func_select_hang,
19  [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
20#include <stdio.h>
21#include <sys/select.h>
22#ifdef HAVE_FCNTL_H
23# include <fcntl.h>
24#endif
25#include <errno.h>]], [[
26  int numfds;
27  fd_set readfds;
28  struct timeval timeout;
29  int fd = open ("/dev/null", O_RDONLY);
30
31  FD_ZERO (&readfds);
32  FD_SET (fd, &readfds);
33  timeout.tv_sec = 0;
34  timeout.tv_usec = 1;
35
36  while ((numfds = select (fd + 1, &readfds, NULL, NULL, &timeout)) < 0
37	 && errno == EINTR);
38  return (numfds <= 0);
39	  ]])],
40	 ccvs_cv_func_select_hang=no,
41	 ccvs_cv_func_select_hang=yes,
42	 dnl When crosscompiling, assume it is broken.
43	 ccvs_cv_func_select_hang=yes)
44  ])
45  if test $ccvs_cv_func_select_hang = yes; then
46    ccvs_PREREQ_SELECT
47
48    AC_LIBOBJ(sunos57-select)
49    AC_DEFINE(select, rpl_select,
50      [Define to rpl_select if the replacement function should be used.])
51  fi
52])
53
54AC_DEFUN([ccvs_PREREQ_SELECT], [
55  AC_CHECK_HEADERS(fcntl.h unistd.h)])
56