Mercurial > hg > nginx
comparison src/os/unix/ngx_freebsd_init.c @ 449:3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 03 Oct 2004 20:02:06 +0000 |
parents | 42d11f017717 |
children | 23fb87bddda1 |
comparison
equal
deleted
inserted
replaced
448:241dc8092a33 | 449:3b1e8c9df9ad |
---|---|
20 | 20 |
21 /* FreeBSD 5.0 */ | 21 /* FreeBSD 5.0 */ |
22 int ngx_freebsd_kern_ipc_zero_copy_send; | 22 int ngx_freebsd_kern_ipc_zero_copy_send; |
23 | 23 |
24 | 24 |
25 int ngx_freebsd_sendfile_nbytes_bug; | 25 ngx_uint_t ngx_freebsd_sendfile_nbytes_bug; |
26 int ngx_freebsd_use_tcp_nopush; | 26 ngx_uint_t ngx_freebsd_use_tcp_nopush; |
27 | 27 |
28 | 28 |
29 ngx_os_io_t ngx_os_io = { | 29 ngx_os_io_t ngx_os_io = { |
30 ngx_unix_recv, | 30 ngx_unix_recv, |
31 ngx_readv_chain, | 31 ngx_readv_chain, |
39 #endif | 39 #endif |
40 }; | 40 }; |
41 | 41 |
42 | 42 |
43 typedef struct { | 43 typedef struct { |
44 char *name; | 44 char *name; |
45 int *value; | 45 int *value; |
46 size_t size; | 46 size_t size; |
47 ngx_uint_t exists; | |
47 } sysctl_t; | 48 } sysctl_t; |
48 | 49 |
49 | 50 |
50 sysctl_t sysctls[] = { | 51 sysctl_t sysctls[] = { |
51 {"hw.ncpu", | 52 { "hw.ncpu", |
52 &ngx_freebsd_hw_ncpu, | 53 &ngx_freebsd_hw_ncpu, |
53 sizeof(int)}, | 54 sizeof(int), 0 }, |
54 | 55 |
55 {"machdep.hlt_logical_cpus", | 56 { "machdep.hlt_logical_cpus", |
56 &ngx_freebsd_machdep_hlt_logical_cpus, | 57 &ngx_freebsd_machdep_hlt_logical_cpus, |
57 sizeof(int)}, | 58 sizeof(int), 0 }, |
58 | 59 |
59 {"net.inet.tcp.sendspace", | 60 { "net.inet.tcp.sendspace", |
60 &ngx_freebsd_net_inet_tcp_sendspace, | 61 &ngx_freebsd_net_inet_tcp_sendspace, |
61 sizeof(int)}, | 62 sizeof(int), 0 }, |
62 | 63 |
63 /* FreeBSD 5.0 */ | 64 { "kern.ipc.zero_copy.send", |
64 | 65 &ngx_freebsd_kern_ipc_zero_copy_send, |
65 {"kern.ipc.zero_copy.send", | 66 sizeof(int), 0 }, |
66 &ngx_freebsd_kern_ipc_zero_copy_send, | 67 |
67 sizeof(int)}, | 68 { NULL, NULL, 0, 0 } |
68 | |
69 {NULL, NULL, 0} | |
70 }; | 69 }; |
71 | 70 |
72 | 71 |
73 void ngx_debug_init() | 72 void ngx_debug_init() |
74 { | 73 { |
82 | 81 |
83 #endif | 82 #endif |
84 } | 83 } |
85 | 84 |
86 | 85 |
87 int ngx_os_init(ngx_log_t *log) | 86 ngx_int_t ngx_os_init(ngx_log_t *log) |
88 { | 87 { |
89 int i, version; | 88 int version; |
90 size_t size; | 89 size_t size; |
91 ngx_err_t err; | 90 ngx_err_t err; |
91 ngx_uint_t i; | |
92 | 92 |
93 size = sizeof(ngx_freebsd_kern_ostype); | 93 size = sizeof(ngx_freebsd_kern_ostype); |
94 if (sysctlbyname("kern.ostype", | 94 if (sysctlbyname("kern.ostype", |
95 ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) { | 95 ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) { |
96 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 96 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
104 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 104 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
105 "sysctlbyname(kern.osrelease) failed"); | 105 "sysctlbyname(kern.osrelease) failed"); |
106 return NGX_ERROR; | 106 return NGX_ERROR; |
107 } | 107 } |
108 | 108 |
109 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s", | |
110 ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease); | |
111 | |
112 | 109 |
113 size = sizeof(int); | 110 size = sizeof(int); |
114 if (sysctlbyname("kern.osreldate", | 111 if (sysctlbyname("kern.osreldate", |
115 &ngx_freebsd_kern_osreldate, &size, NULL, 0) == -1) { | 112 &ngx_freebsd_kern_osreldate, &size, NULL, 0) == -1) { |
116 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 113 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
118 return NGX_ERROR; | 115 return NGX_ERROR; |
119 } | 116 } |
120 | 117 |
121 version = ngx_freebsd_kern_osreldate; | 118 version = ngx_freebsd_kern_osreldate; |
122 | 119 |
123 #ifdef __DragonFly_version | |
124 ngx_log_error(NGX_LOG_INFO, log, 0, | |
125 "kern.osreldate: %d, built on %d", | |
126 version, __DragonFly_version); | |
127 #else | |
128 ngx_log_error(NGX_LOG_INFO, log, 0, | |
129 "kern.osreldate: %d, built on %d", | |
130 version, __FreeBSD_version); | |
131 #endif | |
132 | |
133 | |
134 | 120 |
135 #if (HAVE_SENDFILE) | 121 #if (HAVE_SENDFILE) |
136 | 122 |
137 /* | 123 /* |
138 * The determination of the sendfile() "nbytes bug" is complex enough. | 124 * The determination of the sendfile() "nbytes bug" is complex enough. |
139 * There are two sendfile() syscalls: a new #393 has no bug while | 125 * There are two sendfile() syscalls: a new #393 has no bug while |
140 * an old #336 has the bug in some versions and has not in others. | 126 * an old #336 has the bug in some versions and has not in others. |
141 * Besides libc_r wrapper also emulates the bug in some versions. | 127 * Besides libc_r wrapper also emulates the bug in some versions. |
142 * There's no way to say exactly if a given FreeBSD version has the bug. | 128 * There is no way to say exactly if syscall #336 in FreeBSD circa 4.6 |
143 * We use the algorithm that is correct at least for RELEASEs | 129 * has the bug. We use the algorithm that is correct at least for |
144 * and for syscalls only (not libc_r wrapper). | 130 * RELEASEs and for syscalls only (not libc_r wrapper). |
145 * | 131 * |
146 * 4.6.1-RELEASE and below have the bug | 132 * 4.6.1-RELEASE and below have the bug |
147 * 4.6.2-RELEASE and above have the new syscall | 133 * 4.6.2-RELEASE and above have the new syscall |
148 * | 134 * |
149 * We detect the new sendfile() syscall available at the compile time | 135 * We detect the new sendfile() syscall available at the compile time |
174 | 160 |
175 | 161 |
176 for (i = 0; sysctls[i].name; i++) { | 162 for (i = 0; sysctls[i].name; i++) { |
177 *sysctls[i].value = 0; | 163 *sysctls[i].value = 0; |
178 size = sysctls[i].size; | 164 size = sysctls[i].size; |
165 | |
179 if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0) | 166 if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0) |
180 == -1) { | 167 == 0) |
181 err = ngx_errno; | 168 { |
182 if (err != NGX_ENOENT) { | 169 sysctls[i].exists = 1; |
183 if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) { | 170 continue; |
184 continue; | 171 } |
185 } | 172 |
186 | 173 err = ngx_errno; |
187 ngx_log_error(NGX_LOG_ALERT, log, err, | 174 |
188 "sysctlbyname(%s) failed", sysctls[i].name); | 175 if (err == NGX_ENOENT) { |
189 return NGX_ERROR; | 176 continue; |
190 } | 177 } |
191 | 178 |
192 } else { | 179 #if 0 |
193 ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d", | 180 if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) { |
194 sysctls[i].name, *sysctls[i].value); | 181 continue; |
195 } | 182 } |
183 #endif | |
184 | |
185 ngx_log_error(NGX_LOG_ALERT, log, err, | |
186 "sysctlbyname(%s) failed", sysctls[i].name); | |
187 return NGX_ERROR; | |
196 } | 188 } |
197 | 189 |
198 if (ngx_freebsd_machdep_hlt_logical_cpus) { | 190 if (ngx_freebsd_machdep_hlt_logical_cpus) { |
199 ngx_ncpu = ngx_freebsd_hw_ncpu / 2; | 191 ngx_ncpu = ngx_freebsd_hw_ncpu / 2; |
200 } else { | 192 } else { |
201 ngx_ncpu = ngx_freebsd_hw_ncpu; | 193 ngx_ncpu = ngx_freebsd_hw_ncpu; |
202 } | 194 } |
203 | 195 |
204 return ngx_posix_init(log); | 196 return ngx_posix_init(log); |
205 } | 197 } |
198 | |
199 | |
200 void ngx_os_status(ngx_log_t *log) | |
201 { | |
202 ngx_uint_t i; | |
203 | |
204 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s", | |
205 ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease); | |
206 | |
207 #ifdef __DragonFly_version | |
208 ngx_log_error(NGX_LOG_INFO, log, 0, | |
209 "kern.osreldate: %d, built on %d", | |
210 ngx_freebsd_kern_osreldate, __DragonFly_version); | |
211 #else | |
212 ngx_log_error(NGX_LOG_INFO, log, 0, | |
213 "kern.osreldate: %d, built on %d", | |
214 ngx_freebsd_kern_osreldate, __FreeBSD_version); | |
215 #endif | |
216 | |
217 for (i = 0; sysctls[i].name; i++) { | |
218 if (sysctls[i].exists) { | |
219 ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d", | |
220 sysctls[i].name, *sysctls[i].value); | |
221 } | |
222 } | |
223 | |
224 ngx_posix_status(log); | |
225 } |