Mercurial > hg > nginx
annotate src/os/unix/ngx_posix_init.c @ 8409:26cb2f3259b1 quic
HTTP/3: reallocate strings inserted into the dynamic table.
They should always be allocated from the main QUIC connection pool.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 14 May 2020 16:02:32 +0300 |
parents | 057adb2a9d23 |
children |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
6 |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
539 | 10 #include <nginx.h> |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
473 | 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; | |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
17 |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
18 |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
19 struct rlimit rlmt; |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
355
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
22 ngx_os_io_t ngx_os_io = { |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
23 ngx_unix_recv, |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
24 ngx_readv_chain, |
1689 | 25 ngx_udp_unix_recv, |
2434
f80631ca01c6
set send() slot for POSIX systems
Igor Sysoev <igor@sysoev.ru>
parents:
1689
diff
changeset
|
26 ngx_unix_send, |
6436 | 27 ngx_udp_unix_send, |
6692 | 28 ngx_udp_unix_sendmsg_chain, |
355
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
29 ngx_writev_chain, |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
30 0 |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
31 }; |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
32 |
0fb6c53fb135
nginx-0.0.7-2004-06-15-21:47:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
354
diff
changeset
|
33 |
539 | 34 ngx_int_t |
35 ngx_os_init(ngx_log_t *log) | |
455 | 36 { |
6651
7d4e33092e2a
Always seed PRNG with PID, seconds, and milliseconds.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
37 ngx_time_t *tp; |
7d4e33092e2a
Always seed PRNG with PID, seconds, and milliseconds.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
38 ngx_uint_t n; |
7173
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
39 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE) |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
40 long size; |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
41 #endif |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
42 |
539 | 43 #if (NGX_HAVE_OS_SPECIFIC_INIT) |
44 if (ngx_os_specific_init(log) != NGX_OK) { | |
45 return NGX_ERROR; | |
46 } | |
47 #endif | |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
5826
16013b71feed
Added ngx_init_setproctitle() return code check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5701
diff
changeset
|
49 if (ngx_init_setproctitle(log) != NGX_OK) { |
16013b71feed
Added ngx_init_setproctitle() return code check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5701
diff
changeset
|
50 return NGX_ERROR; |
16013b71feed
Added ngx_init_setproctitle() return code check.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5701
diff
changeset
|
51 } |
509 | 52 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
252
diff
changeset
|
53 ngx_pagesize = getpagesize(); |
589 | 54 ngx_cacheline_size = NGX_CPU_CACHE_LINE; |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
252
diff
changeset
|
55 |
860
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
56 for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ } |
201d017ea470
slab allocator in shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
57 |
4459
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
58 #if (NGX_HAVE_SC_NPROCESSORS_ONLN) |
373
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
59 if (ngx_ncpu == 0) { |
4459
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
60 ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN); |
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
61 } |
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
62 #endif |
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
63 |
ccb2f8e3d08d
Added ngx_ncpu detection for most *nix platforms.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
64 if (ngx_ncpu < 1) { |
373
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
65 ngx_ncpu = 1; |
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
66 } |
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
67 |
7173
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
68 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE) |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
69 size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
70 if (size > 0) { |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
71 ngx_cacheline_size = size; |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
72 } |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
73 #endif |
057adb2a9d23
Use sysconf to determine cacheline size at runtime.
Debayan Ghosh <debayang.qdt@qualcommdatacenter.com>
parents:
6692
diff
changeset
|
74 |
611 | 75 ngx_cpuinfo(); |
76 | |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 ngx_log_error(NGX_LOG_ALERT, log, errno, |
6315
cb31017e961b
Core: fix typo in error message.
Piotr Sikora <piotrsikora@google.com>
parents:
5826
diff
changeset
|
79 "getrlimit(RLIMIT_NOFILE) failed"); |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 return NGX_ERROR; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 } |
577 | 82 |
563 | 83 ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur; |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 |
3786 | 85 #if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4) |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 ngx_inherited_nonblocking = 1; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 #else |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 ngx_inherited_nonblocking = 0; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 #endif |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
6651
7d4e33092e2a
Always seed PRNG with PID, seconds, and milliseconds.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
91 tp = ngx_timeofday(); |
7d4e33092e2a
Always seed PRNG with PID, seconds, and milliseconds.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
92 srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec); |
800 | 93 |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 return NGX_OK; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
539 | 98 void |
99 ngx_os_status(ngx_log_t *log) | |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
100 { |
5701
1209b8a7b077
Configure: the --build= option.
Ruslan Ermilov <ru@nginx.com>
parents:
4759
diff
changeset
|
101 ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER_BUILD); |
541 | 102 |
557 | 103 #ifdef NGX_COMPILER |
104 ngx_log_error(NGX_LOG_NOTICE, log, 0, "built by " NGX_COMPILER); | |
105 #endif | |
106 | |
539 | 107 #if (NGX_HAVE_OS_SPECIFIC_INIT) |
108 ngx_os_specific_status(log); | |
109 #endif | |
110 | |
531 | 111 ngx_log_error(NGX_LOG_NOTICE, log, 0, |
461 | 112 "getrlimit(RLIMIT_NOFILE): %r:%r", |
449
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
113 rlmt.rlim_cur, rlmt.rlim_max); |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
114 } |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
115 |
3b1e8c9df9ad
nginx-0.1.0-2004-10-04-00:02:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
444
diff
changeset
|
116 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4459
diff
changeset
|
117 #if 0 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4459
diff
changeset
|
118 |
539 | 119 ngx_int_t |
120 ngx_posix_post_conf_init(ngx_log_t *log) | |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 ngx_fd_t pp[2]; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 if (pipe(pp) == -1) { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "pipe() failed"); |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 return NGX_ERROR; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 if (dup2(pp[1], STDERR_FILENO) == -1) { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 return NGX_ERROR; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 if (pp[1] > STDERR_FILENO) { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 if (close(pp[1]) == -1) { |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed"); |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 return NGX_ERROR; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 return NGX_OK; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 } |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4459
diff
changeset
|
143 |
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4459
diff
changeset
|
144 #endif |