Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 char    ngx_darwin_kern_ostype[16];
0013 char    ngx_darwin_kern_osrelease[128];
0014 int     ngx_darwin_hw_ncpu;
0015 int     ngx_darwin_kern_ipc_somaxconn;
0016 u_long  ngx_darwin_net_inet_tcp_sendspace;
0017 
0018 ngx_uint_t  ngx_debug_malloc;
0019 
0020 
0021 static ngx_os_io_t ngx_darwin_io = {
0022     ngx_unix_recv,
0023     ngx_readv_chain,
0024     ngx_udp_unix_recv,
0025     ngx_unix_send,
0026     ngx_udp_unix_send,
0027     ngx_udp_unix_sendmsg_chain,
0028 #if (NGX_HAVE_SENDFILE)
0029     ngx_darwin_sendfile_chain,
0030     NGX_IO_SENDFILE
0031 #else
0032     ngx_writev_chain,
0033     0
0034 #endif
0035 };
0036 
0037 
0038 typedef struct {
0039     char        *name;
0040     void        *value;
0041     size_t       size;
0042     ngx_uint_t   exists;
0043 } sysctl_t;
0044 
0045 
0046 sysctl_t sysctls[] = {
0047     { "hw.ncpu",
0048       &ngx_darwin_hw_ncpu,
0049       sizeof(ngx_darwin_hw_ncpu), 0 },
0050 
0051     { "net.inet.tcp.sendspace",
0052       &ngx_darwin_net_inet_tcp_sendspace,
0053       sizeof(ngx_darwin_net_inet_tcp_sendspace), 0 },
0054 
0055     { "kern.ipc.somaxconn",
0056       &ngx_darwin_kern_ipc_somaxconn,
0057       sizeof(ngx_darwin_kern_ipc_somaxconn), 0 },
0058 
0059     { NULL, NULL, 0, 0 }
0060 };
0061 
0062 
0063 void
0064 ngx_debug_init(void)
0065 {
0066 #if (NGX_DEBUG_MALLOC)
0067 
0068     /*
0069      * MacOSX 10.6, 10.7:  MallocScribble fills freed memory with 0x55
0070      *                     and fills allocated memory with 0xAA.
0071      * MacOSX 10.4, 10.5:  MallocScribble fills freed memory with 0x55,
0072      *                     MallocPreScribble fills allocated memory with 0xAA.
0073      * MacOSX 10.3:        MallocScribble fills freed memory with 0x55,
0074      *                     and no way to fill allocated memory.
0075      */
0076 
0077     setenv("MallocScribble", "1", 0);
0078 
0079     ngx_debug_malloc = 1;
0080 
0081 #else
0082 
0083     if (getenv("MallocScribble")) {
0084         ngx_debug_malloc = 1;
0085     }
0086 
0087 #endif
0088 }
0089 
0090 
0091 ngx_int_t
0092 ngx_os_specific_init(ngx_log_t *log)
0093 {
0094     size_t      size;
0095     ngx_err_t   err;
0096     ngx_uint_t  i;
0097 
0098     size = sizeof(ngx_darwin_kern_ostype);
0099     if (sysctlbyname("kern.ostype", ngx_darwin_kern_ostype, &size, NULL, 0)
0100         == -1)
0101     {
0102         err = ngx_errno;
0103 
0104         if (err != NGX_ENOENT) {
0105 
0106             ngx_log_error(NGX_LOG_ALERT, log, err,
0107                           "sysctlbyname(kern.ostype) failed");
0108 
0109             if (err != NGX_ENOMEM) {
0110                 return NGX_ERROR;
0111             }
0112 
0113             ngx_darwin_kern_ostype[size - 1] = '\0';
0114         }
0115     }
0116 
0117     size = sizeof(ngx_darwin_kern_osrelease);
0118     if (sysctlbyname("kern.osrelease", ngx_darwin_kern_osrelease, &size,
0119                      NULL, 0)
0120         == -1)
0121     {
0122         err = ngx_errno;
0123 
0124         if (err != NGX_ENOENT) {
0125 
0126             ngx_log_error(NGX_LOG_ALERT, log, err,
0127                           "sysctlbyname(kern.osrelease) failed");
0128 
0129             if (err != NGX_ENOMEM) {
0130                 return NGX_ERROR;
0131             }
0132 
0133             ngx_darwin_kern_osrelease[size - 1] = '\0';
0134         }
0135     }
0136 
0137     for (i = 0; sysctls[i].name; i++) {
0138         size = sysctls[i].size;
0139 
0140         if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)
0141             == 0)
0142         {
0143             sysctls[i].exists = 1;
0144             continue;
0145         }
0146 
0147         err = ngx_errno;
0148 
0149         if (err == NGX_ENOENT) {
0150             continue;
0151         }
0152 
0153         ngx_log_error(NGX_LOG_ALERT, log, err,
0154                       "sysctlbyname(%s) failed", sysctls[i].name);
0155         return NGX_ERROR;
0156     }
0157 
0158     ngx_ncpu = ngx_darwin_hw_ncpu;
0159 
0160     if (ngx_darwin_kern_ipc_somaxconn > 32767) {
0161         ngx_log_error(NGX_LOG_ALERT, log, 0,
0162                       "sysctl kern.ipc.somaxconn must be less than 32768");
0163         return NGX_ERROR;
0164     }
0165 
0166     ngx_tcp_nodelay_and_tcp_nopush = 1;
0167 
0168     ngx_os_io = ngx_darwin_io;
0169 
0170     return NGX_OK;
0171 }
0172 
0173 
0174 void
0175 ngx_os_specific_status(ngx_log_t *log)
0176 {
0177     u_long      value;
0178     ngx_uint_t  i;
0179 
0180     if (ngx_darwin_kern_ostype[0]) {
0181         ngx_log_error(NGX_LOG_NOTICE, log, 0, "OS: %s %s",
0182                       ngx_darwin_kern_ostype, ngx_darwin_kern_osrelease);
0183     }
0184 
0185     for (i = 0; sysctls[i].name; i++) {
0186         if (sysctls[i].exists) {
0187             if (sysctls[i].size == sizeof(long)) {
0188                 value = *(long *) sysctls[i].value;
0189 
0190             } else {
0191                 value = *(int *) sysctls[i].value;
0192             }
0193 
0194             ngx_log_error(NGX_LOG_NOTICE, log, 0, "%s: %l",
0195                           sysctls[i].name, value);
0196         }
0197     }
0198 }