comparison src/os/unix/ngx_freebsd_init.c @ 86:3973260705cc

nginx-0.0.1-2003-05-12-19:52:24 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 12 May 2003 15:52:24 +0000
parents
children 674d333f4296
comparison
equal deleted inserted replaced
85:3549c2bf9eaf 86:3973260705cc
1
2 #include <ngx_freebsd_init.h>
3
4
5 int freebsd_kern_osreldate;
6 int freebsd_hw_ncpu;
7
8 int freebsd_sendfile_nbytes_bug;
9
10
11 int ngx_os_init(ngx_log_t *log)
12 {
13 size_t size;
14
15 size = 4;
16 if (sysctlbyname("kern.osreldate",
17 &freebsd_kern_osreldate, &size, NULL, 0) == -1) {
18 ngx_log_error(NGX_LOG_ALERT, log, errno,
19 "sysctlbyname(kern.osreldate) failed");
20 return NGX_ERROR;
21 }
22
23 ngx_log_error(NGX_LOG_INFO, log, 0,
24 "kern.osreldate: %d, built on %d",
25 freebsd_kern_osreldate, __FreeBSD_version);
26
27
28 #if HAVE_FREEBSD_SENDFILE
29
30 /* The determination of the sendfile() nbytes bug is complex enough.
31 There're two sendfile() syscalls: a new 393 has no bug while
32 an old 336 has the bug in some versions and has not in others.
33 libc_r wrapper also emulates the bug in some versions.
34 There's no way to say exactly if a given FreeBSD version has bug.
35 Here is the algorithm that work at least for RELEASEs
36 and for syscalls only (not libc_r wrapper). */
37
38 /* detect was the new sendfile() version available at the compile time
39 to allow an old binary to run correctly on an updated FreeBSD system. */
40
41 #if (__FreeBSD__ == 4 && __FreeBSD_version >= 460102) \
42 || __FreeBSD_version == 460002 || __FreeBSD_version >= 500039
43
44 /* a new syscall without the bug */
45 freebsd_sendfile_nbytes_bug = 0;
46
47 #else
48
49 /* an old syscall that can have the bug */
50 freebsd_sendfile_nbytes_bug = 1;
51
52 #endif
53
54 #endif /* HAVE_FREEBSD_SENDFILE */
55
56
57 size = 4;
58 if (sysctlbyname("hw.ncpu", &freebsd_hw_ncpu, &size, NULL, 0) == -1) {
59 ngx_log_error(NGX_LOG_ALERT, log, errno,
60 "sysctlbyname(hw.ncpu) failed");
61 return NGX_ERROR;
62 }
63
64 ngx_log_error(NGX_LOG_INFO, log, 0, "hw.ncpu: %d", freebsd_hw_ncpu);
65
66 return NGX_OK;
67 }