~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/os/unix/ngx_darwin_init.c

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
 
5
 */
 
6
 
 
7
 
 
8
#include <ngx_config.h>
 
9
#include <ngx_core.h>
 
10
 
 
11
 
 
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;
 
17
 
 
18
ngx_uint_t  ngx_debug_malloc;
 
19
 
 
20
 
 
21
static ngx_os_io_t ngx_darwin_io = {
 
22
    ngx_unix_recv,
 
23
    ngx_readv_chain,
 
24
    ngx_udp_unix_recv,
 
25
    ngx_unix_send,
 
26
#if (NGX_HAVE_SENDFILE)
 
27
    ngx_darwin_sendfile_chain,
 
28
    NGX_IO_SENDFILE
 
29
#else
 
30
    ngx_writev_chain,
 
31
    0
 
32
#endif
 
33
};
 
34
 
 
35
 
 
36
typedef struct {
 
37
    char        *name;
 
38
    void        *value;
 
39
    size_t       size;
 
40
    ngx_uint_t   exists;
 
41
} sysctl_t;
 
42
 
 
43
 
 
44
sysctl_t sysctls[] = {
 
45
    { "hw.ncpu",
 
46
      &ngx_darwin_hw_ncpu,
 
47
      sizeof(ngx_darwin_hw_ncpu), 0 },
 
48
 
 
49
    { "net.inet.tcp.sendspace",
 
50
      &ngx_darwin_net_inet_tcp_sendspace,
 
51
      sizeof(ngx_darwin_net_inet_tcp_sendspace), 0 },
 
52
 
 
53
    { "kern.ipc.somaxconn",
 
54
      &ngx_darwin_kern_ipc_somaxconn,
 
55
      sizeof(ngx_darwin_kern_ipc_somaxconn), 0 },
 
56
 
 
57
    { NULL, NULL, 0, 0 }
 
58
};
 
59
 
 
60
 
 
61
void
 
62
ngx_debug_init()
 
63
{
 
64
#if (NGX_DEBUG_MALLOC)
 
65
 
 
66
    /*
 
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.
 
73
     */
 
74
 
 
75
    setenv("MallocScribble", "1", 0);
 
76
 
 
77
    ngx_debug_malloc = 1;
 
78
 
 
79
#else
 
80
 
 
81
    if (getenv("MallocScribble")) {
 
82
        ngx_debug_malloc = 1;
 
83
    }
 
84
 
 
85
#endif
 
86
}
 
87
 
 
88
 
 
89
ngx_int_t
 
90
ngx_os_specific_init(ngx_log_t *log)
 
91
{
 
92
    size_t      size;
 
93
    ngx_err_t   err;
 
94
    ngx_uint_t  i;
 
95
 
 
96
    size = sizeof(ngx_darwin_kern_ostype);
 
97
    if (sysctlbyname("kern.ostype", ngx_darwin_kern_ostype, &size, NULL, 0)
 
98
        == -1)
 
99
    {
 
100
        err = ngx_errno;
 
101
 
 
102
        if (err != NGX_ENOENT) {
 
103
 
 
104
            ngx_log_error(NGX_LOG_ALERT, log, err,
 
105
                          "sysctlbyname(kern.ostype) failed");
 
106
 
 
107
            if (err != NGX_ENOMEM) {
 
108
                return NGX_ERROR;
 
109
            }
 
110
 
 
111
            ngx_darwin_kern_ostype[size - 1] = '\0';
 
112
        }
 
113
    }
 
114
 
 
115
    size = sizeof(ngx_darwin_kern_osrelease);
 
116
    if (sysctlbyname("kern.osrelease", ngx_darwin_kern_osrelease, &size,
 
117
                     NULL, 0)
 
118
        == -1)
 
119
    {
 
120
        err = ngx_errno;
 
121
 
 
122
        if (err != NGX_ENOENT) {
 
123
 
 
124
            ngx_log_error(NGX_LOG_ALERT, log, err,
 
125
                          "sysctlbyname(kern.osrelease) failed");
 
126
 
 
127
            if (err != NGX_ENOMEM) {
 
128
                return NGX_ERROR;
 
129
            }
 
130
 
 
131
            ngx_darwin_kern_osrelease[size - 1] = '\0';
 
132
        }
 
133
    }
 
134
 
 
135
    for (i = 0; sysctls[i].name; i++) {
 
136
        size = sysctls[i].size;
 
137
 
 
138
        if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)
 
139
            == 0)
 
140
        {
 
141
            sysctls[i].exists = 1;
 
142
            continue;
 
143
        }
 
144
 
 
145
        err = ngx_errno;
 
146
 
 
147
        if (err == NGX_ENOENT) {
 
148
            continue;
 
149
        }
 
150
 
 
151
        ngx_log_error(NGX_LOG_ALERT, log, err,
 
152
                      "sysctlbyname(%s) failed", sysctls[i].name);
 
153
        return NGX_ERROR;
 
154
    }
 
155
 
 
156
    ngx_ncpu = ngx_darwin_hw_ncpu;
 
157
 
 
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");
 
161
        return NGX_ERROR;
 
162
    }
 
163
 
 
164
    ngx_tcp_nodelay_and_tcp_nopush = 1;
 
165
 
 
166
    ngx_os_io = ngx_darwin_io;
 
167
 
 
168
    return NGX_OK;
 
169
}
 
170
 
 
171
 
 
172
void
 
173
ngx_os_specific_status(ngx_log_t *log)
 
174
{
 
175
    u_long      value;
 
176
    ngx_uint_t  i;
 
177
 
 
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);
 
181
    }
 
182
 
 
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;
 
187
 
 
188
            } else {
 
189
                value = *(int *) sysctls[i].value;
 
190
            }
 
191
 
 
192
            ngx_log_error(NGX_LOG_NOTICE, log, 0, "%s: %l",
 
193
                          sysctls[i].name, value);
 
194
        }
 
195
    }
 
196
}