diff -ruN nginx-0.6.31_orig/auto/make nginx-0.6.31/auto/make --- nginx-0.6.31_orig/auto/make 2008-03-18 11:36:27.000000000 +0100 +++ nginx-0.6.31/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 diff -ruN nginx-0.6.31_orig/auto/options nginx-0.6.31/auto/options --- nginx-0.6.31_orig/auto/options 2008-04-29 11:27:55.000000000 +0200 +++ nginx-0.6.31/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 diff -ruN nginx-0.6.31_orig/auto/summary nginx-0.6.31/auto/summary --- nginx-0.6.31_orig/auto/summary 2008-04-29 11:27:55.000000000 +0200 +++ nginx-0.6.31/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 diff -ruN nginx-0.6.31_orig/src/core/nginx.c nginx-0.6.31/src/core/nginx.c --- nginx-0.6.31_orig/src/core/nginx.c 2007-12-10 13:09:51.000000000 +0100 +++ nginx-0.6.31/src/core/nginx.c 2008-05-16 11:12:43.000000000 +0200 @@ -9,6 +9,9 @@ #include #include +#ifdef USE_SYSLOG +#include +#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; } diff -ruN nginx-0.6.31_orig/src/core/ngx_conf_file.c nginx-0.6.31/src/core/ngx_conf_file.c --- nginx-0.6.31_orig/src/core/ngx_conf_file.c 2008-04-29 11:28:42.000000000 +0200 +++ nginx-0.6.31/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; diff -ruN nginx-0.6.31_orig/src/core/ngx_log.c nginx-0.6.31/src/core/ngx_log.c --- nginx-0.6.31_orig/src/core/ngx_log.c 2007-07-29 20:05:45.000000000 +0200 +++ nginx-0.6.31/src/core/ngx_log.c 2008-05-16 11:54:22.000000000 +0200 @@ -7,6 +7,9 @@ #include #include +#ifdef USE_SYSLOG +#include +#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); - ngx_write_fd(log->file->fd, errstr, p - errstr); +#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 + 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; diff -ruN nginx-0.6.31_orig/src/http/modules/ngx_http_log_module.c nginx-0.6.31/src/http/modules/ngx_http_log_module.c --- nginx-0.6.31_orig/src/http/modules/ngx_http_log_module.c 2007-11-15 15:26:36.000000000 +0100 +++ nginx-0.6.31/src/http/modules/ngx_http_log_module.c 2008-05-16 11:56:39.000000000 +0200 @@ -9,6 +9,9 @@ #include #include +#ifdef USE_SYSLOG +#include +#endif typedef struct ngx_http_log_op_s ngx_http_log_op_t; @@ -284,6 +287,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; @@ -321,6 +338,7 @@ log->error_log_time = now; } +#endif } @@ -585,7 +603,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; } @@ -637,7 +659,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; }