Mercurial > hg > nginx
annotate src/os/unix/ngx_time.c @ 7668:0a04e5e4c40b
Large block sizes on Linux are now ignored (ticket #1168).
NFS on Linux is known to report wsize as a block size (in both f_bsize
and f_frsize, both in statfs() and statvfs()). On the other hand,
typical file system block sizes on Linux (ext2/ext3/ext4, XFS) are limited
to pagesize. (With FAT, block sizes can be at least up to 512k in
extreme cases, but this doesn't really matter, see below.)
To avoid too aggressive cache clearing on NFS volumes on Linux, block
sizes larger than pagesize are now ignored.
Note that it is safe to ignore large block sizes. Since 3899:e7cd13b7f759
(1.0.1) cache size is calculated based on fstat() st_blocks, and rounding
to file system block size is preserved mostly for Windows.
Note well that on other OSes valid block sizes seen are at least up
to 65536. In particular, UFS on FreeBSD is known to work well with block
and fragment sizes set to 65536.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 22 Jun 2020 18:02:58 +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 } |