Mercurial > hg > nginx-quic
annotate src/core/ngx_syslog.c @ 9080:afebde21cb32 quic
QUIC: disabled datagram fragmentation.
As per RFC 9000, Section 14:
UDP datagrams MUST NOT be fragmented at the IP layer.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Sat, 06 May 2023 16:23:27 +0400 |
parents | 8771d35d55d0 |
children |
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); |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
21 static u_char *ngx_syslog_log_error(ngx_log_t *log, u_char *buf, size_t len); |
5702
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
24 static char *facilities[] = { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
25 "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
|
26 "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
|
27 "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
|
28 NULL |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
31 /* 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
|
32 static char *severities[] = { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
33 "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
|
34 }; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
35 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
36 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
|
37 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
|
38 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
39 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
40 char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
41 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
|
42 { |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
43 ngx_pool_cleanup_t *cln; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
44 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
45 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
|
46 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
|
47 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
48 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
|
49 return NGX_CONF_ERROR; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
52 if (peer->server.sockaddr == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
53 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
|
54 "no syslog server specified"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
55 return NGX_CONF_ERROR; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
58 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
|
59 peer->facility = 23; /* local7 */ |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
62 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
|
63 peer->severity = 6; /* info */ |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
66 if (peer->tag.data == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
67 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
|
68 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
69 |
9056
29adacffdefa
Syslog: removed usage of ngx_cycle->log and ngx_cycle->hostname.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7277
diff
changeset
|
70 peer->hostname = &cf->cycle->hostname; |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
71 peer->logp = &cf->cycle->new_log; |
9056
29adacffdefa
Syslog: removed usage of ngx_cycle->log and ngx_cycle->hostname.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7277
diff
changeset
|
72 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
73 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
|
74 |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
75 peer->conn.read = &ngx_syslog_dummy_event; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
76 peer->conn.write = &ngx_syslog_dummy_event; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
77 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
78 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
|
79 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
80 cln = ngx_pool_cleanup_add(cf->pool, 0); |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
81 if (cln == NULL) { |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
82 return NGX_CONF_ERROR; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
83 } |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
84 |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
85 cln->data = peer; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
86 cln->handler = ngx_syslog_cleanup; |
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
87 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
88 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
89 } |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
92 static char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
93 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
|
94 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
95 u_char *p, *comma, c; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
96 size_t len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
97 ngx_str_t *value; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
98 ngx_url_t u; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
99 ngx_uint_t i; |
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 value = cf->args->elts; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
102 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
103 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
|
104 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
105 for ( ;; ) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
106 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
|
107 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
108 if (comma != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
109 len = comma - p; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
110 *comma = '\0'; |
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 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
113 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
|
114 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
115 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
116 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
|
117 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
118 if (peer->server.sockaddr != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
119 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
|
120 "duplicate syslog \"server\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
121 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
122 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
123 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
124 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
|
125 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
126 u.url.data = p + 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
127 u.url.len = len - 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
128 u.default_port = 514; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
129 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
130 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
|
131 if (u.err) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
132 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
|
133 "%s in syslog server \"%V\"", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
134 u.err, &u.url); |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
137 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
138 } |
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 peer->server = u.addrs[0]; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
141 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
142 } 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
|
143 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 "duplicate syslog \"facility\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
147 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
148 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
149 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
150 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
|
151 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
152 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
|
153 peer->facility = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
154 goto next; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
155 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
156 } |
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 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
|
159 "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
|
160 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
161 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
162 } 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
|
163 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
164 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
|
165 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
|
166 "duplicate syslog \"severity\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
168 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 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
|
171 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 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
|
173 peer->severity = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 goto next; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
176 } |
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 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
|
179 "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
|
180 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
181 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
182 } 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
|
183 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
184 if (peer->tag.data != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
185 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
|
186 "duplicate syslog \"tag\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
187 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
188 } |
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 /* |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
191 * 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
|
192 * 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
|
193 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
194 if (len - 4 > 32) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
195 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
|
196 "syslog tag length exceeds 32"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
197 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
198 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
199 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
200 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
|
201 c = ngx_tolower(p[i]); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
202 |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
203 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
|
204 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
|
205 "syslog \"tag\" only allows " |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
206 "alphanumeric characters " |
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
207 "and underscore"); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
208 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
209 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
210 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
211 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
212 peer->tag.data = p + 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
213 peer->tag.len = len - 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
214 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
215 } else if (len == 10 && ngx_strncmp(p, "nohostname", 10) == 0) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
216 peer->nohostname = 1; |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
217 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
218 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
219 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
|
220 "unknown syslog parameter \"%s\"", p); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
221 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
222 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
223 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
224 next: |
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 if (comma == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
227 break; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
230 p = comma + 1; |
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 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
234 } |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
237 u_char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
238 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
|
239 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
240 ngx_uint_t pri; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
241 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
242 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
|
243 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
244 if (peer->nohostname) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
245 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
|
246 &peer->tag); |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
247 } |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
248 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
249 return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri, &ngx_cached_syslog_time, |
9056
29adacffdefa
Syslog: removed usage of ngx_cycle->log and ngx_cycle->hostname.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7277
diff
changeset
|
250 peer->hostname, &peer->tag); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
251 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
252 |
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 void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
255 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
|
256 size_t len) |
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 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
|
259 ngx_uint_t head_len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
260 ngx_syslog_peer_t *peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
261 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
262 peer = log->wdata; |
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 if (peer->busy) { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
265 return; |
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 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
268 peer->busy = 1; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
269 peer->severity = level - 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
270 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
271 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
|
272 head_len = p - msg; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
273 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
274 len -= NGX_LINEFEED_SIZE; |
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 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
|
277 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
|
278 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
279 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
280 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
|
281 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
282 (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
|
283 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
284 peer->busy = 0; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
285 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
286 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
287 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
288 ssize_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
289 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
|
290 { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
291 ssize_t n; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
292 |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
293 if (peer->log.handler == NULL) { |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
294 peer->log = *peer->logp; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
295 peer->log.handler = ngx_syslog_log_error; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
296 peer->log.data = peer; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
297 peer->log.action = "logging to syslog"; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
298 } |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
299 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
300 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
|
301 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
|
302 return NGX_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
303 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
304 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
305 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
306 if (ngx_send) { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
307 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
|
308 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
309 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
310 /* 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
|
311 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
|
312 } |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
313 |
7272
fa0e093b64d7
Syslog: re-open syslog udp socket on send error (ticket #1477).
Vladimir Homutov <vl@nginx.com>
parents:
6474
diff
changeset
|
314 if (n == NGX_ERROR) { |
5858
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 if (ngx_close_socket(peer->conn.fd) == -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
317 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
318 ngx_close_socket_n " failed"); |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
319 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
320 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
321 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
|
322 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
323 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
324 return n; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
325 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
326 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
327 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
328 static ngx_int_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
329 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
|
330 { |
7277
7f9935f07fe9
Syslog: install cleanup handler only once.
Vladimir Homutov <vl@nginx.com>
parents:
7272
diff
changeset
|
331 ngx_socket_t fd; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
332 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
333 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
|
334 if (fd == (ngx_socket_t) -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
335 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
336 ngx_socket_n " failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
337 return NGX_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
338 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
339 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
340 if (ngx_nonblocking(fd) == -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
341 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
342 ngx_nonblocking_n " failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
343 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
344 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
345 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
346 if (connect(fd, peer->server.sockaddr, peer->server.socklen) == -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
347 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
348 "connect() failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
349 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
350 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
351 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
352 peer->conn.fd = fd; |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
353 peer->conn.log = &peer->log; |
5709
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
354 |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
355 /* UDP sockets are always ready to write */ |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
356 peer->conn.write->ready = 1; |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
357 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
358 return NGX_OK; |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
359 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
360 failed: |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
361 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
362 if (ngx_close_socket(fd) == -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
363 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
364 ngx_close_socket_n " failed"); |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
365 } |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
366 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
367 return NGX_ERROR; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
368 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
369 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
370 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
371 static void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
372 ngx_syslog_cleanup(void *data) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
373 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
374 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
|
375 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
376 /* prevents further use of this peer */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
377 peer->busy = 1; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
378 |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
379 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
|
380 return; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
381 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
382 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
383 if (ngx_close_socket(peer->conn.fd) == -1) { |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
384 ngx_log_error(NGX_LOG_ALERT, &peer->log, ngx_socket_errno, |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
385 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
|
386 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
387 } |
9057
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
388 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
389 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
390 static u_char * |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
391 ngx_syslog_log_error(ngx_log_t *log, u_char *buf, size_t len) |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
392 { |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
393 u_char *p; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
394 ngx_syslog_peer_t *peer; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
395 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
396 p = buf; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
397 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
398 if (log->action) { |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
399 p = ngx_snprintf(buf, len, " while %s", log->action); |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
400 len -= p - buf; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
401 } |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
402 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
403 peer = log->data; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
404 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
405 if (peer) { |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
406 p = ngx_snprintf(p, len, ", server: %V", &peer->server.name); |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
407 } |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
408 |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
409 return p; |
8771d35d55d0
Syslog: introduced error log handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9056
diff
changeset
|
410 } |