Annotation of embedaddon/nginx/src/os/unix/ngx_posix_init.c, revision 1.1

1.1     ! misho       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: #include <nginx.h>
        !            11: 
        !            12: 
        !            13: ngx_int_t   ngx_ncpu;
        !            14: ngx_int_t   ngx_max_sockets;
        !            15: ngx_uint_t  ngx_inherited_nonblocking;
        !            16: ngx_uint_t  ngx_tcp_nodelay_and_tcp_nopush;
        !            17: 
        !            18: 
        !            19: struct rlimit  rlmt;
        !            20: 
        !            21: 
        !            22: ngx_os_io_t ngx_os_io = {
        !            23:     ngx_unix_recv,
        !            24:     ngx_readv_chain,
        !            25:     ngx_udp_unix_recv,
        !            26:     ngx_unix_send,
        !            27:     ngx_writev_chain,
        !            28:     0
        !            29: };
        !            30: 
        !            31: 
        !            32: ngx_int_t
        !            33: ngx_os_init(ngx_log_t *log)
        !            34: {
        !            35:     ngx_uint_t  n;
        !            36: 
        !            37: #if (NGX_HAVE_OS_SPECIFIC_INIT)
        !            38:     if (ngx_os_specific_init(log) != NGX_OK) {
        !            39:         return NGX_ERROR;
        !            40:     }
        !            41: #endif
        !            42: 
        !            43:     ngx_init_setproctitle(log);
        !            44: 
        !            45:     ngx_pagesize = getpagesize();
        !            46:     ngx_cacheline_size = NGX_CPU_CACHE_LINE;
        !            47: 
        !            48:     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
        !            49: 
        !            50: #if (NGX_HAVE_SC_NPROCESSORS_ONLN)
        !            51:     if (ngx_ncpu == 0) {
        !            52:         ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN);
        !            53:     }
        !            54: #endif
        !            55: 
        !            56:     if (ngx_ncpu < 1) {
        !            57:         ngx_ncpu = 1;
        !            58:     }
        !            59: 
        !            60:     ngx_cpuinfo();
        !            61: 
        !            62:     if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
        !            63:         ngx_log_error(NGX_LOG_ALERT, log, errno,
        !            64:                       "getrlimit(RLIMIT_NOFILE) failed)");
        !            65:         return NGX_ERROR;
        !            66:     }
        !            67: 
        !            68:     ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur;
        !            69: 
        !            70: #if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4)
        !            71:     ngx_inherited_nonblocking = 1;
        !            72: #else
        !            73:     ngx_inherited_nonblocking = 0;
        !            74: #endif
        !            75: 
        !            76:     srandom(ngx_time());
        !            77: 
        !            78:     return NGX_OK;
        !            79: }
        !            80: 
        !            81: 
        !            82: void
        !            83: ngx_os_status(ngx_log_t *log)
        !            84: {
        !            85:     ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER);
        !            86: 
        !            87: #ifdef NGX_COMPILER
        !            88:     ngx_log_error(NGX_LOG_NOTICE, log, 0, "built by " NGX_COMPILER);
        !            89: #endif
        !            90: 
        !            91: #if (NGX_HAVE_OS_SPECIFIC_INIT)
        !            92:     ngx_os_specific_status(log);
        !            93: #endif
        !            94: 
        !            95:     ngx_log_error(NGX_LOG_NOTICE, log, 0,
        !            96:                   "getrlimit(RLIMIT_NOFILE): %r:%r",
        !            97:                   rlmt.rlim_cur, rlmt.rlim_max);
        !            98: }
        !            99: 
        !           100: 
        !           101: #if 0
        !           102: 
        !           103: ngx_int_t
        !           104: ngx_posix_post_conf_init(ngx_log_t *log)
        !           105: {
        !           106:     ngx_fd_t  pp[2];
        !           107: 
        !           108:     if (pipe(pp) == -1) {
        !           109:         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed");
        !           110:         return NGX_ERROR;
        !           111:     }
        !           112: 
        !           113:     if (dup2(pp[1], STDERR_FILENO) == -1) {
        !           114:         ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
        !           115:         return NGX_ERROR;
        !           116:     }
        !           117: 
        !           118:     if (pp[1] > STDERR_FILENO) {
        !           119:         if (close(pp[1]) == -1) {
        !           120:             ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed");
        !           121:             return NGX_ERROR;
        !           122:         }
        !           123:     }
        !           124: 
        !           125:     return NGX_OK;
        !           126: }
        !           127: 
        !           128: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>