]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/os-deps.m4
Merged from trunk r13474.
[thirdparty/squid.git] / acinclude / os-deps.m4
1 dnl
2 dnl AUTHOR: Squid Web Cache team
3 dnl
4 dnl SQUID Web Proxy Cache http://www.squid-cache.org/
5 dnl ----------------------------------------------------------
6 dnl Squid is the result of efforts by numerous individuals from
7 dnl the Internet community; see the CONTRIBUTORS file for full
8 dnl details. Many organizations have provided support for Squid's
9 dnl development; see the SPONSORS file for full details. Squid is
10 dnl Copyrighted (C) 2001 by the Regents of the University of
11 dnl California; see the COPYRIGHT file for full details. Squid
12 dnl incorporates software developed and/or copyrighted by other
13 dnl sources; see the CREDITS file for full details.
14 dnl
15 dnl This program is free software; you can redistribute it and/or modify
16 dnl it under the terms of the GNU General Public License as published by
17 dnl the Free Software Foundation; either version 2 of the License, or
18 dnl (at your option) any later version.
19 dnl
20 dnl This program is distributed in the hope that it will be useful,
21 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
22 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 dnl GNU General Public License for more details.
24 dnl
25 dnl You should have received a copy of the GNU General Public License
26 dnl along with this program; if not, write to the Free Software
27 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28
29
30 dnl check that strnstr() works fine. On Macos X it can cause a buffer overrun
31 dnl sets squid_cv_func_strnstr to "yes" or "no", and defines HAVE_STRNSTR
32 AC_DEFUN([SQUID_CHECK_FUNC_STRNSTR],[
33
34 # Yay! This one is a MacOSX brokenness. Its not good enough
35 # to know that strnstr() exists, because MacOSX 10.4 have a bad
36 # copy that crashes with a buffer over-run!
37 AH_TEMPLATE(HAVE_STRNSTR,[MacOS brokenness: strnstr() can overrun on that system])
38 AC_CACHE_CHECK([if strnstr is well implemented], squid_cv_func_strnstr,
39 AC_RUN_IFELSE([AC_LANG_SOURCE([[
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 // we expect this to succeed, or crash on over-run.
44 // if it passes otherwise we may need a better check.
45 int main(int argc, char **argv)
46 {
47 int size = 20;
48 char *str = malloc(size);
49 memset(str, 'x', size);
50 strnstr(str, "fubar", size);
51 return 0;
52 }
53 ]])],[squid_cv_func_strnstr="yes"],[squid_cv_func_strnstr="no"],[:])
54 )
55 if test "$squid_cv_func_strnstr" = "yes" ; then
56 AC_DEFINE(HAVE_STRNSTR,1)
57 fi
58
59 ]) dnl SQUID_CHECK_FUNC_STRNSTR
60
61 dnl check that va_copy is implemented and works
62 dnl sets squid_cv_func_va_copy and defines HAVE_VA_COPY
63 AC_DEFUN([SQUID_CHECK_FUNC_VACOPY],[
64
65 # check that the system provides a functional va_copy call
66
67 AH_TEMPLATE(HAVE_VA_COPY, [The system implements a functional va_copy() ])
68 AC_CACHE_CHECK(if va_copy is implemented, squid_cv_func_va_copy,
69 AC_RUN_IFELSE([AC_LANG_SOURCE([[
70 #include <stdarg.h>
71 #include <stdlib.h>
72 int f (int i, ...) {
73 va_list args1, args2;
74 va_start (args1, i);
75 va_copy (args2, args1);
76 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
77 return 1;
78 va_end (args1); va_end (args2);
79 return 0;
80 }
81 int main(int argc, char **argv) { return f (0, 42); }
82 ]])],[squid_cv_func_va_copy="yes"],[squid_cv_func_va_copy="no"],[:])
83 )
84 if test "$squid_cv_func_va_copy" = "yes" ; then
85 AC_DEFINE(HAVE_VA_COPY, 1)
86 fi
87
88 ]) dnl SQUID_CHECK_FUNC_VACOPY
89
90 dnl same sa SQUID_CHECK_FUNC_VACOPY, but checks __va_copy
91 dnl sets squid_cv_func___va_copy, and defines HAVE___VA_COPY
92 AC_DEFUN([SQUID_CHECK_FUNC___VACOPY],[
93
94 AH_TEMPLATE(HAVE___VA_COPY,[Some systems have __va_copy instead of va_copy])
95 AC_CACHE_CHECK(if __va_copy is implemented, squid_cv_func___va_copy,
96 AC_RUN_IFELSE([AC_LANG_SOURCE([[
97 #include <stdarg.h>
98 #include <stdlib.h>
99 int f (int i, ...) {
100 va_list args1, args2;
101 va_start (args1, i);
102 __va_copy (args2, args1);
103 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
104 return 1;
105 va_end (args1); va_end (args2);
106 return 0;
107 }
108 int main(int argc, char **argv) { return f (0, 42); }
109 ]])],[squid_cv_func___va_copy="yes"],[squid_cv_func___va_copy="no"],[:])
110 )
111 if test "$squid_cv_func___va_copy" = "yes" ; then
112 AC_DEFINE(HAVE___VA_COPY, 1)
113 fi
114 ]) dnl SQUID_CHECK_FUNC___VACOPY
115
116
117 dnl check that epoll actually works
118 dnl sets squid_cv_epoll_works to "yes" or "no"
119 AC_DEFUN([SQUID_CHECK_EPOLL],[
120
121 AC_CACHE_CHECK(if epoll works, squid_cv_epoll_works,
122 AC_RUN_IFELSE([AC_LANG_SOURCE([[
123 #include <sys/epoll.h>
124 #include <stdlib.h>
125 #include <stdio.h>
126 int main(int argc, char **argv)
127 {
128 int fd = epoll_create(256);
129 if (fd < 0) {
130 perror("epoll_create:");
131 return 1;
132 }
133 return 0;
134 }
135 ]])],[squid_cv_epoll_works=yes],[squid_cv_epoll_works=no],[:]))
136
137 ]) dnl SQUID_CHECK_EPOLL
138
139 dnl check that /dev/poll actually works
140 dnl sets squid_cv_devpoll_works to "yes" or "no"
141 AC_DEFUN([SQUID_CHECK_DEVPOLL],[
142
143 AC_CACHE_CHECK(if /dev/poll works, squid_cv_devpoll_works,
144 AC_RUN_IFELSE([AC_LANG_SOURCE([[
145 #include <sys/devpoll.h>
146 #include <fcntl.h>
147 #include <stdlib.h>
148 #include <stdio.h>
149 int main(int argc, char **argv)
150 {
151 int fd = open("/dev/poll", O_RDWR);
152 if (fd < 0) {
153 perror("devpoll_create:");
154 return 1;
155 }
156 return 0;
157 }
158 ]])],[squid_cv_devpoll_works=yes],[squid_cv_devpoll_works=no],[:]))
159
160 ]) dnl SQUID_CHECK_DEVPOLL
161
162
163 dnl check that we have functional libcap2 headers
164 dnl sets squid_cv_sys_capability_works to "yes" or "no"
165
166 AC_DEFUN([SQUID_CHECK_FUNCTIONAL_LIBCAP2],[
167 AC_CACHE_CHECK([for operational libcap2 headers],
168 squid_cv_sys_capability_works,
169 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
170 #include <stdlib.h>
171 #include <stddef.h>
172 #include <sys/capability.h>
173 ]], [[
174 capget(NULL, NULL);
175 capset(NULL, NULL);
176 ]])],
177 [squid_cv_sys_capability_works=yes],
178 [squid_cv_sys_capability_works=no])
179 )
180 ])
181
182
183 dnl Ripped from Samba. Thanks!
184 dnl check that we have Unix sockets. Sets squid_cv_unixsocket to either yes or no depending on the check
185
186 AC_DEFUN([SQUID_CHECK_UNIX_SOCKET],[
187 AC_CACHE_CHECK([for unix domain sockets],squid_cv_unixsocket, [
188 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
189 #include <sys/types.h>
190 #include <stdlib.h>
191 #include <stddef.h>
192 #include <sys/socket.h>
193 #include <sys/un.h>]], [[
194 struct sockaddr_un sunaddr;
195 sunaddr.sun_family = AF_UNIX;
196 ]])],[squid_cv_unixsocket=yes],[squid_cv_unixsocket=no])])
197 ])
198
199
200 dnl check the default FD_SETSIZE size.
201 dnl not cached, people are likely to tune this
202 dnl defines DEFAULT_FD_SETSIZE
203
204 AC_DEFUN([SQUID_CHECK_DEFAULT_FD_SETSIZE],[
205 AC_MSG_CHECKING(Default FD_SETSIZE value)
206 AC_RUN_IFELSE([AC_LANG_SOURCE([[
207 #if HAVE_STDIO_H
208 #include <stdio.h>
209 #endif
210 #if HAVE_UNISTD_H
211 #include <unistd.h>
212 #endif
213 #if HAVE_STDLIB_H
214 #include <stdlib.h>
215 #endif
216 #if HAVE_SYS_TIME_H
217 #include <sys/time.h>
218 #endif
219 #if HAVE_SYS_SELECT_H
220 #include <sys/select.h>
221 #endif
222 #if HAVE_SYS_TYPES_H
223 #include <sys/types.h>
224 #endif
225 #if HAVE_WINSOCK2_H
226 #include <winsock2.h>
227 #elif HAVE_WINSOCK_H
228 #include <winsock.h>
229 #endif
230 int main(int argc, char **argv) {
231 FILE *fp = fopen("conftestval", "w");
232 fprintf (fp, "%d\n", FD_SETSIZE);
233 return 0;
234 }
235 ]])],[DEFAULT_FD_SETSIZE=`cat conftestval`],[DEFAULT_FD_SETSIZE=256],[DEFAULT_FD_SETSIZE=256])
236 AC_MSG_RESULT($DEFAULT_FD_SETSIZE)
237 AC_DEFINE_UNQUOTED(DEFAULT_FD_SETSIZE, $DEFAULT_FD_SETSIZE, [Default FD_SETSIZE value])
238 ])
239
240
241 dnl checks the maximum number of filedescriptor we can open
242 dnl sets shell var squid_filedescriptors_num
243
244 AC_DEFUN([SQUID_CHECK_MAXFD],[
245 AC_CHECK_FUNCS(setrlimit)
246 AC_MSG_CHECKING(Maximum number of filedescriptors we can open)
247 dnl damn! FreeBSD pthreads break dup2().
248 SQUID_STATE_SAVE(maxfd)
249 case $host in
250 i386-unknown-freebsd*)
251 if echo "$LDFLAGS" | grep -q pthread; then
252 LDFLAGS=`echo $LDFLAGS | sed -e "s/-pthread//"`
253 fi
254 esac
255 AC_RUN_IFELSE([AC_LANG_SOURCE([[
256 #include <stdio.h>
257 #include <unistd.h>
258 #include <stdlib.h>
259 #include <sys/time.h> /* needed on FreeBSD */
260 #include <sys/param.h>
261 #include <sys/resource.h>
262 int main(int argc, char **argv) {
263 FILE *fp;
264 int i,j;
265 #if defined(__CYGWIN32__) || defined (__CYGWIN__)
266 /* getrlimit and sysconf returns bogous values on cygwin32.
267 * Number of fds is virtually unlimited in cygwin (sys/param.h)
268 * __CYGWIN32__ is deprecated.
269 */
270 i = NOFILE;
271 #else
272 #if HAVE_SETRLIMIT
273 struct rlimit rl;
274 #if defined(RLIMIT_NOFILE)
275 if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
276 perror("getrlimit: RLIMIT_NOFILE");
277 } else {
278 #if defined(__APPLE__)
279 /* asking for more than OPEN_MAX fails on Leopard */
280 rl.rlim_cur = (OPEN_MAX < rl.rlim_max ? OPEN_MAX : rl.rlim_max);
281 #else
282 rl.rlim_cur = rl.rlim_max; /* set it to the max */
283 #endif
284 if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
285 perror("setrlimit: RLIMIT_NOFILE");
286 }
287 }
288 #elif defined(RLIMIT_OFILE)
289 if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
290 perror("getrlimit: RLIMIT_OFILE");
291 } else {
292 rl.rlim_cur = rl.rlim_max; /* set it to the max */
293 if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
294 perror("setrlimit: RLIMIT_OFILE");
295 }
296 }
297 #endif /* RLIMIT_NOFILE */
298 #endif /* HAVE_SETRLIMIT */
299 /* by starting at 2^14, we will never get higher
300 than 2^15 for squid_filedescriptors_num */
301 i = j = 1<<14;
302 while (j) {
303 j >>= 1;
304 if (dup2(0, i) < 0) {
305 i -= j;
306 } else {
307 close(i);
308 i += j;
309 }
310 }
311 i++;
312 #endif /* IF !DEF CYGWIN */
313 fp = fopen("conftestval", "w");
314 fprintf (fp, "%d\n", i & ~0x3F);
315 return 0;
316 }
317 ]])],[squid_filedescriptors_num=`cat conftestval`],[squid_filedescriptors_num=256],[squid_filedescriptors_num=256])
318 dnl Microsoft MSVCRT.DLL supports 2048 maximum FDs
319 case "$host_os" in
320 mingw|mingw32)
321 squid_filedescriptors_num="2048"
322 ;;
323 esac
324 AC_MSG_RESULT($squid_filedescriptors_num)
325 SQUID_STATE_ROLLBACK(maxfd)
326
327 if test `expr $squid_filedescriptors_num % 64` != 0; then
328 AC_MSG_WARN([$squid_filedescriptors_num is not an multiple of 64. This may cause issues on certain platforms.])
329 fi
330 ])
331
332
333 dnl Check whether this OS defines sin6_len as a member of sockaddr_in6 as a backup to ss_len
334 dnl defines HAVE_SIN6_LEN_IN_SAI
335 dnl TODO: move to AC_CHECK_MEMBER?
336
337 AC_DEFUN([SQUID_CHECK_SIN6_LEN_IN_SAI],[
338 AC_CACHE_CHECK([for sin6_len field in struct sockaddr_in6],
339 ac_cv_have_sin6_len_in_struct_sai, [
340 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
341 #include <sys/types.h>
342 #include <sys/socket.h>
343 #include <netinet/in.h>
344 ]], [[ struct sockaddr_in6 s; s.sin6_len = 1; ]])],[ ac_cv_have_sin6_len_in_struct_sai="yes" ],[ ac_cv_have_sin6_len_in_struct_sai="no"
345 ])
346 ])
347 SQUID_DEFINE_BOOL(HAVE_SIN6_LEN_IN_SAI,$ac_cv_have_sin6_len_in_struct_sai,
348 [Defined if struct sockaddr_in6 has sin6_len])
349 ])
350
351
352 dnl Check whether this OS defines ss_len as a member of sockaddr_storage
353 dnl defines HAVE_SS_LEN_IN_SS
354 dnl TODO: move to AC_CHECK_MEMBER?
355
356 AC_DEFUN([SQUID_CHECK_SS_LEN_IN_SOCKADDR_STORAGE],[
357 AC_CACHE_CHECK([for ss_len field in struct sockaddr_storage],
358 ac_cv_have_ss_len_in_struct_ss, [
359 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
360 #include <sys/types.h>
361 #include <sys/socket.h>
362 #include <netinet/in.h>
363 ]], [[ struct sockaddr_storage s; s.ss_len = 1; ]])],[ ac_cv_have_ss_len_in_struct_ss="yes" ],[ ac_cv_have_ss_len_in_struct_ss="no"
364 ])
365 ])
366 SQUID_DEFINE_BOOL(HAVE_SS_LEN_IN_SS,$ac_cv_have_ss_len_in_struct_ss,
367 [Define if sockaddr_storage has field ss_len])
368 ])
369
370
371 dnl Check whether this OS defines sin_len as a member of sockaddr_in as a backup to ss_len
372 dnl defines HAVE_SIN_LEN_IN_SAI
373 dnl TODO: move to AC_CHECK_MEMBER?
374
375 AC_DEFUN([SQUID_CHECK_SIN_LEN_IN_SOCKADDR_IN],[
376 AC_CACHE_CHECK([for sin_len field in struct sockaddr_in],
377 ac_cv_have_sin_len_in_struct_sai, [
378 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
379 #include <sys/types.h>
380 #include <sys/socket.h>
381 #include <netinet/in.h>
382 ]], [[ struct sockaddr_in s; s.sin_len = 1; ]])],[ ac_cv_have_sin_len_in_struct_sai="yes" ],[ ac_cv_have_sin_len_in_struct_sai="no"
383 ])
384 ])
385 SQUID_DEFINE_BOOL(HAVE_SIN_LEN_IN_SAI,$ac_cv_have_sin_len_in_struct_sai,[Define if sockaddr_in has field sin_len])
386 ])
387
388
389 dnl detects default UDP buffer size
390 dnl not cached since people are likely to tune this
391 dnl defines SQUID_DETECT_UDP_SO_SNDBUF
392
393 AC_DEFUN([SQUID_DETECT_UDP_SND_BUFSIZE],[
394 AC_MSG_CHECKING(Default UDP send buffer size)
395 AC_RUN_IFELSE([AC_LANG_SOURCE([[
396 #include <stdlib.h>
397 #include <stdio.h>
398 #include <sys/types.h>
399 #if HAVE_SYS_SOCKET_H
400 #include <sys/socket.h>
401 #endif
402 #if HAVE_NETINET_IN_H
403 #include <netinet/in.h>
404 #endif
405 #if HAVE_WINSOCK2_H
406 #include <winsock2.h>
407 #elif HAVE_WINSOCK_H
408 #include <winsock.h>
409 #endif
410 int main(int argc, char **argv)
411 {
412 FILE *fp;
413 int fd,val=0;
414 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
415 int len=sizeof(int);
416 WSADATA wsaData;
417 WSAStartup(2, &wsaData);
418 #else
419 socklen_t len=sizeof(socklen_t);
420 #endif
421 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1;
422 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
423 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) return 1;
424 WSACleanup();
425 #else
426 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) return 1;
427 #endif
428 if (val<=0) return 1;
429 fp = fopen("conftestval", "w");
430 fprintf (fp, "%d\n", val);
431 return 0;
432 }
433 ]])],[SQUID_DETECT_UDP_SO_SNDBUF=`cat conftestval`],[SQUID_DETECT_UDP_SO_SNDBUF=16384],[SQUID_DETECT_UDP_SO_SNDBUF=16384])
434 AC_MSG_RESULT($SQUID_DETECT_UDP_SO_SNDBUF)
435 AC_DEFINE_UNQUOTED(SQUID_DETECT_UDP_SO_SNDBUF, $SQUID_DETECT_UDP_SO_SNDBUF,[UDP send buffer size])
436 ])
437
438
439 dnl detects default UDP buffer size
440 dnl not cached since people are likely to tune this
441 dnl defines SQUID_DETECT_UDP_SO_RCVBUF
442
443 AC_DEFUN([SQUID_DETECT_UDP_RECV_BUFSIZE],[
444 AC_MSG_CHECKING(Default UDP receive buffer size)
445 AC_RUN_IFELSE([AC_LANG_SOURCE([[
446 #include <stdlib.h>
447 #include <stdio.h>
448 #include <sys/types.h>
449 #if HAVE_SYS_SOCKET_H
450 #include <sys/socket.h>
451 #endif
452 #if HAVE_NETINET_IN_H
453 #include <netinet/in.h>
454 #endif
455 #if HAVE_WINSOCK2_H
456 #include <winsock2.h>
457 #elif HAVE_WINSOCK_H
458 #include <winsock.h>
459 #endif
460 int main(int argc, char **argv)
461 {
462 FILE *fp;
463 int fd,val=0;
464 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
465 int len=sizeof(int);
466 WSADATA wsaData;
467 WSAStartup(2, &wsaData);
468 #else
469 socklen_t len=sizeof(socklen_t);
470 #endif
471 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1;
472 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
473 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) return 1;
474 WSACleanup();
475 #else
476 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) return 1;
477 #endif
478 if (val <= 0) return 1;
479 fp = fopen("conftestval", "w");
480 fprintf (fp, "%d\n", val);
481 return 0;
482 }
483 ]])],[SQUID_DETECT_UDP_SO_RCVBUF=`cat conftestval`],[SQUID_DETECT_UDP_SO_RCVBUF=16384],[SQUID_DETECT_UDP_SO_RCVBUF=16384])
484 AC_MSG_RESULT($SQUID_DETECT_UDP_SO_RCVBUF)
485 AC_DEFINE_UNQUOTED(SQUID_DETECT_UDP_SO_RCVBUF, $SQUID_DETECT_UDP_SO_RCVBUF,[UDP receive buffer size])
486 ])
487
488
489 dnl detects default TCP buffer size
490 dnl not cached since people are likely to tune this
491 dnl defines SQUID_TCP_SO_SNDBUF
492
493 AC_DEFUN([SQUID_DETECT_TCP_SND_BUFSIZE],[
494 AC_MSG_CHECKING(Default TCP send buffer size)
495 AC_RUN_IFELSE([AC_LANG_SOURCE([[
496 #include <stdlib.h>
497 #include <stdio.h>
498 #include <sys/types.h>
499 #if HAVE_SYS_SOCKET_H
500 #include <sys/socket.h>
501 #endif
502 #if HAVE_NETINET_IN_H
503 #include <netinet/in.h>
504 #endif
505 #if HAVE_WINSOCK2_H
506 #include <winsock2.h>
507 #elif HAVE_WINSOCK_H
508 #include <winsock.h>
509 #endif
510 int main(int argc, char **argv)
511 {
512 FILE *fp;
513 int fd,val=0;
514 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
515 int len=sizeof(int);
516 WSADATA wsaData;
517 WSAStartup(2, &wsaData);
518 #else
519 socklen_t len=sizeof(socklen_t);
520 #endif
521 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return 1;
522 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
523 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&val, &len) < 0) return 1;
524 WSACleanup();
525 #else
526 if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) return 1;
527 #endif
528 if (val <= 0) return 1;
529 fp = fopen("conftestval", "w");
530 fprintf (fp, "%d\n", val);
531 return 0;
532 }
533 ]])],[SQUID_TCP_SO_SNDBUF=`cat conftestval`],[SQUID_TCP_SO_SNDBUF=16384],[SQUID_TCP_SO_SNDBUF=16384])
534 AC_MSG_RESULT($SQUID_TCP_SO_SNDBUF)
535 if test $SQUID_TCP_SO_SNDBUF -gt 32768; then
536 AC_MSG_NOTICE([Limiting send buffer size to 32K])
537 SQUID_TCP_SO_SNDBUF=32768
538 fi
539 AC_DEFINE_UNQUOTED(SQUID_TCP_SO_SNDBUF, $SQUID_TCP_SO_SNDBUF,[TCP send buffer size])
540 ])
541
542
543 dnl detects default TCP buffer size
544 dnl not cached since people are likely to tune this
545 dnl defines SQUID_TCP_SO_RECVBUF
546
547 AC_DEFUN([SQUID_DETECT_TCP_RECV_BUFSIZE],[
548 AC_MSG_CHECKING(Default TCP receive buffer size)
549 AC_RUN_IFELSE([AC_LANG_SOURCE([[
550 #include <stdlib.h>
551 #include <stdio.h>
552 #include <sys/types.h>
553 #if HAVE_SYS_SOCKET_H
554 #include <sys/socket.h>
555 #endif
556 #if HAVE_NETINET_IN_H
557 #include <netinet/in.h>
558 #endif
559 #if HAVE_WINSOCK2_H
560 #include <winsock2.h>
561 #elif HAVE_WINSOCK_H
562 #include <winsock.h>
563 #endif
564 int main(int argc, char **argv)
565 {
566 FILE *fp;
567 int fd,val=0;
568 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
569 int len=sizeof(int);
570 WSADATA wsaData;
571 WSAStartup(2, &wsaData);
572 #else
573 socklen_t len=sizeof(socklen_t);
574 #endif
575 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return 1;
576 #if (defined(WIN32) || defined(__WIN32__) || defined(__WIN32)) && !(defined(__CYGWIN32__) || defined(__CYGWIN__))
577 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&val, &len) < 0) return 1;
578 WSACleanup();
579 #else
580 if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &val, &len) < 0) return 1;
581 #endif
582 if (val <= 0) return 1;
583 fp = fopen("conftestval", "w");
584 fprintf (fp, "%d\n", val);
585 return 0;
586 }
587 ]])],[SQUID_TCP_SO_RCVBUF=`cat conftestval`],[SQUID_TCP_SO_RCVBUF=16384],[SQUID_TCP_SO_RCVBUF=16384])
588 AC_MSG_RESULT($SQUID_TCP_SO_RCVBUF)
589 if test $SQUID_TCP_SO_RCVBUF -gt 65535; then
590 AC_MSG_NOTICE([Limiting receive buffer size to 64K])
591 SQUID_TCP_SO_RCVBUF=65535
592 fi
593 AC_DEFINE_UNQUOTED(SQUID_TCP_SO_RCVBUF, $SQUID_TCP_SO_RCVBUF,[TCP receive buffer size])
594 ])
595
596
597 dnl check if we need to define sys_errlist as external
598 dnl defines NEED_SYS_ERRLIST
599
600 AC_DEFUN([SQUID_CHECK_NEED_SYS_ERRLIST],[
601 AC_CACHE_CHECK(if sys_errlist is already defined, ac_cv_needs_sys_errlist,
602 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[char *s = sys_errlist;]])],[ac_cv_needs_sys_errlist="no"],[ac_cv_needs_sys_errlist="yes"])
603 )
604 SQUID_DEFINE_BOOL(NEED_SYS_ERRLIST,$ac_cv_needs_sys_errlist,[If we need to declare sys_errlist as extern])
605 ])
606
607
608 dnl check if MAXPATHLEN is defined in the system headers
609 dnl or define it ourselves
610
611 AC_DEFUN([SQUID_CHECK_MAXPATHLEN],[
612 AC_MSG_CHECKING(for system-provided MAXPATHLEN)
613 AC_LINK_IFELSE([
614 AC_LANG_PROGRAM([[
615 #include <sys/param.h>]], [[
616 int i = MAXPATHLEN;]])], [
617 AC_MSG_RESULT(yes)], [
618 AC_MSG_RESULT(no)
619 AC_DEFINE(MAXPATHLEN,256,[If MAXPATHLEN has not been defined])])
620 ])
621
622
623 dnl check that we have a working statvfs
624 dnl sets the ac_cv_func_statvfs shell variable and defines HAVE_STATVFS
625
626 AC_DEFUN([SQUID_CHECK_WORKING_STATVFS],[
627 AC_CACHE_CHECK(for working statvfs() interface,ac_cv_func_statvfs,[
628 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
629 #include <stdlib.h>
630 #include <stdio.h>
631 #include <sys/types.h>
632 #include <sys/statvfs.h>
633 ]], [[
634 struct statvfs sfs;
635 sfs.f_blocks = sfs.f_bfree = sfs.f_frsize =
636 sfs.f_files = sfs.f_ffree = 0;
637 statvfs("/tmp", &sfs);
638 ]])],[ac_cv_func_statvfs=yes],[ac_cv_func_statvfs=no])
639 ])
640 SQUID_DEFINE_BOOL(HAVE_STATVFS,$ac_cv_func_statvfs,[set to 1 if our system has statvfs(), and if it actually works])
641 ])
642
643
644 dnl check that we can use the libresolv _dns_ttl_ hack
645 dnl sets the ac_cv_libresolv_dns_ttl_hack shell variable and defines LIBRESOLV_DNS_TTL_HACK
646
647 AC_DEFUN([SQUID_CHECK_LIBRESOLV_DNS_TTL_HACK],[
648 AC_CACHE_CHECK(for libresolv _dns_ttl_ hack, ac_cv_libresolv_dns_ttl_hack, [
649 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern int _dns_ttl_;]], [[return _dns_ttl_;]])],
650 [ac_cv_libresolv_dns_ttl_hack=yes],[ac_cv_libresolv_dns_ttl_hack=no]) ])
651 SQUID_DEFINE_BOOL(LIBRESOLV_DNS_TTL_HACK,$ac_cv_libresolv_dns_ttl_hack,
652 [libresolv.a has been hacked to export _dns_ttl_])
653 ])
654
655
656 dnl checks for availability of some resolver fields
657 dnl sets ac_cv_have_res_ext_nsaddr_list shell variable
658 dnl defines _SQUID_RES_NSADDR6_COUNT _SQUID_RES_NSADDR6_LARRAY
659 dnl defines _SQUID_RES_NSADDR6_LPTR _SQUID_RES_NSADDR6_COUNT
660 dnl defines _SQUID_RES_NSADDR_LIST _SQUID_RES_NSADDR_COUNT
661
662 AC_DEFUN([SQUID_CHECK_RESOLVER_FIELDS],[
663 AC_CACHE_CHECK(for _res_ext.nsaddr_list, ac_cv_have_res_ext_nsaddr_list,
664 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
665 #if HAVE_SYS_TYPES_H
666 #include <sys/types.h>
667 #endif
668 #if HAVE_NETINET_IN_H
669 #include <netinet/in.h>
670 #endif
671 #if HAVE_ARPA_INET_H
672 #include <arpa/inet.h>
673 #endif
674 #if HAVE_ARPA_NAMESER_H
675 #include <arpa/nameser.h>
676 #endif
677 #if HAVE_RESOLV_H
678 #include <resolv.h>
679 #endif
680 ]],
681 [[_res_ext.nsaddr_list[[0]].s_addr;]])],[
682 ac_cv_have_res_ext_nsaddr_list="yes" ],[
683 ac_cv_have_res_ext_nsaddr_list="no"]))
684 if test "$ac_cv_have_res_ext_nsaddr_list" = "yes" ; then
685 AC_DEFINE(_SQUID_RES_NSADDR6_LARRAY,_res_ext.nsaddr_list,[If _res_ext structure has nsaddr_list member])
686 AC_DEFINE(_SQUID_RES_NSADDR6_COUNT,ns6count,[Nameserver Counter for IPv6 _res_ext])
687 fi
688
689 if test "$_SQUID_RES_NSADDR6_LIST" = ""; then
690 AC_CACHE_CHECK(for _res._u._ext.nsaddrs, ac_cv_have_res_ext_nsaddrs,
691 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
692 #if HAVE_SYS_TYPES_H
693 #include <sys/types.h>
694 #endif
695 #if HAVE_NETINET_IN_H
696 #include <netinet/in.h>
697 #endif
698 #if HAVE_ARPA_INET_H
699 #include <arpa/inet.h>
700 #endif
701 #if HAVE_ARPA_NAMESER_H
702 #include <arpa/nameser.h>
703 #endif
704 #if HAVE_RESOLV_H
705 #include <resolv.h>
706 #endif
707 ]], i
708 [[_res._u._ext.nsaddrs[[0]]->sin6_addr;]])],
709 [ac_cv_have_res_ext_nsaddrs="yes"],[ac_cv_have_res_ext_nsaddrs="no"]))
710 if test "$ac_cv_have_res_ext_nsaddrs" = "yes" ; then
711 AC_DEFINE(_SQUID_RES_NSADDR6_LPTR,_res._u._ext.nsaddrs,[If _res structure has _ext.nsaddrs member])
712 AC_DEFINE(_SQUID_RES_NSADDR6_COUNT,_res._u._ext.nscount6,[Nameserver Counter for IPv6 _res])
713 fi
714 fi
715
716 AC_CACHE_CHECK(for _res.nsaddr_list, ac_cv_have_res_nsaddr_list,
717 AC_COMPILE_IFELSE([
718 AC_LANG_PROGRAM([[
719 #if HAVE_SYS_TYPES_H
720 #include <sys/types.h>
721 #endif
722 #if HAVE_NETINET_IN_H
723 #include <netinet/in.h>
724 #endif
725 #if HAVE_ARPA_INET_H
726 #include <arpa/inet.h>
727 #endif
728 #if HAVE_ARPA_NAMESER_H
729 #include <arpa/nameser.h>
730 #endif
731 #if HAVE_RESOLV_H
732 #include <resolv.h>
733 #endif
734 ]], [[_res.nsaddr_list[[0]];]])],
735 [ac_cv_have_res_nsaddr_list="yes"],[ac_cv_have_res_nsaddr_list="no"]))
736 if test $ac_cv_have_res_nsaddr_list = "yes" ; then
737 AC_DEFINE(_SQUID_RES_NSADDR_LIST,_res.nsaddr_list,[If _res structure has nsaddr_list member])
738 AC_DEFINE(_SQUID_RES_NSADDR_COUNT,_res.nscount,[Nameserver counter for IPv4 _res])
739 fi
740
741 if test "$_SQUID_RES_NSADDR_LIST" = ""; then
742 AC_CACHE_CHECK(for _res.ns_list, ac_cv_have_res_ns_list,
743 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
744 #if HAVE_SYS_TYPES_H
745 #include <sys/types.h>
746 #endif
747 #if HAVE_NETINET_IN_H
748 #include <netinet/in.h>
749 #endif
750 #if HAVE_ARPA_INET_H
751 #include <arpa/inet.h>
752 #endif
753 #if HAVE_ARPA_NAMESER_H
754 #include <arpa/nameser.h>
755 #endif
756 #if HAVE_RESOLV_H
757 #include <resolv.h>
758 #endif
759 ]],
760 [[_res.ns_list[[0]].addr;]])],
761 [ac_cv_have_res_ns_list="yes"],[ac_cv_have_res_ns_list="no"]))
762 if test $ac_cv_have_res_ns_list = "yes" ; then
763 AC_DEFINE(_SQUID_RES_NSADDR_LIST,_res.ns_list,[If _res structure has ns_list member])
764 AC_DEFINE(_SQUID_RES_NSADDR_COUNT,_res.nscount,[Nameserver counter for IPv4 _res])
765 fi
766 fi
767 ])
768
769
770 dnl checks the winsock library to use (ws2_32 or wsock32)
771 dnl may set ac_cv_func_select as a side effect
772 AC_DEFUN([SQUID_CHECK_WINSOCK_LIB],[
773 AC_CHECK_HEADERS(winsock2.h winsock.h)
774 SQUID_STATE_SAVE(winsock)
775 SQUID_SEARCH_LIBS([squid_getprotobynumber],[ws2_32 wsock32],,,,[
776 #if HAVE_WINSOCK2_H
777 #include <winsock2.h>
778 #elif HAVE_WINSOCK_H
779 #include <winsock.h>
780 #endif
781 /* ugly hack. */
782 void squid_getprotobynumber(void) {
783 getprotobynumber(1);
784 }
785 ])
786 AC_MSG_CHECKING([for winsock library])
787 case "$ac_cv_search_squid_getprotobynumber" in
788 "no")
789 AC_MSG_RESULT([winsock library not found])
790 ;;
791 "none required")
792 AC_MSG_RESULT([winsock library already in LIBS])
793 ;;
794 "-lws2_32")
795 AC_MSG_RESULT([winsock2])
796 XTRA_LIBS="-lws2_32 $XTRA_LIBS"
797 ac_cv_func_select='yes'
798 ;;
799 "-lwsock32")
800 AC_MSG_RESULT([winsock])
801 XTRA_LIBS="-lwsock32 $XTRA_LIBS"
802 ac_cv_func_select='yes'
803 ;;
804 esac
805 SQUID_STATE_ROLLBACK(winsock)
806 ])
807
808 dnl check that setresuid is properly implemented.
809 dnl sets squid_cv_resuid_works to "yes" or "no"
810 AC_DEFUN([SQUID_CHECK_SETRESUID_WORKS],[
811 AC_CACHE_CHECK(if setresuid is actually implemented, squid_cv_resuid_works,
812 AC_RUN_IFELSE([
813 AC_LANG_SOURCE([[
814 #if HAVE_STDLIB_H
815 #include <stdlib.h>
816 #endif
817 #if HAVE_STDIO_H
818 #include <stdio.h>
819 #endif
820 #if HAVE_UNISTD_H
821 #include <unistd.h>
822 #endif
823 int main(int argc, char **argv) {
824 if(setresuid(-1,-1,-1)) {
825 perror("setresuid:");
826 return 1;
827 }
828 return 0;
829 }
830 ]])],[
831 squid_cv_resuid_works="yes" ],[
832 squid_cv_resuid_works="no" ],[:])
833 )
834 ])
835
836 dnl check that we have functional CPU clock access for the profiler
837 dnl sets squid_cv_profiler_works to "yes" or "no"
838
839 AC_DEFUN([SQUID_CHECK_FUNCTIONAL_CPU_PROFILER],[
840 AC_CACHE_CHECK([for operational CPU clock access],
841 squid_cv_cpu_profiler_works,
842 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
843 #if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) )
844 // okay
845 #elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) )
846 // okay
847 #elif defined(__GNUC__) && defined(__alpha)
848 // okay
849 #elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */
850 // okay
851 #else
852 #error This CPU is unsupported. No profiling available here.
853 #endif
854 ]])],[
855 squid_cv_cpu_profiler_works=yes],[
856 squid_cv_cpu_profiler_works=no])
857 )
858 ])
859
860 dnl check whether recv takes a char* or void* as a second argument
861 AC_DEFUN([SQUID_CHECK_RECV_ARG_TYPE],[
862 AC_CACHE_CHECK([whether recv takes a pointer to void or char as second argument],
863 squid_cv_recv_second_arg_type, [
864 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
865 #include <sys/types.h>
866 #if HAVE_SYS_SOCKET_H
867 #include <sys/socket.h>
868 #endif
869 #if HAVE_WINSOCK2_H
870 #include <winsock2.h>
871 #elif HAVE_WINSOCK_H
872 #include <winsock.h>
873 #endif
874 int main (int argc, char ** argv) {
875 void *buf;
876 recv(0,buf,0,0);
877 }
878 ]])],[squid_cv_recv_second_arg_type=void],
879 [squid_cv_recv_second_arg_type=char])
880 AC_MSG_RESULT($squid_cv_recv_second_arg_type*)
881 ])
882 AC_DEFINE_UNQUOTED(RECV_ARG_TYPE,$squid_cv_recv_second_arg_type,
883 [Base type of the second argument to recv(2)])
884 ])