2 dnl Bash specific tests
4 dnl Some derived from PDKSH 5.1.3 autoconf tests
7 dnl Check if dup2() does not clear the close on exec flag
9 AC_DEFUN(BASH_DUP2_CLOEXEC_CHECK,
10 [AC_MSG_CHECKING(if dup2 fails to clear the close-on-exec flag)
11 AC_CACHE_VAL(bash_cv_dup2_broken,
13 #include <sys/types.h>
18 fd1 = open("/dev/null", 2);
19 if (fcntl(fd1, 2, 1) < 0)
24 fl = fcntl(fd2, 1, 0);
25 /* fl will be 1 if dup2 did not reset the close-on-exec flag. */
28 ], bash_cv_dup2_broken=yes, bash_cv_dup2_broken=no,
29 [AC_MSG_ERROR(cannot check dup2 if cross compiling -- defaulting to no)
30 bash_cv_dup2_broken=no])
32 AC_MSG_RESULT($bash_cv_dup2_broken)
33 if test $bash_cv_dup2_broken = yes; then
34 AC_DEFINE(DUP2_BROKEN)
38 dnl Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
39 AC_DEFUN(BASH_SIGNAL_CHECK,
40 [AC_REQUIRE([AC_TYPE_SIGNAL])
41 AC_MSG_CHECKING(for type of signal functions)
42 AC_CACHE_VAL(bash_cv_signal_vintage,
44 AC_TRY_LINK([#include <signal.h>],[
47 sigemptyset(&ss); sigsuspend(&ss);
48 sigaction(SIGINT, &sa, (struct sigaction *) 0);
49 sigprocmask(SIG_BLOCK, &ss, (sigset_t *) 0);
50 ], bash_cv_signal_vintage=posix,
52 AC_TRY_LINK([#include <signal.h>], [
53 int mask = sigmask(SIGINT);
54 sigsetmask(mask); sigblock(mask); sigpause(mask);
55 ], bash_cv_signal_vintage=4.2bsd,
59 RETSIGTYPE foo() { }], [
60 int mask = sigmask(SIGINT);
61 sigset(SIGINT, foo); sigrelse(SIGINT);
62 sighold(SIGINT); sigpause(SIGINT);
63 ], bash_cv_signal_vintage=svr3, bash_cv_signal_vintage=v7
68 AC_MSG_RESULT($bash_cv_signal_vintage)
69 if test "$bash_cv_signal_vintage" = posix; then
70 AC_DEFINE(HAVE_POSIX_SIGNALS)
71 elif test "$bash_cv_signal_vintage" = "4.2bsd"; then
72 AC_DEFINE(HAVE_BSD_SIGNALS)
73 elif test "$bash_cv_signal_vintage" = svr3; then
74 AC_DEFINE(HAVE_USG_SIGHOLD)
78 dnl Check if the pgrp of setpgrp() can't be the pid of a zombie process.
79 AC_DEFUN(BASH_PGRP_SYNC,
80 [AC_REQUIRE([AC_FUNC_GETPGRP])
81 AC_MSG_CHECKING(whether pgrps need synchronization)
82 AC_CACHE_VAL(bash_cv_pgrp_pipe,
90 # define getpgID() getpgrp()
92 # define getpgID() getpgrp(0)
93 # define setpgid(x,y) setpgrp(x,y)
95 int pid1, pid2, fds[2];
99 switch (pid1 = fork()) {
103 setpgid(0, getpid());
108 sleep(2); /* let first child die */
113 switch (pid2 = fork()) {
118 ok = getpgID() == pid1;
119 write(fds[1], &ok, 1);
125 if (read(fds[0], &ok, 1) != 1)
131 ], bash_cv_pgrp_pipe=no,bash_cv_pgrp_pipe=yes,
132 [AC_MSG_ERROR(cannot check pgrp synchronization if cross compiling -- defaulting to no)
133 bash_cv_pgrp_pipe=no])
135 AC_MSG_RESULT($bash_cv_pgrp_pipe)
136 if test $bash_cv_pgrp_pipe = yes; then
142 dnl check for typedef'd symbols in header files, but allow the caller to
143 dnl specify the include files to be checked in addition to the default
145 dnl BASH_CHECK_TYPE(TYPE, HEADERS, DEFAULT[, VALUE-IF-FOUND])
146 AC_DEFUN(BASH_CHECK_TYPE,
147 [AC_REQUIRE([AC_HEADER_STDC])dnl
148 AC_MSG_CHECKING(for $1)
149 AC_CACHE_VAL(bash_cv_type_$1,
150 [AC_EGREP_CPP($1, [#include <sys/types.h>
155 ], bash_cv_type_$1=yes, bash_cv_type_$1=no)])
156 AC_MSG_RESULT($bash_cv_type_$1)
157 ifelse($#, 4, [if test $bash_cv_type_$1 = yes; then
160 if test $bash_cv_type_$1 = no; then
166 dnl Type of struct rlimit fields: some systems (OSF/1, NetBSD, RISC/os 5.0)
167 dnl have a rlim_t, others (4.4BSD based systems) use quad_t, others use
168 dnl long and still others use int (HP-UX 9.01, SunOS 4.1.3). To simplify
169 dnl matters, this just checks for rlim_t, quad_t, or long.
171 AC_DEFUN(BASH_RLIMIT_TYPE,
172 [AC_MSG_CHECKING(for size and type of struct rlimit fields)
173 AC_CACHE_VAL(bash_cv_type_rlimit,
174 [AC_TRY_COMPILE([#include <sys/types.h>
175 #include <sys/resource.h>],
176 [rlim_t xxx;], bash_cv_type_rlimit=rlim_t,[
178 #include <sys/types.h>
179 #include <sys/time.h>
180 #include <sys/resource.h>
185 if (sizeof(rl.rlim_cur) == sizeof(quad_t))
189 }], bash_cv_type_rlimit=quad_t, bash_cv_type_rlimit=long,
190 [AC_MSG_ERROR(cannot check quad_t if cross compiling -- defaulting to long)
191 bash_cv_type_rlimit=long])])
193 AC_MSG_RESULT($bash_cv_type_rlimit)
194 if test $bash_cv_type_rlimit = quad_t; then
195 AC_DEFINE(RLIMTYPE, quad_t)
196 elif test $bash_cv_type_rlimit = rlim_t; then
197 AC_DEFINE(RLIMTYPE, rlim_t)
202 dnl Check for sys_siglist[] or _sys_siglist[]
204 AC_DEFUN(BASH_DECL_UNDER_SYS_SIGLIST,
205 [AC_MSG_CHECKING([for _sys_siglist in signal.h or unistd.h])
206 AC_CACHE_VAL(bash_cv_decl_under_sys_siglist,
208 #include <sys/types.h>
212 #endif], [ char *msg = _sys_siglist[2]; ],
213 bash_cv_decl_under_sys_siglist=yes, bash_cv_decl_under_sys_siglist=no,
214 [AC_MSG_ERROR(cannot check for _sys_siglist[] if cross compiling -- defaulting to no)])])dnl
215 AC_MSG_RESULT($bash_cv_decl_under_sys_siglist)
216 if test $bash_cv_decl_under_sys_siglist = yes; then
217 AC_DEFINE(UNDER_SYS_SIGLIST_DECLARED)
221 AC_DEFUN(BASH_UNDER_SYS_SIGLIST,
222 [AC_REQUIRE([BASH_DECL_UNDER_SYS_SIGLIST])
223 AC_MSG_CHECKING([for _sys_siglist in system C library])
224 AC_CACHE_VAL(bash_cv_under_sys_siglist,
226 #include <sys/types.h>
231 #ifndef UNDER_SYS_SIGLIST_DECLARED
232 extern char *_sys_siglist[];
236 char *msg = (char *)_sys_siglist[2];
239 bash_cv_under_sys_siglist=yes, bash_cv_under_sys_siglist=no,
240 [AC_MSG_ERROR(cannot check for _sys_siglist[] if cross compiling -- defaulting to no)
241 bash_cv_under_sys_siglist=no])])
242 AC_MSG_RESULT($bash_cv_under_sys_siglist)
243 if test $bash_cv_under_sys_siglist = yes; then
244 AC_DEFINE(HAVE_UNDER_SYS_SIGLIST)
248 AC_DEFUN(BASH_SYS_SIGLIST,
249 [AC_REQUIRE([AC_DECL_SYS_SIGLIST])
250 AC_MSG_CHECKING([for sys_siglist in system C library])
251 AC_CACHE_VAL(bash_cv_sys_siglist,
253 #include <sys/types.h>
258 #ifndef SYS_SIGLIST_DECLARED
259 extern char *sys_siglist[];
263 char *msg = sys_siglist[2];
266 bash_cv_sys_siglist=yes, bash_cv_sys_siglist=no,
267 [AC_MSG_ERROR(cannot check for sys_siglist if cross compiling -- defaulting to no)
268 bash_cv_sys_siglist=no])])
269 AC_MSG_RESULT($bash_cv_sys_siglist)
270 if test $bash_cv_sys_siglist = yes; then
271 AC_DEFINE(HAVE_SYS_SIGLIST)
275 dnl Check for sys_errlist[] and sys_nerr, check for declaration
276 AC_DEFUN(BASH_SYS_ERRLIST,
277 [AC_MSG_CHECKING([for sys_errlist and sys_nerr])
278 AC_CACHE_VAL(bash_cv_sys_errlist,
279 [AC_TRY_LINK([#include <errno.h>],
280 [extern char *sys_errlist[];
282 char *msg = sys_errlist[sys_nerr - 1];],
283 bash_cv_sys_errlist=yes, bash_cv_sys_errlist=no)])dnl
284 AC_MSG_RESULT($bash_cv_sys_errlist)
285 if test $bash_cv_sys_errlist = yes; then
286 AC_DEFINE(HAVE_SYS_ERRLIST)
290 dnl Check to see if opendir will open non-directories (not a nice thing)
291 AC_DEFUN(BASH_FUNC_OPENDIR_CHECK,
292 [AC_REQUIRE([AC_HEADER_DIRENT])dnl
293 AC_MSG_CHECKING(if opendir() opens non-directories)
294 AC_CACHE_VAL(bash_cv_opendir_not_robust,
297 #include <sys/types.h>
301 #endif /* HAVE_UNISTD_H */
302 #if defined(HAVE_DIRENT_H)
305 # define dirent direct
306 # ifdef HAVE_SYS_NDIR_H
307 # include <sys/ndir.h>
308 # endif /* SYSNDIR */
309 # ifdef HAVE_SYS_DIR_H
310 # include <sys/dir.h>
315 #endif /* HAVE_DIRENT_H */
320 unlink("/tmp/not_a_directory");
321 fd = open("/tmp/not_a_directory", O_WRONLY|O_CREAT, 0666);
324 dir = opendir("/tmp/not_a_directory");
325 unlink("/tmp/not_a_directory");
327 }], bash_cv_opendir_not_robust=yes,bash_cv_opendir_not_robust=no,
328 [AC_MSG_ERROR(cannot check opendir if cross compiling -- defaulting to no)
329 bash_cv_opendir_not_robust=no]
331 AC_MSG_RESULT($bash_cv_opendir_not_robust)
332 if test $bash_cv_opendir_not_robust = yes; then
333 AC_DEFINE(OPENDIR_NOT_ROBUST)
338 AC_DEFUN(BASH_TYPE_SIGHANDLER,
339 [AC_MSG_CHECKING([whether signal handlers are of type void])
340 AC_CACHE_VAL(bash_cv_void_sighandler,
341 [AC_TRY_COMPILE([#include <sys/types.h>
349 void (*signal ()) ();],
350 [int i;], bash_cv_void_sighandler=yes, bash_cv_void_sighandler=no)])dnl
351 AC_MSG_RESULT($bash_cv_void_sighandler)
352 if test $bash_cv_void_sighandler = yes; then
353 AC_DEFINE(VOID_SIGHANDLER)
357 AC_DEFUN(BASH_TYPE_INT32_T,
359 if test "X$bash_cv_type_int32_t" = "X"; then
362 AC_MSG_CHECKING(which builtin C type is 32 bits wide)
365 AC_CACHE_VAL(bash_cv_type_int32_t,
372 # if SIZEOF_LONG == 4
375 # error cannot find 32 bit type...
378 }], bash_cv_type_int32_t=int, bash_cv_type_int32_t=long,
379 [AC_MSG_ERROR(cannot check type sizes if cross-compiling -- defaulting to int)
380 bash_cv_type_int32_t=int]
382 if test "X$_bash_needmsg" = "Xyes"; then
383 AC_MSG_CHECKING(which builtin C type is 32 bits wide)
385 AC_MSG_RESULT($bash_cv_type_int32_t);
386 if test "$bash_cv_type_int32_t" = "int"; then
387 AC_DEFINE(int32_t, int)
389 AC_DEFINE(int32_t, long)
393 AC_DEFUN(BASH_TYPE_U_INT32_T,
395 if test "X$bash_cv_type_u_int32_t" = "X"; then
398 AC_MSG_CHECKING(which unsigned builtin C type is 32 bits wide)
401 AC_CACHE_VAL(bash_cv_type_u_int32_t,
408 # if SIZEOF_LONG == 4
411 # error cannot find 32 bit type...
414 }], bash_cv_type_u_int32_t=int, bash_cv_type_u_int32_t=long,
415 [AC_MSG_ERROR(cannot check type sizes if cross-compiling -- defaulting to int)
416 bash_cv_type_u_int32_t=int]
418 if test "X$_bash_needmsg" = "Xyes"; then
419 AC_MSG_CHECKING(which unsigned builtin C type is 32 bits wide)
421 AC_MSG_RESULT($bash_cv_type_u_int32_t);
422 if test "$bash_cv_type_u_int32_t" = "int"; then
423 AC_DEFINE(u_int32_t, unsigned int)
425 AC_DEFINE(u_int32_t, unsigned long)
429 AC_DEFUN(BASH_TYPE_PTRDIFF_T,
431 if test "X$bash_cv_type_ptrdiff_t" = "X"; then
434 AC_MSG_CHECKING(which builtin C type is correct for ptrdiff_t)
437 AC_CACHE_VAL(bash_cv_type_ptrdiff_t,
441 #if SIZEOF_CHAR_P == SIZEOF_INT
444 # if SIZEOF_CHAR_P == SIZEOF_LONG
447 # error cannot find type for pointer arithmetic...
450 }], bash_cv_type_ptrdiff_t=int, bash_cv_type_ptrdiff_t=long,
451 [AC_MSG_ERROR(cannot check type sizes if cross-compiling -- defaulting to int)
452 bash_cv_type_ptrdiff_t=int]
454 if test "X$_bash_needmsg" = "Xyes"; then
455 AC_MSG_CHECKING(which builtin C type is correct for ptrdiff_t)
457 AC_MSG_RESULT($bash_cv_type_ptrdiff_t);
458 if test "$bash_cv_type_ptrdiff_t" = "int"; then
459 AC_DEFINE(ptrdiff_t, int)
461 AC_DEFINE(ptrdiff_t, long)
465 AC_DEFUN(BASH_FUNC_STRSIGNAL,
466 [AC_MSG_CHECKING([for the existence of strsignal])
467 AC_CACHE_VAL(bash_cv_have_strsignal,
468 [AC_TRY_LINK([#include <sys/types.h>
469 #include <signal.h>],
470 [char *s = (char *)strsignal(2);],
471 bash_cv_have_strsignal=yes, bash_cv_have_strsignal=no)])
472 AC_MSG_RESULT($bash_cv_have_strsignal)
473 if test $bash_cv_have_strsignal = yes; then
474 AC_DEFINE(HAVE_STRSIGNAL)
478 AC_DEFUN(BASH_FUNC_LSTAT,
479 [dnl Cannot use AC_CHECK_FUNCS(lstat) because Linux defines lstat() as an
480 dnl inline function in <sys/stat.h>.
481 AC_CACHE_CHECK([for lstat], bash_cv_func_lstat,
483 #include <sys/types.h>
484 #include <sys/stat.h>
485 ],[ lstat(".",(struct stat *)0); ],
486 bash_cv_func_lstat=yes, bash_cv_func_lstat=no)])
487 if test $bash_cv_func_lstat = yes; then
488 AC_DEFINE(HAVE_LSTAT)
492 AC_DEFUN(BASH_STRUCT_TERMIOS_LDISC,
493 [AC_MSG_CHECKING([for a c_line member of struct termios])
494 AC_CACHE_VAL(bash_cv_termios_ldisc,
495 [AC_TRY_COMPILE([#include <sys/types.h>
496 #include <termios.h>],[struct termios t; int i; i = t.c_line;],
497 bash_cv_termios_ldisc=yes, bash_cv_termios_ldisc=no)])dnl
498 AC_MSG_RESULT($bash_cv_termios_ldisc)
499 if test $bash_cv_termios_ldisc = yes; then
500 AC_DEFINE(TERMIOS_LDISC)
504 AC_DEFUN(BASH_STRUCT_TERMIO_LDISC,
505 [AC_MSG_CHECKING([for a c_line member of struct termio])
506 AC_CACHE_VAL(bash_cv_termio_ldisc,
507 [AC_TRY_COMPILE([#include <sys/types.h>
508 #include <termio.h>],[struct termio t; int i; i = t.c_line;],
509 bash_cv_termio_ldisc=yes, bash_cv_termio_ldisc=no)])dnl
510 AC_MSG_RESULT($bash_cv_termio_ldisc)
511 if test $bash_cv_termio_ldisc = yes; then
512 AC_DEFINE(TERMIO_LDISC)
516 AC_DEFUN(BASH_FUNC_GETENV,
517 [AC_MSG_CHECKING(to see if getenv can be redefined)
518 AC_CACHE_VAL(bash_cv_getenv_redef,
530 #if defined (__linux__) || defined (__bsdi__) || defined (convex)
534 #endif /* !__linux__ && !__bsdi__ && !convex */
541 /* The next allows this program to run, but does not allow bash to link
542 when it redefines getenv. I'm not really interested in figuring out
548 exit(s == 0); /* force optimizer to leave getenv in */
550 ], bash_cv_getenv_redef=yes, bash_cv_getenv_redef=no,
551 [AC_MSG_ERROR(cannot check getenv redefinition if cross compiling -- defaulting to yes)
552 bash_cv_getenv_redef=yes]
554 AC_MSG_RESULT($bash_cv_getenv_redef)
555 if test $bash_cv_getenv_redef = yes; then
556 AC_DEFINE(CAN_REDEFINE_GETENV)
560 AC_DEFUN(BASH_FUNC_PRINTF,
561 [AC_MSG_CHECKING(for declaration of printf in <stdio.h>)
562 AC_CACHE_VAL(bash_cv_printf_declared,
566 typedef int (*_bashfunc)(const char *, ...);
568 typedef int (*_bashfunc)();
573 pf = (_bashfunc) printf;
576 ], bash_cv_printf_declared=yes, bash_cv_printf_declared=no,
577 [AC_MSG_ERROR(cannot check printf declaration if cross compiling -- defaulting to yes)
578 bash_cv_printf_declared=yes]
580 AC_MSG_RESULT($bash_cv_printf_declared)
581 if test $bash_cv_printf_declared = yes; then
582 AC_DEFINE(PRINTF_DECLARED)
586 AC_DEFUN(BASH_FUNC_ULIMIT_MAXFDS,
587 [AC_MSG_CHECKING(whether ulimit can substitute for getdtablesize)
588 AC_CACHE_VAL(bash_cv_ulimit_maxfds,
592 long maxfds = ulimit(4, 0L);
593 exit (maxfds == -1L);
595 ], bash_cv_ulimit_maxfds=yes, bash_cv_ulimit_maxfds=no,
596 [AC_MSG_ERROR(cannot check ulimit if cross compiling -- defaulting to no)
597 bash_cv_ulimit_maxfds=no]
599 AC_MSG_RESULT($bash_cv_ulimit_maxfds)
600 if test $bash_cv_ulimit_maxfds = yes; then
601 AC_DEFINE(ULIMIT_MAXFDS)
605 AC_DEFUN(BASH_CHECK_LIB_TERMCAP,
607 if test "X$bash_cv_termcap_lib" = "X"; then
610 AC_MSG_CHECKING(which library has the termcap functions)
613 AC_CACHE_VAL(bash_cv_termcap_lib,
614 [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap,
615 [AC_CHECK_LIB(curses, tgetent, bash_cv_termcap_lib=libcurses,
616 [AC_CHECK_LIB(ncurses, tgetent, bash_cv_termcap_lib=libncurses,
617 bash_cv_termcap_lib=gnutermcap)])])])
618 if test "X$_bash_needmsg" = "Xyes"; then
619 AC_MSG_CHECKING(which library has the termcap functions)
621 AC_MSG_RESULT(using $bash_cv_termcap_lib)
622 if test $bash_cv_termcap_lib = gnutermcap && test -z "$prefer_curses"; then
623 LDFLAGS="$LDFLAGS -L./lib/termcap"
624 TERMCAP_LIB="./lib/termcap/libtermcap.a"
625 TERMCAP_DEP="./lib/termcap/libtermcap.a"
626 elif test $bash_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then
627 TERMCAP_LIB=-ltermcap
629 elif test $bash_cv_termcap_lib = libncurses; then
630 TERMCAP_LIB=-lncurses
638 AC_DEFUN(BASH_FUNC_GETCWD,
639 [AC_MSG_CHECKING([if getcwd() calls popen()])
640 AC_CACHE_VAL(bash_cv_getcwd_calls_popen,
664 FILE *_popen(command, type)
668 return (popen (command, type));
692 ], bash_cv_getcwd_calls_popen=no, bash_cv_getcwd_calls_popen=yes,
693 [AC_MSG_ERROR(cannot check whether getcwd calls popen if cross compiling -- defaulting to no)
694 bash_cv_getcwd_calls_popen=no]
696 AC_MSG_RESULT($bash_cv_getcwd_calls_popen)
697 if test $bash_cv_getcwd_calls_popen = yes; then
698 AC_DEFINE(GETCWD_BROKEN)
702 AC_DEFUN(BASH_STRUCT_DIRENT_D_INO,
703 [AC_REQUIRE([AC_HEADER_DIRENT])
704 AC_MSG_CHECKING(if struct dirent has a d_ino member)
705 AC_CACHE_VAL(bash_cv_dirent_has_dino,
708 #include <sys/types.h>
711 #endif /* HAVE_UNISTD_H */
712 #if defined(HAVE_DIRENT_H)
715 # define dirent direct
716 # ifdef HAVE_SYS_NDIR_H
717 # include <sys/ndir.h>
718 # endif /* SYSNDIR */
719 # ifdef HAVE_SYS_DIR_H
720 # include <sys/dir.h>
725 #endif /* HAVE_DIRENT_H */
727 struct dirent d; int z; z = d.d_ino;
728 ], bash_cv_dirent_has_dino=yes, bash_cv_dirent_has_dino=no)])
729 AC_MSG_RESULT($bash_cv_dirent_has_dino)
730 if test $bash_cv_dirent_has_dino = yes; then
731 AC_DEFINE(STRUCT_DIRENT_HAS_D_INO)
735 AC_DEFUN(BASH_STRUCT_DIRENT_D_FILENO,
736 [AC_REQUIRE([AC_HEADER_DIRENT])
737 AC_MSG_CHECKING(if struct dirent has a d_fileno member)
738 AC_CACHE_VAL(bash_cv_dirent_has_d_fileno,
741 #include <sys/types.h>
744 #endif /* HAVE_UNISTD_H */
745 #if defined(HAVE_DIRENT_H)
748 # define dirent direct
749 # ifdef HAVE_SYS_NDIR_H
750 # include <sys/ndir.h>
751 # endif /* SYSNDIR */
752 # ifdef HAVE_SYS_DIR_H
753 # include <sys/dir.h>
758 #endif /* HAVE_DIRENT_H */
760 struct dirent d; int z; z = d.d_fileno;
761 ], bash_cv_dirent_has_d_fileno=yes, bash_cv_dirent_has_d_fileno=no)])
762 AC_MSG_RESULT($bash_cv_dirent_has_d_fileno)
763 if test $bash_cv_dirent_has_d_fileno = yes; then
764 AC_DEFINE(STRUCT_DIRENT_HAS_D_FILENO)
768 AC_DEFUN(BASH_REINSTALL_SIGHANDLERS,
769 [AC_REQUIRE([AC_TYPE_SIGNAL])
770 AC_REQUIRE([BASH_SIGNAL_CHECK])
771 AC_MSG_CHECKING([if signal handlers must be reinstalled when invoked])
772 AC_CACHE_VAL(bash_cv_must_reinstall_sighandlers,
779 typedef RETSIGTYPE sigfunc();
783 #ifdef HAVE_POSIX_SIGNALS
785 set_signal_handler(sig, handler)
789 struct sigaction act, oact;
790 act.sa_handler = handler;
792 sigemptyset (&act.sa_mask);
793 sigemptyset (&oact.sa_mask);
794 sigaction (sig, &act, &oact);
795 return (oact.sa_handler);
798 #define set_signal_handler(s, h) signal(s, h)
811 set_signal_handler(SIGINT, sigint);
812 kill((int)getpid(), SIGINT);
813 kill((int)getpid(), SIGINT);
816 ], bash_cv_must_reinstall_sighandlers=no, bash_cv_must_reinstall_sighandlers=yes,
817 [AC_MSG_ERROR(cannot check signal handling if cross compiling -- defaulting to no)
818 bash_cv_must_reinstall_sighandlers=no]
820 AC_MSG_RESULT($bash_cv_must_reinstall_sighandlers)
821 if test $bash_cv_must_reinstall_sighandlers = yes; then
822 AC_DEFINE(MUST_REINSTALL_SIGHANDLERS)
826 AC_DEFUN(BASH_FUNC_SBRK_DECLARED,
827 [AC_MSG_CHECKING(for declaration of sbrk in <unistd.h>)
828 AC_CACHE_VAL(bash_cv_sbrk_declared,
829 [AC_EGREP_HEADER(sbrk, unistd.h,
830 bash_cv_sbrk_declared=yes, bash_cv_sbrk_declared=no)])
831 AC_MSG_RESULT($bash_cv_sbrk_declared)
832 if test $bash_cv_sbrk_declared = yes; then
833 AC_DEFINE(SBRK_DECLARED)
837 dnl check that some necessary job control definitions are present
838 AC_DEFUN(BASH_JOB_CONTROL_MISSING,
839 [AC_REQUIRE([BASH_SIGNAL_CHECK])
840 AC_MSG_CHECKING(for presence of necessary job control definitions)
841 AC_CACHE_VAL(bash_cv_job_control_missing,
843 #include <sys/types.h>
844 #ifdef HAVE_SYS_WAIT_H
845 #include <sys/wait.h>
852 /* Add more tests in here as appropriate. */
856 #if !defined (HAVE_POSIX_SIGNALS) && !defined (HAVE_BSD_SIGNALS)
860 /* signals and tty control. */
861 #if !defined (SIGTSTP) || !defined (SIGSTOP) || !defined (SIGCONT)
865 /* process control */
866 #if !defined (WNOHANG) || !defined (WUNTRACED)
870 /* Posix systems have tcgetpgrp and waitpid. */
871 #if defined (_POSIX_VERSION) && !defined (HAVE_TCGETPGRP)
875 #if defined (_POSIX_VERSION) && !defined (HAVE_WAITPID)
879 /* Other systems have TIOCSPGRP/TIOCGPRGP and wait3. */
880 #if !defined (_POSIX_VERSION) && !defined (HAVE_WAIT3)
885 }], bash_cv_job_control_missing=present, bash_cv_job_control_missing=missing,
886 [AC_MSG_ERROR(cannot check job control if cross-compiling -- defaulting to missing)
887 bash_cv_job_control_missing=missing]
889 AC_MSG_RESULT($bash_cv_job_control_missing)
890 if test $bash_cv_job_control_missing = missing; then
891 AC_DEFINE(JOB_CONTROL_MISSING)
895 dnl check whether named pipes are present
896 dnl this requires a previous check for mkfifo, but that is awkward to specify
897 AC_DEFUN(BASH_SYS_NAMED_PIPES,
898 [AC_MSG_CHECKING(for presence of named pipes)
899 AC_CACHE_VAL(bash_cv_sys_named_pipes,
901 #include <sys/types.h>
902 #include <sys/stat.h>
907 /* Add more tests in here as appropriate. */
912 #if defined (HAVE_MKFIFO)
916 #if !defined (S_IFIFO) && (defined (_POSIX_VERSION) && !defined (S_ISFIFO))
924 fd = mknod ("/tmp/sh-np-autoconf", 0666 | S_IFIFO, 0);
928 unlink ("/tmp/sh-np-autoconf");
930 }], bash_cv_sys_named_pipes=present, bash_cv_sys_named_pipes=missing,
931 [AC_MSG_ERROR(cannot check for named pipes if cross-compiling -- defaulting to missing)
932 bash_cv_sys_named_pipes=missing]
934 AC_MSG_RESULT($bash_cv_sys_named_pipes)
935 if test $bash_cv_sys_named_pipes = missing; then
936 AC_DEFINE(NAMED_PIPES_MISSING)
940 AC_DEFUN(BASH_FUNC_POSIX_SETJMP,
941 [AC_REQUIRE([BASH_SIGNAL_CHECK])
942 AC_MSG_CHECKING(for presence of POSIX-style sigsetjmp/siglongjmp)
943 AC_CACHE_VAL(bash_cv_func_sigsetjmp,
948 #include <sys/types.h>
954 #if !defined (_POSIX_VERSION) || !defined (HAVE_POSIX_SIGNALS)
965 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &set);
966 sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &oset);
969 code = sigsetjmp(xx, 1);
971 exit(0); /* could get sigmask and compare to oset here. */
974 sigaddset(&set, SIGINT);
975 sigprocmask(SIG_BLOCK, &set, (sigset_t *)NULL);
981 }], bash_cv_func_sigsetjmp=present, bash_cv_func_sigsetjmp=missing,
982 [AC_MSG_ERROR(cannot check for sigsetjmp/siglongjmp if cross-compiling -- defaulting to missing)
983 bash_cv_func_sigsetjmp=missing]
985 AC_MSG_RESULT($bash_cv_func_sigsetjmp)
986 if test $bash_cv_func_sigsetjmp = present; then
987 AC_DEFINE(HAVE_POSIX_SIGSETJMP)
991 AC_DEFUN(BASH_HAVE_TIOCGWINSZ,
992 [AC_MSG_CHECKING(for TIOCGWINSZ in sys/ioctl.h)
993 AC_CACHE_VAL(bash_cv_tiocgwinsz_in_ioctl,
994 [AC_TRY_COMPILE([#include <sys/types.h>
995 #include <sys/ioctl.h>], [int x = TIOCGWINSZ;],
996 bash_cv_tiocgwinsz_in_ioctl=yes,bash_cv_tiocgwinsz_in_ioctl=no)])
997 AC_MSG_RESULT($bash_cv_tiocgwinsz_in_ioctl)
998 if test $bash_cv_tiocgwinsz_in_ioctl = yes; then
999 AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
1003 AC_DEFUN(BASH_STRUCT_WINSIZE,
1004 [AC_MSG_CHECKING(for struct winsize in sys/ioctl.h and termios.h)
1005 AC_CACHE_VAL(bash_cv_struct_winsize_header,
1006 [AC_TRY_COMPILE([#include <sys/types.h>
1007 #include <sys/ioctl.h>], [struct winsize x;],
1008 bash_cv_struct_winsize_header=ioctl_h,
1009 [AC_TRY_COMPILE([#include <sys/types.h>
1010 #include <termios.h>], [struct winsize x;],
1011 bash_cv_struct_winsize_header=termios_h, bash_cv_struct_winsize_header=other)
1013 if test $bash_cv_struct_winsize_header = ioctl_h; then
1014 AC_MSG_RESULT(sys/ioctl.h)
1015 AC_DEFINE(STRUCT_WINSIZE_IN_SYS_IOCTL)
1016 elif test $bash_cv_struct_winsize_header = termios_h; then
1017 AC_MSG_RESULT(termios.h)
1018 AC_DEFINE(STRUCT_WINSIZE_IN_TERMIOS)
1020 AC_MSG_RESULT(not found)
1024 AC_DEFUN(BASH_HAVE_TIOCSTAT,
1025 [AC_MSG_CHECKING(for TIOCSTAT in sys/ioctl.h)
1026 AC_CACHE_VAL(bash_cv_tiocstat_in_ioctl,
1027 [AC_TRY_COMPILE([#include <sys/types.h>
1028 #include <sys/ioctl.h>], [int x = TIOCSTAT;],
1029 bash_cv_tiocstat_in_ioctl=yes,bash_cv_tiocstat_in_ioctl=no)])
1030 AC_MSG_RESULT($bash_cv_tiocstat_in_ioctl)
1031 if test $bash_cv_tiocstat_in_ioctl = yes; then
1032 AC_DEFINE(TIOCSTAT_IN_SYS_IOCTL)
1036 AC_DEFUN(BASH_HAVE_FIONREAD,
1037 [AC_MSG_CHECKING(for FIONREAD in sys/ioctl.h)
1038 AC_CACHE_VAL(bash_cv_fionread_in_ioctl,
1039 [AC_TRY_COMPILE([#include <sys/types.h>
1040 #include <sys/ioctl.h>], [int x = FIONREAD;],
1041 bash_cv_fionread_in_ioctl=yes,bash_cv_fionread_in_ioctl=no)])
1042 AC_MSG_RESULT($bash_cv_fionread_in_ioctl)
1043 if test $bash_cv_fionread_in_ioctl = yes; then
1044 AC_DEFINE(FIONREAD_IN_SYS_IOCTL)
1049 dnl See if speed_t is declared in <sys/types.h>. Some versions of linux
1050 dnl require a definition of speed_t each time <termcap.h> is included,
1051 dnl but you can only get speed_t if you include <termios.h> (on some
1052 dnl versions) or <sys/types.h> (on others).
1054 AC_DEFUN(BASH_MISC_SPEED_T,
1055 [AC_MSG_CHECKING(for speed_t in sys/types.h)
1056 AC_CACHE_VAL(bash_cv_speed_t_in_sys_types,
1057 [AC_TRY_COMPILE([#include <sys/types.h>], [speed_t x;],
1058 bash_cv_speed_t_in_sys_types=yes,bash_cv_speed_t_in_sys_types=no)])
1059 AC_MSG_RESULT($bash_cv_speed_t_in_sys_types)
1060 if test $bash_cv_speed_t_in_sys_types = yes; then
1061 AC_DEFINE(SPEED_T_IN_SYS_TYPES)
1065 AC_DEFUN(BASH_CHECK_GETPW_FUNCS,
1066 [AC_MSG_CHECKING(whether programs are able to redeclare getpw functions)
1067 AC_CACHE_VAL(bash_cv_can_redecl_getpw,
1068 [AC_TRY_COMPILE([#include <sys/types.h>
1070 extern struct passwd *getpwent();
1071 extern struct passwd *getpwuid();
1072 extern struct passwd *getpwnam();],
1073 [struct passwd *z; z = getpwent(); z = getpwuid(0); z = getpwnam("root");],
1074 bash_cv_can_redecl_getpw=yes,bash_cv_can_redecl_getpw=no)])
1075 AC_MSG_RESULT($bash_cv_can_redecl_getpw)
1076 if test $bash_cv_can_redecl_getpw = no; then
1077 AC_DEFINE(HAVE_GETPW_DECLS)
1081 AC_DEFUN(BASH_CHECK_DEV_FD,
1082 [AC_MSG_CHECKING(whether /dev/fd is available)
1083 AC_CACHE_VAL(bash_cv_dev_fd,
1084 [if test -d /dev/fd && test -r /dev/fd/0; then
1085 bash_cv_dev_fd=standard
1086 elif test -d /proc/self/fd && test -r /proc/self/fd/0; then
1087 bash_cv_dev_fd=whacky
1089 bash_cv_dev_fd=absent
1092 AC_MSG_RESULT($bash_cv_dev_fd)
1093 if test $bash_cv_dev_fd = "standard"; then
1094 AC_DEFINE(HAVE_DEV_FD)
1095 AC_DEFINE(DEV_FD_PREFIX, "/dev/fd/")
1096 elif test $bash_cv_dev_fd = "whacky"; then
1097 AC_DEFINE(HAVE_DEV_FD)
1098 AC_DEFINE(DEV_FD_PREFIX, "/proc/self/fd/")
1103 dnl Check for the presence of getpeername (the only networking function
1104 dnl bash currently requires) in libsocket. If libsocket is present,
1105 dnl check for libnsl and add it to LIBS if it's there, since most
1106 dnl systems with libsocket require linking with libnsl as well.
1107 dnl This should only be called if getpeername was not found in libc.
1109 AC_DEFUN(BASH_CHECK_SOCKLIB,
1111 if test "X$bash_cv_have_socklib" = "X"; then
1114 AC_MSG_CHECKING(for socket library)
1117 AC_CACHE_VAL(bash_cv_have_socklib,
1118 [AC_CHECK_LIB(socket, getpeername,
1119 bash_cv_have_socklib=yes, bash_cv_have_socklib=no, -lnsl)])
1120 if test "X$_bash_needmsg" = Xyes; then
1121 AC_MSG_RESULT($bash_cv_have_socklib)
1124 if test $bash_cv_have_socklib = yes; then
1125 # check for libnsl, add it to LIBS if present
1126 if test "X$bash_cv_have_libnsl" = "X"; then
1129 AC_MSG_CHECKING(for libnsl)
1132 AC_CACHE_VAL(bash_cv_have_libnsl,
1133 [AC_CHECK_LIB(nsl, t_open,
1134 bash_cv_have_libnsl=yes, bash_cv_have_libnsl=no)])
1135 if test "X$_bash_needmsg" = Xyes; then
1136 AC_MSG_RESULT($bash_cv_have_libnsl)
1139 if test $bash_cv_have_libnsl = yes; then
1140 LIBS="-lsocket -lnsl $LIBS"
1142 LIBS="-lsocket $LIBS"
1144 AC_DEFINE(HAVE_LIBSOCKET)
1145 AC_DEFINE(HAVE_GETPEERNAME)
1149 AC_DEFUN(BASH_DEFAULT_MAIL_DIR,
1150 [AC_MSG_CHECKING(for default mail directory)
1151 AC_CACHE_VAL(bash_cv_mail_dir,
1152 [if test -d /var/mail; then
1153 bash_cv_mail_dir=/var/mail
1154 elif test -d /usr/mail; then
1155 bash_cv_mail_dir=/usr/mail
1156 elif test -d /var/spool/mail; then
1157 bash_cv_mail_dir=/var/spool/mail
1158 elif test -d /usr/spool/mail; then
1159 bash_cv_mail_dir=/usr/spool/mail
1161 bash_cv_mail_dir=unknown
1164 AC_MSG_RESULT($bash_cv_mail_dir)
1165 if test $bash_cv_mail_dir = "/var/mail"; then
1166 AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/var/mail")
1167 elif test $bash_cv_mail_dir = "/usr/mail"; then
1168 AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/usr/mail")
1169 elif test $bash_cv_mail_dir = "/var/spool/mail"; then
1170 AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/var/spool/mail")
1171 elif test $bash_cv_mail_dir = "/usr/spool/mail"; then
1172 AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "/usr/spool/mail")
1174 AC_DEFINE(DEFAULT_MAIL_DIRECTORY, "unknown")
1179 dnl Check if HPUX needs _KERNEL defined for RLIMIT_* definitions
1181 AC_DEFUN(BASH_KERNEL_RLIMIT_CHECK,
1182 [AC_MSG_CHECKING([whether $host_os needs _KERNEL for RLIMIT defines])
1183 AC_CACHE_VAL(bash_cv_kernel_rlimit,
1185 #include <sys/types.h>
1186 #include <sys/resource.h>
1191 ], bash_cv_kernel_rlimit=no,
1193 #include <sys/types.h>
1195 #include <sys/resource.h>
1201 ], bash_cv_kernel_rlimit=yes, bash_cv_kernel_rlimit=no)]
1203 AC_MSG_RESULT($bash_cv_kernel_rlimit)
1204 if test $bash_cv_kernel_rlimit = yes; then
1205 AC_DEFINE(RLIMIT_NEEDS_KERNEL)
1209 AC_DEFUN(BASH_FUNC_STRCOLL,
1211 AC_MSG_CHECKING(whether or not strcoll and strcmp differ)
1212 AC_CACHE_VAL(bash_cv_func_strcoll_broken,
1215 #if defined (HAVE_LOCALE_H)
1224 char *deflocale, *defcoll;
1226 #ifdef HAVE_SETLOCALE
1227 deflocale = setlocale(LC_ALL, "");
1228 defcoll = setlocale(LC_COLLATE, "");
1232 /* These two values are taken from tests/glob-test. */
1233 r1 = strcoll("abd", "aXd");
1237 r2 = strcmp("abd", "aXd");
1239 /* These two should both be greater than 0. It is permissible for
1240 a system to return different values, as long as the sign is the
1243 /* Exit with 1 (failure) if these two values are both > 0, since
1244 this tests whether strcoll(3) is broken with respect to strcmp(3)
1245 in the default locale. */
1246 exit (r1 > 0 && r2 > 0);
1248 ], bash_cv_func_strcoll_broken=yes, bash_cv_func_strcoll_broken=no,
1249 [AC_MSG_ERROR(cannot check strcoll if cross compiling -- defaulting to no)
1250 bash_cv_func_strcoll_broken=no]
1252 AC_MSG_RESULT($bash_cv_func_strcoll_broken)
1253 if test $bash_cv_func_strcoll_broken = yes; then
1254 AC_DEFINE(STRCOLL_BROKEN)
1259 dnl If available, use support for large files unless the user specified
1260 dnl one of the CPPFLAGS, LDFLAGS, or LIBS variables (<eggert@twinsun.com>
1261 dnl via GNU patch 2.5)
1263 AC_DEFUN(BASH_LARGE_FILE_SUPPORT,
1264 [AC_MSG_CHECKING(whether large file support needs explicit enabling)
1268 ac_shellvars='CPPFLAGS LDFLAGS LIBS'
1269 for ac_shellvar in $ac_shellvars; do
1270 case $ac_shellvar in
1271 CPPFLAGS) ac_lfsvar=LFS_CFLAGS ac_lfs64var=LFS64_CFLAGS ;;
1272 *) ac_lfsvar=LFS_$ac_shellvar ac_lfs64var=LFS64_$ac_shellvar ;;
1274 eval test '"${'$ac_shellvar'+set}"' = set && ac_set=$ac_shellvar
1275 (getconf $ac_lfsvar) >/dev/null 2>&1 || { ac_result=no; break; }
1276 ac_getconf=`getconf $ac_lfsvar`
1277 ac_getconf64=`getconf $ac_lfs64var`
1278 ac_getconfs=$ac_getconfs$ac_getconf\ $ac_getconf64
1279 eval ac_test_$ac_shellvar="\$ac_getconf\ \$ac_getconf64"
1281 case "$ac_result$ac_getconfs" in
1282 yes) ac_result=no ;;
1284 case "$ac_result$ac_set" in
1285 yes?*) ac_result="yes, but $ac_set is already set, so use its settings"
1287 AC_MSG_RESULT($ac_result)
1290 for ac_shellvar in $ac_shellvars; do
1291 eval $ac_shellvar=\$ac_test_$ac_shellvar
1297 dnl AC_SYS_RESTARTABLE_SYSCALLS tests only for restarted system calls
1298 dnl after a signal handler has been installed with signal(). Since
1299 dnl Bash uses sigaction() if it is available, we need to check whether
1300 dnl or not a signal handler installed with sigaction and SA_RESTART
1301 dnl causes system calls to be restarted after the signal is caught
1303 AC_DEFUN(BASH_SYS_RESTARTABLE_SYSCALLS,
1304 [AC_REQUIRE([BASH_SIGNAL_CHECK])
1305 AC_CACHE_CHECK(for restartable system calls with posix sigaction,
1306 bash_cv_sys_restartable_syscalls,
1308 [/* Exit 0 (true) if wait returns something other than -1,
1309 i.e. the pid of the child, which means that wait was restarted
1310 after getting the signal. */
1311 #include <sys/types.h>
1313 static int caught = 0;
1314 void ucatch (isig) int isig; { caught = 1; }
1317 #if !defined (_POSIX_VERSION) || !defined (HAVE_POSIX_SIGNALS)
1320 struct sigaction act, oact;
1323 act.sa_handler = ucatch;
1324 /* Might want to add SA_RESTART here, but bash's set_signal_handler
1327 sigemptyset(&act.sa_mask);
1328 sigemptyset(&oact.sa_mask);
1330 /* A possible race condition here, but in practice it never happens. */
1331 if (i == 0) { sleep (3); kill (getppid (), SIGINT); sleep (3); exit (0); }
1332 sigaction(SIGINT, &act, &oact);
1334 if (status == -1) wait(&i);
1335 exit (status == -1);
1338 ], bash_cv_sys_restartable_syscalls=yes, bash_cv_sys_restartable_syscalls=no,
1339 AC_MSG_ERROR(cannot check restartable syscalls if cross compiling))
1341 if test $bash_cv_sys_restartable_syscalls = yes; then
1342 AC_DEFINE(HAVE_RESTARTABLE_SYSCALLS)