3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
8 #include <ngx_config.h>
12 char ngx_darwin_kern_ostype
[16];
13 char ngx_darwin_kern_osrelease
[128];
14 int ngx_darwin_hw_ncpu
;
15 int ngx_darwin_kern_ipc_somaxconn
;
16 u_long ngx_darwin_net_inet_tcp_sendspace
;
18 ngx_uint_t ngx_debug_malloc
;
21 static ngx_os_io_t ngx_darwin_io
= {
26 #if (NGX_HAVE_SENDFILE)
27 ngx_darwin_sendfile_chain
,
44 sysctl_t sysctls
[] = {
47 sizeof(ngx_darwin_hw_ncpu
), 0 },
49 { "net.inet.tcp.sendspace",
50 &ngx_darwin_net_inet_tcp_sendspace
,
51 sizeof(ngx_darwin_net_inet_tcp_sendspace
), 0 },
53 { "kern.ipc.somaxconn",
54 &ngx_darwin_kern_ipc_somaxconn
,
55 sizeof(ngx_darwin_kern_ipc_somaxconn
), 0 },
64 #if (NGX_DEBUG_MALLOC)
67 * MacOSX 10.6, 10.7: MallocScribble fills freed memory with 0x55
68 * and fills allocated memory with 0xAA.
69 * MacOSX 10.4, 10.5: MallocScribble fills freed memory with 0x55,
70 * MallocPreScribble fills allocated memory with 0xAA.
71 * MacOSX 10.3: MallocScribble fills freed memory with 0x55,
72 * and no way to fill allocated memory.
75 setenv("MallocScribble", "1", 0);
81 if (getenv("MallocScribble")) {
90 ngx_os_specific_init(ngx_log_t
*log
)
96 size
= sizeof(ngx_darwin_kern_ostype
);
97 if (sysctlbyname("kern.ostype", ngx_darwin_kern_ostype
, &size
, NULL
, 0)
102 if (err
!= NGX_ENOENT
) {
104 ngx_log_error(NGX_LOG_ALERT
, log
, err
,
105 "sysctlbyname(kern.ostype) failed");
107 if (err
!= NGX_ENOMEM
) {
111 ngx_darwin_kern_ostype
[size
- 1] = '\0';
115 size
= sizeof(ngx_darwin_kern_osrelease
);
116 if (sysctlbyname("kern.osrelease", ngx_darwin_kern_osrelease
, &size
,
122 if (err
!= NGX_ENOENT
) {
124 ngx_log_error(NGX_LOG_ALERT
, log
, err
,
125 "sysctlbyname(kern.osrelease) failed");
127 if (err
!= NGX_ENOMEM
) {
131 ngx_darwin_kern_osrelease
[size
- 1] = '\0';
135 for (i
= 0; sysctls
[i
].name
; i
++) {
136 size
= sysctls
[i
].size
;
138 if (sysctlbyname(sysctls
[i
].name
, sysctls
[i
].value
, &size
, NULL
, 0)
141 sysctls
[i
].exists
= 1;
147 if (err
== NGX_ENOENT
) {
151 ngx_log_error(NGX_LOG_ALERT
, log
, err
,
152 "sysctlbyname(%s) failed", sysctls
[i
].name
);
156 ngx_ncpu
= ngx_darwin_hw_ncpu
;
158 if (ngx_darwin_kern_ipc_somaxconn
> 32767) {
159 ngx_log_error(NGX_LOG_ALERT
, log
, 0,
160 "sysctl kern.ipc.somaxconn must be less than 32768");
164 ngx_tcp_nodelay_and_tcp_nopush
= 1;
166 ngx_os_io
= ngx_darwin_io
;
173 ngx_os_specific_status(ngx_log_t
*log
)
178 if (ngx_darwin_kern_ostype
[0]) {
179 ngx_log_error(NGX_LOG_NOTICE
, log
, 0, "OS: %s %s",
180 ngx_darwin_kern_ostype
, ngx_darwin_kern_osrelease
);
183 for (i
= 0; sysctls
[i
].name
; i
++) {
184 if (sysctls
[i
].exists
) {
185 if (sysctls
[i
].size
== sizeof(long)) {
186 value
= *(long *) sysctls
[i
].value
;
189 value
= *(int *) sysctls
[i
].value
;
192 ngx_log_error(NGX_LOG_NOTICE
, log
, 0, "%s: %l",
193 sysctls
[i
].name
, value
);