xref: /freebsd/contrib/ntp/sntp/m4/ntp_rlimit.m4 (revision 9034852c)
12b15cb3dSCy Schubertdnl ######################################################################
22b15cb3dSCy Schubertdnl rlimit capabilities checks
32b15cb3dSCy SchubertAC_DEFUN([NTP_RLIMIT_ITEMS], [
42b15cb3dSCy Schubert
52b15cb3dSCy SchubertAC_CACHE_CHECK(
62b15cb3dSCy Schubert    [for RLIMIT_MEMLOCK],
72b15cb3dSCy Schubert    [ntp_cv_rlimit_memlock],
82b15cb3dSCy Schubert    [AC_COMPILE_IFELSE(
92b15cb3dSCy Schubert	[AC_LANG_PROGRAM(
102b15cb3dSCy Schubert	    [[
112b15cb3dSCy Schubert		#ifdef HAVE_SYS_TYPES_H
122b15cb3dSCy Schubert		# include <sys/types.h>
132b15cb3dSCy Schubert		#endif
142b15cb3dSCy Schubert		#ifdef HAVE_SYS_TIME_H
152b15cb3dSCy Schubert		# include <sys/time.h>
162b15cb3dSCy Schubert		#endif
172b15cb3dSCy Schubert		#ifdef HAVE_SYS_RESOURCE_H
182b15cb3dSCy Schubert		# include <sys/resource.h>
192b15cb3dSCy Schubert		#endif
202b15cb3dSCy Schubert	    ]],
212b15cb3dSCy Schubert	    [[
222b15cb3dSCy Schubert		getrlimit(RLIMIT_MEMLOCK, 0);
232b15cb3dSCy Schubert	    ]]
242b15cb3dSCy Schubert	)],
252b15cb3dSCy Schubert	[ntp_cv_rlimit_memlock=yes],
262b15cb3dSCy Schubert	[ntp_cv_rlimit_memlock=no]
272b15cb3dSCy Schubert    )]
282b15cb3dSCy Schubert)
29*9034852cSGleb Smirnoffcase "$host" in
30*9034852cSGleb Smirnoff *-*-*linux*)
31*9034852cSGleb Smirnoff    ntp_dflt_rlimit_memlock="-1" ;;
32*9034852cSGleb Smirnoff *) ntp_dflt_rlimit_memlock="32" ;;
33*9034852cSGleb Smirnoffesac
342b15cb3dSCy Schubertcase "$ntp_cv_rlimit_memlock" in
352b15cb3dSCy Schubert yes)
362b15cb3dSCy Schubert    AC_SUBST([HAVE_RLIMIT_MEMLOCK])
37*9034852cSGleb Smirnoff    HAVE_RLIMIT_MEMLOCK=" memlock $ntp_dflt_rlimit_memlock"  ;;
382b15cb3dSCy Schubertesac
392b15cb3dSCy Schubert
402b15cb3dSCy SchubertAC_CACHE_CHECK(
412b15cb3dSCy Schubert    [for RLIMIT_STACK],
422b15cb3dSCy Schubert    [ntp_cv_rlimit_stack],
432b15cb3dSCy Schubert    [AC_COMPILE_IFELSE(
442b15cb3dSCy Schubert	[AC_LANG_PROGRAM(
452b15cb3dSCy Schubert	    [[
462b15cb3dSCy Schubert		#ifdef HAVE_SYS_TYPES_H
472b15cb3dSCy Schubert		# include <sys/types.h>
482b15cb3dSCy Schubert		#endif
492b15cb3dSCy Schubert		#ifdef HAVE_SYS_TIME_H
502b15cb3dSCy Schubert		# include <sys/time.h>
512b15cb3dSCy Schubert		#endif
522b15cb3dSCy Schubert		#ifdef HAVE_SYS_RESOURCE_H
532b15cb3dSCy Schubert		# include <sys/resource.h>
542b15cb3dSCy Schubert		#endif
552b15cb3dSCy Schubert	    ]],
562b15cb3dSCy Schubert	    [[
572b15cb3dSCy Schubert		getrlimit(RLIMIT_STACK, 0);
582b15cb3dSCy Schubert	    ]]
592b15cb3dSCy Schubert	)],
602b15cb3dSCy Schubert	[ntp_cv_rlimit_stack=yes],
612b15cb3dSCy Schubert	[ntp_cv_rlimit_stack=no]
622b15cb3dSCy Schubert    )]
632b15cb3dSCy Schubert)
642b15cb3dSCy Schubertcase "$ntp_cv_rlimit_stack" in
652b15cb3dSCy Schubert yes)
662b15cb3dSCy Schubert    AC_SUBST([HAVE_RLIMIT_STACK])
672b15cb3dSCy Schubert    HAVE_RLIMIT_STACK=" stacksize 50"
682b15cb3dSCy Schubertesac
692b15cb3dSCy Schubert
70*9034852cSGleb Smirnoff# HMS: Only if we are doing the MLOCKALL stuff...
71*9034852cSGleb SmirnoffAC_MSG_CHECKING([for the default number of 4k stack pages])
72*9034852cSGleb SmirnoffAC_ARG_WITH(
73*9034852cSGleb Smirnoff    [stack-limit],
74*9034852cSGleb Smirnoff    [AS_HELP_STRING(
75*9034852cSGleb Smirnoff	[--with-stack-limit],
76*9034852cSGleb Smirnoff	[? =50 (200 for openbsd) 4k pages]
77*9034852cSGleb Smirnoff    )],
78*9034852cSGleb Smirnoff    [ans=$withval],
79*9034852cSGleb Smirnoff    [ans=yes]
80*9034852cSGleb Smirnoff)
81*9034852cSGleb Smirnoffcase "$ans" in
82*9034852cSGleb Smirnoff yes | no)
83*9034852cSGleb Smirnoff    case "$host" in
84*9034852cSGleb Smirnoff     *-*-openbsd*)
85*9034852cSGleb Smirnoff	ans=200
86*9034852cSGleb Smirnoff	;;
87*9034852cSGleb Smirnoff     *) ans=50
88*9034852cSGleb Smirnoff        ;;
89*9034852cSGleb Smirnoff    esac
90*9034852cSGleb Smirnoff    ;;
91*9034852cSGleb Smirnoff [[1-9]][[0-9]]*)
92*9034852cSGleb Smirnoff    ;;
93*9034852cSGleb Smirnoff *) AC_MSG_ERROR(["--with-stack-limit requires an integer argument."])
94*9034852cSGleb Smirnoff    ;;
95*9034852cSGleb Smirnoffesac
96*9034852cSGleb SmirnoffAC_MSG_RESULT([$ans])
97*9034852cSGleb SmirnoffAC_DEFINE_UNQUOTED([DFLT_RLIMIT_STACK], [$ans],
98*9034852cSGleb Smirnoff    [Default number of 4k pages for RLIMIT_STACK])
99*9034852cSGleb Smirnoff
100*9034852cSGleb Smirnoff# HMS: only if we have RLIMIT_MEMLOCK
101*9034852cSGleb SmirnoffAC_MSG_CHECKING([for the default number of megabytes to MEMLOCK])
102*9034852cSGleb SmirnoffAC_ARG_WITH(
103*9034852cSGleb Smirnoff    [memlock],
104*9034852cSGleb Smirnoff    [AS_HELP_STRING(
105*9034852cSGleb Smirnoff	[--with-memlock],
106*9034852cSGleb Smirnoff	[? =32 (-1 on linux) megabytes]
107*9034852cSGleb Smirnoff    )],
108*9034852cSGleb Smirnoff    [ans=$withval],
109*9034852cSGleb Smirnoff    [ans=yes]
110*9034852cSGleb Smirnoff)
111*9034852cSGleb Smirnoffcase "$ans" in
112*9034852cSGleb Smirnoff yes | no)
113*9034852cSGleb Smirnoff    ans=$ntp_dflt_rlimit_memlock
114*9034852cSGleb Smirnoff    ;;
115*9034852cSGleb Smirnoff [[1-9]][[0-9]]*) ;;
116*9034852cSGleb Smirnoff *) AC_MSG_ERROR(["--with-memlock requires an integer argument."])
117*9034852cSGleb Smirnoff     ;;
118*9034852cSGleb Smirnoffesac
119*9034852cSGleb SmirnoffAC_MSG_RESULT([$ans])
120*9034852cSGleb SmirnoffAC_DEFINE_UNQUOTED([DFLT_RLIMIT_MEMLOCK], [$ans],
121*9034852cSGleb Smirnoff    [Default number of megabytes for RLIMIT_MEMLOCK])
122*9034852cSGleb Smirnoff
1232b15cb3dSCy Schubert])dnl
124*9034852cSGleb Smirnoff
1252b15cb3dSCy Schubertdnl ======================================================================
126