1dnl ######################################################################
2dnl rlimit capabilities checks
3AC_DEFUN([NTP_RLIMIT_ITEMS], [
4
5AC_CACHE_CHECK(
6    [for RLIMIT_MEMLOCK],
7    [ntp_cv_rlimit_memlock],
8    [AC_COMPILE_IFELSE(
9          [AC_LANG_PROGRAM(
10              [[
11                    #ifdef HAVE_SYS_TYPES_H
12                    # include <sys/types.h>
13                    #endif
14                    #ifdef HAVE_SYS_TIME_H
15                    # include <sys/time.h>
16                    #endif
17                    #ifdef HAVE_SYS_RESOURCE_H
18                    # include <sys/resource.h>
19                    #endif
20              ]],
21              [[
22                    getrlimit(RLIMIT_MEMLOCK, 0);
23              ]]
24          )],
25          [ntp_cv_rlimit_memlock=yes],
26          [ntp_cv_rlimit_memlock=no]
27    )]
28)
29case "$host" in
30 *-*-*linux*)
31    ntp_dflt_rlimit_memlock="-1" ;;
32 *) ntp_dflt_rlimit_memlock="32" ;;
33esac
34case "$ntp_cv_rlimit_memlock" in
35 yes)
36    AC_SUBST([HAVE_RLIMIT_MEMLOCK])
37    HAVE_RLIMIT_MEMLOCK=" memlock $ntp_dflt_rlimit_memlock"  ;;
38esac
39
40AC_CACHE_CHECK(
41    [for RLIMIT_STACK],
42    [ntp_cv_rlimit_stack],
43    [AC_COMPILE_IFELSE(
44          [AC_LANG_PROGRAM(
45              [[
46                    #ifdef HAVE_SYS_TYPES_H
47                    # include <sys/types.h>
48                    #endif
49                    #ifdef HAVE_SYS_TIME_H
50                    # include <sys/time.h>
51                    #endif
52                    #ifdef HAVE_SYS_RESOURCE_H
53                    # include <sys/resource.h>
54                    #endif
55              ]],
56              [[
57                    getrlimit(RLIMIT_STACK, 0);
58              ]]
59          )],
60          [ntp_cv_rlimit_stack=yes],
61          [ntp_cv_rlimit_stack=no]
62    )]
63)
64case "$ntp_cv_rlimit_stack" in
65 yes)
66    AC_SUBST([HAVE_RLIMIT_STACK])
67    HAVE_RLIMIT_STACK=" stacksize 50"
68esac
69
70# HMS: Only if we are doing the MLOCKALL stuff...
71AC_MSG_CHECKING([for the default number of 4k stack pages])
72AC_ARG_WITH(
73    [stack-limit],
74    [AS_HELP_STRING(
75          [--with-stack-limit],
76          [? =50 (200 for openbsd) 4k pages]
77    )],
78    [ans=$withval],
79    [ans=yes]
80)
81case "$ans" in
82 yes | no)
83    case "$host" in
84     *-*-openbsd*)
85          ans=200
86          ;;
87     *) ans=50
88        ;;
89    esac
90    ;;
91 [[1-9]][[0-9]]*)
92    ;;
93 *) AC_MSG_ERROR(["--with-stack-limit requires an integer argument."])
94    ;;
95esac
96AC_MSG_RESULT([$ans])
97AC_DEFINE_UNQUOTED([DFLT_RLIMIT_STACK], [$ans],
98    [Default number of 4k pages for RLIMIT_STACK])
99
100# HMS: only if we have RLIMIT_MEMLOCK
101AC_MSG_CHECKING([for the default number of megabytes to MEMLOCK])
102AC_ARG_WITH(
103    [memlock],
104    [AS_HELP_STRING(
105          [--with-memlock],
106          [? =32 (-1 on linux) megabytes]
107    )],
108    [ans=$withval],
109    [ans=yes]
110)
111case "$ans" in
112 yes | no)
113    ans=$ntp_dflt_rlimit_memlock
114    ;;
115 [[1-9]][[0-9]]*) ;;
116 *) AC_MSG_ERROR(["--with-memlock requires an integer argument."])
117     ;;
118esac
119AC_MSG_RESULT([$ans])
120AC_DEFINE_UNQUOTED([DFLT_RLIMIT_MEMLOCK], [$ans],
121    [Default number of megabytes for RLIMIT_MEMLOCK])
122
123])dnl
124
125dnl ======================================================================
126