summaryrefslogtreecommitdiff
path: root/www/nginx-devel/files/extra-patch-syslog_support
blob: 16031340521e20556ffb39fcd324963436509876 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
diff -u a/src/core/nginx.c b/src/core/nginx.c
index 80a5d18..fdad5d5 100644
--- src/core/nginx.c.orig
+++ src/core/nginx.c
@@ -8,6 +8,9 @@
 #include <ngx_core.h>
 #include <nginx.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
 static ngx_int_t ngx_get_options(int argc, char *const *argv);
@@ -278,6 +281,11 @@ main(int argc, char *const *argv)
     ngx_ssl_init(log);
 #endif
 
+    /* SYSLOG SUPPORT */
+#ifdef USE_SYSLOG
+    openlog("nginx", LOG_NDELAY, SYSLOG_FACILITY);
+#endif
+
     /*
      * init_cycle->log is required for signal handlers and
      * ngx_process_options()
@@ -396,6 +404,10 @@ main(int argc, char *const *argv)
         ngx_master_process_cycle(cycle);
     }
 
+#ifdef USE_SYSLOG
+    closelog();
+#endif
+
     return 0;
 }
 
diff -u a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 83c1073..1817627 100644
--- src/core/ngx_conf_file.c.orig
+++ src/core/ngx_conf_file.c
@@ -907,6 +907,12 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
     ngx_str_null(&full);
 #endif
 
+#ifdef USE_SYSLOG
+    if (name->len) {
+      name->len = 0;
+    }
+#endif
+
     if (name->len) {
         full = *name;
 
diff -u a/src/core/ngx_log.c b/src/core/ngx_log.c
index c0485c6..b4ae00a 100644
--- src/core/ngx_log.c.orig
+++ src/core/ngx_log.c
@@ -7,6 +7,9 @@
 #include <ngx_config.h>
 #include <ngx_core.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
@@ -90,9 +93,11 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
     u_char  *p, *last, *msg;
     u_char   errstr[NGX_MAX_ERROR_STR];
 
+#ifndef USE_SYSLOG
     if (log->file->fd == NGX_INVALID_FILE) {
         return;
     }
+#endif
 
     last = errstr + NGX_MAX_ERROR_STR;
 
@@ -139,7 +144,21 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
 
     ngx_linefeed(p);
 
+#ifdef USE_SYSLOG
+    /* allocate a string which can hold the error message */
+    char *syslogstr;
+
+    if ((syslogstr = calloc((p - errstr + 1), sizeof(char))) != NULL) {
+      strncpy(syslogstr, errstr, p - errstr);
+
+      /* write to syslog */
+      syslog(LOG_CRIT, "%s", syslogstr);
+
+      free(syslogstr);
+    }
+#else
     (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
+#endif
 
     if (!ngx_use_stderr
         || level > NGX_LOG_WARN
@@ -428,6 +447,10 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
+#ifdef USE_SYSLOG
+    value[1].data = "stderr";
+#endif
+
     if (ngx_strcmp(value[1].data, "stderr") == 0) {
         ngx_str_null(&name);
 
diff -u a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 5f356c3..5232ad6 100644
--- src/http/modules/ngx_http_log_module.c.orig
+++ src/http/modules/ngx_http_log_module.c
@@ -8,6 +8,9 @@
 #include <ngx_core.h>
 #include <ngx_http.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
 
 typedef struct ngx_http_log_op_s  ngx_http_log_op_t;
 
@@ -310,6 +313,19 @@ static void
 ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
     size_t len)
 {
+#ifdef USE_SYSLOG
+  /* allocate a string which can hold the error message */
+  char *syslogstr;
+
+  if ((syslogstr = calloc((len + 1), sizeof(char))) != NULL) {
+    strncpy(syslogstr, buf, len);
+
+    /* write to syslog */
+    syslog(LOG_NOTICE, "%s", syslogstr);
+
+    free(syslogstr);
+  }
+#else
     u_char     *name;
     time_t      now;
     ssize_t     n;
@@ -354,6 +370,7 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
 
         log->error_log_time = now;
     }
+#endif
 }
 
 
@@ -818,7 +835,11 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
         return NGX_CONF_ERROR;
     }
 
+#ifdef USE_SYSLOG
+    ngx_http_access_log.data = "";
+#endif
     log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
+
     if (log->file == NULL) {
         return NGX_CONF_ERROR;
     }
@@ -883,7 +904,11 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     n = ngx_http_script_variables_count(&value[1]);
 
     if (n == 0) {
+#ifdef USE_SYSLOG
+        value[1].data = "";
+#endif
         log->file = ngx_conf_open_file(cf->cycle, &value[1]);
+
         if (log->file == NULL) {
             return NGX_CONF_ERROR;
         }
-- 
1.6.3.3

--- auto/summary.orig	2010-07-08 19:57:36.000000000 +0400
+++ auto/summary	2010-12-08 12:25:16.000000000 +0300
@@ -73,6 +73,11 @@
     *)     echo "  + using libatomic_ops library: $NGX_LIBATOMIC" ;;
 esac
 
+case $USE_SYSLOG in
+    YES)   echo "  + using syslog with $SYSLOG_FACILITY facility" ;;
+    *)     echo "  + syslog is not used" ;;
+esac
+
 echo
 
 
--- auto/make.orig	2009-05-12 17:15:43.000000000 +0400
+++ auto/make	2010-12-08 12:32:25.000000000 +0300
@@ -15,6 +15,13 @@
 ngx_objs_dir=$NGX_OBJS$ngx_regex_dirsep
 ngx_use_pch=`echo $NGX_USE_PCH | sed -e "s/\//$ngx_regex_dirsep/g"`
 
+#SYSLOG
+if test -z "${SYSLOG_FACILITY}"; then
+    SYSLOG_FACILITY="LOG_DAEMON"
+fi
+if test "${USE_SYSLOG}" = "YES"; then
+    CFLAGS="$CFLAGS -DUSE_SYSLOG -DSYSLOG_FACILITY=${SYSLOG_FACILITY}"
+fi
 
 cat << END                                                     > $NGX_MAKEFILE
 
--- auto/options.orig	2011-11-01 09:01:14.000000000 +0400
+++ auto/options	2011-11-01 09:02:42.000000000 +0400
@@ -120,6 +120,8 @@
 MD5_OPT=
 MD5_ASM=NO
 
+USE_SYSLOG=NO
+
 USE_SHA1=NO
 SHA1=NONE
 SHA1_OPT=
@@ -274,6 +276,9 @@
         --with-md5-opt=*)                MD5_OPT="$value"           ;;
         --with-md5-asm)                  MD5_ASM=YES                ;;
 
+        --with-syslog)                   USE_SYSLOG=YES             ;;
+        --with-syslog-facility=*)        SYSLOG_FACILITY="$value"   ;;
+
         --with-sha1=*)                   SHA1="$value"              ;;
         --with-sha1-opt=*)               SHA1_OPT="$value"          ;;
         --with-sha1-asm)                 SHA1_ASM=YES               ;;
@@ -418,6 +423,9 @@
   --with-md5-opt=OPTIONS             set additional options for md5 building
   --with-md5-asm                     use md5 assembler sources
 
+  --with-syslog                      use syslog instead of files to log messages
+  --with-syslog-facility=FACILITY    set syslog facility
+
   --with-sha1=DIR                    set path to sha1 library sources
   --with-sha1-opt=OPTIONS            set additional options for sha1 building
   --with-sha1-asm                    use sha1 assembler sources