Mercurial > hg > nginx-quic
annotate src/core/ngx_syslog.c @ 7246:04ebf29eaf5b
Configure: fixed static compilation with OpenSSL 1.1.1.
OpenSSL now uses pthread_atfork(), and this requires -lpthread on Linux
to compile. Introduced NGX_LIBPTHREAD to add it as appropriate, similar
to existing NGX_LIBDL.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 22 Mar 2018 15:55:57 +0300 |
parents | 2cd019520210 |
children | fa0e093b64d7 |
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 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
42 peer->pool = cf->pool; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
43 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
|
44 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
|
45 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
46 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
|
47 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
48 } |
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 if (peer->server.sockaddr == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
51 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
|
52 "no syslog server specified"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
53 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
54 } |
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 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
|
57 peer->facility = 23; /* local7 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
58 } |
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 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
|
61 peer->severity = 6; /* info */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
62 } |
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 if (peer->tag.data == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
65 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
|
66 } |
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 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
|
69 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
70 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
71 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
72 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
73 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
74 static char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
75 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
|
76 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
77 u_char *p, *comma, c; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
78 size_t len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
79 ngx_str_t *value; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
80 ngx_url_t u; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
81 ngx_uint_t i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
82 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
83 value = cf->args->elts; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
84 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
85 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
|
86 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
87 for ( ;; ) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
88 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
|
89 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
90 if (comma != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
91 len = comma - p; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
92 *comma = '\0'; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
93 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
94 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
95 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
|
96 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
97 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
98 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
|
99 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
100 if (peer->server.sockaddr != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
101 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
|
102 "duplicate syslog \"server\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
103 return NGX_CONF_ERROR; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
106 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
|
107 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
108 u.url.data = p + 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
109 u.url.len = len - 7; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
110 u.default_port = 514; |
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_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
|
113 if (u.err) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
114 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
|
115 "%s in syslog server \"%V\"", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
116 u.err, &u.url); |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
119 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
120 } |
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 peer->server = u.addrs[0]; |
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 } 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
|
125 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
126 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
|
127 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
|
128 "duplicate syslog \"facility\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
129 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
130 } |
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 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
|
133 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
134 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
|
135 peer->facility = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
136 goto next; |
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 } |
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 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
|
141 "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
|
142 return NGX_CONF_ERROR; |
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 } 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
|
145 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 "duplicate syslog \"severity\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
149 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
150 } |
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 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
|
153 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
154 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
|
155 peer->severity = i; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
156 goto next; |
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 } |
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 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
|
161 "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
|
162 return NGX_CONF_ERROR; |
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 } 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
|
165 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
166 if (peer->tag.data != NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 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
|
168 "duplicate syslog \"tag\""); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 } |
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 * 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
|
174 * 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
|
175 */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
176 if (len - 4 > 32) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
177 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
|
178 "syslog tag length exceeds 32"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
179 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 } |
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 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
|
183 c = ngx_tolower(p[i]); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
184 |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
185 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
|
186 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
|
187 "syslog \"tag\" only allows " |
5922
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
188 "alphanumeric characters " |
68f64bc17fa4
Syslog: allowed underscore symbol in tag (ticket #667).
Vladimir Homutov <vl@nginx.com>
parents:
5858
diff
changeset
|
189 "and underscore"); |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
190 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
191 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
192 } |
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 peer->tag.data = p + 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
195 peer->tag.len = len - 4; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
196 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
197 } else if (len == 10 && ngx_strncmp(p, "nohostname", 10) == 0) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
198 peer->nohostname = 1; |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
199 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
200 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
201 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
|
202 "unknown syslog parameter \"%s\"", p); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
203 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
204 } |
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 next: |
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 if (comma == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
209 break; |
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 p = comma + 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
213 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
214 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
215 return NGX_CONF_OK; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
216 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
217 |
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 u_char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
220 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
|
221 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
222 ngx_uint_t pri; |
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 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
|
225 |
6286
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
226 if (peer->nohostname) { |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
227 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
|
228 &peer->tag); |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
229 } |
a6a2016b8e31
Syslog: added "nohostname" option.
Vladimir Homutov <vl@nginx.com>
parents:
5922
diff
changeset
|
230 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
231 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
|
232 &ngx_cycle->hostname, &peer->tag); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
233 } |
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 void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
237 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
|
238 size_t len) |
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 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
|
241 ngx_uint_t head_len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
242 ngx_syslog_peer_t *peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
243 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
244 peer = log->wdata; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
245 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
246 if (peer->busy) { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
247 return; |
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 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
250 peer->busy = 1; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
251 peer->severity = level - 1; |
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 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
|
254 head_len = p - msg; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
255 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
256 len -= NGX_LINEFEED_SIZE; |
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 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
|
259 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
|
260 } |
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 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
|
263 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
264 (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
|
265 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
266 peer->busy = 0; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
267 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
268 |
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 ssize_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
271 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
|
272 { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
273 ssize_t n; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
274 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
275 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
|
276 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
|
277 return NGX_ERROR; |
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 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
281 /* log syslog socket events with valid log */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
282 peer->conn.log = ngx_cycle->log; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
283 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
284 if (ngx_send) { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
285 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
|
286 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
287 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
288 /* 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
|
289 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
|
290 } |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
291 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
292 #if (NGX_HAVE_UNIX_DOMAIN) |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
293 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
294 if (n == NGX_ERROR && peer->server.sockaddr->sa_family == AF_UNIX) { |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
295 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
296 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
|
297 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
|
298 ngx_close_socket_n " failed"); |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
299 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
300 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
301 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
|
302 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
303 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
304 #endif |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
305 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
306 return n; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
307 } |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
310 static ngx_int_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
311 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
|
312 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
313 ngx_socket_t fd; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
314 ngx_pool_cleanup_t *cln; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
315 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
316 peer->conn.read = &ngx_syslog_dummy_event; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
317 peer->conn.write = &ngx_syslog_dummy_event; |
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 ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
320 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 ngx_socket_n " failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
325 return NGX_ERROR; |
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 if (ngx_nonblocking(fd) == -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
329 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
|
330 ngx_nonblocking_n " failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
331 goto failed; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
334 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
|
335 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
|
336 "connect() failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
337 goto failed; |
5702
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 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
340 cln = ngx_pool_cleanup_add(peer->pool, 0); |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
341 if (cln == NULL) { |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
342 goto failed; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
343 } |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
344 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
345 cln->data = peer; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
346 cln->handler = ngx_syslog_cleanup; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
347 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
348 peer->conn.fd = fd; |
5709
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
349 |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
350 /* UDP sockets are always ready to write */ |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
351 peer->conn.write->ready = 1; |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
352 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
353 return NGX_OK; |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
354 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
355 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 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
|
358 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
|
359 ngx_close_socket_n " failed"); |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
360 } |
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 return NGX_ERROR; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
363 } |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
366 static void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
367 ngx_syslog_cleanup(void *data) |
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 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
|
370 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
371 /* prevents further use of this peer */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
372 peer->busy = 1; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
373 |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
374 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
|
375 return; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
376 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
377 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
382 } |