Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

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 #include <nginx.h>
0011 
0012 
0013 ngx_int_t   ngx_ncpu;
0014 ngx_int_t   ngx_max_sockets;
0015 ngx_uint_t  ngx_inherited_nonblocking;
0016 ngx_uint_t  ngx_tcp_nodelay_and_tcp_nopush;
0017 
0018 
0019 struct rlimit  rlmt;
0020 
0021 
0022 ngx_os_io_t ngx_os_io = {
0023     ngx_unix_recv,
0024     ngx_readv_chain,
0025     ngx_udp_unix_recv,
0026     ngx_unix_send,
0027     ngx_udp_unix_send,
0028     ngx_udp_unix_sendmsg_chain,
0029     ngx_writev_chain,
0030     0
0031 };
0032 
0033 
0034 ngx_int_t
0035 ngx_os_init(ngx_log_t *log)
0036 {
0037     ngx_time_t  *tp;
0038     ngx_uint_t   n;
0039 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
0040     long         size;
0041 #endif
0042 
0043 #if (NGX_HAVE_OS_SPECIFIC_INIT)
0044     if (ngx_os_specific_init(log) != NGX_OK) {
0045         return NGX_ERROR;
0046     }
0047 #endif
0048 
0049     if (ngx_init_setproctitle(log) != NGX_OK) {
0050         return NGX_ERROR;
0051     }
0052 
0053     ngx_pagesize = getpagesize();
0054     ngx_cacheline_size = NGX_CPU_CACHE_LINE;
0055 
0056     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
0057 
0058 #if (NGX_HAVE_SC_NPROCESSORS_ONLN)
0059     if (ngx_ncpu == 0) {
0060         ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN);
0061     }
0062 #endif
0063 
0064     if (ngx_ncpu < 1) {
0065         ngx_ncpu = 1;
0066     }
0067 
0068 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
0069     size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
0070     if (size > 0) {
0071         ngx_cacheline_size = size;
0072     }
0073 #endif
0074 
0075     ngx_cpuinfo();
0076 
0077     if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
0078         ngx_log_error(NGX_LOG_ALERT, log, errno,
0079                       "getrlimit(RLIMIT_NOFILE) failed");
0080         return NGX_ERROR;
0081     }
0082 
0083     ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur;
0084 
0085 #if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4)
0086     ngx_inherited_nonblocking = 1;
0087 #else
0088     ngx_inherited_nonblocking = 0;
0089 #endif
0090 
0091     tp = ngx_timeofday();
0092     srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec);
0093 
0094     return NGX_OK;
0095 }
0096 
0097 
0098 void
0099 ngx_os_status(ngx_log_t *log)
0100 {
0101     ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER_BUILD);
0102 
0103 #ifdef NGX_COMPILER
0104     ngx_log_error(NGX_LOG_NOTICE, log, 0, "built by " NGX_COMPILER);
0105 #endif
0106 
0107 #if (NGX_HAVE_OS_SPECIFIC_INIT)
0108     ngx_os_specific_status(log);
0109 #endif
0110 
0111     ngx_log_error(NGX_LOG_NOTICE, log, 0,
0112                   "getrlimit(RLIMIT_NOFILE): %r:%r",
0113                   rlmt.rlim_cur, rlmt.rlim_max);
0114 }
0115 
0116 
0117 #if 0
0118 
0119 ngx_int_t
0120 ngx_posix_post_conf_init(ngx_log_t *log)
0121 {
0122     ngx_fd_t  pp[2];
0123 
0124     if (pipe(pp) == -1) {
0125         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed");
0126         return NGX_ERROR;
0127     }
0128 
0129     if (dup2(pp[1], STDERR_FILENO) == -1) {
0130         ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
0131         return NGX_ERROR;
0132     }
0133 
0134     if (pp[1] > STDERR_FILENO) {
0135         if (close(pp[1]) == -1) {
0136             ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed");
0137             return NGX_ERROR;
0138         }
0139     }
0140 
0141     return NGX_OK;
0142 }
0143 
0144 #endif