summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Glagolev2009-04-01 20:36:13 +0400
committerVlad Glagolev2009-04-01 20:36:13 +0400
commit03cb2502e304e7b01f150315aef134c7381ce3f1 (patch)
tree04156a34887d739a0a67022c66f83a1e02588c45
parentaf3a198d0767abdddbe7952cc00b74aca1f14201 (diff)
nginx: added optional syslog support
-rwxr-xr-xhttp/nginx/BUILD1
-rwxr-xr-xhttp/nginx/CONFIGURE2
-rwxr-xr-xhttp/nginx/DEPENDS6
-rw-r--r--http/nginx/HISTORY4
-rwxr-xr-xhttp/nginx/PRE_BUILD6
-rw-r--r--http/nginx/syslog.patch276
6 files changed, 294 insertions, 1 deletions
diff --git a/http/nginx/BUILD b/http/nginx/BUILD
index c8dc35cc24..a889656d15 100755
--- a/http/nginx/BUILD
+++ b/http/nginx/BUILD
@@ -14,6 +14,7 @@ local TEMP_DIR="$INSTALL_ROOT/var/spool/nginx" &&
--http-fastcgi-temp-path="$TEMP_DIR/fastcgi_temp" \
--http-log-path="$INSTALL_ROOT/var/log/nginx/access.log" \
--error-log-path="$INSTALL_ROOT/var/log/nginx/error.log" \
+ $NGINX_OPTS \
$OPTS &&
make
diff --git a/http/nginx/CONFIGURE b/http/nginx/CONFIGURE
new file mode 100755
index 0000000000..356eb6d701
--- /dev/null
+++ b/http/nginx/CONFIGURE
@@ -0,0 +1,2 @@
+config_query_option NGINX_OPTS "build with syslog support?" n \
+ "--with-syslog" ""
diff --git a/http/nginx/DEPENDS b/http/nginx/DEPENDS
index d0ee1c7c45..07236ffbf3 100755
--- a/http/nginx/DEPENDS
+++ b/http/nginx/DEPENDS
@@ -6,4 +6,8 @@ optional_depends pcre \
optional_depends perl \
"--with-http_perl_module" "" \
- "for embedded Perl support"
+ "for embedded Perl support" &&
+
+if list_find "$NGINX_OPTS" "--with-syslog"; then
+ depends SYSTEM-LOGGER
+fi
diff --git a/http/nginx/HISTORY b/http/nginx/HISTORY
index 021ba8caaa..a100f7d6bb 100644
--- a/http/nginx/HISTORY
+++ b/http/nginx/HISTORY
@@ -1,3 +1,7 @@
+2009-04-01 Vlad Glagolev <stealth@sourcemage.org>
+ * BUILD, CONFIGURE, DEPENDS: added ability to use syslogging support
+ * PRE_BUILD, syslog.patch: added
+
2009-02-03 Vlad Glagolev <stealth@sourcemage.org>
* DETAILS: PATCHLEVEL=1
* BUILD: fixed temp dir path
diff --git a/http/nginx/PRE_BUILD b/http/nginx/PRE_BUILD
new file mode 100755
index 0000000000..6b9619e6c3
--- /dev/null
+++ b/http/nginx/PRE_BUILD
@@ -0,0 +1,6 @@
+default_pre_build &&
+cd "$SOURCE_DIRECTORY" &&
+
+if list_find "$NGINX_OPTS" "--with-syslog"; then
+ patch -p0 < "$SPELL_DIRECTORY/syslog.patch"
+fi
diff --git a/http/nginx/syslog.patch b/http/nginx/syslog.patch
new file mode 100644
index 0000000000..8295e2d31b
--- /dev/null
+++ b/http/nginx/syslog.patch
@@ -0,0 +1,276 @@
+--- auto/make.orig 2008-03-18 11:36:27.000000000 +0100
++++ auto/make 2008-05-16 11:12:43.000000000 +0200
+@@ -13,6 +13,10 @@
+ ngx_objs_dir=$NGX_OBJS$ngx_regex_dirsep
+ ngx_use_pch=`echo $NGX_USE_PCH | sed -e "s/\//$ngx_regex_dirsep/g"`
+
++#SYSLOG
++if [[ "${USE_SYSLOG}" == "YES" ]]; then
++ CFLAGS="$CFLAGS -DUSE_SYSLOG"
++fi
+
+ cat << END > $NGX_MAKEFILE
+
+--- auto/options.orig 2008-04-29 11:27:55.000000000 +0200
++++ auto/options 2008-05-16 11:12:43.000000000 +0200
+@@ -102,6 +102,8 @@
+ MD5_OPT=
+ MD5_ASM=NO
+
++USE_SYSLOG=NO
++
+ USE_SHA1=NO
+ SHA1=NONE
+ SHA1_OPT=
+@@ -225,6 +227,8 @@
+ --with-md5-opt=*) MD5_OPT="$value" ;;
+ --with-md5-asm) MD5_ASM=YES ;;
+
++ --with-syslog) USE_SYSLOG=YES ;;
++
+ --with-sha1=*) SHA1="$value" ;;
+ --with-sha1-opt=*) SHA1_OPT="$value" ;;
+ --with-sha1-asm) SHA1_ASM=YES ;;
+@@ -233,6 +237,8 @@
+ --with-zlib-opt=*) ZLIB_OPT="$value" ;;
+ --with-zlib-asm=*) ZLIB_ASM="$value" ;;
+
++ --with-syslog) USE_SYSLOG="YES" ;;
++
+ --test-build-devpoll) NGX_TEST_BUILD_DEVPOLL=YES ;;
+ --test-build-eventport) NGX_TEST_BUILD_EVENTPORT=YES ;;
+ --test-build-epoll) NGX_TEST_BUILD_EPOLL=YES ;;
+@@ -341,6 +347,8 @@
+ --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-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
+@@ -356,6 +364,8 @@
+
+ --with-debug enable the debugging logging
+
++ --with-syslog enable syslog support (disables writing to file)
++
+ END
+
+ exit 1
+--- auto/summary.orig 2008-04-29 11:27:55.000000000 +0200
++++ auto/summary 2008-05-16 11:12:43.000000000 +0200
+@@ -83,6 +83,11 @@
+ *) echo " + using zlib library: $ZLIB" ;;
+ esac
+
++case $USE_SYSLOG in
++ YES) echo " + using syslog" ;;
++ *) echo " + syslog is not used" ;;
++esac
++
+ echo
+
+
+--- src/core/nginx.c.orig 2007-12-10 13:09:51.000000000 +0100
++++ src/core/nginx.c 2008-05-16 11:12:43.000000000 +0200
+@@ -9,6 +9,9 @@
+ #include <ngx_event.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_getopt(ngx_cycle_t *cycle, int argc, char *const *argv);
+@@ -221,6 +224,11 @@
+ ngx_ssl_init(log);
+ #endif
+
++ /* SYSLOG SUPPORT */
++#ifdef USE_SYSLOG
++ openlog("nginx", LOG_ODELAY, LOG_DAEMON);
++#endif
++
+ /* init_cycle->log is required for signal handlers and ngx_getopt() */
+
+ ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
+@@ -358,6 +366,10 @@
+ ngx_single_process_cycle(cycle);
+ }
+
++#ifdef USE_SYSLOG
++ closelog();
++#endif
++
+ return 0;
+ }
+
+--- src/core/ngx_conf_file.c.orig 2008-04-29 11:28:42.000000000 +0200
++++ src/core/ngx_conf_file.c 2008-05-16 11:12:43.000000000 +0200
+@@ -751,6 +751,11 @@
+ full.data = NULL;
+ #endif
+
++#ifdef USE_SYSLOG
++if (name) {
++ name = NULL;
++}
++#endif
+ if (name) {
+ full = *name;
+
+--- src/core/ngx_log.c.orig 2008-11-20 20:23:08.000000000 +0300
++++ src/core/ngx_log.c 2009-04-01 17:52:42.969516782 +0400
+@@ -7,6 +7,9 @@
+ #include <ngx_config.h>
+ #include <ngx_core.h>
+
++#ifdef USE_SYSLOG
++#include <syslog.h>
++#endif
+
+ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+
+@@ -81,9 +84,11 @@
+ #endif
+ u_char errstr[NGX_MAX_ERROR_STR], *p, *last;
+
++ #ifndef USE_SYSLOG
+ if (log->file->fd == NGX_INVALID_FILE) {
+ return;
+ }
++ #endif
+
+ last = errstr + NGX_MAX_ERROR_STR;
+
+@@ -158,7 +163,22 @@
+
+ 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
+ }
+
+
+@@ -242,13 +262,17 @@
+ ngx_log_t *log;
+ ngx_str_t *value, *name;
+
++#ifndef USE_SYSLOG
+ if (args) {
+ value = args->elts;
+ name = &value[1];
+
+ } else {
++#endif
+ name = NULL;
++#ifndef USE_SYSLOG
+ }
++#endif
+
+ log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
+ if (log == NULL) {
+@@ -325,6 +349,10 @@
+
+ value = cf->args->elts;
+
++#ifdef USE_SYSLOG
++ value[1].data = "stderr";
++#endif
++
+ if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
+ cf->cycle->new_log->file->fd = ngx_stderr.fd;
+ cf->cycle->new_log->file->name.len = 0;
+--- src/http/modules/ngx_http_log_module.c.orig 2007-11-15 15:26:36.000000000 +0100
++++ src/http/modules/ngx_http_log_module.c 2008-05-16 11:56:39.000000000 +0200
+@@ -9,6 +9,9 @@
+ #include <ngx_http.h>
+ #include <nginx.h>
+
++#ifdef USE_SYSLOG
++#include <syslog.h>
++#endif
+
+ typedef struct ngx_http_log_op_s ngx_http_log_op_t;
+
+@@ -160,7 +163,11 @@
+
+
+ static ngx_str_t ngx_http_combined_fmt =
++#ifdef USE_SYSLOG
++ ngx_string("$remote_addr - $remote_user "
++#else
+ ngx_string("$remote_addr - $remote_user [$time_local] "
++#endif
+ "\"$request\" $status $body_bytes_sent "
+ "\"$http_referer\" \"$http_user_agent\"");
+
+@@ -285,6 +292,20 @@
+ 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
+ time_t now;
+ ssize_t n;
+ ngx_err_t err;
+@@ -322,6 +343,7 @@
+
+ log->error_log_time = now;
+ }
++#endif
+ }
+
+
+@@ -654,7 +676,11 @@
+ return NGX_CONF_ERROR;
+ }
+
++#ifdef USE_SYLOG
++ log->file = ngx_conf_open_file(cf->cycle, NULL);
++#else
+ log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log);
++#endif
+ if (log->file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+@@ -706,7 +732,11 @@
+ return NGX_CONF_ERROR;
+ }
+
++#ifdef USE_SYSLOG
++ log->file = ngx_conf_open_file(cf->cycle, NULL);
++#else
+ log->file = ngx_conf_open_file(cf->cycle, &value[1]);
++#endif
+ if (log->file == NULL) {
+ return NGX_CONF_ERROR;
+ }