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 #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 
0040 #if (NGX_HAVE_OS_SPECIFIC_INIT)
0041     if (ngx_os_specific_init(log) != NGX_OK) {
0042         return NGX_ERROR;
0043     }
0044 #endif
0045 
0046     if (ngx_init_setproctitle(log) != NGX_OK) {
0047         return NGX_ERROR;
0048     }
0049 
0050     ngx_pagesize = getpagesize();
0051     ngx_cacheline_size = NGX_CPU_CACHE_LINE;
0052 
0053     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
0054 
0055 #if (NGX_HAVE_SC_NPROCESSORS_ONLN)
0056     if (ngx_ncpu == 0) {
0057         ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN);
0058     }
0059 #endif
0060 
0061     if (ngx_ncpu < 1) {
0062         ngx_ncpu = 1;
0063     }
0064 
0065     ngx_cpuinfo();
0066 
0067     if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
0068         ngx_log_error(NGX_LOG_ALERT, log, errno,
0069                       "getrlimit(RLIMIT_NOFILE) failed");
0070         return NGX_ERROR;
0071     }
0072 
0073     ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur;
0074 
0075 #if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4)
0076     ngx_inherited_nonblocking = 1;
0077 #else
0078     ngx_inherited_nonblocking = 0;
0079 #endif
0080 
0081     tp = ngx_timeofday();
0082     srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec);
0083 
0084     return NGX_OK;
0085 }
0086 
0087 
0088 void
0089 ngx_os_status(ngx_log_t *log)
0090 {
0091     ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER_BUILD);
0092 
0093 #ifdef NGX_COMPILER
0094     ngx_log_error(NGX_LOG_NOTICE, log, 0, "built by " NGX_COMPILER);
0095 #endif
0096 
0097 #if (NGX_HAVE_OS_SPECIFIC_INIT)
0098     ngx_os_specific_status(log);
0099 #endif
0100 
0101     ngx_log_error(NGX_LOG_NOTICE, log, 0,
0102                   "getrlimit(RLIMIT_NOFILE): %r:%r",
0103                   rlmt.rlim_cur, rlmt.rlim_max);
0104 }
0105 
0106 
0107 #if 0
0108 
0109 ngx_int_t
0110 ngx_posix_post_conf_init(ngx_log_t *log)
0111 {
0112     ngx_fd_t  pp[2];
0113 
0114     if (pipe(pp) == -1) {
0115         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed");
0116         return NGX_ERROR;
0117     }
0118 
0119     if (dup2(pp[1], STDERR_FILENO) == -1) {
0120         ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
0121         return NGX_ERROR;
0122     }
0123 
0124     if (pp[1] > STDERR_FILENO) {
0125         if (close(pp[1]) == -1) {
0126             ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed");
0127             return NGX_ERROR;
0128         }
0129     }
0130 
0131     return NGX_OK;
0132 }
0133 
0134 #endif