Mercurial > hg > nginx
annotate src/os/unix/ngx_errno.c @ 9320:cf73b65983c2 default tip
release-1.27.3 tag
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 13 Aug 2024 17:26:33 +0300 |
parents | c43a2e8fdf7e |
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:
305
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:
305
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:
305
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:
305
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
7 |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
7785
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
12 static ngx_str_t ngx_unknown_error = ngx_string("Unknown error"); |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
13 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
14 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
15 #if (NGX_HAVE_STRERRORDESC_NP) |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
16 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
17 /* |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
18 * The strerrordesc_np() function, introduced in glibc 2.32, is |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
19 * async-signal-safe. This makes it possible to use it directly, |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
20 * without copying error messages. |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
21 */ |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
22 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
23 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
24 u_char * |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
25 ngx_strerror(ngx_err_t err, u_char *errstr, size_t size) |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
26 { |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
27 size_t len; |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
28 const char *msg; |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
29 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
30 msg = strerrordesc_np(err); |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
31 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
32 if (msg == NULL) { |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
33 msg = (char *) ngx_unknown_error.data; |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
34 len = ngx_unknown_error.len; |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
35 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
36 } else { |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
37 len = ngx_strlen(msg); |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
38 } |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
39 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
40 size = ngx_min(size, len); |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
41 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
42 return ngx_cpymem(errstr, msg, size); |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
43 } |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
44 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
45 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
46 ngx_int_t |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
47 ngx_strerror_init(void) |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
48 { |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
49 return NGX_OK; |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
50 } |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
51 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
52 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
53 #else |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
54 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
55 /* |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
56 * The strerror() messages are copied because: |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
57 * |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
58 * 1) strerror() and strerror_r() functions are not Async-Signal-Safe, |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3787
diff
changeset
|
59 * therefore, they cannot be used in signal handlers; |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
60 * |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
61 * 2) a direct sys_errlist[] array may be used instead of these functions, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
62 * but Linux linker warns about its usage: |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
63 * |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
64 * warning: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
65 * warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
66 * |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
67 * causing false bug reports. |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
68 */ |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
71 static ngx_str_t *ngx_sys_errlist; |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
72 static ngx_err_t ngx_first_error; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
73 static ngx_err_t ngx_last_error; |
211
fd9fecc4193f
nginx-0.0.1-2003-12-15-16:57:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
210
diff
changeset
|
74 |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
75 |
2335
3d8ab5957202
ngx_strerror_r() style and size == 0 bug fix
Igor Sysoev <igor@sysoev.ru>
parents:
501
diff
changeset
|
76 u_char * |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
77 ngx_strerror(ngx_err_t err, u_char *errstr, size_t size) |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
78 { |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
79 ngx_str_t *msg; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
80 |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
81 if (err >= ngx_first_error && err < ngx_last_error) { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
82 msg = &ngx_sys_errlist[err - ngx_first_error]; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
83 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
84 } else { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
85 msg = &ngx_unknown_error; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
86 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
87 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
88 size = ngx_min(size, msg->len); |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
89 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
90 return ngx_cpymem(errstr, msg->data, size); |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
91 } |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
92 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
93 |
4693
f1a0de6eb505
Fixed return type of ngx_strerror_init().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
94 ngx_int_t |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
95 ngx_strerror_init(void) |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
96 { |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
97 char *msg; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
98 u_char *p; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
99 size_t len; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
100 ngx_err_t err; |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
101 |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
102 #if (NGX_SYS_NERR) |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
103 ngx_first_error = 0; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
104 ngx_last_error = NGX_SYS_NERR; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
105 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
106 #elif (EPERM > 1000 && EPERM < 0x7fffffff - 1000) |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
107 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
108 /* |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
109 * If number of errors is not known, and EPERM error code has large |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
110 * but reasonable value, guess possible error codes based on the error |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
111 * messages returned by strerror(), starting from EPERM. Notably, |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
112 * this covers GNU/Hurd, where errors start at 0x40000001. |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
113 */ |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
114 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
115 for (err = EPERM; err > EPERM - 1000; err--) { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
116 ngx_set_errno(0); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
117 msg = strerror(err); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
118 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
119 if (errno == EINVAL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
120 || msg == NULL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
121 || strncmp(msg, "Unknown error", 13) == 0) |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
122 { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
123 continue; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
124 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
125 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
126 ngx_first_error = err; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
127 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
128 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
129 for (err = EPERM; err < EPERM + 1000; err++) { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
130 ngx_set_errno(0); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
131 msg = strerror(err); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
132 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
133 if (errno == EINVAL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
134 || msg == NULL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
135 || strncmp(msg, "Unknown error", 13) == 0) |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
136 { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
137 continue; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
138 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
139 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
140 ngx_last_error = err + 1; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
141 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
142 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
143 #else |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
144 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
145 /* |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
146 * If number of errors is not known, guess it based on the error |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
147 * messages returned by strerror(). |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
148 */ |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
149 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
150 ngx_first_error = 0; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
151 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
152 for (err = 0; err < 1000; err++) { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
153 ngx_set_errno(0); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
154 msg = strerror(err); |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
155 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
156 if (errno == EINVAL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
157 || msg == NULL |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
158 || strncmp(msg, "Unknown error", 13) == 0) |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
159 { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
160 continue; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
161 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
162 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
163 ngx_last_error = err + 1; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
164 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
165 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
166 #endif |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
167 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
168 /* |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
169 * ngx_strerror() is not ready to work at this stage, therefore, |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
170 * malloc() is used and possible errors are logged using strerror(). |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
171 */ |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
172 |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
173 len = (ngx_last_error - ngx_first_error) * sizeof(ngx_str_t); |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
174 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
175 ngx_sys_errlist = malloc(len); |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
176 if (ngx_sys_errlist == NULL) { |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
177 goto failed; |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
178 } |
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
179 |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
180 for (err = ngx_first_error; err < ngx_last_error; err++) { |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
181 msg = strerror(err); |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
182 |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
183 if (msg == NULL) { |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
184 ngx_sys_errlist[err - ngx_first_error] = ngx_unknown_error; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
185 continue; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
186 } |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
187 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
188 len = ngx_strlen(msg); |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
189 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
190 p = malloc(len); |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
191 if (p == NULL) { |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
192 goto failed; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
193 } |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
194 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
195 ngx_memcpy(p, msg, len); |
7784
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
196 ngx_sys_errlist[err - ngx_first_error].len = len; |
8cc5b0365ee5
Improved maximum errno detection.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4693
diff
changeset
|
197 ngx_sys_errlist[err - ngx_first_error].data = p; |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
198 } |
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
199 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
200 return NGX_OK; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
201 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
202 failed: |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
203 |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
204 err = errno; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
205 ngx_log_stderr(0, "malloc(%uz) failed (%d: %s)", len, err, strerror(err)); |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
206 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2335
diff
changeset
|
207 return NGX_ERROR; |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
211
diff
changeset
|
208 } |
7785
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
209 |
c43a2e8fdf7e
Introduced strerrordesc_np() support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7784
diff
changeset
|
210 #endif |