Mercurial > hg > nginx-quic
annotate src/core/ngx_syslog.c @ 8285:0697294f79a4 quic
QUIC: removed redundant "app" flag from ngx_quic_close_frame_t.
The flag was introduced to create type-aware CONNECTION_CLOSE frames,
and now is replaced with frame type information, directly accessible.
Notably, this fixes type logging for received frames in b3d9e57d0f62.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 03 Feb 2021 12:39:41 +0300 |
parents | 7f9935f07fe9 |
children | 29adacffdefa |
rev | line source |
---|---|
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
2 /* |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
4 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
5 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
6 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
10 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
11 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
12 #define NGX_SYSLOG_MAX_STR \ |
6474 | 13 NGX_MAX_ERROR_STR + sizeof("<255>Jan 01 00:00:00 ") - 1 \ |
14 + (NGX_MAXHOSTNAMELEN - 1) + 1 /* space */ \ | |
15 + 32 /* tag */ + 2 /* colon, space */ | |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
16 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
17 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
18 static char *ngx_syslog_parse_args(ngx_conf_t *cf, ngx_syslog_peer_t *peer); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
19 static ngx_int_t ngx_syslog_init_peer(ngx_syslog_peer_t *peer); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
20 static void ngx_syslog_cleanup(void *data); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
21 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
22 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
23 static char *facilities[] = { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
24 "kern", "user", "mail", "daemon", "auth", "intern", "lpr", "news", "uucp", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
25 "clock", "authpriv", "ftp", "ntp", "audit", "alert", "cron", "local0", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
26 "local1", "local2", "local3", "local4", "local5", "local6", "local7", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
27 NULL |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
28 }; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
29 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
30 /* note 'error/warn' like in nginx.conf, not 'err/warning' */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
31 static char *severities[] = { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
32 "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", NULL |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
33 }; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
34 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
35 static ngx_log_t ngx_syslog_dummy_log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
36 static ngx_event_t ngx_syslog_dummy_event; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
37 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
38 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
39 char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
40 ngx_syslog_process_conf(ngx_conf_t *cf, ngx_syslog_peer_t *peer) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
41 { |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
42 ngx_pool_cleanup_t *cln; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
43 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
44 peer->facility = NGX_CONF_UNSET_UINT; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
45 peer->severity = NGX_CONF_UNSET_UINT; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
46 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
47 if (ngx_syslog_parse_args(cf, peer) != NGX_CONF_OK) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
48 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
49 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
50 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
51 if (peer->server.sockaddr == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
52 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
53 "no syslog server specified"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
54 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
55 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
56 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
57 if (peer->facility == NGX_CONF_UNSET_UINT) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
58 peer->facility = 23; /* local7 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
59 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
60 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
61 if (peer->severity == NGX_CONF_UNSET_UINT) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
62 peer->severity = 6; /* info */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
63 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
64 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
65 if (peer->tag.data == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
66 ngx_str_set(&peer->tag, "nginx"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
67 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
68 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
69 peer->conn.fd = (ngx_socket_t) -1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
70 |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
71 peer->conn.read = &ngx_syslog_dummy_event; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
72 peer->conn.write = &ngx_syslog_dummy_event; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
73 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
74 ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
75 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
76 cln = ngx_pool_cleanup_add(cf->pool, 0); |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
77 if (cln == NULL) { |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
78 return NGX_CONF_ERROR; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
79 } |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
80 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
81 cln->data = peer; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
82 cln->handler = ngx_syslog_cleanup; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
83 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
84 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
85 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
86 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
87 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
88 static char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
89 ngx_syslog_parse_args(ngx_conf_t *cf, ngx_syslog_peer_t *peer) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
90 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
91 u_char *p, *comma, c; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
92 size_t len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
93 ngx_str_t *value; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
94 ngx_url_t u; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
95 ngx_uint_t i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
96 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
97 value = cf->args->elts; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
98 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
99 p = value[1].data + sizeof("syslog:") - 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
100 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
101 for ( ;; ) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
102 comma = (u_char *) ngx_strchr(p, ','); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
103 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
104 if (comma != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
105 len = comma - p; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
106 *comma = '\0'; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
107 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
108 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
109 len = value[1].data + value[1].len - p; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
110 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
111 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
112 if (ngx_strncmp(p, "server=", 7) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
113 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
114 if (peer->server.sockaddr != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
115 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
116 "duplicate syslog \"server\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
117 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
118 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
119 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
120 ngx_memzero(&u, sizeof(ngx_url_t)); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
121 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
122 u.url.data = p + 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
123 u.url.len = len - 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
124 u.default_port = 514; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
125 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
126 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
127 if (u.err) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
128 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
129 "%s in syslog server \"%V\"", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
130 u.err, &u.url); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
131 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
132 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
133 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
134 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
135 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
136 peer->server = u.addrs[0]; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
137 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
138 } else if (ngx_strncmp(p, "facility=", 9) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
139 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
140 if (peer->facility != NGX_CONF_UNSET_UINT) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
141 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
142 "duplicate syslog \"facility\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
143 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
144 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
145 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
146 for (i = 0; facilities[i] != NULL; i++) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
147 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
148 if (ngx_strcmp(p + 9, facilities[i]) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
149 peer->facility = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
150 goto next; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
151 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
152 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
153 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
154 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
155 "unknown syslog facility \"%s\"", p + 9); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
156 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
157 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
158 } else if (ngx_strncmp(p, "severity=", 9) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
159 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
160 if (peer->severity != NGX_CONF_UNSET_UINT) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
161 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
162 "duplicate syslog \"severity\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
163 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
164 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
165 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
166 for (i = 0; severities[i] != NULL; i++) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
168 if (ngx_strcmp(p + 9, severities[i]) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 peer->severity = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 goto next; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
171 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
173 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 "unknown syslog severity \"%s\"", p + 9); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
176 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
177 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
178 } else if (ngx_strncmp(p, "tag=", 4) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
179 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 if (peer->tag.data != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
181 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
182 "duplicate syslog \"tag\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
183 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
184 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
185 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
186 /* |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
187 * RFC 3164: the TAG is a string of ABNF alphanumeric characters |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
188 * that MUST NOT exceed 32 characters. |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
189 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
190 if (len - 4 > 32) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
191 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
192 "syslog tag length exceeds 32"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
193 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
194 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
195 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
196 for (i = 4; i < len; i++) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
197 c = ngx_tolower(p[i]); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
198 |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
199 if (c < '0' || (c > '9' && c < 'a' && c != '_') || c > 'z') { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
200 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
201 "syslog \"tag\" only allows " |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
202 "alphanumeric characters " |
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
203 "and underscore"); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
204 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
205 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
206 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
207 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
208 peer->tag.data = p + 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
209 peer->tag.len = len - 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
210 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
211 } else if (len == 10 && ngx_strncmp(p, "nohostname", 10) == 0) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
212 peer->nohostname = 1; |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
213 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
214 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
215 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
216 "unknown syslog parameter \"%s\"", p); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
217 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
218 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
219 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
220 next: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
221 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
222 if (comma == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
223 break; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
224 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
225 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
226 p = comma + 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
227 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
228 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
229 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
230 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
231 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
232 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
233 u_char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
234 ngx_syslog_add_header(ngx_syslog_peer_t *peer, u_char *buf) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
235 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
236 ngx_uint_t pri; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
237 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
238 pri = peer->facility * 8 + peer->severity; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
239 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
240 if (peer->nohostname) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
241 return ngx_sprintf(buf, "<%ui>%V %V: ", pri, &ngx_cached_syslog_time, |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
242 &peer->tag); |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
243 } |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
244 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
245 return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri, &ngx_cached_syslog_time, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
246 &ngx_cycle->hostname, &peer->tag); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
247 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
248 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
249 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
250 void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
251 ngx_syslog_writer(ngx_log_t *log, ngx_uint_t level, u_char *buf, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
252 size_t len) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
253 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
254 u_char *p, msg[NGX_SYSLOG_MAX_STR]; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
255 ngx_uint_t head_len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
256 ngx_syslog_peer_t *peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
257 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
258 peer = log->wdata; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
259 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
260 if (peer->busy) { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
261 return; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
262 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
263 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
264 peer->busy = 1; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
265 peer->severity = level - 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
266 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
267 p = ngx_syslog_add_header(peer, msg); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
268 head_len = p - msg; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
269 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
270 len -= NGX_LINEFEED_SIZE; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
271 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
272 if (len > NGX_SYSLOG_MAX_STR - head_len) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
273 len = NGX_SYSLOG_MAX_STR - head_len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
274 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
275 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
276 p = ngx_snprintf(p, len, "%s", buf); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
277 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
278 (void) ngx_syslog_send(peer, msg, p - msg); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
279 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
280 peer->busy = 0; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
281 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
282 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
283 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
284 ssize_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
285 ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
286 { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
287 ssize_t n; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
288 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
289 if (peer->conn.fd == (ngx_socket_t) -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
290 if (ngx_syslog_init_peer(peer) != NGX_OK) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
291 return NGX_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
292 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
293 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
294 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
295 /* log syslog socket events with valid log */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
296 peer->conn.log = ngx_cycle->log; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
297 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
298 if (ngx_send) { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
299 n = ngx_send(&peer->conn, buf, len); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
300 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
301 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
302 /* event module has not yet set ngx_io */ |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
303 n = ngx_os_io.send(&peer->conn, buf, len); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
304 } |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
305 |
7272
fa0e093b64d7
Syslog: re-open syslog udp socket on send error (ticket #1477).
Vladimir Homutov <vl@nginx.com>
parents:
6474
diff
changeset
|
306 if (n == NGX_ERROR) { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
307 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
308 if (ngx_close_socket(peer->conn.fd) == -1) { |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
309 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
310 ngx_close_socket_n " failed"); |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
311 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
312 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
313 peer->conn.fd = (ngx_socket_t) -1; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
314 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
315 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
316 return n; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
317 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
318 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
319 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
320 static ngx_int_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
321 ngx_syslog_init_peer(ngx_syslog_peer_t *peer) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
322 { |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
323 ngx_socket_t fd; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
324 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
325 fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
326 if (fd == (ngx_socket_t) -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
327 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
328 ngx_socket_n " failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
329 return NGX_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
330 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
331 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
332 if (ngx_nonblocking(fd) == -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
333 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
334 ngx_nonblocking_n " failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
335 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
336 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
337 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
338 if (connect(fd, peer->server.sockaddr, peer->server.socklen) == -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
339 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
340 "connect() failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
341 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
342 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
343 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
344 peer->conn.fd = fd; |
5709
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
345 |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
346 /* UDP sockets are always ready to write */ |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
347 peer->conn.write->ready = 1; |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
348 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
349 return NGX_OK; |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
350 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
351 failed: |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
352 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
353 if (ngx_close_socket(fd) == -1) { |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
354 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
355 ngx_close_socket_n " failed"); |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
356 } |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
357 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
358 return NGX_ERROR; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
359 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
360 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
361 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
362 static void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
363 ngx_syslog_cleanup(void *data) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
364 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
365 ngx_syslog_peer_t *peer = data; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
366 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
367 /* prevents further use of this peer */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
368 peer->busy = 1; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
369 |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
370 if (peer->conn.fd == (ngx_socket_t) -1) { |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
371 return; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
372 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
373 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
374 if (ngx_close_socket(peer->conn.fd) == -1) { |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
375 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
376 ngx_close_socket_n " failed"); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
377 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
378 } |