Mercurial > hg > nginx
annotate src/os/unix/ngx_time.c @ 8018:5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
In 7583:efd71d49bde0 (nginx 1.17.5) along with introduction of the
ioctl(FIONREAD) support proper handling of systems without EPOLLRDHUP
support in the kernel (but with EPOLLRDHUP in headers) was broken.
Before the change, rev->available was never set to 0 unless
ngx_use_epoll_rdhup was also set (that is, runtime test for EPOLLRDHUP
introduced in 6536:f7849bfb6d21 succeeded). After the change,
rev->available might reach 0 on systems without runtime EPOLLRDHUP
support, stopping further reading in ngx_readv_chain() and ngx_unix_recv().
And, if EOF happened to be already reported along with the last event,
it is not reported again by epoll_wait(), leading to connection hangs
and timeouts on such systems.
This affects Linux kernels before 2.6.17 if nginx was compiled
with newer headers, and, more importantly, emulation layers, such as
DigitalOcean's App Platform's / gVisor's epoll emulation layer.
Fix is to explicitly check ngx_use_epoll_rdhup before the corresponding
rev->pending_eof tests in ngx_readv_chain() and ngx_unix_recv().
author | Marcus Ball <marcus.ball@live.com> |
---|---|
date | Mon, 30 May 2022 02:38:07 +0300 |
parents | d620f497c50f |
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:
370
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:
370
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:
370
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:
370
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
9 #include <ngx_core.h> |
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
10 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2220 | 12 /* |
13 * FreeBSD does not test /etc/localtime change, however, we can workaround it | |
14 * by calling tzset() with TZ and then without TZ to update timezone. | |
15 * The trick should work since FreeBSD 2.1.0. | |
16 * | |
17 * Linux does not test /etc/localtime change in localtime(), | |
18 * but may stat("/etc/localtime") several times in every strftime(), | |
19 * therefore we use it to update timezone. | |
20 * | |
21 * Solaris does not test /etc/TIMEZONE change too and no workaround available. | |
22 */ | |
23 | |
24 void | |
25 ngx_timezone_update(void) | |
26 { | |
27 #if (NGX_FREEBSD) | |
28 | |
29 if (getenv("TZ")) { | |
30 return; | |
31 } | |
32 | |
33 putenv("TZ=UTC"); | |
34 | |
35 tzset(); | |
36 | |
37 unsetenv("TZ"); | |
38 | |
39 tzset(); | |
40 | |
41 #elif (NGX_LINUX) | |
42 time_t s; | |
43 struct tm *t; | |
44 char buf[4]; | |
45 | |
46 s = time(0); | |
47 | |
48 t = localtime(&s); | |
49 | |
50 strftime(buf, 4, "%H", t); | |
51 | |
52 #endif | |
53 } | |
54 | |
55 | |
563 | 56 void |
57 ngx_localtime(time_t s, ngx_tm_t *tm) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 { |
469 | 59 #if (NGX_HAVE_LOCALTIME_R) |
563 | 60 (void) localtime_r(&s, tm); |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
61 |
179
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
62 #else |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
63 ngx_tm_t *t; |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
64 |
563 | 65 t = localtime(&s); |
179
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
66 *tm = *t; |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
67 |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
68 #endif |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
69 |
28
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
70 tm->ngx_tm_mon++; |
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
71 tm->ngx_tm_year += 1900; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 } |
509 | 73 |
74 | |
563 | 75 void |
76 ngx_libc_localtime(time_t s, struct tm *tm) | |
509 | 77 { |
78 #if (NGX_HAVE_LOCALTIME_R) | |
563 | 79 (void) localtime_r(&s, tm); |
509 | 80 |
81 #else | |
82 struct tm *t; | |
83 | |
563 | 84 t = localtime(&s); |
509 | 85 *tm = *t; |
86 | |
87 #endif | |
88 } | |
89 | |
90 | |
563 | 91 void |
92 ngx_libc_gmtime(time_t s, struct tm *tm) | |
509 | 93 { |
94 #if (NGX_HAVE_LOCALTIME_R) | |
563 | 95 (void) gmtime_r(&s, tm); |
509 | 96 |
97 #else | |
98 struct tm *t; | |
99 | |
563 | 100 t = gmtime(&s); |
509 | 101 *tm = *t; |
102 | |
103 #endif | |
104 } |