diff --git a/m4/ChangeLog b/m4/ChangeLog
index 8940b512d492cf6467aafa70c4f7894c758cf00c..2a620870e232260535ed24ded47db0d7616b4bf8 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-17  Larry Jones  <lawrence.jones@siemens.com>
+
+	* sunos57-select.m4: Properly conditionalize the test program.
+
 2008-11-13  Larry Jones  <lawrence.jones@siemens.com>
 
 	* sunos57-select.m4: Need <sys/time.h> for struct timeval.
diff --git a/m4/sunos57-select.m4 b/m4/sunos57-select.m4
index fd92e5a765540ab32bf7aca399a077b16a00aefb..3ae58066cba7549c6e083ce9df0342dbfc7f3e40 100644
--- a/m4/sunos57-select.m4
+++ b/m4/sunos57-select.m4
@@ -13,14 +13,25 @@ dnl function that works around the problem.
 
 AC_DEFUN([ccvs_FUNC_SELECT],
 [
+ AC_REQUIRE([gl_HEADER_SYS_SELECT])
  AC_REQUIRE([gl_HEADER_SYS_TIME_H])
- AC_CHECK_HEADERS([fcntl.h])
+ AC_CHECK_HEADERS([sys/types.h unistd.h fcntl.h])
  AC_CACHE_CHECK([whether select hangs on /dev/null fd when timeout is NULL],
   ccvs_cv_func_select_hang,
   [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
 #include <stdio.h>
-#include <sys/select.h>
-#include <sys/time.h>
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif