Mercurial > hg > nginx-quic
annotate src/core/ngx_syslog.c @ 6133:af7eba90645d
Win32: shared memory base addresses and remapping.
Two mechanisms are implemented to make it possible to store pointers
in shared memory on Windows, in particular on Windows Vista and later
versions with ASLR:
- The ngx_shm_remap() function added to allow remapping of a shared memory
zone to the address originally used for it in the master process. While
important, it doesn't solve the problem by itself as in many cases it's
not possible to use the address because of conflicts with other
allocations.
- We now create mappings at the same address in all processes by starting
mappings at predefined addresses normally unused by newborn processes.
These two mechanisms combined allow to use shared memory on Windows
almost without problems, including reloads.
Based on the patch by Sergey Brester:
http://mailman.nginx.org/pipermail/nginx-devel/2015-April/006836.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 27 Apr 2015 18:25:42 +0300 |
parents | 68f64bc17fa4 |
children | a6a2016b8e31 |
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 \ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
13 NGX_MAX_ERROR_STR + sizeof("<255>Jan 01 00:00:00 ") - 1 \ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
14 + (NGX_MAXHOSTNAMELEN - 1) + 1 /* space */ \ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
15 + 32 /* tag */ + 2 /* colon, space */ |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
197 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
198 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
|
199 "unknown syslog parameter \"%s\"", p); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
200 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
201 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
202 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
203 next: |
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 if (comma == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
206 break; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
209 p = comma + 1; |
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 return NGX_CONF_OK; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
216 u_char * |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
217 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
|
218 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
219 ngx_uint_t pri; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
220 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
221 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
|
222 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
223 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
|
224 &ngx_cycle->hostname, &peer->tag); |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
227 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
228 void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
229 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
|
230 size_t len) |
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 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
|
233 ngx_uint_t head_len; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
234 ngx_syslog_peer_t *peer; |
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 peer = log->wdata; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
237 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
238 if (peer->busy) { |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
239 return; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
240 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
241 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
242 peer->busy = 1; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
243 peer->severity = level - 1; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
244 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
245 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
|
246 head_len = p - msg; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
247 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
248 len -= NGX_LINEFEED_SIZE; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
249 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
250 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
|
251 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
|
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 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
|
255 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
256 (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
|
257 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
258 peer->busy = 0; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
259 } |
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 ssize_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
263 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
|
264 { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
265 ssize_t n; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
266 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
267 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
|
268 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
|
269 return NGX_ERROR; |
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 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
272 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
273 /* log syslog socket events with valid log */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
274 peer->conn.log = ngx_cycle->log; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
275 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
276 if (ngx_send) { |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
277 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
|
278 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
279 } else { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
280 /* 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
|
281 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
|
282 } |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
283 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
284 #if (NGX_HAVE_UNIX_DOMAIN) |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
285 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
286 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
|
287 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
288 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
|
289 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
|
290 ngx_close_socket_n " failed"); |
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 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
293 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
|
294 } |
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 #endif |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
297 |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
298 return n; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
299 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
300 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
301 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
302 static ngx_int_t |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
303 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
|
304 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
305 ngx_socket_t fd; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
306 ngx_pool_cleanup_t *cln; |
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 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
|
309 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
|
310 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
311 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
|
312 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 ngx_socket_n " failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
317 return NGX_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
318 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
319 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
320 if (ngx_nonblocking(fd) == -1) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
321 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
|
322 ngx_nonblocking_n " failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
323 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
324 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
325 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
326 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
|
327 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
328 "connect() failed"); |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
329 goto failed; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
330 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
331 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
332 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
|
333 if (cln == NULL) { |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
334 goto failed; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
335 } |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
336 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
337 cln->data = peer; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
338 cln->handler = ngx_syslog_cleanup; |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
339 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
340 peer->conn.fd = fd; |
5709
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
341 |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
342 /* UDP sockets are always ready to write */ |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
343 peer->conn.write->ready = 1; |
44532046d9d7
Syslog: fixed message sending on win32.
Vladimir Homutov <vl@nginx.com>
parents:
5708
diff
changeset
|
344 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
345 return NGX_OK; |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
346 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
347 failed: |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
348 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
349 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
|
350 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
|
351 ngx_close_socket_n " failed"); |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
352 } |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
353 |
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
354 return NGX_ERROR; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
355 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
356 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
357 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
358 static void |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
359 ngx_syslog_cleanup(void *data) |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
360 { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
361 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
|
362 |
5857
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
363 /* prevents further use of this peer */ |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
364 peer->busy = 1; |
2cb5275bf5e7
Syslog: enabled logging of send errors.
Vladimir Homutov <vl@nginx.com>
parents:
5709
diff
changeset
|
365 |
5858
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
366 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
|
367 return; |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
368 } |
02c2352d5b01
Syslog: improved error handling of unix domain sockets.
Vladimir Homutov <vl@nginx.com>
parents:
5857
diff
changeset
|
369 |
5708
aacd994167d3
Syslog: fixed possible resource leak and more verbose logging.
Vladimir Homutov <vl@nginx.com>
parents:
5702
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
374 } |