Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ngx_posix_init.c
Go to the documentation of this file.
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 
17 
18 
19 struct rlimit rlmt;
20 
21 
28  0
29 };
30 
31 
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 
44 
45  ngx_pagesize = getpagesize();
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 
72 #else
74 #endif
75 
76  srandom(ngx_time());
77 
78  return NGX_OK;
79 }
80 
81 
82 void
84 {
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)
93 #endif
94 
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