# HG changeset patch # User Igor Sysoev # Date 1100120400 -10800 # Node ID 46833bd150cbb162e29decefdada323516a36c37 # Parent 77eee314ddbd44e986c7deb31600d8388726044d nginx 0.1.5 *) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive. diff --git a/CHANGES b/CHANGES --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,26 @@ + +Changes with nginx 0.1.5 11 Nov 2004 + + *) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned + not enough data" alerts. + + *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors + on Solaris in proxy mode without sendfile. On other platforms that do + not support sendfile at all the process got caught in an endless loop. + + *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. + + *) Bugfix: segmentation fault on Solaris. + + *) Bugfix: on-line upgrade did not work on Linux. + + *) Bugfix: the ngx_http_autoindex_module module did not escape the + spaces, the quotes, and the percent signs in the directory listing. + + *) Change: the decrease of the copy operations. + + *) Feature: the userid_p3p directive. + Changes with nginx 0.1.4 26 Oct 2004 diff --git a/CHANGES.ru b/CHANGES.ru --- a/CHANGES.ru +++ b/CHANGES.ru @@ -1,3 +1,29 @@ + +Изменения в nginx 0.1.5 11.11.2004 + + *) Исправление: на Solaris и Linux могло быть очень много сообщений + "recvmsg() returned not enough data". + + *) Исправление: в режиме прокси без использования sendfile на Solaris + возникала ошибка "writev() failed (22: Invalid argument)". На других + платформах, не поддерживающих sendfile, процесс зацикливался. + + *) Исправление: при использовании sendfile в режиме прокси на Solaris + возникал segmentation fault. + + *) Исправление: segmentation fault на Solaris. + + *) Исправление: обновление исполняемого файла на лету не работало на + Linux. + + *) Исправление: в списке файлов, выдаваемом модулем + ngx_http_autoindex_module, не перекодировались пробелы, кавычки и + знаки процента. + + *) Изменение: уменьшение операций копирования. + + *) Добавление: директива userid_p3p. + Изменения в nginx 0.1.4 26.10.2004 diff --git a/auto/cc/bcc b/auto/cc/bcc --- a/auto/cc/bcc +++ b/auto/cc/bcc @@ -32,17 +32,31 @@ CFLAGS="$CFLAGS -w!" # disable logo CFLAGS="$CFLAGS -q" + # precompiled headers CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.csm" NGX_PCH="$OBJS/ngx_config.csm" NGX_BUILD_PCH="-H=$OBJS/ngx_config.csm" NGX_USE_PCH="-Hu -H=$OBJS/ngx_config.csm" -LINK="\$(CC)" + +# Win32 GUI mode application +LINK="\$(CC) -laa" + + +# the resource file +NGX_RES="$OBJS/nginx.res" +NGX_RCC="brcc32 -fo$OBJS/nginx.res \$(CORE_INCS) $NGX_WIN32_RC" +# the pragma allows to link the resource file using bcc32 and +# to avoid the direct ilink32 calling and the c0w32.obj's WinMain/main problem +NGX_PRAGMA="#pragma resource \"$OBJS/nginx.res\"" + ngx_include_opt="-I" ngx_objout="-o" ngx_binout="-e" ngx_objext="obj" ngx_binext=".exe" -ngx_dirsep='\\' + +ngx_regex_dirsep='\\' +ngx_dirsep="\\" diff --git a/auto/cc/conf b/auto/cc/conf --- a/auto/cc/conf +++ b/auto/cc/conf @@ -64,8 +64,8 @@ else # . auto/cc/acc # ;; - msvc) - # MSVC 6.0 SP2 + msvc*) + # MSVC++ 6.0 SP2, MSVC++ Toolkit 2003 . auto/cc/msvc ;; @@ -93,6 +93,22 @@ CFLAGS="$CFLAGS $NGX_CC_OPT" if [ "$PLATFORM" != win32 ]; then + if test -n "$NGX_LD_OPT"; then + ngx_feature=--with-ld-opt=\"$NGX_LD_OPT\" + ngx_feature_name=DUMMY + ngx_feature_run=no + ngx_feature_incs= + ngx_feature_libs= + ngx_feature_test= + . auto/feature + + if [ $ngx_found = no ]; then + echo $0: error: the invalid value in --with-ld-opt=\"$NGX_LD_OPT\" + echo + exit 1 + fi + fi + ngx_feature="gcc variadic macros" ngx_feature_name=HAVE_GCC_VARIADIC_MACROS ngx_feature_run=yes diff --git a/auto/cc/gcc b/auto/cc/gcc --- a/auto/cc/gcc +++ b/auto/cc/gcc @@ -104,6 +104,3 @@ if [ ".$CPP" = "." ]; then fi LINK="\$(CC)" - - -CC_STRONG="-Wall -Werror" diff --git a/auto/cc/icc b/auto/cc/icc --- a/auto/cc/icc +++ b/auto/cc/icc @@ -64,6 +64,3 @@ CFLAGS="$CFLAGS -Werror" CFLAGS="$CFLAGS -g" LINK="\$(CC)" - - -CC_STRONG="-w1 -Werror" diff --git a/auto/cc/msvc b/auto/cc/msvc --- a/auto/cc/msvc +++ b/auto/cc/msvc @@ -2,7 +2,7 @@ # Copyright (C) Igor Sysoev -# MSVC 6.0 SP2 +# MSVC 6.0 SP2, MSVC Toolkit 2003 (7.1) # optimizations @@ -31,8 +31,8 @@ case $CPU in ;; pentium4) - # optimize for Pentium 4 - #CPU_OPT="-G7" + # optimize for Pentium 4, MSVC 7 + CPU_OPT="-G7" ;; esac @@ -47,30 +47,48 @@ CFLAGS="$CFLAGS -W4" # stop on warning CFLAGS="$CFLAGS -WX" -# link with libcmt.lib, multithreaded -#LIBC="-MT" -# link with msvcrt.dll -LIBC="-MD" +# disable logo +CFLAGS="$CFLAGS -nologo" + + +LINK="\$(CC)" + +# the link flags +CORE_LINK="$CORE_LINK -link -verbose:lib" + +if [ $NGX_CC_NAME = msvc7 ]; then + # link with libcmt.lib, multithreaded + LIBC="-MT" +else + # link with msvcrt.dll + LIBC="-MD" +fi CFLAGS="$CFLAGS $LIBC" -# disable logo -CFLAGS="$CFLAGS -nologo" - -LINK="\$(CC)" - -# link flags -CORE_LINK="$CORE_LINK -link -verbose:lib" +# Win32 GUI mode application +CORE_LIBS="$CORE_LIBS kernel32.lib user32.lib" +CORE_LINK="$CORE_LINK -subsystem:windows -entry:mainCRTStartup" # debug CFLAGS="$CFLAGS -Yd" CORE_LINK="$CORE_LINK -debug -debugtype:coff" + # precompiled headers -CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch" -NGX_PCH="$OBJS/ngx_config.pch" -NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch" -NGX_USE_PCH="-Yungx_config.h -Fp$OBJS/ngx_config.pch" +if [ $NGX_CC_NAME != msvc7 ]; then + CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch" + NGX_PCH="$OBJS/ngx_config.pch" + NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch" + NGX_USE_PCH="-Yungx_config.h -Fp$OBJS/ngx_config.pch" +fi + + +# the resource file +NGX_RES="$OBJS/nginx.res" +NGX_RCC="rc -fo$NGX_RES \$(CORE_INCS) $NGX_WIN32_RC" +CORE_LINK="$NGX_RES $CORE_LINK" + ngx_objout="-Fo" ngx_binout="-Fe" diff --git a/auto/cc/name b/auto/cc/name --- a/auto/cc/name +++ b/auto/cc/name @@ -6,8 +6,17 @@ echo $ngx_n "checking for C compiler ... if [ $CC = cl ]; then - NGX_CC_NAME=msvc - echo " using Microsoft Visual C compiler" + if `$NGX_WINE $CC -v 2>&1 \ + | grep '^Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13' \ + 2>&1 >/dev/null`; then + + NGX_CC_NAME=msvc7 + echo " using Microsoft Visual C++ 7 compiler" + + else + NGX_CC_NAME=msvc + echo " using Microsoft Visual C++ compiler" + fi else if [ $CC = wcl386 ]; then diff --git a/auto/cc/owc b/auto/cc/owc --- a/auto/cc/owc +++ b/auto/cc/owc @@ -59,18 +59,25 @@ CFLAGS="$CFLAGS -d2" CFLAGS="$CFLAGS -zq" # Open Watcom C 1.2 -#have=HAVE_C99_VARIADIC_MACROS . auto/have +#have=NGX_HAVE_C99_VARIADIC_MACROS . auto/have -# precompiled headers + +# the precompiled headers CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch" NGX_PCH="$OBJS/ngx_config.pch" NGX_BUILD_PCH="-fhq=$OBJS/ngx_config.pch" NGX_USE_PCH="-fh=$OBJS/ngx_config.pch" + LINK="\$(CC)" -# link flags -CORE_LINK="$CORE_LINK -l=nt" +# the link flags, built target is NT GUI mode application +CORE_LINK="$CORE_LINK -l=nt_win" + + +# the resource file +NGX_RCC="wrc \$(CORE_INCS) -fo=$OBJS/nginx.res $NGX_WIN32_RC $OBJS/nginx.exe" + ngx_include_opt="-i=" ngx_objout="-fo" diff --git a/auto/feature b/auto/feature --- a/auto/feature +++ b/auto/feature @@ -35,6 +35,7 @@ END ngx_test="$CC $CC_TEST_FLAGS $CC_WARN $CC_AUX_FLAGS \ -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs" + eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" diff --git a/auto/lib/md5/conf b/auto/lib/md5/conf --- a/auto/lib/md5/conf +++ b/auto/lib/md5/conf @@ -17,12 +17,12 @@ if [ $MD5 != NONE ]; then case "$NGX_CC_NAME" in - msvc | owc | bcc) + msvc* | owc* | bcc) LINK_DEPS="$LINK_DEPS $MD5/md5.lib" CORE_LIBS="$CORE_LIBS $MD5/md5.lib" ;; - icc) + icc*) LINK_DEPS="$LINK_DEPS $MD5/libmd5.a" # to allow -ipo optimization we link with the *.o but not library diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf --- a/auto/lib/pcre/conf +++ b/auto/lib/pcre/conf @@ -9,7 +9,7 @@ if [ $PCRE != NONE ]; then case "$NGX_CC_NAME" in - msvc | owc | bcc) + msvc* | owc* | bcc) have=NGX_PCRE . auto/have have=PCRE_STATIC . auto/have CORE_DEPS="$CORE_DEPS $PCRE/pcre.h" @@ -17,7 +17,7 @@ if [ $PCRE != NONE ]; then CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib" ;; - icc) + icc*) have=NGX_PCRE . auto/have CORE_DEPS="$CORE_DEPS $PCRE/pcre.h" diff --git a/auto/lib/zlib/conf b/auto/lib/zlib/conf --- a/auto/lib/zlib/conf +++ b/auto/lib/zlib/conf @@ -7,12 +7,12 @@ if [ $ZLIB != NONE ]; then case "$NGX_CC_NAME" in - msvc | owc | bcc) + msvc* | owc* | bcc) LINK_DEPS="$LINK_DEPS $ZLIB/zlib.lib" CORE_LIBS="$CORE_LIBS $ZLIB/zlib.lib" ;; - icc) + icc*) LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" # to allow -ipo optimization we link with the *.o but not library diff --git a/auto/make b/auto/make --- a/auto/make +++ b/auto/make @@ -132,7 +132,15 @@ ngx_all_objs=`echo $ngx_all_srcs \ ngx_modules_obj=`echo $ngx_modules_c | sed -e "s/\(.*\.\)c/\1$ngx_objext/"` -ngx_deps=`echo $ngx_all_objs $ngx_modules_obj $LINK_DEPS \ + +if test -n "$NGX_RES"; then + ngx_res=$NGX_RES +else + ngx_res="$NGX_RC $NGX_ICONS" + ngx_rcc=`echo $NGX_RCC | sed -e "s/\//$ngx_regex_dirsep/g"` +fi + +ngx_deps=`echo $ngx_all_objs $ngx_modules_obj $ngx_res $LINK_DEPS \ | sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g" \ -e "s/\//$ngx_regex_dirsep/g"` @@ -146,10 +154,12 @@ ngx_libs=${CORE_LIBS:+`echo $NGX_LD_OPT ngx_link=${CORE_LINK:+`echo $CORE_LINK \ | sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_regex_cont/"`} + cat << END >> $NGX_MAKEFILE $NGX_OBJS${ngx_dirsep}nginx${ngx_binext}: $ngx_deps$ngx_spacer \$(LINK) ${ngx_binout}$NGX_OBJS${ngx_dirsep}nginx$ngx_cont$ngx_objs$ngx_libs$ngx_link + $ngx_rcc END @@ -256,6 +266,24 @@ END fi +# Win32 resource file + +if test -n "$NGX_RES"; then + + ngx_res=`echo "$NGX_RES: $NGX_RC $NGX_ICONS" \ + | sed -e "s/\//$ngx_regex_dirsep/g"` + ngx_rcc=`echo $NGX_RCC | sed -e "s/\//$ngx_regex_dirsep/g"` + + cat << END >> $NGX_MAKEFILE + +$ngx_res + $ngx_rcc + +END + +fi + + # the precompiled headers if test -n "$NGX_PCH"; then diff --git a/auto/modules b/auto/modules --- a/auto/modules +++ b/auto/modules @@ -154,9 +154,14 @@ if [ $IMAP = YES ]; then fi -echo "#include " > $NGX_MODULES_C -echo "#include " >> $NGX_MODULES_C -echo >> $NGX_MODULES_C +cat << END > $NGX_MODULES_C + +#include +#include + +$NGX_PRAGMA + +END for mod in $modules do @@ -171,5 +176,8 @@ do echo " &$mod," >> $NGX_MODULES_C done -echo " NULL" >> $NGX_MODULES_C -echo "};" >> $NGX_MODULES_C +cat << END >> $NGX_MODULES_C + NULL +}; + +END diff --git a/auto/options b/auto/options --- a/auto/options +++ b/auto/options @@ -26,6 +26,9 @@ TEST_BUILD_DEVPOLL=NO TEST_BUILD_EPOLL=NO TEST_BUILD_RTSIG=NO +PLATFORM= +NGX_WINE= + EVENT_FOUND=NO EVENT_RTSIG=NO @@ -195,9 +198,8 @@ if [ $HTTP = NO ]; then fi -if [ ".$PLATFORM" = ".win32" -a $EVENT_POLL = YES ]; then - EVENT_POLL=NO - echo "$0: warning: --with-poll_module option is ignored for win32" +if [ ".$PLATFORM" = ".win32" ]; then + NGX_WINE=$WINE fi @@ -211,12 +213,6 @@ if test -z "$NGX_GROUP"; then fi -if test -z "$NGX_USER"; then - NGX_USER=nobody - NGX_GROUP=nobody -fi - - case ".$SBIN_PATH" in ./*) ;; diff --git a/auto/os/conf b/auto/os/conf --- a/auto/os/conf +++ b/auto/os/conf @@ -45,6 +45,12 @@ esac if [ $PLATFORM != win32 ]; then + if test -z "$NGX_USER"; then + NGX_USER=nobody + NGX_GROUP=nobody + fi + + ngx_feature="/dev/poll" ngx_feature_name="devpoll" ngx_feature_run=no diff --git a/auto/os/linux b/auto/os/linux --- a/auto/os/linux +++ b/auto/os/linux @@ -20,6 +20,13 @@ ngx_spacer=' CC_AUX_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64" + +if test -z "$NGX_USER"; then + NGX_USER=nobody + NGX_GROUP=nogroup +fi + + # Linux kernel version version=`grep "#define LINUX_VERSION_CODE" /usr/include/linux/version.h \ diff --git a/auto/os/win32 b/auto/os/win32 --- a/auto/os/win32 +++ b/auto/os/win32 @@ -15,7 +15,8 @@ CORE_INCS="$WIN32_INCS" CORE_DEPS="$WIN32_DEPS" CORE_SRCS="$WIN32_SRCS $IOCP_SRCS" OS_CONFIG="$WIN32_CONFIG" -CORE_LIBS="$CORE_LIBS ws2_32.lib" +CORE_LIBS="$CORE_LIBS shell32.lib ws2_32.lib" +NGX_ICONS="$NGX_WIN32_ICONS" EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE" EVENT_FOUND=YES diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -175,8 +175,10 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \ src/os/win32/ngx_shared.h \ src/os/win32/ngx_process.h \ src/os/win32/ngx_atomic.h \ + src/os/win32/ngx_thread.h \ src/os/win32/ngx_socket.h \ src/os/win32/ngx_os.h \ + src/os/win32/ngx_gui.h \ src/os/win32/ngx_process_cycle.h" WIN32_CONFIG=src/os/win32/ngx_win32_config.h @@ -187,14 +189,19 @@ WIN32_SRCS="$CORE_SRCS $EVENT_SRCS \ src/os/win32/ngx_files.c \ src/os/win32/ngx_time.c \ src/os/win32/ngx_process.c \ + src/os/win32/ngx_thread.c \ src/os/win32/ngx_socket.c \ src/os/win32/ngx_wsarecv.c \ src/os/win32/ngx_wsarecv_chain.c \ src/os/win32/ngx_wsasend_chain.c \ src/os/win32/ngx_win32_init.c \ + src/os/win32/ngx_gui.c \ src/os/win32/ngx_process_cycle.c \ src/event/ngx_event_acceptex.c" +NGX_WIN32_ICONS="src/os/win32/nginx.ico src/os/win32/tray.ico" +NGX_WIN32_RC="src/os/win32/nginx.rc" + HTTP_MODULES="ngx_http_module \ ngx_http_core_module \ diff --git a/auto/unix b/auto/unix --- a/auto/unix +++ b/auto/unix @@ -8,17 +8,17 @@ ngx_fmt_collect=yes # C types ngx_type="int"; . auto/types/sizeof -ngx_formats="%d"; . auto/fmt/fmt +#ngx_formats="%d"; . auto/fmt/fmt ngx_type="long"; . auto/types/sizeof -ngx_formats="%ld"; . auto/fmt/fmt +#ngx_formats="%ld"; . auto/fmt/fmt ngx_type="long long"; . auto/types/sizeof -ngx_formats="%lld %qd"; . auto/fmt/fmt +#ngx_formats="%lld %qd"; . auto/fmt/fmt ngx_type="void *"; . auto/types/sizeof; ngx_ptr_size=$ngx_size -ngx_fmt_name=PTR_FMT; -eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt +#ngx_fmt_name=PTR_FMT; +#eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt # POSIX types @@ -46,28 +46,28 @@ ngx_type="rlim_t"; ngx_types="int"; . au # printf() formats -CC_WARN=$CC_STRONG -ngx_fmt_collect=no - -ngx_fmt_name=OFF_T_FMT; ngx_type="off_t"; . auto/types/sizeof +#CC_WARN=$CC_STRONG +#ngx_fmt_collect=no +# +#ngx_fmt_name=OFF_T_FMT; ngx_type="off_t"; . auto/types/sizeof ngx_param=OFF_T_MAX_VALUE; ngx_value=$ngx_max_value; . auto/types/value -eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt - -ngx_fmt_name=TIME_T_FMT; ngx_type="time_t"; . auto/types/sizeof +#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt +# +#ngx_fmt_name=TIME_T_FMT; ngx_type="time_t"; . auto/types/sizeof ngx_param=TIME_T_SIZE; ngx_value=$ngx_size; . auto/types/value ngx_param=TIME_T_LEN; ngx_value=$ngx_max_len; . auto/types/value -eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt - -ngx_fmt_name=SIZE_T_FMT; ngx_type="size_t"; . auto/types/sizeof -eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt - -ngx_fmt_name=SIZE_T_X_FMT; . auto/fmt/xfmt - -ngx_fmt_name=PID_T_FMT; ngx_type="pid_t"; . auto/types/sizeof -eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt - -ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof -eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt +#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt +# +#ngx_fmt_name=SIZE_T_FMT; ngx_type="size_t"; . auto/types/sizeof +#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt +# +#ngx_fmt_name=SIZE_T_X_FMT; . auto/fmt/xfmt +# +#ngx_fmt_name=PID_T_FMT; ngx_type="pid_t"; . auto/types/sizeof +#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt +# +#ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof +#eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt # syscalls, libc calls and some features @@ -93,19 +93,23 @@ ngx_feature_test="char buf[1]; ssize_t n ngx_feature="strerror_r()" ngx_feature_name="strerror_r" -ngx_feature_run=no +ngx_feature_run=yes ngx_feature_incs="#include " ngx_feature_libs= -ngx_feature_test="char buf[20]; int n; n = strerror_r(1, buf, 20)" +ngx_feature_test="char buf[32]; int n; n = strerror_r(1, buf, 32); + if (n > 32) return 1;" . auto/feature -ngx_feature="gnu_strerror_r()" +# GNU style strerror_r() returns not length, but pointer + +ngx_feature="gnu style strerror_r()" ngx_feature_name="gnu_strerror_r" -ngx_feature_run=no +ngx_feature_run=yes ngx_feature_incs="#include " ngx_feature_libs= -ngx_feature_test="char buf[20], *str; str = strerror_r(1, buf, 20)" +ngx_feature_test="char buf[32]; int n; n = strerror_r(1, buf, 32); + if (n < 32) return 1;" . auto/feature @@ -184,16 +188,6 @@ ngx_feature_test="int id; . auto/feature -ngx_feature="struct sockaddr_in.sin_len" -ngx_feature_name="sin_len" -ngx_feature_run=no -ngx_feature_incs="#include -#include " -ngx_feature_libs= -ngx_feature_test="struct sockaddr_in sa; sa.sin_len = 5" -. auto/feature - - ngx_feature="struct msghdr.msg_control" ngx_feature_name="msghdr_msg_control" ngx_feature_run=no diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -18,6 +18,13 @@ static char *ngx_core_module_init_conf(n static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static ngx_conf_enum_t ngx_debug_points[] = { + { ngx_string("stop"), NGX_DEBUG_POINTS_STOP }, + { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT }, + { ngx_null_string, 0 } +}; + + static ngx_command_t ngx_core_commands[] = { { ngx_string("daemon"), @@ -41,6 +48,13 @@ static ngx_command_t ngx_core_commands[ offsetof(ngx_core_conf_t, worker_processes), NULL }, + { ngx_string("debug_points"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_enum_slot, + 0, + offsetof(ngx_core_conf_t, debug_points), + &ngx_debug_points }, + #if (NGX_THREADS) { ngx_string("worker_threads"), @@ -97,6 +111,7 @@ ngx_module_t ngx_core_module = { ngx_uint_t ngx_max_module; + int main(int argc, char *const *argv, char *const *envp) { ngx_int_t i; @@ -118,7 +133,7 @@ int main(int argc, char *const *argv, ch ngx_pid = ngx_getpid(); - if (!(log = ngx_log_init_stderr())) { + if (!(log = ngx_log_init())) { return 1; } @@ -165,7 +180,7 @@ int main(int argc, char *const *argv, ch if (cycle == NULL) { if (ngx_test_config) { ngx_log_error(NGX_LOG_EMERG, log, 0, - "the configuration file %s test failed", + "the configuration file \"%s\" test failed", init_cycle.conf_file.data); } @@ -174,7 +189,7 @@ int main(int argc, char *const *argv, ch if (ngx_test_config) { ngx_log_error(NGX_LOG_INFO, log, 0, - "the configuration file %s was tested successfully", + "the configuration file \"%s\" was tested successfully", cycle->conf_file.data); return 0; } @@ -187,7 +202,7 @@ int main(int argc, char *const *argv, ch ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; -#if (WIN32) +#if (NGX_WIN32) #if 0 @@ -241,11 +256,14 @@ static ngx_int_t ngx_add_inherited_socke return NGX_OK; } - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, + ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "using inherited sockets from \"%s\"", inherited); - ngx_init_array(cycle->listening, cycle->pool, - 10, sizeof(ngx_listening_t), NGX_ERROR); + if (ngx_array_init(&cycle->listening, cycle->pool, 10, + sizeof(ngx_listening_t)) == NGX_ERROR) + { + return NGX_ERROR; + } for (p = inherited, v = p; *p; p++) { if (*p == ':' || *p == ';') { @@ -260,7 +278,7 @@ static ngx_int_t ngx_add_inherited_socke v = p + 1; - if (!(ls = ngx_push_array(&cycle->listening))) { + if (!(ls = ngx_array_push(&cycle->listening))) { return NGX_ERROR; } @@ -276,7 +294,8 @@ static ngx_int_t ngx_add_inherited_socke ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) { - char *env[3], *var, *p; + char *env[3], *var; + u_char *p; ngx_uint_t i; ngx_pid_t pid; ngx_exec_ctx_t ctx; @@ -290,20 +309,22 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_ + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, cycle->log); - p = (char *) ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); + p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { - p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd); + p = ngx_sprintf(p, "%ud;", ls[i].fd); } + *p = '\0'; + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var); env[0] = var; #if (NGX_SETPROCTITLE_USES_ENV) - /* allocate spare 300 bytes for the new binary process title */ + /* allocate the spare 300 bytes for the new binary process title */ env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -430,12 +451,13 @@ static void *ngx_core_module_create_conf ccf->daemon = NGX_CONF_UNSET; ccf->master = NGX_CONF_UNSET; ccf->worker_processes = NGX_CONF_UNSET; + ccf->debug_points = NGX_CONF_UNSET; + ccf->user = (ngx_uid_t) NGX_CONF_UNSET; + ccf->group = (ngx_gid_t) NGX_CONF_UNSET; #if (NGX_THREADS) ccf->worker_threads = NGX_CONF_UNSET; - ccf->thread_stack_size = NGX_CONF_UNSET; + ccf->thread_stack_size = NGX_CONF_UNSET_SIZE; #endif - ccf->user = (ngx_uid_t) NGX_CONF_UNSET; - ccf->group = (ngx_gid_t) NGX_CONF_UNSET; return ccf; } @@ -445,7 +467,7 @@ static char *ngx_core_module_init_conf(n { ngx_core_conf_t *ccf = conf; -#if !(WIN32) +#if !(NGX_WIN32) struct passwd *pwd; struct group *grp; #endif @@ -453,6 +475,7 @@ static char *ngx_core_module_init_conf(n ngx_conf_init_value(ccf->daemon, 1); ngx_conf_init_value(ccf->master, 1); ngx_conf_init_value(ccf->worker_processes, 1); + ngx_conf_init_value(ccf->debug_points, 0); #if (NGX_THREADS) ngx_conf_init_value(ccf->worker_threads, 0); @@ -460,9 +483,9 @@ static char *ngx_core_module_init_conf(n ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); #endif -#if !(WIN32) +#if !(NGX_WIN32) - if (ccf->user == (uid_t) NGX_CONF_UNSET) { + if (ccf->user == (uid_t) NGX_CONF_UNSET && geteuid() == 0) { pwd = getpwnam(NGX_USER); if (pwd == NULL) { @@ -509,7 +532,7 @@ static char *ngx_core_module_init_conf(n static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { -#if (WIN32) +#if (NGX_WIN32) ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "\"user\" is not supported, ignored"); diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.1.4" +#define NGINX_VER "nginx/0.1.5" #define NGINX_VAR "NGINX" #define NGX_NEWPID_EXT ".newbin" diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -73,7 +73,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN); if (fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_open_file_n " %s failed", filename->data); + ngx_open_file_n " \"%s\" failed", filename->data); return NGX_CONF_ERROR; } @@ -84,7 +84,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_fd_info_n " %s failed", filename->data); + ngx_fd_info_n " \"%s\" failed", filename->data); } if (!(cf->conf_file->buffer = ngx_create_temp_buf(cf->pool, 1024))) { @@ -103,8 +103,12 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx rc = ngx_conf_read_token(cf); /* - * ngx_conf_read_token() returns NGX_OK, NGX_ERROR, - * NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE + * ngx_conf_read_token() may return + * NGX_ERROR there is error + * NGX_OK the token terminated by ";" was found + * NGX_CONF_BLOCK_START the token terminated by "{" was found + * NGX_CONF_BLOCK_DONE the "}" was found + * NGX_CONF_FILE_DONE the configuration file is done */ #if 0 @@ -115,13 +119,16 @@ ngx_log_debug(cf->log, "token %d" _ rc); break; } - if (rc != NGX_OK) { + if (rc != NGX_OK && rc != NGX_CONF_BLOCK_START) { break; } if (cf->handler) { - /* custom handler, i.e. used in http "types { ... }" directive */ + /* + * the custom handler, i.e., that is used in the http's + * "types { ... }" directive + */ rv = (*cf->handler)(cf, NULL, cf->handler_conf); if (rv == NGX_CONF_OK) { @@ -182,6 +189,31 @@ ngx_log_debug(cf->log, "command '%s'" _ break; } + if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK) + { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "directive \"%s\" in %s:%d " + "is not terminated by \";\"", + name->data, + cf->conf_file->file.name.data, + cf->conf_file->line); + rc = NGX_ERROR; + break; + } + + if ((cmd->type & NGX_CONF_BLOCK) + && rc != NGX_CONF_BLOCK_START) + { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "directive \"%s\" in %s:%d " + "has not the opening \"{\"", + name->data, + cf->conf_file->file.name.data, + cf->conf_file->line); + rc = NGX_ERROR; + break; + } + /* is the directive's argument count right ? */ if (cmd->type & NGX_CONF_ANY) { @@ -396,10 +428,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d ' continue; } - if (ch == ';' || ch == '{') { + if (ch == ';') { return NGX_OK; } + if (ch == '{') { + return NGX_CONF_BLOCK_START; + } + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "unexpected '%c' in %s:%d", ch, cf->conf_file->file.name.data, @@ -427,6 +463,10 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d ' return NGX_ERROR; } + if (ch == '{') { + return NGX_CONF_BLOCK_START; + } + return NGX_OK; case '}': @@ -538,10 +578,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d ' ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); #endif - if (ch == ';' || ch == '{') { + if (ch == ';') { return NGX_OK; } + if (ch == '{') { + return NGX_CONF_BLOCK_START; + } + found = 0; } } @@ -575,6 +619,18 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t return NGX_OK; } +#if (NGX_WIN32) + + if (name->len > 2 + && name->data[1] == ':' + && ((name->data[0] >= 'a' && name->data[0] <= 'z') + || (name->data[0] >= 'A' && name->data[0] <= 'Z'))) + { + return NGX_OK; + } + +#endif + old = *name; name->len = cycle->root.len + old.len; @@ -664,20 +720,22 @@ ngx_open_file_t *ngx_conf_open_file(ngx_ void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, char *fmt, ...) { - int len; - char errstr[NGX_MAX_CONF_ERRSTR]; + u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; va_list args; + last = errstr + NGX_MAX_CONF_ERRSTR; + va_start(args, fmt); - len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args); + buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); va_end(args); + *buf = '\0'; + if (err) { - len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1, - " (%d: ", err); - len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1); - errstr[len++] = ')'; - errstr[len] = '\0'; + buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err); + buf = ngx_strerror_r(err, buf, last - buf - 1); + *buf++ = ')'; + *buf = '\0'; } ngx_log_error(level, cf->log, 0, "%s in %s:%d", diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -59,8 +59,9 @@ #define NGX_CONF_OK NULL #define NGX_CONF_ERROR (char *) -1 -#define NGX_CONF_BLOCK_DONE 1 -#define NGX_CONF_FILE_DONE 2 +#define NGX_CONF_BLOCK_START 1 +#define NGX_CONF_BLOCK_DONE 2 +#define NGX_CONF_FILE_DONE 3 #define NGX_MODULE 0, 0 diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -39,7 +39,7 @@ #endif -#if !(WIN32) +#if !(NGX_WIN32) #define ngx_signal_helper(n) SIG##n #define ngx_signal_value(n) ngx_signal_helper(n) @@ -72,8 +72,6 @@ typedef int ngx_int_t; typedef u_int ngx_uint_t; typedef int ngx_flag_t; #define NGX_INT_T_LEN sizeof("-2147483648") - 1 -#define NGX_INT_T_FMT "d" -#define NGX_UINT_T_FMT "u" #else @@ -81,8 +79,6 @@ typedef long ngx_int_t; typedef u_long ngx_uint_t; typedef long ngx_flag_t; #define NGX_INT_T_LEN sizeof("-9223372036854775808") - 1 -#define NGX_INT_T_FMT "lld" -#define NGX_UINT_T_FMT "llu" #endif @@ -131,5 +127,12 @@ typedef long ngx_flag_t; #define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN */ +#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8)) +#define NGX_MAX_UINT32_VALUE 0xffffffffLL +#else +#define NGX_MAX_UINT32_VALUE 0xffffffff +#endif + + #endif /* _NGX_CONFIG_H_INCLUDED_ */ diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -30,28 +30,27 @@ ngx_listening_t *ngx_listening_inet_stre return NULL; } -#if (HAVE_SIN_LEN) - addr_in->sin_len = sizeof(struct sockaddr_in); -#endif addr_in->sin_family = AF_INET; addr_in->sin_addr.s_addr = addr; addr_in->sin_port = htons(port); - if (!(ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6))) { + + ls->addr_text.data = ngx_palloc(cf->pool, + INET_ADDRSTRLEN - 1 + sizeof(":65535") - 1); + if (ls->addr_text.data == NULL) { return NULL; } len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, INET_ADDRSTRLEN); - ls->addr_text.len = ngx_snprintf((char *) ls->addr_text.data + len, - 6, ":%d", port); + + ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port) + - ls->addr_text.data; + ls->fd = (ngx_socket_t) -1; ls->family = AF_INET; ls->type = SOCK_STREAM; ls->protocol = IPPROTO_IP; -#if (WIN32) - ls->flags = WSA_FLAG_OVERLAPPED; -#endif ls->sockaddr = (struct sockaddr *) addr_in; ls->socklen = sizeof(struct sockaddr_in); ls->addr = offsetof(struct sockaddr_in, sin_addr); @@ -63,6 +62,7 @@ ngx_listening_t *ngx_listening_inet_stre ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle) { + size_t len; ngx_uint_t i; ngx_listening_t *ls; struct sockaddr_in *addr_in; @@ -95,20 +95,26 @@ ngx_int_t ngx_set_inherited_sockets(ngx_ ls[i].ignore = 1; continue; } + ls[i].addr_text_max_len = INET_ADDRSTRLEN; - ls[i].addr_text.data = ngx_palloc(cycle->pool, ls[i].addr_text_max_len); + + ls[i].addr_text.data = ngx_palloc(cycle->pool, INET_ADDRSTRLEN - 1 + + sizeof(":65535") - 1); if (ls[i].addr_text.data == NULL) { return NGX_ERROR; } ls[i].family = addr_in->sin_family; - ls[i].addr_text.len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr, - ls[i].addr_text.data, - ls[i].addr_text_max_len); - if (ls[i].addr_text.len == 0) { + len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr, + ls[i].addr_text.data, INET_ADDRSTRLEN); + if (len == 0) { return NGX_ERROR; } + + ls[i].addr_text.len = ngx_sprintf(ls[i].addr_text.data + len, ":%d", + ntohs(addr_in->sin_port)) + - ls[i].addr_text.data; } return NGX_OK; @@ -157,16 +163,15 @@ ngx_int_t ngx_open_listening_sockets(ngx continue; } - s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol, - ls[i].flags); + s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol); if (s == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_socket_n " %s failed", ls[i].addr_text.data); + ngx_socket_n " %V failed", &ls[i].addr_text); return NGX_ERROR; } -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 * so to find a connection we divide a socket number by 4. @@ -182,8 +187,8 @@ ngx_int_t ngx_open_listening_sockets(ngx if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuseaddr, sizeof(int)) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "setsockopt(SO_REUSEADDR) %s failed", - ls[i].addr_text.data); + "setsockopt(SO_REUSEADDR) %V failed", + &ls[i].addr_text); return NGX_ERROR; } @@ -192,8 +197,8 @@ ngx_int_t ngx_open_listening_sockets(ngx if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) { if (ngx_nonblocking(s) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_nonblocking_n " %s failed", - ls[i].addr_text.data); + ngx_nonblocking_n " %V failed", + &ls[i].addr_text); return NGX_ERROR; } } @@ -202,8 +207,8 @@ ngx_int_t ngx_open_listening_sockets(ngx if (ls[i].nonblocking) { if (ngx_nonblocking(s) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_nonblocking_n " %s failed", - ls[i].addr_text.data); + ngx_nonblocking_n " %V failed", + &ls[i].addr_text); return NGX_ERROR; } } @@ -212,15 +217,15 @@ ngx_int_t ngx_open_listening_sockets(ngx if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) { err = ngx_socket_errno; ngx_log_error(NGX_LOG_EMERG, log, err, - "bind() to %s failed", ls[i].addr_text.data); + "bind() to %V failed", &ls[i].addr_text); if (err != NGX_EADDRINUSE) return NGX_ERROR; if (ngx_close_socket(s) == -1) ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_close_socket_n " %s failed", - ls[i].addr_text.data); + ngx_close_socket_n " %V failed", + &ls[i].addr_text); failed = 1; continue; @@ -228,7 +233,7 @@ ngx_int_t ngx_open_listening_sockets(ngx if (listen(s, ls[i].backlog) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "listen() to %s failed", ls[i].addr_text.data); + "listen() to %V failed", &ls[i].addr_text); return NGX_ERROR; } @@ -273,7 +278,7 @@ void ngx_close_listening_sockets(ngx_cyc for (i = 0; i < cycle->listening.nelts; i++) { fd = ls[i].fd; -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 * so to find a connection we divide a socket number by 4. @@ -296,8 +301,7 @@ void ngx_close_listening_sockets(ngx_cyc if (ngx_close_socket(ls[i].fd) == -1) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno, - ngx_close_socket_n " %s failed", - ls[i].addr_text.data); + ngx_close_socket_n " %V failed", &ls[i].addr_text); } cycle->connections[fd].fd = (ngx_socket_t) -1; @@ -408,7 +412,7 @@ ngx_int_t ngx_connection_error(ngx_conne } if (err == NGX_ECONNRESET -#if !(WIN32) +#if !(NGX_WIN32) || err == NGX_EPIPE #endif || err == NGX_ENOTCONN diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -24,7 +24,6 @@ typedef struct { int family; int type; int protocol; - int flags; /* Winsock2 flags */ void (*handler)(ngx_connection_t *c); /* handler of accepted connection */ @@ -48,9 +47,6 @@ typedef struct { unsigned inherited:1; /* inherited from previous process */ unsigned nonblocking_accept:1; unsigned nonblocking:1; -#if 0 - unsigned overlapped:1; /* Winsock2 overlapped */ -#endif unsigned shared:1; /* shared between threads or processes */ #if (HAVE_DEFERRED_ACCEPT) unsigned deferred_accept:1; diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -9,6 +9,7 @@ #include +static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2); static void ngx_clean_old_cycles(ngx_event_t *ev); @@ -195,7 +196,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t failed = 0; -#if !(WIN32) +#if !(NGX_WIN32) if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { failed = 1; } @@ -204,6 +205,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t if (!failed) { + /* open the new files */ + part = &cycle->open_files.part; file = part->elts; @@ -227,7 +230,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, - "log: %0X %d \"%s\"", + "log: %p %d \"%s\"", &file[i], file[i].fd, file[i].name.data); if (file[i].fd == NGX_INVALID_FILE) { @@ -238,7 +241,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t break; } -#if (WIN32) +#if (NGX_WIN32) if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_file_append_mode_n " \"%s\" failed", @@ -266,6 +269,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t } if (!failed) { + + /* handle the listening sockets */ + if (old_cycle->listening.nelts) { ls = old_cycle->listening.elts; for (i = 0; i < old_cycle->listening.nelts; i++) { @@ -274,16 +280,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t nls = cycle->listening.elts; for (n = 0; n < cycle->listening.nelts; n++) { + for (i = 0; i < old_cycle->listening.nelts; i++) { if (ls[i].ignore) { continue; } - if (ngx_memcmp(nls[n].sockaddr, - ls[i].sockaddr, ls[i].socklen) == 0) + if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr) + == NGX_OK) { fd = ls[i].fd; -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 so * to find a connection we divide a socket number by 4. @@ -294,10 +301,10 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t if (fd >= (ngx_socket_t) cycle->connection_n) { ngx_log_error(NGX_LOG_EMERG, log, 0, "%d connections is not enough to hold " - "an open listening socket on %s, " + "an open listening socket on %V, " "required at least %d connections", cycle->connection_n, - ls[i].addr_text.data, fd); + &ls[i].addr_text, fd); failed = 1; break; } @@ -372,8 +379,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t if (ngx_close_socket(ls[i].fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_close_socket_n " %s failed", - ls[i].addr_text.data); + ngx_close_socket_n " %V failed", + &ls[i].addr_text); } } @@ -384,12 +391,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t /* commit the new cycle configuration */ -#if !(WIN32) +#if !(NGX_WIN32) if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, - "dup2: %0X %d \"%s\"", + "dup2: %p %d \"%s\"", cycle->log->file, cycle->log->file->fd, cycle->log->file->name.data); @@ -426,8 +433,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t if (ngx_close_socket(ls[i].fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_close_socket_n " %s failed", - ls[i].addr_text.data); + ngx_close_socket_n " %V failed", + &ls[i].addr_text); } } @@ -512,13 +519,38 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t } -#if !(WIN32) +static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2) +{ + struct sockaddr_in *sin1, *sin2; + + /* AF_INET only */ + + if (s1->sa_family != AF_INET || s2->sa_family != AF_INET) { + return NGX_DECLINED; + } + + sin1 = (struct sockaddr_in *) s1; + sin2 = (struct sockaddr_in *) s2; + + if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) { + return NGX_DECLINED; + } + + if (sin1->sin_port != sin2->sin_port) { + return NGX_DECLINED; + } + + return NGX_OK; +} + + +#if !(NGX_WIN32) ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) { ngx_uint_t trunc; size_t len; - u_char *name, pid[NGX_INT64_LEN + 1]; + u_char *name, pid[NGX_INT64_LEN]; ngx_file_t file; ngx_core_conf_t *ccf, *old_ccf; @@ -548,8 +580,6 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t } } - len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); - ngx_memzero(&file, sizeof(ngx_file_t)); file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; file.log = cycle->log; @@ -566,6 +596,8 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t } if (!ngx_test_config) { + len = ngx_sprintf(pid, "%P", ngx_pid) - pid; + if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { return NGX_ERROR; } @@ -615,7 +647,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle ngx_uint_t i; ngx_list_part_t *part; ngx_open_file_t *file; -#if !(WIN32) +#if !(NGX_WIN32) ngx_file_info_t fi; #endif @@ -649,7 +681,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle continue; } -#if (WIN32) +#if (NGX_WIN32) if (ngx_file_append_mode(fd) == NGX_ERROR) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_file_append_mode_n " \"%s\" failed", @@ -730,7 +762,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle file[i].fd = fd; } -#if !(WIN32) +#if !(NGX_WIN32) if (cycle->log->file->fd != STDERR_FILENO) { if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -12,6 +12,10 @@ #include +#define NGX_DEBUG_POINTS_STOP 1 +#define NGX_DEBUG_POINTS_ABORT 2 + + struct ngx_cycle_s { void ****conf_ctx; ngx_pool_t *pool; @@ -40,6 +44,7 @@ typedef struct { ngx_flag_t master; ngx_int_t worker_processes; + ngx_int_t debug_points; ngx_uid_t user; ngx_gid_t group; diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -55,9 +55,8 @@ int ngx_create_temp_file(ngx_file_t *fil num = ngx_next_temp_number(0); for ( ;; ) { - ngx_snprintf((char *) - (file->name.data + path->name.len + 1 + path->len), - 11, "%010u", num); + ngx_sprintf(file->name.data + path->name.len + 1 + path->len, + "%010ud%Z", num); ngx_create_hashed_filename(file, path); @@ -83,7 +82,7 @@ int ngx_create_temp_file(ngx_file_t *fil if ((path->level[0] == 0) || (err != NGX_ENOENT -#if (WIN32) +#if (NGX_WIN32) && err != NGX_ENOTDIR #endif )) { diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -9,6 +9,17 @@ #include +/* + * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as + * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", + * however, they were implemented long before the ngx_sprintf() appeared + * and they are faster by 1.5-2.5 times, so it is worth to keep them. + * + * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times + * than using FreeBSD libc's snrpintf(). + */ + + ngx_inline static size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len) { size_t n; @@ -105,15 +116,8 @@ size_t ngx_sock_ntop(int family, struct text[n] = '\0'; return n; - -#if 0 - return ngx_snprintf((char *) text, - len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len, - "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); -#endif } - size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len) { u_char *p; @@ -163,12 +167,6 @@ size_t ngx_inet_ntop(int family, void *a text[n] = '\0'; return n; - -#if 0 - return ngx_snprintf((char *) text, - len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len, - "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); -#endif } diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -8,7 +8,7 @@ #include -static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len); +static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len); static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -38,7 +38,7 @@ ngx_module_t ngx_errlog_module = { ngx_errlog_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -65,121 +65,104 @@ void ngx_log_error_core(ngx_uint_t level const char *fmt, va_list args) #endif { - char errstr[MAX_ERROR_STR]; - size_t len, max; #if (NGX_HAVE_VARIADIC_MACROS) - va_list args; + va_list args; #endif + u_char errstr[NGX_MAX_ERROR_STR], *p, *last; if (log->file->fd == NGX_INVALID_FILE) { return; } + last = errstr + NGX_MAX_ERROR_STR; + ngx_memcpy(errstr, ngx_cached_err_log_time.data, ngx_cached_err_log_time.len); -#if (WIN32) - max = MAX_ERROR_STR - 2; -#else - max = MAX_ERROR_STR - 1; -#endif + p = errstr + ngx_cached_err_log_time.len; - len = ngx_cached_err_log_time.len; - - len += ngx_snprintf(errstr + len, max - len, " [%s] ", err_levels[level]); + p = ngx_sprintf(p, " [%s] ", err_levels[level]); /* pid#tid */ - len += ngx_snprintf(errstr + len, max - len, - PID_T_FMT "#" TID_T_FMT ": ", ngx_log_pid, ngx_log_tid); + p = ngx_sprintf(p, "%P#" NGX_TID_T_FMT ": ", ngx_log_pid, ngx_log_tid); if (log->data && *(int *) log->data != -1) { - len += ngx_snprintf(errstr + len, max - len, - "*%u ", *(u_int *) log->data); + p = ngx_sprintf(p, "*%ud ", *(u_int *) log->data); } #if (NGX_HAVE_VARIADIC_MACROS) va_start(args, fmt); - len += ngx_vsnprintf(errstr + len, max - len, fmt, args); + p = ngx_vsnprintf(p, last - p, fmt, args); va_end(args); #else - len += ngx_vsnprintf(errstr + len, max - len, fmt, args); + p = ngx_vsnprintf(p, last - p, fmt, args); #endif if (err) { - if (len > max - 50) { + if (p > last - 50) { /* leave a space for an error code */ - len = max - 50; - errstr[len++] = '.'; - errstr[len++] = '.'; - errstr[len++] = '.'; + p = last - 50; + *p++ = '.'; + *p++ = '.'; + *p++ = '.'; } -#if (WIN32) +#if (NGX_WIN32) + if ((unsigned) err >= 0x80000000) { - len += ngx_snprintf(errstr + len, max - len, " (%X: ", err); + p = ngx_snprintf(p, last - p, " (%Xd: ", err); + } else { - len += ngx_snprintf(errstr + len, max - len, " (%d: ", err); + p = ngx_snprintf(p, last - p, " (%d: ", err); } + #else - len += ngx_snprintf(errstr + len, max - len, " (%d: ", err); + + p = ngx_snprintf(p, last - p, " (%d: ", err); + #endif - if (len >= max) { - ngx_log_write(log, errstr, max); - return; - } - - len += ngx_strerror_r(err, errstr + len, max - len); - - if (len >= max) { - ngx_log_write(log, errstr, max); - return; - } + p = ngx_strerror_r(err, p, last - p); - errstr[len++] = ')'; - - if (len >= max) { - ngx_log_write(log, errstr, max); - return; - } - - } else { - if (len >= max) { - ngx_log_write(log, errstr, max); - return; + if (p < last) { + *p++ = ')'; } } if (level != NGX_LOG_DEBUG && log->handler) { - len += log->handler(log->data, errstr + len, max - len); - - if (len >= max) { - len = max; - } + p = log->handler(log->data, p, last - p); } - ngx_log_write(log, errstr, len); + ngx_log_write(log, errstr, p - errstr); } -static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len) +static void ngx_log_write(ngx_log_t *log, u_char *errstr, size_t len) { -#if (WIN32) +#if (NGX_WIN32) u_long written; + if (len >= NGX_MAX_ERROR_STR - 1) { + len = NGX_MAX_ERROR_STR - 2; + } + errstr[len++] = CR; errstr[len++] = LF; WriteFile(log->file->fd, errstr, len, &written, NULL); #else + if (len == NGX_MAX_ERROR_STR) { + len--; + } + errstr[len++] = LF; write(log->file->fd, errstr, len); @@ -192,7 +175,7 @@ static void ngx_log_write(ngx_log_t *log void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, ...) { - va_list args; + va_list args; if (log->log_level >= level) { va_start(args, fmt); @@ -204,46 +187,39 @@ void ngx_log_error(ngx_uint_t level, ngx void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...) { - va_list args; + va_list args; va_start(args, fmt); ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args); va_end(args); } - -void ngx_assert_core(ngx_log_t *log, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - ngx_log_error_core(NGX_LOG_ALERT, log, 0, fmt, args); - va_end(args); -} - #endif -ngx_log_t *ngx_log_init_stderr() +ngx_log_t *ngx_log_init() { -#if (WIN32) + ngx_log.file = &ngx_stderr; + ngx_log.log_level = NGX_LOG_NOTICE; - ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE); - ngx_stderr.fd = ngx_stderr_fileno; +#if (NGX_WIN32) - if (ngx_stderr_fileno == NGX_INVALID_FILE) { + ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); - /* TODO: where can we log error ? */ - + if (ngx_stderr.fd == NGX_INVALID_FILE) { + ngx_message_box("nginx", MB_OK, ngx_errno, + "Could not open error log file: " + ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); return NULL; - - } else if (ngx_stderr_fileno == NULL) { + } - /* there are no associated standard handles */ - - /* TODO: where can we can log possible errors ? */ - - ngx_stderr.fd = NGX_INVALID_FILE; + if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) { + ngx_message_box("nginx", MB_OK, ngx_errno, + "Could not open error log file: " + ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH + "\" failed"); + return NULL; } #else @@ -252,61 +228,10 @@ ngx_log_t *ngx_log_init_stderr() #endif - ngx_log.file = &ngx_stderr; - ngx_log.log_level = NGX_LOG_NOTICE; - return &ngx_log; } -#if 0 - -ngx_int_t ngx_log_init_error_log() -{ - ngx_fd_t fd; - -#ifdef NGX_ERROR_LOG_PATH - - fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR, - NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); - - if (fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, - ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); - return NGX_ERROR; - } - -#if (WIN32) - - if (ngx_file_append_mode(fd) == NGX_ERROR) { - ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, - ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH - "\" failed"); - return NGX_ERROR; - } - -#else - - if (dup2(fd, STDERR_FILENO) == NGX_ERROR) { - ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_errno, - "dup2(STDERR) failed"); - return NGX_ERROR; - } - -#endif - -#else /* no NGX_ERROR_LOG_PATH */ - - ngx_log.log_level = NGX_LOG_INFO; - -#endif - - return NGX_OK; -} - -#endif - - ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args) { ngx_log_t *log; diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -40,7 +40,7 @@ #define NGX_LOG_DEBUG_ALL 0x7ffffff0 -typedef size_t (*ngx_log_handler_pt) (void *ctx, char *buf, size_t len); +typedef u_char *(*ngx_log_handler_pt) (void *ctx, u_char *buf, size_t len); struct ngx_log_s { @@ -50,7 +50,8 @@ struct ngx_log_s { ngx_log_handler_pt handler; }; -#define MAX_ERROR_STR 2048 + +#define NGX_MAX_ERROR_STR 2048 /*********************************/ @@ -88,7 +89,6 @@ void ngx_log_error(ngx_uint_t level, ngx void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, const char *fmt, va_list args); void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...); -void ngx_assert_core(ngx_log_t *log, const char *fmt, ...); #endif /* VARIADIC MACROS */ @@ -195,10 +195,7 @@ void ngx_assert_core(ngx_log_t *log, con #define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t)) #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t)) -ngx_log_t *ngx_log_init_stderr(); -#if 0 -ngx_int_t ngx_log_init_error_log(); -#endif +ngx_log_t *ngx_log_init(); ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args); char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log); diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -162,7 +162,11 @@ ngx_int_t ngx_output_chain(ngx_output_ch ctx->in = ctx->in->next; } - ngx_alloc_link_and_set_buf(cl, ctx->buf, ctx->pool, NGX_ERROR); + if (!(cl = ngx_alloc_chain_link(ctx->pool))) { + return NGX_ERROR; + } + cl->buf = ctx->buf; + cl->next = NULL; *last_out = cl; last_out = &cl->next; ctx->buf = NULL; @@ -266,7 +270,7 @@ static ngx_int_t ngx_output_chain_copy_b if ((size_t) n != size) { ngx_log_error(NGX_LOG_ALERT, src->file->log, 0, - ngx_read_file_n " reads only %d of %d from file", + ngx_read_file_n " reads only %z of %uz from file", n, size); if (n == 0) { return NGX_ERROR; @@ -306,20 +310,24 @@ ngx_int_t ngx_chain_writer(void *data, n for (/* void */; in; in = in->next) { ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, - "WRITER buf: %d", ngx_buf_size(in->buf)); + "chain writer buf size: %uz", ngx_buf_size(in->buf)); - ngx_alloc_link_and_set_buf(cl, in->buf, ctx->pool, NGX_ERROR); + if (!(cl = ngx_alloc_chain_link(ctx->pool))) { + return NGX_ERROR; + } + cl->buf = in->buf; + cl->next = NULL; *ctx->last = cl; ctx->last = &cl->next; } ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, - "WRITER0: %X", ctx->out); + "chain writer in: %p", ctx->out); ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit); ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, - "WRITER1: %X", ctx->out); + "chain writer out: %p", ctx->out); if (ctx->out == NGX_CHAIN_ERROR) { return NGX_ERROR; diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c --- a/src/core/ngx_palloc.c +++ b/src/core/ngx_palloc.c @@ -33,8 +33,7 @@ void ngx_destroy_pool(ngx_pool_t *pool) for (l = pool->large; l; l = l->next) { - ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, - "free: " PTR_FMT, l->alloc); + ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc); if (l->alloc) { free(l->alloc); @@ -50,8 +49,7 @@ void ngx_destroy_pool(ngx_pool_t *pool) for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, - "free: " PTR_FMT ", unused: " SIZE_T_FMT, - p, p->end - p->last); + "free: %p, unused: %uz", p, p->end - p->last); if (n == NULL) { break; @@ -164,7 +162,7 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, vo for (l = pool->large; l; l = l->next) { if (p == l->alloc) { ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, - "free: " PTR_FMT, l->alloc); + "free: %p", l->alloc); free(l->alloc); l->alloc = NULL; diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c --- a/src/core/ngx_regex.c +++ b/src/core/ngx_regex.c @@ -53,11 +53,11 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t if (re == NULL) { if ((size_t) erroff == pattern->len) { - ngx_snprintf((char *) err->data, err->len - 1, + ngx_snprintf(err->data, err->len - 1, "pcre_compile() failed: %s in \"%s\"", errstr, pattern->data); } else { - ngx_snprintf((char *) err->data, err->len - 1, + ngx_snprintf(err->data, err->len - 1, "pcre_compile() failed: %s in \"%s\" at \"%s\"", errstr, pattern->data, pattern->data + erroff); } diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -30,42 +30,92 @@ u_char *ngx_cpystrn(u_char *dst, u_char /* * supported formats: - * %[0][width]O off_t - * %[0][width]T time_t - * %[0][width]S ssize_t - * %[0][width]uS size_t - * %[0][width]uxS size_t in hex - * %[0][width]l long - * %[0][width]d int - * %[0][width]i ngx_int_t - * %[0][width]ui ngx_uint_t - * %[0][width]uxi ngx_uint_t in hex - * %s null-terminated string - * %c char - * %% % + * %[0][width]O off_t + * %[0][width]T time_t + * %[0][width][u][x|X]z ssize_t/size_t + * %[0][width][u][x|X]d int/u_int + * %[0][width][u][x|X]l long + * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t + * %[0][width][u][x|X]D int32_t/uint32_t + * %[0][width][u][x|X]L int64_t/uint64_t + * %P ngx_pid_t + * %r rlim_t + * %p pointer + * %V pointer to ngx_str_t + * %s null-terminated string + * %Z '\0' + * %c char + * %% % * + * TODO: + * %M ngx_msec_t + * %A ngx_atomic_t + * + * reserved: + * %t ptrdiff_t + * %S null-teminated wchar string + * %C wchar */ -u_char *ngx_sprintf(u_char *buf, char *fmt, ...) + +u_char *ngx_sprintf(u_char *buf, const char *fmt, ...) +{ + u_char *p; + va_list args; + + va_start(args, fmt); + p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args); + va_end(args); + + return p; +} + + +u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) { - u_char *p, c, temp[NGX_MAX_INT_LEN]; - int d; - long l; - off_t offset; - size_t size, len; - ssize_t ssize; - time_t sec; - va_list arg; - ngx_int_t i; - ngx_uint_t ui, zero, width, sign, hexadecimal; - static u_char hex[] = "0123456789abcdef"; + u_char *p; + va_list args; + + va_start(args, fmt); + p = ngx_vsnprintf(buf, max, fmt, args); + va_end(args); + + return p; +} + - va_start(arg, fmt); +u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) +{ + u_char *p, zero, *last, temp[NGX_MAX_INT_LEN]; + int d; + size_t len; + uint32_t ui32; + int64_t i64; + uint64_t ui64; + ngx_str_t *s; + ngx_uint_t width, sign, hexadecimal; + static u_char hex[] = "0123456789abcdef"; + static u_char HEX[] = "0123456789ABCDEF"; - while (*fmt) { + if (max == 0) { + return buf; + } + + last = buf + max; + + while (*fmt && buf < last) { + + /* + * "buf < last" means that we could copy at least one character: + * the plain character, "%%", "%c", and minus without the checking + */ + if (*fmt == '%') { - zero = (*++fmt == '0') ? 1 : 0; + i64 = 0; + ui64 = 0; + + zero = (u_char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hexadecimal = 0; @@ -85,8 +135,15 @@ u_char *ngx_sprintf(u_char *buf, char *f fmt++; continue; + case 'X': + hexadecimal = 2; + sign = 0; + fmt++; + continue; + case 'x': hexadecimal = 1; + sign = 0; fmt++; continue; @@ -100,137 +157,116 @@ u_char *ngx_sprintf(u_char *buf, char *f switch (*fmt) { - case 'O': - offset = va_arg(arg, off_t); - - if (offset < 0) { - *buf++ = '-'; - offset = -offset; - } - - do { - *--p = (u_char) (offset % 10 + '0'); - } while (offset /= 10); - - break; - - case 'T': - sec = va_arg(arg, time_t); - - if (sec < 0) { - *buf++ = '-'; - sec = -sec; - } - - do { - *--p = (u_char) (sec % 10 + '0'); - } while (sec /= 10); - - break; - - case 'S': - if (sign) { - ssize = va_arg(arg, ssize_t); - - if (ssize < 0) { - *buf++ = '-'; - size = (size_t) -ssize; - - } else { - size = (size_t) ssize; - } - - } else { - size = va_arg(arg, size_t); - } - - if (hexadecimal) { - do { - *--p = hex[size & 0xf]; - } while (size >>= 4); - - } else { - do { - *--p = (u_char) (size % 10 + '0'); - } while (size /= 10); - } - - break; + case 'V': + s = va_arg(args, ngx_str_t *); - case 'l': - l = va_arg(arg, long); - - if (l < 0) { - *buf++ = '-'; - l = -l; - } - - do { - *--p = (u_char) (l % 10 + '0'); - } while (l /= 10); - - break; - - case 'd': - d = va_arg(arg, int); - - if (d < 0) { - *buf++ = '-'; - d = -d; - } - - do { - *--p = (u_char) (d % 10 + '0'); - } while (d /= 10); - - break; + len = (buf + s->len < last) ? s->len : (size_t) (last - buf); + buf = ngx_cpymem(buf, s->data, len); + fmt++; - case 'i': - if (sign) { - i = va_arg(arg, ngx_int_t); - - if (i < 0) { - *buf++ = '-'; - ui = (ngx_uint_t) -i; - - } else { - ui = (ngx_uint_t) i; - } - - } else { - ui = va_arg(arg, ngx_uint_t); - } - - if (hexadecimal) { - do { - *--p = hex[ui & 0xf]; - } while (ui >>= 4); - - } else { - do { - *--p = (u_char) (ui % 10 + '0'); - } while (ui /= 10); - } - - break; + continue; case 's': - p = va_arg(arg, u_char *); + p = va_arg(args, u_char *); - while (*p) { + while (*p && buf < last) { *buf++ = *p++; } fmt++; continue; + case 'O': + i64 = (int64_t) va_arg(args, off_t); + sign = 1; + break; + + case 'P': + i64 = (int64_t) va_arg(args, ngx_pid_t); + sign = 1; + break; + + case 'T': + i64 = (int64_t) va_arg(args, time_t); + sign = 1; + break; + + case 'z': + if (sign) { + i64 = (int64_t) va_arg(args, ssize_t); + } else { + ui64 = (uint64_t) va_arg(args, size_t); + } + break; + + case 'i': + if (sign) { + i64 = (int64_t) va_arg(args, ngx_int_t); + } else { + ui64 = (uint64_t) va_arg(args, ngx_uint_t); + } + break; + + case 'd': + if (sign) { + i64 = (int64_t) va_arg(args, int); + } else { + ui64 = (uint64_t) va_arg(args, u_int); + } + break; + + case 'l': + if (sign) { + i64 = (int64_t) va_arg(args, long); + } else { + ui64 = (uint64_t) va_arg(args, u_long); + } + break; + + case 'D': + if (sign) { + i64 = (int64_t) va_arg(args, int32_t); + } else { + ui64 = (uint64_t) va_arg(args, uint32_t); + } + break; + + case 'L': + if (sign) { + i64 = va_arg(args, int64_t); + } else { + ui64 = va_arg(args, uint64_t); + } + break; + +#if !(NGX_WIN32) + case 'r': + i64 = (int64_t) va_arg(args, rlim_t); + sign = 1; + break; +#endif + + case 'p': + ui64 = (uintptr_t) va_arg(args, void *); + hexadecimal = 2; + sign = 0; + zero = '0'; + width = 8; + break; + case 'c': - d = va_arg(arg, int); + d = va_arg(args, int); *buf++ = (u_char) (d & 0xff); fmt++; continue; + case 'Z': + *buf++ = '\0'; + fmt++; + + continue; + case '%': *buf++ = '%'; fmt++; @@ -243,15 +279,71 @@ u_char *ngx_sprintf(u_char *buf, char *f continue; } + if (sign) { + if (i64 < 0) { + *buf++ = '-'; + ui64 = (uint64_t) -i64; + + } else { + ui64 = (uint64_t) i64; + } + } + + if (hexadecimal == 1) { + do { + + /* the "(uint32_t)" cast disables the BCC's warning */ + *--p = hex[(uint32_t) (ui64 & 0xf)]; + + } while (ui64 >>= 4); + + } else if (hexadecimal == 2) { + do { + + /* the "(uint32_t)" cast disables the BCC's warning */ + *--p = HEX[(uint32_t) (ui64 & 0xf)]; + + } while (ui64 >>= 4); + + } else if (ui64 <= NGX_MAX_UINT32_VALUE) { + + /* + * To divide 64-bit number and to find the remainder + * on the x86 platform gcc and icc call the libc functions + * [u]divdi3() and [u]moddi3(), they call another function + * in return. On FreeBSD it is the qdivrem() function, + * its source code is about 170 lines of the code. + * The glibc counterpart is about 150 lines of the code. + * + * For 32-bit numbers gcc and icc use the inlined + * multiplication and shifts. For example, unsigned + * "i32 / 10" is compiled to "(i32 * 0xCCCCCCCD) >> 35". + */ + + ui32 = (uint32_t) ui64; + + do { + *--p = (u_char) (ui32 % 10 + '0'); + } while (ui32 /= 10); + + } else { + do { + *--p = (u_char) (ui64 % 10 + '0'); + } while (ui64 /= 10); + } + len = (temp + NGX_MAX_INT_LEN) - p; - c = (u_char) (zero ? '0' : ' '); - - while (len++ < width) { - *buf++ = c; + while (len++ < width && buf < last) { + *buf++ = zero; } - buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p)); + len = (temp + NGX_MAX_INT_LEN) - p; + if (buf + len > last) { + len = last - buf; + } + + buf = ngx_cpymem(buf, p, len); fmt++; @@ -260,10 +352,6 @@ u_char *ngx_sprintf(u_char *buf, char *f } } - va_end(arg); - - *buf = '\0'; - return buf; } @@ -505,12 +593,14 @@ ngx_int_t ngx_decode_base64(ngx_str_t *d } -ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size) +ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, + ngx_uint_t type) { - ngx_int_t n; - ngx_uint_t i; + ngx_uint_t i, n; + uint32_t *escape; static u_char hex[] = "0123456789abcdef"; - static uint32_t escape[] = + + static uint32_t uri[] = { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ @@ -527,6 +617,31 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; + static uint32_t html[] = + { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ + + /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ + 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */ + + /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ + 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ + + /* ~}| {zyx wvut srqp onml kjih gfed cba` */ + 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ + + 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ + 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ + 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ + 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; + + + if (type == NGX_ESCAPE_HTML) { + escape = html; + + } else { + escape = uri; + } + if (dst == NULL) { /* find the number of the characters to be escaped */ @@ -555,5 +670,5 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_ } } - return NGX_OK; + return 0; } diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -22,16 +22,13 @@ typedef struct { #define ngx_null_string { 0, NULL } -#if (WIN32) +#if (NGX_WIN32) #define ngx_strncasecmp(s1, s2, n) \ strnicmp((const char *) s1, (const char *) s2, n) #define ngx_strcasecmp(s1, s2) \ stricmp((const char *) s1, (const char *) s2) -#define ngx_snprintf _snprintf -#define ngx_vsnprintf _vsnprintf - #else #define ngx_strncasecmp(s1, s2, n) \ @@ -39,21 +36,20 @@ typedef struct { #define ngx_strcasecmp(s1, s2) \ strcasecmp((const char *) s1, (const char *) s2) -#define ngx_snprintf snprintf -#define ngx_vsnprintf vsnprintf - #endif -#define ngx_strncmp(s1, s2, n) \ - strncmp((const char *) s1, (const char *) s2, n) +#define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n) + /* msvc and icc compile strcmp() to inline loop */ #define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2) + #define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2) #define ngx_strlen(s) strlen((const char *) s) + /* * msvc and icc compile memset() to the inline "rep stos" * while ZeroMemory() and bzero() are the calls. @@ -62,15 +58,20 @@ typedef struct { #define ngx_memzero(buf, n) memset(buf, 0, n) #define ngx_memset(buf, c, n) memset(buf, c, n) + /* msvc and icc compile memcpy() to the inline "rep movs" */ #define ngx_memcpy(dst, src, n) memcpy(dst, src, n) #define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + n + /* msvc and icc compile memcmp() to the inline loop */ #define ngx_memcmp memcmp + u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n); -u_char *ngx_sprintf(u_char *buf, char *fmt, ...); +u_char *ngx_sprintf(u_char *buf, const char *fmt, ...); +u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...); +u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args); ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n); ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n); @@ -86,7 +87,13 @@ void ngx_md5_text(u_char *text, u_char * void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src); ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src); -ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size); + + +#define NGX_ESCAPE_URI 0 +#define NGX_ESCAPE_HTML 1 + +ngx_uint_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, + ngx_uint_t type); #define ngx_qsort qsort diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -94,7 +94,7 @@ void ngx_time_init() ngx_old_elapsed_msec = 0; ngx_elapsed_msec = 0; -#if !(WIN32) +#if !(NGX_WIN32) tzset(); #endif @@ -150,15 +150,14 @@ void ngx_time_update(time_t s) p = cached_http_time[slot]; - ngx_snprintf((char *) p, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), - "%s, %02d %s %4d %02d:%02d:%02d GMT", - week[ngx_cached_gmtime.ngx_tm_wday], - ngx_cached_gmtime.ngx_tm_mday, - months[ngx_cached_gmtime.ngx_tm_mon - 1], - ngx_cached_gmtime.ngx_tm_year, - ngx_cached_gmtime.ngx_tm_hour, - ngx_cached_gmtime.ngx_tm_min, - ngx_cached_gmtime.ngx_tm_sec); + ngx_sprintf(p, "%s, %02d %s %4d %02d:%02d:%02d GMT", + week[ngx_cached_gmtime.ngx_tm_wday], + ngx_cached_gmtime.ngx_tm_mday, + months[ngx_cached_gmtime.ngx_tm_mon - 1], + ngx_cached_gmtime.ngx_tm_year, + ngx_cached_gmtime.ngx_tm_hour, + ngx_cached_gmtime.ngx_tm_min, + ngx_cached_gmtime.ngx_tm_sec); ngx_cached_http_time.data = p; @@ -183,24 +182,22 @@ void ngx_time_update(time_t s) p = cached_err_log_time[slot]; - ngx_snprintf((char *) p, sizeof("1970/09/28 12:00:00"), - "%4d/%02d/%02d %02d:%02d:%02d", - tm.ngx_tm_year, tm.ngx_tm_mon, - tm.ngx_tm_mday, tm.ngx_tm_hour, - tm.ngx_tm_min, tm.ngx_tm_sec); + ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d", + tm.ngx_tm_year, tm.ngx_tm_mon, + tm.ngx_tm_mday, tm.ngx_tm_hour, + tm.ngx_tm_min, tm.ngx_tm_sec); ngx_cached_err_log_time.data = p; p = cached_http_log_time[slot]; - ngx_snprintf((char *) p, sizeof("28/Sep/1970:12:00:00 +0600"), - "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d", - tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1], - tm.ngx_tm_year, tm.ngx_tm_hour, - tm.ngx_tm_min, tm.ngx_tm_sec, - ngx_gmtoff < 0 ? '-' : '+', - abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60)); + ngx_sprintf(p, "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d", + tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1], + tm.ngx_tm_year, tm.ngx_tm_hour, + tm.ngx_tm_min, tm.ngx_tm_sec, + ngx_gmtoff < 0 ? '-' : '+', + abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60)); ngx_cached_http_log_time.data = p; @@ -213,9 +210,6 @@ void ngx_time_update(time_t s) u_char *ngx_http_time(u_char *buf, time_t t) -#if 0 -size_t ngx_http_time(u_char *buf, time_t t) -#endif { ngx_tm_t tm; @@ -229,25 +223,10 @@ size_t ngx_http_time(u_char *buf, time_t tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); - -#if 0 - return ngx_snprintf((char *) buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), - "%s, %02d %s %4d %02d:%02d:%02d GMT", - week[tm.ngx_tm_wday], - tm.ngx_tm_mday, - months[tm.ngx_tm_mon - 1], - tm.ngx_tm_year, - tm.ngx_tm_hour, - tm.ngx_tm_min, - tm.ngx_tm_sec); -#endif } u_char *ngx_http_cookie_time(u_char *buf, time_t t) -#if 0 -size_t ngx_http_cookie_time(u_char *buf, time_t t) -#endif { ngx_tm_t tm; @@ -270,32 +249,6 @@ size_t ngx_http_cookie_time(u_char *buf, tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); - -#if 0 - if (tm.ngx_tm_year > 2037) { - return ngx_snprintf((char *) buf, - sizeof("Mon, 28-Sep-1970 06:00:00 GMT"), - "%s, %02d-%s-%d %02d:%02d:%02d GMT", - week[tm.ngx_tm_wday], - tm.ngx_tm_mday, - months[tm.ngx_tm_mon - 1], - tm.ngx_tm_year, - tm.ngx_tm_hour, - tm.ngx_tm_min, - tm.ngx_tm_sec); - } else { - return ngx_snprintf((char *) buf, - sizeof("Mon, 28-Sep-70 06:00:00 GMT"), - "%s, %02d-%s-%02d %02d:%02d:%02d GMT", - week[tm.ngx_tm_wday], - tm.ngx_tm_mday, - months[tm.ngx_tm_mon - 1], - tm.ngx_tm_year % 100, - tm.ngx_tm_hour, - tm.ngx_tm_min, - tm.ngx_tm_sec); - } -#endif } diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -110,6 +110,10 @@ static int ngx_aio_del_connection(ngx_co return NGX_OK; } + if (flags & NGX_CLOSE_EVENT) { + return NGX_OK; + } + rc = aio_cancel(c->fd, NULL); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc); diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -208,7 +208,7 @@ static int ngx_devpoll_add_event(ngx_eve #if (NGX_DEBUG) c = ev->data; ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "devpoll add event: fd:%d ev:%04X", c->fd, event); + "devpoll add event: fd:%d ev:%04Xd", c->fd, event); #endif ev->active = 1; @@ -229,7 +229,7 @@ static int ngx_devpoll_del_event(ngx_eve #endif ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "devpoll del event: fd:%d ev:%04X", c->fd, event); + "devpoll del event: fd:%d ev:%04Xd", c->fd, event); if (ngx_devpoll_set_event(ev, POLLREMOVE, flags) == NGX_ERROR) { return NGX_ERROR; @@ -268,7 +268,7 @@ static int ngx_devpoll_set_event(ngx_eve c = ev->data; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "devpoll fd:%d ev:%04X fl:%04X", c->fd, event, flags); + "devpoll fd:%d ev:%04Xd fl:%04Xd", c->fd, event, flags); if (nchanges >= max_changes) { ngx_log_error(NGX_LOG_WARN, ev->log, 0, @@ -453,13 +453,13 @@ int ngx_devpoll_process_events(ngx_cycle } ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "devpoll: fd:%d, ev:%04X, rev:%04X", + "devpoll: fd:%d, ev:%04Xd, rev:%04Xd", event_list[i].fd, event_list[i].events, event_list[i].revents); if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "ioctl(DP_POLL) error fd:%d ev:%04X rev:%04X", + "ioctl(DP_POLL) error fd:%d ev:%04Xd rev:%04Xd", event_list[i].fd, event_list[i].events, event_list[i].revents); } @@ -468,7 +468,7 @@ int ngx_devpoll_process_events(ngx_cycle { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "strange ioctl(DP_POLL) events " - "fd:%d ev:%04X rev:%04X", + "fd:%d ev:%04Xd rev:%04Xd", event_list[i].fd, event_list[i].events, event_list[i].revents); } diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -232,7 +232,7 @@ static int ngx_epoll_add_event(ngx_event ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "epoll add event: fd:%d op:%d ev:%08X", + "epoll add event: fd:%d op:%d ev:%08XD", c->fd, op, ee.events); if (epoll_ctl(ep, op, c->fd, &ee) == -1) { @@ -291,7 +291,7 @@ static int ngx_epoll_del_event(ngx_event } ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "epoll del event: fd:%d op:%d ev:%08X", + "epoll del event: fd:%d op:%d ev:%08XD", c->fd, op, ee.events); if (epoll_ctl(ep, op, c->fd, &ee) == -1) { @@ -314,7 +314,7 @@ static int ngx_epoll_add_connection(ngx_ ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance); ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, - "epoll add connection: fd:%d ev:%08X", c->fd, ee.events); + "epoll add connection: fd:%d ev:%08XD", c->fd, ee.events); if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) { ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, @@ -513,7 +513,7 @@ int ngx_epoll_process_events(ngx_cycle_t */ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "epoll: stale event " PTR_FMT, c); + "epoll: stale event %p", c); continue; } @@ -522,18 +522,18 @@ int ngx_epoll_process_events(ngx_cycle_t #endif ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, - "epoll: fd:%d ev:%04X d:" PTR_FMT, + "epoll: fd:%d ev:%04XD d:%p", c->fd, event_list[i].events, event_list[i].data); if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, - "epoll_wait() error on fd:%d ev:%04X", + "epoll_wait() error on fd:%d ev:%04XD", c->fd, event_list[i].events); } if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { ngx_log_error(NGX_LOG_ALERT, log, 0, - "strange epoll_wait() events fd:%d ev:%04X", + "strange epoll_wait() events fd:%d ev:%04XD", c->fd, event_list[i].events); } diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -367,7 +367,7 @@ static ngx_int_t ngx_kqueue_set_event(ng c = ev->data; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, - "kevent set event: %d: ft:%d fl:%04X", + "kevent set event: %d: ft:%d fl:%04Xd", c->fd, filter, flags); if (nchanges >= max_changes) { @@ -599,7 +599,7 @@ static ngx_int_t ngx_kqueue_process_even */ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "kevent: stale event " PTR_FMT, ev); + "kevent: stale event %p", ev); continue; } @@ -776,9 +776,8 @@ static ngx_inline void ngx_kqueue_dump_e { ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0, (kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ? - "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" - PTR_FMT: - "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT, + "kevent: %p: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p": + "kevent: %d: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p", kev->ident, kev->filter, kev->flags, kev->fflags, kev->data, kev->udata); diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c --- a/src/event/modules/ngx_poll_module.c +++ b/src/event/modules/ngx_poll_module.c @@ -302,7 +302,7 @@ static ngx_int_t ngx_poll_process_events if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) { for (i = 0; i < nevents; i++) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "poll: %d: fd:%d ev:%04X", + "poll: %d: fd:%d ev:%04Xd", i, event_list[i].fd, event_list[i].events); } } @@ -380,13 +380,13 @@ static ngx_int_t ngx_poll_process_events #if 0 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "poll: %d: fd:%d ev:%04X rev:%04X", + "poll: %d: fd:%d ev:%04Xd rev:%04Xd", i, event_list[i].fd, event_list[i].events, event_list[i].revents); #else if (event_list[i].revents) { ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "poll: %d: fd:%d ev:%04X rev:%04X", + "poll: %d: fd:%d ev:%04Xd rev:%04Xd", i, event_list[i].fd, event_list[i].events, event_list[i].revents); } @@ -394,7 +394,7 @@ static ngx_int_t ngx_poll_process_events if (event_list[i].revents & POLLNVAL) { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "poll() error fd:%d ev:%04X rev:%04X", + "poll() error fd:%d ev:%04Xd rev:%04Xd", event_list[i].fd, event_list[i].events, event_list[i].revents); } @@ -402,7 +402,7 @@ static ngx_int_t ngx_poll_process_events if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "strange poll() events fd:%d ev:%04X rev:%04X", + "strange poll() events fd:%d ev:%04Xd rev:%04Xd", event_list[i].fd, event_list[i].events, event_list[i].revents); } @@ -529,7 +529,7 @@ static ngx_int_t ngx_poll_process_events for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "accept event " PTR_FMT, ev); + "accept event %p", ev); if (ev == NULL) { break; diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c --- a/src/event/modules/ngx_rtsig_module.c +++ b/src/event/modules/ngx_rtsig_module.c @@ -383,7 +383,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_c } else { err = 0; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "rtsig signo:%d fd:%d band:%X", + "rtsig signo:%d fd:%d band:%04Xd", signo, si.si_fd, si.si_band); } @@ -434,7 +434,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_c ngx_accept_mutex_unlock(); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "rtsig: stale event " PTR_FMT, c); + "rtsig: stale event %p", c); return NGX_OK; } diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -23,7 +23,7 @@ static fd_set master_write_fd_se static fd_set work_read_fd_set; static fd_set work_write_fd_set; -#if (WIN32) +#if (NGX_WIN32) static int max_read; static int max_write; #else @@ -114,7 +114,7 @@ static ngx_int_t ngx_select_init(ngx_cyc ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_ONESHOT_EVENT; -#if (WIN32) +#if (NGX_WIN32) max_read = max_write = 0; #else max_fd = -1; @@ -150,7 +150,7 @@ static ngx_int_t ngx_select_add_event(ng return NGX_OK; } -#if (WIN32) +#if (NGX_WIN32) if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE) || (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE)) @@ -211,7 +211,7 @@ static ngx_int_t ngx_select_del_event(ng ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "select del event fd:%d ev:%d", c->fd, event); -#if (WIN32) +#if (NGX_WIN32) if (event == NGX_READ_EVENT) { FD_CLR(c->fd, &master_read_fd_set); @@ -280,7 +280,7 @@ static ngx_int_t ngx_select_process_even expire = 1; -#if !(WIN32) +#if !(NGX_WIN32) if (ngx_accept_mutex) { if (ngx_accept_disabled > 0) { @@ -324,7 +324,7 @@ static ngx_int_t ngx_select_process_even "select event: fd:%d wr:%d", c->fd, ev->write); } -#if !(WIN32) +#if !(NGX_WIN32) ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "max_fd: %d", max_fd); #endif @@ -348,9 +348,9 @@ static ngx_int_t ngx_select_process_even work_write_fd_set = master_write_fd_set; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "select read fd_set: %08X", *(int *) &work_read_fd_set); + "select read fd_set: %08Xd", *(int *) &work_read_fd_set); -#if (WIN32) +#if (NGX_WIN32) ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp); #else ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp); @@ -433,7 +433,7 @@ static ngx_int_t ngx_select_process_even "select ready %d", ready); if (err) { -#if (WIN32) +#if (NGX_WIN32) ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed"); #else ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, @@ -534,7 +534,7 @@ static ngx_int_t ngx_select_process_even for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "accept event " PTR_FMT, ev); + "accept event %p", ev); if (ev == NULL) { break; @@ -597,7 +597,7 @@ static char *ngx_select_init_conf(ngx_cy /* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */ -#if !(WIN32) +#if !(NGX_WIN32) if ((unsigned) ecf->connections > FD_SETSIZE) { ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "the maximum number of files " @@ -606,7 +606,7 @@ static char *ngx_select_init_conf(ngx_cy } #endif -#if (NGX_THREADS) +#if (NGX_THREADS) && !(NGX_WIN32) ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "select() is not supported in the threaded mode"); return NGX_CONF_ERROR; diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -191,7 +191,7 @@ ngx_module_t ngx_event_core_module = { static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) { -#if !(WIN32) +#if !(NGX_WIN32) size_t size; char *shared; @@ -240,7 +240,7 @@ static ngx_int_t ngx_event_module_init(n #endif ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "counter: " PTR_FMT ", %d", + "counter: %p, %d", ngx_connection_counter, *ngx_connection_counter); #endif @@ -259,7 +259,7 @@ static ngx_int_t ngx_event_process_init( ngx_core_conf_t *ccf; ngx_event_conf_t *ecf; ngx_event_module_t *module; -#if (WIN32) +#if (NGX_WIN32) ngx_iocp_conf_t *iocpcf; #endif @@ -352,7 +352,7 @@ static ngx_int_t ngx_event_process_init( fd = s[i].fd; -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 * so to find a connection we divide a socket number by 4. @@ -412,10 +412,10 @@ static ngx_int_t ngx_event_process_init( } } -#if (WIN32) +#if (NGX_WIN32) if (ngx_event_flags & NGX_USE_IOCP_EVENT) { - rev->event_handler = &ngx_event_acceptex; + rev->event_handler = ngx_event_acceptex; if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) { return NGX_ERROR; @@ -429,7 +429,8 @@ static ngx_int_t ngx_event_process_init( } } else { - rev->event_handler = &ngx_event_accept; + rev->event_handler = ngx_event_accept; + if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { return NGX_ERROR; } @@ -437,7 +438,7 @@ static ngx_int_t ngx_event_process_init( #else - rev->event_handler = &ngx_event_accept; + rev->event_handler = ngx_event_accept; if (ngx_accept_mutex) { continue; @@ -580,7 +581,7 @@ static char *ngx_event_connections(ngx_c ecf->connections = ngx_atoi(value[1].data, value[1].len); if (ecf->connections == (ngx_uint_t) NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid number \"%s\"", value[1].data); + "invalid number \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -631,12 +632,12 @@ static char *ngx_event_use(ngx_conf_t *c { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "when the server runs without a master process " - "the \"%s\" event type must be the same as " + "the \"%V\" event type must be the same as " "in previous configuration - \"%s\" " "and it can not be changed on the fly, " "to change it you need to stop server " "and start it again", - value[1].data, old_ecf->name); + &value[1], old_ecf->name); return NGX_CONF_ERROR; } @@ -647,7 +648,7 @@ static char *ngx_event_use(ngx_conf_t *c } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid event type \"%s\"", value[1].data); + "invalid event type \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -681,7 +682,7 @@ static char *ngx_event_debug_connection( if (h == NULL || h->h_addr_list[0] == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "host %s not found", value[1].data); + "host \"%s\" not found", value[1].data); return NGX_CONF_ERROR; } @@ -755,7 +756,7 @@ static char *ngx_event_init_conf(ngx_cyc #elif (HAVE_SELECT) -#if (WIN32) +#if (NGX_WIN32) ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS); #else ngx_conf_init_unsigned_value(ecf->connections, diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -81,7 +81,7 @@ struct ngx_event_s { unsigned posted_ready:1; #endif -#if (WIN32) +#if (NGX_WIN32) /* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */ unsigned accept_context_updated:1; #endif @@ -473,7 +473,7 @@ ngx_int_t ngx_disable_accept_events(ngx_ ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle); -#if (WIN32) +#if (NGX_WIN32) void ngx_event_acceptex(ngx_event_t *ev); int ngx_event_post_acceptex(ngx_listening_t *ls, int n); #endif @@ -490,7 +490,7 @@ ngx_int_t ngx_send_lowat(ngx_connection_ #include #include -#if (WIN32) +#if (NGX_WIN32) #include #endif diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -11,13 +11,13 @@ typedef struct { - int flag; - u_char *name; + int flag; + ngx_str_t *name; } ngx_accept_log_ctx_t; static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); -static size_t ngx_accept_log_error(void *data, char *buf, size_t len); +static u_char *ngx_accept_log_error(void *data, u_char *buf, size_t len); void ngx_event_accept(ngx_event_t *ev) @@ -46,8 +46,8 @@ void ngx_event_accept(ngx_event_t *ev) ls = ev->data; ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "accept on %s, ready: %d", - ls->listening->addr_text.data, ev->available); + "accept on %V, ready: %d", + &ls->listening->addr_text, ev->available); ev->ready = 0; accepted = 0; @@ -88,7 +88,7 @@ void ngx_event_accept(ngx_event_t *ev) /* -1 disables the connection number logging */ ctx->flag = -1; - ctx->name = ls->listening->addr_text.data; + ctx->name = &ls->listening->addr_text; log->data = ctx; log->handler = ngx_accept_log_error; @@ -114,8 +114,7 @@ void ngx_event_accept(ngx_event_t *ev) } ngx_log_error(NGX_LOG_ALERT, ev->log, err, - "accept() on %s failed", - ls->listening->addr_text.data); + "accept() on %V failed", &ls->listening->addr_text); if (err == NGX_ECONNABORTED) { if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { @@ -144,10 +143,10 @@ void ngx_event_accept(ngx_event_t *ev) if ((ngx_uint_t) s >= ecf->connections) { ngx_log_error(NGX_LOG_ALERT, ev->log, 0, - "accept() on %s returned socket #%d while " + "accept() on %V returned socket #%d while " "only %d connections was configured, " "closing the connection", - ls->listening->addr_text.data, s, ecf->connections); + &ls->listening->addr_text, s, ecf->connections); ngx_close_accepted_socket(s, log); ngx_destroy_pool(pool); @@ -185,7 +184,7 @@ void ngx_event_accept(ngx_event_t *ev) } } -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 * so to find a connection we divide a socket number by 4. @@ -193,9 +192,9 @@ void ngx_event_accept(ngx_event_t *ev) if (s % 4) { ngx_log_error(NGX_LOG_EMERG, ev->log, 0, - "accept() on %s returned socket #%d, " + "accept() on %V returned socket #%d, " "not divisible by 4", - ls->listening->addr_text.data, s); + &ls->listening->addr_text, s); exit(1); } @@ -467,9 +466,9 @@ static void ngx_close_accepted_socket(ng } -static size_t ngx_accept_log_error(void *data, char *buf, size_t len) +static u_char *ngx_accept_log_error(void *data, u_char *buf, size_t len) { ngx_accept_log_ctx_t *ctx = data; - return ngx_snprintf(buf, len, " while accept() on %s", ctx->name); + return ngx_snprintf(buf, len, " while accept() on %V", ctx->name); } diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -13,7 +13,7 @@ /* AF_INET only */ -int ngx_event_connect_peer(ngx_peer_connection_t *pc) +ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) { int rc; ngx_uint_t instance; @@ -107,7 +107,7 @@ int ngx_event_connect_peer(ngx_peer_conn /* ngx_unlock_mutex(pc->peers->mutex); */ - s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); + s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (s == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, @@ -165,7 +165,7 @@ int ngx_event_connect_peer(ngx_peer_conn return NGX_ERROR; } -#if (WIN32) +#if (NGX_WIN32) /* * Winsock assignes a socket number divisible by 4 * so to find a connection we divide a socket number by 4. @@ -261,7 +261,7 @@ int ngx_event_connect_peer(ngx_peer_conn addr.sin_addr.s_addr = peer->addr; ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, - "connect to %s, #%d", peer->addr_port_text.data, c->number); + "connect to %V, #%d", &peer->addr_port_text, c->number); rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); diff --git a/src/event/ngx_event_connect.h b/src/event/ngx_event_connect.h --- a/src/event/ngx_event_connect.h +++ b/src/event/ngx_event_connect.h @@ -60,7 +60,7 @@ typedef struct { } ngx_peer_connection_t; -int ngx_event_connect_peer(ngx_peer_connection_t *pc); +ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc); void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc); diff --git a/src/event/ngx_event_mutex.c b/src/event/ngx_event_mutex.c --- a/src/event/ngx_event_mutex.c +++ b/src/event/ngx_event_mutex.c @@ -13,7 +13,7 @@ ngx_int_t ngx_event_mutex_timedlock(ngx_ ngx_event_t *ev) { ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "lock event mutex " PTR_FMT " lock:%X", m, m->lock); + "lock event mutex %p lock:%XD", m, m->lock); if (m->lock) { @@ -48,13 +48,12 @@ ngx_int_t ngx_event_mutex_unlock(ngx_eve if (m->lock == 0) { ngx_log_error(NGX_LOG_ALERT, log, 0, - "tring to unlock the free event mutex " PTR_FMT, m); + "tring to unlock the free event mutex %p", m); return NGX_ERROR; } ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, - "unlock event mutex " PTR_FMT ", next event: " PTR_FMT, - m, m->events); + "unlock event mutex %p, next event: %p", m, m->events); m->lock = 0; diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -73,7 +73,7 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t } if (!SSL_is_init_finished(c->ssl->ssl)) { - handshake = "in SSL handshake"; + handshake = " in SSL handshake"; } else { handshake = ""; @@ -269,7 +269,7 @@ static ngx_int_t ngx_ssl_write(ngx_conne if (sslerr == SSL_ERROR_WANT_READ) { if (!SSL_is_init_finished(c->ssl->ssl)) { - handshake = "in SSL handshake"; + handshake = " in SSL handshake"; } else { handshake = ""; @@ -310,6 +310,9 @@ ngx_int_t ngx_ssl_shutdown(ngx_connectio } again = 0; +#if (NGX_SUPPRESS_WARN) + sslerr = 0; +#endif for ( ;; ) { n = SSL_shutdown(c->ssl->ssl); @@ -366,23 +369,18 @@ ngx_int_t ngx_ssl_shutdown(ngx_connectio void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...) { - int len; - char errstr[NGX_MAX_CONF_ERRSTR]; - va_list args; + u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last; + va_list args; + + last = errstr + NGX_MAX_CONF_ERRSTR; va_start(args, fmt); - len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args); + p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args); va_end(args); - errstr[len++] = ' '; - errstr[len++] = '('; - errstr[len++] = 'S'; - errstr[len++] = 'S'; - errstr[len++] = 'L'; - errstr[len++] = ':'; - errstr[len++] = ' '; + p = ngx_cpystrn(p, " (SSL: ", last - p); - ERR_error_string_n(ERR_get_error(), errstr + len, sizeof(errstr) - len - 1); + ERR_error_string_n(ERR_get_error(), (char *) p, last - p); ngx_log_error(level, log, err, "%s)", errstr); } diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -79,7 +79,8 @@ ngx_int_t ngx_event_pipe(ngx_event_pipe_ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) { - int n, rc, size; + ssize_t n, size; + ngx_int_t rc; ngx_buf_t *b; ngx_chain_t *chain, *cl, *tl; @@ -109,7 +110,7 @@ ngx_int_t ngx_event_pipe_read_upstream(n n = p->preread_size; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe preread: %d", n); + "pipe preread: %z", n); if (n) { p->read = 1; @@ -197,7 +198,7 @@ ngx_int_t ngx_event_pipe_read_upstream(n rc = ngx_event_pipe_write_chain_to_temp_file(p); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe temp offset: %d", p->temp_file->offset); + "pipe temp offset: %O", p->temp_file->offset); if (rc == NGX_AGAIN) { if (ngx_event_flags & NGX_USE_LEVEL_EVENT @@ -237,7 +238,7 @@ ngx_int_t ngx_event_pipe_read_upstream(n n = ngx_recv_chain(p->upstream, chain); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe recv chain: %d", n); + "pipe recv chain: %z", n); if (p->free_raw_bufs) { chain->next = p->free_raw_bufs; @@ -303,7 +304,7 @@ ngx_int_t ngx_event_pipe_read_upstream(n for (cl = p->busy; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf busy " PTR_FMT ", pos " PTR_FMT ", size: %d", + "pipe buf busy %p, pos %p, size: %z", cl->buf->start, cl->buf->pos, cl->buf->last - cl->buf->pos); } @@ -311,9 +312,8 @@ ngx_int_t ngx_event_pipe_read_upstream(n for (cl = p->out; cl; cl = cl->next) { if (cl->buf->in_file && cl->buf->temporary) { ngx_log_debug5(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf out shadow " - PTR_FMT ", pos " PTR_FMT ", size: %d " - "file: " OFF_T_FMT ", size: %d", + "pipe buf out shadow %p, pos %p, size: %z " + "file: %O, size: %z", cl->buf->start, cl->buf->pos, cl->buf->last - cl->buf->pos, cl->buf->file_pos, @@ -321,13 +321,12 @@ ngx_int_t ngx_event_pipe_read_upstream(n } else if (cl->buf->in_file) { ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf out file " OFF_T_FMT ", size: %d", + "pipe buf out file %O, size: %z", cl->buf->file_pos, cl->buf->file_last - cl->buf->file_pos); } else { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf out " PTR_FMT ", pos " PTR_FMT - ", size: %d", + "pipe buf out %p, pos %p, size: %z", cl->buf->start, cl->buf->pos, cl->buf->last - cl->buf->pos); } @@ -335,14 +334,14 @@ ngx_int_t ngx_event_pipe_read_upstream(n for (cl = p->in; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf in " PTR_FMT ", pos " PTR_FMT ", size: %d", + "pipe buf in %p, pos %p, size: %z", cl->buf->start, cl->buf->pos, cl->buf->last - cl->buf->pos); } for (cl = p->free_raw_bufs; cl; cl = cl->next) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf free " PTR_FMT ", last " PTR_FMT ", size: %d", + "pipe buf free %p, last %p, size: %z", cl->buf->start, cl->buf->last, cl->buf->end - cl->buf->last); } @@ -443,7 +442,7 @@ ngx_int_t ngx_event_pipe_write_to_downst } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe write busy: " SIZE_T_FMT, bsize); + "pipe write busy: %uz", bsize); out = NULL; ll = NULL; @@ -482,7 +481,7 @@ ngx_int_t ngx_event_pipe_write_to_downst } ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe write: out:" PTR_FMT ", f:%d", out, flush); + "pipe write: out:%p, f:%d", out, flush); if (out == NULL && !flush) { break; @@ -553,13 +552,13 @@ static ngx_int_t ngx_event_pipe_write_ch ll = NULL; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe offset: %d", p->temp_file->offset); + "pipe offset: %O", p->temp_file->offset); do { bsize = cl->buf->last - cl->buf->pos; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, - "pipe buf " PTR_FMT ", pos " PTR_FMT ", size: %d", + "pipe buf %p, pos %p, size: %z", cl->buf->start, cl->buf->pos, bsize); if ((size + bsize > p->temp_file_write_size) @@ -574,7 +573,7 @@ static ngx_int_t ngx_event_pipe_write_ch } while (cl); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %d", size); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %z", size); if (cl) { p->in = cl; diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c --- a/src/event/ngx_event_posted.c +++ b/src/event/ngx_event_posted.c @@ -25,7 +25,7 @@ void ngx_event_process_posted(ngx_cycle_ ev = (ngx_event_t *) ngx_posted_events; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "posted event " PTR_FMT, ev); + "posted event %p", ev); if (ev == NULL) { return; @@ -38,7 +38,7 @@ void ngx_event_process_posted(ngx_cycle_ } -#if (NGX_THREADS) +#if (NGX_THREADS) && !(NGX_WIN32) void ngx_wakeup_worker_thread(ngx_cycle_t *cycle) { @@ -87,7 +87,7 @@ ngx_int_t ngx_event_thread_process_poste for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "posted event " PTR_FMT, ev); + "posted event %p", ev); if (ev == NULL) { return NGX_OK; @@ -96,7 +96,7 @@ ngx_int_t ngx_event_thread_process_poste if (ngx_trylock(ev->lock) == 0) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "posted event " PTR_FMT " is busy", ev); + "posted event %p is busy", ev); ev = ev->next; continue; @@ -105,8 +105,7 @@ ngx_int_t ngx_event_thread_process_poste if (ev->lock != ev->own_lock) { if (*(ev->own_lock)) { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "the own lock of the posted event " - PTR_FMT " is busy", ev); + "the own lock of the posted event %p is busy", ev); ngx_unlock(ev->lock); ev = ev->next; continue; @@ -153,7 +152,7 @@ ngx_int_t ngx_event_thread_process_poste } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "posted event " PTR_FMT " is done", ev); + "posted event %p is done", ev); break; } diff --git a/src/event/ngx_event_posted.h b/src/event/ngx_event_posted.h --- a/src/event/ngx_event_posted.h +++ b/src/event/ngx_event_posted.h @@ -22,10 +22,10 @@ ev->next->prev = &ev->next; \ } \ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ - "post event " PTR_FMT, ev); \ + "post event %p", ev); \ } else { \ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ - "update posted event " PTR_FMT, ev); \ + "update posted event %p", ev); \ } #define ngx_delete_posted_event(ev) \ @@ -35,7 +35,7 @@ } \ ev->prev = NULL; \ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ - "delete posted event " PTR_FMT, ev); + "delete posted event %p", ev); diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -110,14 +110,13 @@ void ngx_event_expire_timers(ngx_msec_t */ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "event " PTR_FMT " is busy in expire timers", - ev); + "event %p is busy in expire timers", ev); break; } #endif ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "event timer del: %d: %d", + "event timer del: %d: %i", ngx_event_ident(ev->data), ev->rbtree_key); ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree, diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -89,7 +89,7 @@ ngx_inline static void ngx_event_add_tim if (abs(key - ev->rbtree_key) < 100 / NGX_TIMER_RESOLUTION) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "event timer: %d, old: %d, new: %d", + "event timer: %d, old: %i, new: %i", ngx_event_ident(ev->data), ev->rbtree_key, key); return; } @@ -100,7 +100,7 @@ ngx_inline static void ngx_event_add_tim ev->rbtree_key = key; ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "event timer add: %d: %d", + "event timer add: %d: %i", ngx_event_ident(ev->data), ev->rbtree_key); if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c --- a/src/http/modules/ngx_http_access_handler.c +++ b/src/http/modules/ngx_http_access_handler.c @@ -97,8 +97,9 @@ static ngx_int_t ngx_http_access_handler rule = alcf->rules->elts; for (i = 0; i < alcf->rules->nelts; i++) { -ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%08X %08X %08X", - addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); + ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "%08XD %08XD %08XD", + addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); if ((addr_in->sin_addr.s_addr & rule[i].mask) == rule[i].addr) { if (rule[i].deny) { @@ -157,8 +158,8 @@ static char *ngx_http_access_rule(ngx_co } if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%s\"", - value[1].data); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%V\"", + &value[1]); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c --- a/src/http/modules/ngx_http_autoindex_handler.c +++ b/src/http/modules/ngx_http_autoindex_handler.c @@ -24,6 +24,7 @@ typedef struct { typedef struct { ngx_str_t name; + ngx_uint_t escape; ngx_uint_t dir; time_t mtime; off_t size; @@ -269,10 +270,13 @@ static ngx_int_t ngx_http_autoindex_hand } entry->name.len = len; + entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len, + NGX_ESCAPE_HTML); - if (!(entry->name.data = ngx_palloc(pool, len + 1))) { + if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) { return ngx_http_autoindex_error(r, &dir, dname.data); } + ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1); entry->dir = ngx_de_is_dir(&dir); @@ -298,7 +302,7 @@ static ngx_int_t ngx_http_autoindex_hand for (i = 0; i < entries.nelts; i++) { len += sizeof("") - 1 + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("") - 1 @@ -329,7 +333,17 @@ static ngx_int_t ngx_http_autoindex_hand for (i = 0; i < entries.nelts; i++) { b->last = ngx_cpymem(b->last, "last = ngx_cpymem(b->last, entry[i].name.data, entry[i].name.len); + + if (entry[i].escape) { + ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len, + NGX_ESCAPE_HTML); + + b->last += entry[i].name.len + entry[i].escape; + + } else { + b->last = ngx_cpymem(b->last, entry[i].name.data, + entry[i].name.len); + } if (entry[i].dir) { *b->last++ = '/'; @@ -375,7 +389,7 @@ static ngx_int_t ngx_http_autoindex_hand } else { length = entry[i].size; - if (length > 1024 * 1024 * 1024) { + if (length > 1024 * 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024 * 1024)); if ((length % (1024 * 1024 * 1024)) > (1024 * 1024 * 1024 / 2 - 1)) @@ -384,7 +398,7 @@ static ngx_int_t ngx_http_autoindex_hand } scale = 'G'; - } else if (length > 1024 * 1024) { + } else if (length > 1024 * 1024 - 1) { size = (ngx_int_t) (length / (1024 * 1024)); if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) { size++; diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -125,7 +125,7 @@ ngx_module_t ngx_http_charset_filter_mo ngx_http_charset_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_charset_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -287,8 +287,7 @@ static char *ngx_charset_map_block(ngx_c if (src == dst) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"charset_map\" between the same charsets " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } @@ -299,8 +298,7 @@ static char *ngx_charset_map_block(ngx_c { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate \"charset_map\" between " - "\"%s\" and \"%s\"", - value[1].data, value[2].data); + "\"%V\" and \"%V\"", &value[1], &value[2]); return NGX_CONF_ERROR; } } @@ -357,14 +355,14 @@ static char *ngx_charset_map(ngx_conf_t src = ngx_hextoi(value[0].data, value[0].len); if (src == NGX_ERROR || src > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[0].data); + "invalid value \"%V\"", &value[0]); return NGX_CONF_ERROR; } dst = ngx_hextoi(value[1].data, value[1].len); if (dst == NGX_ERROR || dst > 255) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[1].data); + "invalid value \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -525,8 +523,8 @@ static char *ngx_http_charset_init_main_ ngx_log_error(NGX_LOG_EMERG, cf->log, 0, " no \"charset_map\" between the charsets " - "\"%s\" and \"%s\"", - charset[i].name.data, charset[n].name.data); + "\"%V\" and \"%V\"", + &charset[i].name, &charset[n].name); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c --- a/src/http/modules/ngx_http_chunked_filter.c +++ b/src/http/modules/ngx_http_chunked_filter.c @@ -32,7 +32,7 @@ ngx_module_t ngx_http_chunked_filter_mo NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_chunked_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; @@ -84,7 +84,11 @@ static ngx_int_t ngx_http_chunked_body_f size += ngx_buf_size(cl->buf); if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) { - ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + + if (!(tl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + tl->buf = cl->buf; *ll = tl; ll = &tl->next; @@ -102,30 +106,22 @@ static ngx_int_t ngx_http_chunked_body_f return NGX_ERROR; } - if (!(chunk = ngx_palloc(r->pool, 11))) { + if (!(chunk = ngx_palloc(r->pool, sizeof("00000000" CRLF) - 1))) { return NGX_ERROR; } b->temporary = 1; b->pos = chunk; - b->last = ngx_sprintf(chunk, "%uxS" CRLF, size); + b->last = ngx_sprintf(chunk, "%xz" CRLF, size); out.buf = b; -#if 0 - ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); - len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); - - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); - b->temporary = 1; - b->pos = chunk; - b->last = chunk + len; - - out.buf = b; -#endif } if (cl->buf->last_buf) { - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->last_buf = 1; b->pos = (u_char *) CRLF "0" CRLF CRLF; @@ -147,7 +143,10 @@ static ngx_int_t ngx_http_chunked_body_f return ngx_http_next_body_filter(r, out.next); } - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->pos = (u_char *) CRLF; b->last = b->pos + 2; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -80,7 +80,7 @@ static ngx_int_t ngx_http_gzip_proxied(n static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size); static void ngx_http_gzip_filter_free(void *opaque, void *address); -ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); +static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, uintptr_t data); @@ -507,7 +507,11 @@ static ngx_int_t ngx_http_gzip_body_filt b->pos = gzheader; b->last = b->pos + 10; - ngx_alloc_link_and_set_buf(cl, b, r->pool, ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; ctx->out = cl; ctx->last_out = &cl->next; @@ -534,7 +538,7 @@ static ngx_int_t ngx_http_gzip_body_filt && !ctx->redo) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in: " PTR_FMT, ctx->in); + "gzip in: %p", ctx->in); if (ctx->in == NULL) { break; @@ -547,7 +551,7 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_buf:" PTR_FMT " ni:" PTR_FMT " ai:%d", + "gzip in_buf:%p ni:%p ai:%ud", ctx->in_buf, ctx->zstream.next_in, ctx->zstream.avail_in); @@ -608,10 +612,10 @@ static ngx_int_t ngx_http_gzip_body_filt } ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d redo:%d", - ctx->zstream.next_in, ctx->zstream.next_out, - ctx->zstream.avail_in, ctx->zstream.avail_out, - ctx->flush, ctx->redo); + "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d", + ctx->zstream.next_in, ctx->zstream.next_out, + ctx->zstream.avail_in, ctx->zstream.avail_out, + ctx->flush, ctx->redo); rc = deflate(&ctx->zstream, ctx->flush); @@ -622,13 +626,13 @@ static ngx_int_t ngx_http_gzip_body_filt } ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d", + "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", ctx->zstream.next_in, ctx->zstream.next_out, ctx->zstream.avail_in, ctx->zstream.avail_out, rc); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "gzip in_buf:" PTR_FMT " pos:" PTR_FMT, + "gzip in_buf:%p pos:%p", ctx->in_buf, ctx->in_buf->pos); @@ -646,8 +650,11 @@ static ngx_int_t ngx_http_gzip_body_filt /* zlib wants to output some more gzipped data */ - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -663,8 +670,11 @@ static ngx_int_t ngx_http_gzip_body_filt ctx->out_buf->flush = 0; ctx->flush = Z_NO_FLUSH; - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -686,8 +696,11 @@ static ngx_int_t ngx_http_gzip_body_filt ngx_pfree(r->pool, ctx->preallocated); - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -703,8 +716,11 @@ static ngx_int_t ngx_http_gzip_body_filt b->last_buf = 1; - ngx_alloc_link_and_set_buf(cl, b, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = b; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; trailer = (struct gztrailer *) b->pos; @@ -735,8 +751,11 @@ static ngx_int_t ngx_http_gzip_body_filt } if (conf->no_buffer && ctx->in == NULL) { - ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, - ngx_http_gzip_error(ctx)); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return ngx_http_gzip_error(ctx); + } + cl->buf = ctx->out_buf; + cl->next = NULL; *ctx->last_out = cl; ctx->last_out = &cl->next; @@ -782,10 +801,12 @@ static void *ngx_http_gzip_filter_alloc( ngx_uint_t alloc; alloc = items * size; + if (alloc % 512 != 0) { /* - * the zlib deflate_state allocation, it takes about 6K, we allocate 8K + * The zlib deflate_state allocation, it takes about 6K, + * we allocate 8K. Other allocations are divisible by 512. */ alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1); @@ -797,14 +818,14 @@ static void *ngx_http_gzip_filter_alloc( ctx->allocated -= alloc; ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip alloc: n:%d s:%d a:%d p:" PTR_FMT, + "gzip alloc: n:%ud s:%ud a:%ud p:%p", items, size, alloc, p); return p; } ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, - "gzip filter failed to use preallocated memory: %d of %d", + "gzip filter failed to use preallocated memory: %ud of %ud", items * size, ctx->allocated); p = ngx_palloc(ctx->request->pool, items * size); @@ -819,7 +840,7 @@ static void ngx_http_gzip_filter_free(vo ngx_http_gzip_ctx_t *ctx = opaque; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, - "gzip free: %X", address); + "gzip free: %p", address); #endif } @@ -837,8 +858,6 @@ static u_char *ngx_http_gzip_log_ratio(n return buf + 1; } - /* we prefer do not use the FPU */ - zint = (ngx_uint_t) (ctx->zin / ctx->zout); zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); @@ -855,16 +874,10 @@ static u_char *ngx_http_gzip_log_ratio(n } return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, - "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT, - zint, zfrac); -#endif } -ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) +static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) { deflateEnd(&ctx->zstream); diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c --- a/src/http/modules/ngx_http_headers_filter.c +++ b/src/http/modules/ngx_http_headers_filter.c @@ -138,12 +138,6 @@ static ngx_int_t ngx_http_headers_filter conf->expires) - cc->value.data; -#if 0 - cc->value.len = ngx_snprintf((char *) cc->value.data, - sizeof("max-age=") + TIME_T_LEN, - "max-age=" TIME_T_FMT, - conf->expires); -#endif } } } diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -143,7 +143,7 @@ static ngx_int_t ngx_http_index_handler( &r->uri, &crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache get: " PTR_FMT, ctx->cache); + "http index cache get: %p", ctx->cache); if (ctx->cache && !ctx->cache->expired) { @@ -251,7 +251,7 @@ static ngx_int_t ngx_http_index_handler( err = ngx_errno; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); if (err == NGX_ENOTDIR) { return ngx_http_index_error(r, ctx, err); @@ -275,7 +275,7 @@ static ngx_int_t ngx_http_index_handler( } ngx_log_error(NGX_LOG_ERR, log, err, - ngx_open_file_n " %s failed", name); + ngx_open_file_n " \"%s\" failed", name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -331,7 +331,7 @@ static ngx_int_t ngx_http_index_handler( ctx->redirect.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http index cache alloc: " PTR_FMT, ctx->cache); + "http index cache alloc: %p", ctx->cache); if (ctx->cache) { ctx->cache->fd = NGX_INVALID_FILE; @@ -373,7 +373,7 @@ static ngx_int_t ngx_http_index_test_dir } ngx_log_error(NGX_LOG_CRIT, r->connection->log, err, - ngx_file_info_n " %s failed", ctx->path.data); + ngx_file_info_n " \"%s\" failed", ctx->path.data); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -502,17 +502,17 @@ static char *ngx_http_index_set_index(ng if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "first index \"%s\" in \"%s\" directive " + "first index \"%V\" in \"%V\" directive " "must not be absolute", - value[1].data, cmd->name.data); + &value[1], &cmd->name); return NGX_CONF_ERROR; } for (i = 1; i < cf->args->nelts; i++) { if (value[i].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "index \"%s\" in \"%s\" directive is invalid", - value[1].data, cmd->name.data); + "index \"%V\" in \"%V\" directive is invalid", + &value[1], &cmd->name); return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c --- a/src/http/modules/ngx_http_not_modified_filter.c +++ b/src/http/modules/ngx_http_not_modified_filter.c @@ -33,7 +33,7 @@ ngx_module_t ngx_http_not_modified_filt NULL, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_not_modified_filter_init, /* init module */ - NULL /* init child */ + NULL /* init process */ }; diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -107,11 +107,13 @@ static ngx_http_output_body_filter_pt static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) { - ngx_int_t rc; - ngx_uint_t boundary, suffix, i; u_char *p; size_t len; off_t start, end; + ngx_int_t rc; + uint32_t boundary; + ngx_uint_t suffix, i; + ngx_table_elt_t *content_range; ngx_http_range_t *range; ngx_http_range_filter_ctx_t *ctx; @@ -141,8 +143,11 @@ static ngx_int_t ngx_http_range_header_f return ngx_http_next_header_filter(r); } - ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t), - NGX_ERROR); + if (ngx_array_init(&r->headers_out.ranges, r->pool, 5, + sizeof(ngx_http_range_t)) == NGX_ERROR) + { + return NGX_ERROR; + } rc = 0; range = NULL; @@ -180,8 +185,10 @@ static ngx_int_t ngx_http_range_header_f while (*p == ' ') { p++; } if (*p == ',' || *p == '\0') { - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), - NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; range->end = r->headers_out.content_length_n; @@ -223,7 +230,10 @@ static ngx_int_t ngx_http_range_header_f break; } - ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR); + if (!(range = ngx_array_push(&r->headers_out.ranges))) { + return NGX_ERROR; + } + range->start = start; if (end >= r->headers_out.content_length_n) { @@ -249,29 +259,26 @@ static ngx_int_t ngx_http_range_header_f r->headers_out.status = rc; r->headers_out.ranges.nelts = 0; - r->headers_out.content_range = ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; } - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; + r->headers_out.content_range = content_range; + + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; - r->headers_out.content_range->value.data = - ngx_palloc(r->pool, 8 + 20 + 1); - if (r->headers_out.content_range->value.data == NULL) { + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN); + + if (content_range->value.data == NULL) { return NGX_ERROR; } - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes */%O", r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; -#if 0 - ngx_snprintf((char *) r->headers_out.content_range->value.data, - 8 + 20 + 1, "bytes */" OFF_T_FMT, - r->headers_out.content_length_n); -#endif + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes */%O", + r->headers_out.content_length_n) + - content_range->value.data; r->headers_out.content_length_n = -1; if (r->headers_out.content_length) { @@ -280,176 +287,134 @@ static ngx_int_t ngx_http_range_header_f } return rc; + } + + r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; + + if (r->headers_out.ranges.nelts == 1) { + + if (!(content_range = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } + + r->headers_out.content_range = content_range; + + content_range->key.len = sizeof("Content-Range") - 1; + content_range->key.data = (u_char *) "Content-Range"; + + content_range->value.data = + ngx_palloc(r->pool, sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); + if (content_range->value.data == NULL) { + return NGX_ERROR; + } + + /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ + + content_range->value.len = ngx_sprintf(content_range->value.data, + "bytes %O-%O/%O", + range->start, range->end - 1, + r->headers_out.content_length_n) + - content_range->value.data; + + r->headers_out.content_length_n = range->end - range->start; + + return ngx_http_next_header_filter(r); + } + + + /* TODO: what if no content_type ?? */ + + ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, + sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); + + + len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1 + + r->headers_out.content_type->value.len + + sizeof(CRLF "Content-Range: bytes ") - 1; + + if (r->headers_out.charset.len) { + len += sizeof("; charset=") - 1 + r->headers_out.charset.len; + } + + if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) { + return NGX_ERROR; + } + + boundary = ngx_next_temp_number(0); + + /* + * The boundary header of the range: + * CRLF + * "--0123456789" CRLF + * "Content-Type: image/jpeg" CRLF + * "Content-Range: bytes " + */ + + if (r->headers_out.charset.len) { + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V; charset=%V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value, + &r->headers_out.charset) + - ctx->boundary_header.data; + + r->headers_out.charset.len = 0; } else { - r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; - - if (r->headers_out.ranges.nelts == 1) { - - r->headers_out.content_range = - ngx_list_push(&r->headers_out.headers); - if (r->headers_out.content_range == NULL) { - return NGX_ERROR; - } - - r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; - r->headers_out.content_range->key.data = (u_char *) "Content-Range"; - - ngx_test_null(r->headers_out.content_range->value.data, - ngx_palloc(r->pool, 6 + 20 + 1 + 20 + 1 + 20 + 1), - NGX_ERROR); - - /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ - - r->headers_out.content_range->value.len = - ngx_sprintf(r->headers_out.content_range->value.data, - "bytes %O-%O/%O", - range->start, range->end - 1, - r->headers_out.content_length_n) - - r->headers_out.content_range->value.data; - -#if 0 - ngx_snprintf((char *) - r->headers_out.content_range->value.data, - 6 + 20 + 1 + 20 + 1 + 20 + 1, - "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT, - range->start, range->end - 1, - r->headers_out.content_length_n); -#endif + ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, + CRLF "--%010ud" CRLF + "Content-Type: %V" CRLF + "Content-Range: bytes ", + boundary, + &r->headers_out.content_type->value) + - ctx->boundary_header.data; + } - r->headers_out.content_length_n = range->end - range->start; - - } else { - -#if 0 - /* TODO: what if no content_type ?? */ + r->headers_out.content_type->value.data = + ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; " + "boundary=0123456789") - 1); - if (!(r->headers_out.content_type = - ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) - { - return NGX_ERROR; - } -#endif - - ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, - sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); + if (r->headers_out.content_type->value.data == NULL) { + return NGX_ERROR; + } - len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len - + 2 + 21 + 1; - - if (r->headers_out.charset.len) { - len += 10 + r->headers_out.charset.len; - } - - ngx_test_null(ctx->boundary_header.data, ngx_palloc(r->pool, len), - NGX_ERROR); + /* "Content-Type: multipart/byteranges; boundary=0123456789" */ - boundary = ngx_next_temp_number(0); - - /* - * The boundary header of the range: - * CRLF - * "--0123456789" CRLF - * "Content-Type: image/jpeg" CRLF - * "Content-Range: bytes " - */ + r->headers_out.content_type->value.len = + ngx_sprintf(r->headers_out.content_type->value.data, + "multipart/byteranges; boundary=%010ud", + boundary) + - r->headers_out.content_type->value.data; - if (r->headers_out.charset.len) { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data) - - ctx->boundary_header.data; -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s; charset=%s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data, - r->headers_out.charset.data); -#endif - - r->headers_out.charset.len = 0; + /* the size of the last boundary CRLF "--0123456789--" CRLF */ + len = sizeof(CRLF "--0123456789--" CRLF) - 1; - } else { - ctx->boundary_header.len = - ngx_sprintf(ctx->boundary_header.data, - CRLF "--%010ui" CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data) - - ctx->boundary_header.data; + range = r->headers_out.ranges.elts; + for (i = 0; i < r->headers_out.ranges.nelts; i++) { -#if 0 - ngx_snprintf((char *) ctx->boundary_header.data, len, - CRLF "--%010" NGX_UINT_T_FMT CRLF - "Content-Type: %s" CRLF - "Content-Range: bytes ", - boundary, - r->headers_out.content_type->value.data); + /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ -#endif - } - - ngx_test_null(r->headers_out.content_type->value.data, - ngx_palloc(r->pool, 31 + 10 + 1), - NGX_ERROR); + range[i].content_range.data = + ngx_palloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4); - /* "Content-Type: multipart/byteranges; boundary=0123456789" */ - - r->headers_out.content_type->value.len = - ngx_sprintf(r->headers_out.content_type->value.data, - "multipart/byteranges; boundary=%010ui", - boundary) - - r->headers_out.content_type->value.data; -#if 0 - ngx_snprintf((char *) - r->headers_out.content_type->value.data, - 31 + 10 + 1, - "multipart/byteranges; boundary=%010" - NGX_UINT_T_FMT, - boundary); -#endif - - /* the size of the last boundary CRLF "--0123456789--" CRLF */ - len = 4 + 10 + 4; - - range = r->headers_out.ranges.elts; - for (i = 0; i < r->headers_out.ranges.nelts; i++) { - ngx_test_null(range[i].content_range.data, - ngx_palloc(r->pool, 20 + 1 + 20 + 1 + 20 + 5), - NGX_ERROR); + if (range[i].content_range.data == NULL) { + return NGX_ERROR; + } - /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ + range[i].content_range.len = ngx_sprintf(range[i].content_range.data, + "%O-%O/%O" CRLF CRLF, + range[i].start, range[i].end - 1, + r->headers_out.content_length_n) + - range[i].content_range.data; - range[i].content_range.len = - ngx_sprintf(range[i].content_range.data, - "%O-%O/%O" CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n) - - range[i].content_range.data; -#if 0 - ngx_snprintf((char *) range[i].content_range.data, - 20 + 1 + 20 + 1 + 20 + 5, - OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF, - range[i].start, range[i].end - 1, - r->headers_out.content_length_n); -#endif + len += ctx->boundary_header.len + range[i].content_range.len + + (size_t) (range[i].end - range[i].start); + } - len += ctx->boundary_header.len + range[i].content_range.len - + (size_t) (range[i].end - range[i].start); - } - - r->headers_out.content_length_n = len; - r->headers_out.content_length = NULL; - } - } + r->headers_out.content_length_n = len; + r->headers_out.content_length = NULL; return ngx_http_next_header_filter(r); } @@ -496,33 +461,54 @@ static ngx_int_t ngx_http_range_body_fil * "Content-Range: bytes " */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->memory = 1; b->pos = ctx->boundary_header.data; b->last = ctx->boundary_header.data + ctx->boundary_header.len; - ngx_test_null(hcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + hcl->buf = b; + /* "SSSS-EEEE/TTTT" CRLF CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->temporary = 1; b->pos = range[i].content_range.data; b->last = range[i].content_range.data + range[i].content_range.len; - ngx_test_null(rcl, ngx_alloc_chain_link(r->pool), NGX_ERROR); + if (!(rcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + rcl->buf = b; + /* the range data */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->in_file = 1; b->file_pos = range[i].start; b->file_last = range[i].end; b->file = in->buf->file; - ngx_alloc_link_and_set_buf(dcl, b, r->pool, NGX_ERROR); + if (!(dcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + dcl->buf = b; *ll = hcl; hcl->next = rcl; @@ -532,15 +518,29 @@ static ngx_int_t ngx_http_range_body_fil /* the last boundary CRLF "--0123456789--" CRLF */ - ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR); + if (!(b = ngx_calloc_buf(r->pool))) { + return NGX_ERROR; + } + b->temporary = 1; b->last_buf = 1; - ngx_test_null(b->pos, ngx_palloc(r->pool, 4 + 10 + 4), NGX_ERROR); + + b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1); + if (b->pos == NULL) { + return NGX_ERROR; + } + b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10); *b->last++ = '-'; *b->last++ = '-'; *b->last++ = CR; *b->last++ = LF; - ngx_alloc_link_and_set_buf(hcl, b, r->pool, NGX_ERROR); + if (!(hcl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + hcl->buf = b; + hcl->next = NULL; + *ll = hcl; return ngx_http_next_body_filter(r, out); diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c --- a/src/http/modules/ngx_http_rewrite_handler.c +++ b/src/http/modules/ngx_http_rewrite_handler.c @@ -146,8 +146,8 @@ static ngx_int_t ngx_http_rewrite_handle if (rc == NGX_DECLINED) { if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" does not match \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" does not match \"%V\"", + &rule[i].re_name, &r->uri); } continue; @@ -156,15 +156,15 @@ static ngx_int_t ngx_http_rewrite_handle if (rc < 0) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_regex_exec_n - " failed: %d on \"%s\" using \"%s\"", - rc, r->uri.data, rule[i].re_name.data); + " failed: %d on \"%V\" using \"%V\"", + rc, &r->uri, &rule[i].re_name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "\"%s\" matches \"%s\"", - rule[i].re_name.data, r->uri.data); + "\"%V\" matches \"%V\"", + &rule[i].re_name, &r->uri); } if (rule[i].status) { @@ -177,7 +177,7 @@ static ngx_int_t ngx_http_rewrite_handle uri.len += matches[2 * n + 1] - matches[2 * n]; } - if (!(uri.data = ngx_palloc(r->pool, uri.len + 1))) { + if (!(uri.data = ngx_palloc(r->pool, uri.len))) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -203,11 +203,9 @@ static ngx_int_t ngx_http_rewrite_handle } } - *p = '\0'; - if (scf->log) { ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, - "rewritten uri: \"%s\"", uri.data); + "rewritten uri: \"%V\"", &uri); } r->uri = uri; @@ -353,7 +351,7 @@ static char *ngx_http_rewrite_rule(ngx_c } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } @@ -427,7 +425,7 @@ static char *ngx_http_rewrite_rule(ngx_c } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%s\"", value[3].data); + "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; } } diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -197,7 +197,7 @@ static ngx_int_t ngx_http_static_handler &name, &file_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache get: " PTR_FMT, file); + "http open file cache get: %p", file); if (file && !file->expired) { r->cache = file; @@ -216,7 +216,7 @@ static ngx_int_t ngx_http_static_handler &name, &redirect_crc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache get: " PTR_FMT, redirect); + "http redirect cache get: %p", redirect); if (redirect && !redirect->expired) { @@ -247,7 +247,7 @@ static ngx_int_t ngx_http_static_handler /* open file */ -#if (WIN9X) +#if (NGX_WIN9X) /* TODO: redirect cache */ @@ -276,7 +276,8 @@ static ngx_int_t ngx_http_static_handler } if (ngx_is_dir(&fi)) { - ngx_log_debug(log, "HTTP DIR: '%s'" _ name.data); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, + "HTTP DIR: \"%s\"", name.data); if (!(r->headers_out.location = ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) @@ -384,7 +385,7 @@ static ngx_int_t ngx_http_static_handler location.len--; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http redirect cache alloc: " PTR_FMT, redirect); + "http redirect cache alloc: %p", redirect); if (redirect) { redirect->fd = NGX_INVALID_FILE; @@ -403,11 +404,11 @@ static ngx_int_t ngx_http_static_handler return NGX_HTTP_MOVED_PERMANENTLY; } -#if !(WIN32) /* the not regular files are probably Unix specific */ +#if !(NGX_WIN32) /* the not regular files are probably Unix specific */ if (!ngx_is_file(&fi)) { ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, - "%s is not a regular file", name.data); + "\"%s\" is not a regular file", name.data); if (ngx_close_file(fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, @@ -459,7 +460,7 @@ static ngx_int_t ngx_http_static_handler #endif ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, - "http open file cache alloc: " PTR_FMT, file); + "http open file cache alloc: %p", file); if (file) { file->fd = fd; diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c --- a/src/http/modules/ngx_http_userid_filter.c +++ b/src/http/modules/ngx_http_userid_filter.c @@ -27,15 +27,13 @@ typedef struct { ngx_str_t domain; ngx_str_t path; time_t expires; - - ngx_int_t p3p; - ngx_str_t p3p_string; + ngx_str_t p3p; } ngx_http_userid_conf_t; typedef struct { - uint32_t uid_got[4]; - uint32_t uid_set[4]; + uint32_t uid_got[4]; + uint32_t uid_set[4]; } ngx_http_userid_ctx_t; @@ -56,8 +54,10 @@ static ngx_int_t ngx_http_userid_pre_con static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child); -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); static uint32_t sequencer_v1 = 1; @@ -79,8 +79,11 @@ static ngx_conf_enum_t ngx_http_userid_ }; -static ngx_conf_post_handler_pt ngx_conf_check_domain_p = - ngx_conf_check_domain; +static ngx_conf_post_handler_pt ngx_http_userid_domain_p = + ngx_http_userid_domain; + +static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; +static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p; static ngx_command_t ngx_http_userid_commands[] = { @@ -111,14 +114,14 @@ static ngx_command_t ngx_http_userid_co ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, domain), - &ngx_conf_check_domain_p }, + &ngx_http_userid_domain_p }, { ngx_string("userid_path"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_userid_conf_t, path), - NULL }, + &ngx_http_userid_path_p }, { ngx_string("userid_expires"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, @@ -127,6 +130,13 @@ static ngx_command_t ngx_http_userid_co 0, NULL }, + { ngx_string("userid_p3p"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_userid_conf_t, p3p), + &ngx_http_userid_p3p_p }, + ngx_null_command }; @@ -210,40 +220,44 @@ static ngx_int_t ngx_http_userid_get_uid for (i = 0; i < r->headers_in.cookies.nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "cookie: \"%s\"", cookies[i]->value.data); + "cookie: \"%V\"", &cookies[i]->value); + if (conf->name.len >= cookies[i]->value.len) { + continue; + } + + start = cookies[i]->value.data; end = cookies[i]->value.data + cookies[i]->value.len; - for (start = cookies[i]->value.data; start < end; /* void */) { + while (start < end) { - if (conf->name.len >= cookies[i]->value.len - || ngx_strncmp(start, conf->name.data, conf->name.len) != 0) - { - start += conf->name.len; + if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) { + while (start < end && *start++ != ';') { /* void */ } - - for (/* void */; start < end && *start == ' '; start++) { /**/ } + while (start < end && *start == ' ') { start++; } continue; } - for (start += conf->name.len; start < end && *start == ' '; start++) - { - /* void */ - } + start += conf->name.len; - if (*start != '=') { + while (start < end && *start == ' ') { start++; } + + if (start == end || *start++ != '=') { + /* the invalid "Cookie" header */ break; } - for (start++; start < end && *start == ' '; start++) { /* void */ } + while (start < end && *start == ' ') { start++; } - for (last = start; last < end && *last != ';'; last++) { /**/ } + last = start; + + while (last < end && *last++ != ';') { /* void */ } if (last - start < 22) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent too short userid cookie \"%s\"", - cookies[i]->value.data); + "client sent too short userid cookie \"%V\"", + &cookies[i]->value); break; } @@ -259,13 +273,13 @@ static ngx_int_t ngx_http_userid_get_uid if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent invalid userid cookie \"%s\"", - cookies[i]->value.data); + "client sent invalid userid cookie \"%V\"", + &cookies[i]->value); break; } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid: %08X%08X%08X%08X", + "uid: %08XD%08XD%08XD%08XD", ctx->uid_got[0], ctx->uid_got[1], ctx->uid_got[2], ctx->uid_got[3]); @@ -280,14 +294,13 @@ static ngx_int_t ngx_http_userid_get_uid static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf) - { u_char *cookie, *p; size_t len; socklen_t slen; struct sockaddr_in addr_in; ngx_str_t src, dst; - ngx_table_elt_t *set_cookie; + ngx_table_elt_t *set_cookie, *p3p; /* TODO: mutex for sequencers */ @@ -333,18 +346,14 @@ static ngx_int_t ngx_http_userid_set_uid } } - len = conf->name.len + 1 + ngx_base64_encoded_length(16) + 1; + len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len; if (conf->expires) { len += sizeof(expires) - 1 + 2; } if (conf->domain.len > 1) { - len += sizeof("; domain=") - 1 + conf->domain.len; - } - - if (conf->path.len) { - len += sizeof("; path=") - 1 + conf->path.len; + len += conf->domain.len; } if (!(cookie = ngx_palloc(r->pool, len))) { @@ -371,19 +380,10 @@ static ngx_int_t ngx_http_userid_set_uid } if (conf->domain.len > 1) { - p = ngx_cpymem(p, "; domain=", sizeof("; domain=") - 1); p = ngx_cpymem(p, conf->domain.data, conf->domain.len); } - if (conf->path.len) { - p = ngx_cpymem(p, "; path=", sizeof("; path=") - 1); - p = ngx_cpymem(p, conf->path.data, conf->path.len); - } - - *p = '\0'; - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "uid cookie: \"%s\"", cookie); + p = ngx_cpymem(p, conf->path.data, conf->path.len); if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) { return NGX_ERROR; @@ -394,6 +394,21 @@ static ngx_int_t ngx_http_userid_set_uid set_cookie->value.len = p - cookie; set_cookie->value.data = cookie; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "uid cookie: \"%V\"", &set_cookie->value); + + if (conf->p3p.len == 1) { + return NGX_OK; + } + + if (!(p3p = ngx_list_push(&r->headers_out.headers))) { + return NGX_ERROR; + } + + p3p->key.len = sizeof("P3P") - 1; + p3p->key.data = (u_char *) "P3P"; + p3p->value = conf->p3p; + return NGX_OK; } @@ -425,9 +440,9 @@ static u_char *ngx_http_userid_log_uid_g *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_got[0], ctx->uid_got[1], - ctx->uid_got[2], ctx->uid_got[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_got[0], ctx->uid_got[1], + ctx->uid_got[2], ctx->uid_got[3]); } @@ -458,9 +473,9 @@ static u_char *ngx_http_userid_log_uid_s *buf++ = '='; - return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", - ctx->uid_set[0], ctx->uid_set[1], - ctx->uid_set[2], ctx->uid_set[3]); + return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", + ctx->uid_set[0], ctx->uid_set[1], + ctx->uid_set[2], ctx->uid_set[3]); } @@ -510,6 +525,8 @@ static void *ngx_http_userid_create_conf conf->domain.date = NULL; conf->path.len = 0; conf->path.date = NULL; + conf->p3p.len = 0; + conf->p3p.date = NULL; */ @@ -531,7 +548,8 @@ static char *ngx_http_userid_merge_conf( ngx_conf_merge_str_value(conf->name, prev->name, "uid"); ngx_conf_merge_str_value(conf->domain, prev->domain, "."); - ngx_conf_merge_str_value(conf->path, prev->path, "/"); + ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); + ngx_conf_merge_str_value(conf->p3p, prev->p3p, "."); ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); @@ -540,15 +558,49 @@ static char *ngx_http_userid_merge_conf( } -char *ngx_conf_check_domain(ngx_conf_t *cf, void *post, void *data) +char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) { ngx_str_t *domain = data; + u_char *p, *new; + if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { domain->len = 1; domain->data = (u_char *) "."; + + return NGX_CONF_OK; } + if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) { + return NGX_CONF_ERROR; + } + + p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); + p = ngx_cpymem(p, domain->data, domain->len); + + domain->len += sizeof("; domain=") - 1; + domain->data = new; + + return NGX_CONF_OK; +} + + +char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *path = data; + + u_char *p, *new; + + if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) { + return NGX_CONF_ERROR; + } + + p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); + p = ngx_cpymem(p, path->data, path->len); + + path->len += sizeof("; path=") - 1; + path->data = new; + return NGX_CONF_OK; } @@ -586,3 +638,16 @@ char *ngx_http_userid_expires(ngx_conf_t return NGX_CONF_OK; } + + +char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) +{ + ngx_str_t *p3p = data; + + if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) { + p3p->len = 1; + p3p->data = (u_char *) "."; + } + + return NGX_CONF_OK; +} diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c --- a/src/http/modules/proxy/ngx_http_proxy_cache.c +++ b/src/http/modules/proxy/ngx_http_proxy_cache.c @@ -173,8 +173,8 @@ static int ngx_http_proxy_process_cached ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache status %d \"%s\"", - c->status, c->status_line.data); + "http cache status %ui \"%V\"", + c->status, &c->status_line); /* TODO: ngx_init_table */ c->headers_in.headers = ngx_create_table(r->pool, 20); @@ -219,8 +219,7 @@ static int ngx_http_proxy_process_cached } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cache header: \"%s: %s\"", - h->key.data, h->value.data); + "http cache header: \"%V: %V\"", &h->key, &h->value); continue; @@ -614,7 +613,7 @@ int ngx_http_proxy_update_cache(ngx_http ep = p->upstream->event_pipe; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http cache update len: " OFF_T_FMT ":" OFF_T_FMT, + "http cache update len: %O:%O", p->cache->ctx.length, ep->read_length); if (p->cache->ctx.length == -1) { diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -710,26 +710,75 @@ void ngx_http_proxy_close_connection(ngx } -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len) { ngx_http_proxy_log_ctx_t *ctx = data; - ngx_http_request_t *r; - ngx_peer_connection_t *peer; + u_char *p; + ngx_int_t escape; + ngx_str_t uri; + ngx_http_request_t *r; + ngx_peer_connection_t *peer; + ngx_http_proxy_upstream_conf_t *uc; r = ctx->proxy->request; + uc = ctx->proxy->lcf->upstream; peer = &ctx->proxy->upstream->peer; - return ngx_snprintf(buf, len, - " while %s, client: %s, URL: %s, upstream: %s%s%s%s%s", - ctx->proxy->action, - r->connection->addr_text.data, - r->unparsed_uri.data, - peer->peers->peers[peer->cur_peer].addr_port_text.data, - ctx->proxy->lcf->upstream->uri.data, - r->uri.data + ctx->proxy->lcf->upstream->location->len, - r->args.len ? "?" : "", - r->args.len ? r->args.data : (u_char *) ""); + p = ngx_snprintf(buf, len, + " while %s, client: %V, URL: %V, upstream: %V%V", + ctx->proxy->action, + &r->connection->addr_text, + &r->unparsed_uri, + &peer->peers->peers[peer->cur_peer].addr_port_text, + &ctx->proxy->lcf->upstream->uri); + len -= p - buf; + buf = p; + + if (r->quoted_uri) { + escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); + } else { + escape = 0; + } + + if (escape) { + if (len >= r->uri.len - uc->location->len + escape) { + + ngx_escape_uri(buf, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + buf += r->uri.len - uc->location->len + escape; + + if (r->args.len == 0) { + return buf; + } + + len -= r->uri.len - uc->location->len + escape; + + return ngx_snprintf(buf, len, "?%V", &r->args); + } + + p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape); + if (p == NULL) { + return buf; + } + + ngx_escape_uri(p, r->uri.data + uc->location->len, + r->uri.len - uc->location->len, NGX_ESCAPE_URI); + + uri.len = r->uri.len - uc->location->len + escape; + uri.data = p; + + } else { + uri.len = r->uri.len - uc->location->len; + uri.data = r->uri.data + uc->location->len; + + } + + return ngx_snprintf(buf, len, "%V%s%V", + &uri, r->args.len ? "?" : "", &r->args); } @@ -759,8 +808,7 @@ static u_char *ngx_http_proxy_log_proxy_ *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expired); + buf = ngx_sprintf(buf, "%T", p->state->expired); } *buf++ = '/'; @@ -769,8 +817,7 @@ static u_char *ngx_http_proxy_log_proxy_ *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->bl_time); + buf = ngx_sprintf(buf, "%T", p->state->bl_time); } *buf++ = '/'; @@ -783,8 +830,7 @@ static u_char *ngx_http_proxy_log_proxy_ *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, - p->state->status); + buf = ngx_sprintf(buf, "%ui", p->state->status); } *buf++ = '/'; @@ -803,8 +849,7 @@ static u_char *ngx_http_proxy_log_proxy_ *buf++ = '-'; } else { - buf += ngx_snprintf((char *) buf, TIME_T_LEN, - TIME_T_FMT, p->state->expires); + buf = ngx_sprintf(buf, "%T", p->state->expires); } *buf++ = ' '; @@ -1166,7 +1211,7 @@ static char *ngx_http_proxy_set_pass(ngx lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]); lcf->peers->peers[i].port = lcf->upstream->port; - len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1; + len = INET_ADDRSTRLEN - 1 + 1 + lcf->upstream->port_text.len; lcf->peers->peers[i].addr_port_text.data = ngx_palloc(cf->pool, len); @@ -1181,12 +1226,12 @@ static char *ngx_http_proxy_set_pass(ngx lcf->peers->peers[i].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[i].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[i].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); lcf->peers->peers[i].addr_port_text.len = - len + lcf->upstream->port_text.len + 1; + len + lcf->upstream->port_text.len; } } else { @@ -1204,10 +1249,11 @@ static char *ngx_http_proxy_set_pass(ngx lcf->peers->peers[0].addr = addr; lcf->peers->peers[0].port = lcf->upstream->port; - len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1; + len = lcf->upstream->host.len + 1 + lcf->upstream->port_text.len; - lcf->peers->peers[0].addr_port_text.data = - ngx_palloc(cf->pool, len + 1); + lcf->peers->peers[0].addr_port_text.len = len; + + lcf->peers->peers[0].addr_port_text.data = ngx_palloc(cf->pool, len); if (lcf->peers->peers[0].addr_port_text.data == NULL) { return NGX_CONF_ERROR; } @@ -1219,9 +1265,9 @@ static char *ngx_http_proxy_set_pass(ngx lcf->peers->peers[0].addr_port_text.data[len++] = ':'; - ngx_cpystrn(lcf->peers->peers[0].addr_port_text.data + len, - lcf->upstream->port_text.data, - lcf->upstream->port_text.len + 1); + ngx_memcpy(lcf->peers->peers[0].addr_port_text.data + len, + lcf->upstream->port_text.data, + lcf->upstream->port_text.len); } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -245,7 +245,7 @@ void ngx_http_proxy_check_broken_connect void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev); void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p); -size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len); +u_char *ngx_http_proxy_log_error(void *data, u_char *buf, size_t len); void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc); void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p); diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -25,7 +25,8 @@ static void ngx_http_proxy_process_upstr static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p); static void ngx_http_proxy_process_body(ngx_event_t *ev); -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type); +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type); static ngx_str_t http_methods[] = { @@ -137,7 +138,8 @@ static ngx_chain_t *ngx_http_proxy_creat if (r->quoted_uri) { escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, + NGX_ESCAPE_URI); } else { escape = 0; } @@ -246,7 +248,7 @@ static ngx_chain_t *ngx_http_proxy_creat if (escape) { ngx_escape_uri(b->last, r->uri.data + uc->location->len, - r->uri.len - uc->location->len); + r->uri.len - uc->location->len, NGX_ESCAPE_URI); b->last += r->uri.len - uc->location->len + escape; } else { @@ -409,8 +411,8 @@ static ngx_chain_t *ngx_http_proxy_creat *(b->last++) = CR; *(b->last++) = LF; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http proxy header: \"%s: %s\"", - header[i].key.data, header[i].value.data); + "http proxy header: \"%V: %V\"", + &header[i].key, &header[i].value); } /* add "\r\n" at the header end */ @@ -670,7 +672,7 @@ void ngx_http_proxy_upstream_busy_lock(n static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) { - int rc; + ngx_int_t rc; ngx_connection_t *c; ngx_http_request_t *r; ngx_output_chain_ctx_t *output; @@ -683,7 +685,7 @@ static void ngx_http_proxy_connect(ngx_h rc = ngx_event_connect_peer(&p->upstream->peer); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy connect: %d", rc); + "http proxy connect: %i", rc); if (rc == NGX_ERROR) { ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); @@ -705,6 +707,8 @@ static void ngx_http_proxy_connect(ngx_h c->write->event_handler = ngx_http_proxy_send_request_handler; c->read->event_handler = ngx_http_proxy_process_upstream_status_line; + c->sendfile = r->connection->sendfile; + c->pool = r->pool; c->read->log = c->write->log = c->log = r->connection->log; @@ -1028,8 +1032,8 @@ static void ngx_http_proxy_process_upstr p->upstream->status_line.len + 1); ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, - "http proxy status %d \"%s\"", - p->upstream->status, p->upstream->status_line.data); + "http proxy status %ui \"%V\"", + p->upstream->status, &p->upstream->status_line); /* init or reinit the p->upstream->headers_in.headers table */ @@ -1143,8 +1147,7 @@ static void ngx_http_proxy_process_upstr } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http proxy header: \"%s: %s\"", - h->key.data, h->value.data); + "http proxy header: \"%V: %V\"", &h->key, &h->value); continue; @@ -1467,7 +1470,7 @@ static void ngx_http_proxy_process_body( if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, - "http proxy upstream exit: " PTR_FMT, ep->out); + "http proxy upstream exit: %p", ep->out); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); ngx_http_proxy_finalize_request(p, 0); return; @@ -1484,12 +1487,13 @@ static void ngx_http_proxy_process_body( } -static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type) +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, + ngx_uint_t ft_type) { - int status; + ngx_uint_t status; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, - "http proxy next upstream: %d", ft_type); + "http proxy next upstream: %ui", ft_type); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -83,7 +83,7 @@ static char *ngx_http_block(ngx_conf_t * ngx_http_core_srv_conf_t **cscfp, *cscf; ngx_http_core_loc_conf_t *clcf; ngx_http_core_main_conf_t *cmcf; -#if (WIN32) +#if (NGX_WIN32) ngx_iocp_conf_t *iocpcf; #endif @@ -343,9 +343,8 @@ static char *ngx_http_block(ngx_conf_t * if (in_addr[a].default_server) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, - "the duplicate default server in %s:%d", - lscf[l].file_name.data, - lscf[l].line); + "the duplicate default server in %V:%d", + &lscf[l].file_name, lscf[l].line); return NGX_CONF_ERROR; } @@ -516,7 +515,7 @@ static char *ngx_http_block(ngx_conf_t * clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; ls->log = clcf->err_log; -#if (WIN32) +#if (NGX_WIN32) iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); if (iocpcf->acceptex_read) { ls->post_accept_buffer_size = cscf->client_header_buffer_size; @@ -582,18 +581,18 @@ static char *ngx_http_block(ngx_conf_t * in_port = in_ports.elts; for (p = 0; p < in_ports.nelts; p++) { ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "port: %d %08x", in_port[p].port, &in_port[p]); + "port: %d %p", in_port[p].port, &in_port[p]); in_addr = in_port[p].addrs.elts; for (a = 0; a < in_port[p].addrs.nelts; a++) { ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20); ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "%s:%d %08x", + "%s:%d %p", address, in_port[p].port, in_addr[a].core_srv_conf); s_name = in_addr[a].names.elts; for (n = 0; n < in_addr[a].names.nelts; n++) { ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "%s:%d %s %08x", - address, in_port[p].port, s_name[n].name.data, + "%s:%d %V %p", + address, in_port[p].port, &s_name[n].name, s_name[n].core_srv_conf); } } @@ -671,7 +670,7 @@ static ngx_int_t ngx_http_add_names(ngx_ for (i = 0; i < cscf->server_names.nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, - "name: %s", server_names[i].name.data); + "name: %V", &server_names[i].name); /* TODO: duplicate names can be checked here */ diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -33,7 +33,7 @@ typedef struct ngx_http_cleanup_s ngx_h typedef struct { - u_int connection; + u_int connection; /* * we declare "action" as "char *" because the actions are usually @@ -41,9 +41,9 @@ typedef struct { * all the time their types */ - char *action; - u_char *client; - u_char *url; + char *action; + ngx_str_t *client; + ngx_http_request_t *request; } ngx_http_log_ctx_t; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -10,7 +10,7 @@ #include #include -/* STUB */ + #define NGX_HTTP_LOCATION_EXACT 1 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 #define NGX_HTTP_LOCATION_REGEX 3 @@ -329,12 +329,12 @@ ngx_module_t ngx_http_core_module = { void ngx_http_handler(ngx_http_request_t *r) { - ngx_http_log_ctx_t *lcx; + ngx_http_log_ctx_t *ctx; r->connection->unexpected_eof = 0; - lcx = r->connection->log->data; - lcx->action = NULL; + ctx = r->connection->log->data; + ctx->action = NULL; switch (r->headers_in.connection_type) { case 0: @@ -526,17 +526,15 @@ ngx_int_t ngx_http_find_location_config( ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, - r->headers_in.content_length_n, - clcf->client_max_body_size); + "http cl:%z max:%uz", + r->headers_in.content_length_n, clcf->client_max_body_size); if (r->headers_in.content_length_n != -1 && clcf->client_max_body_size && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client intented to send too large body: " - SIZE_T_FMT " bytes", + "client intented to send too large body: %z bytes", r->headers_in.content_length_n); return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; @@ -583,9 +581,8 @@ static ngx_int_t ngx_http_find_location( #endif ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "find location: %s\"%s\"", - clcfp[i]->exact_match ? "= " : "", - clcfp[i]->name.data); + "find location: %s\"%V\"", + clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name); if (clcfp[i]->auto_redirect && r->uri.len == clcfp[i]->name.len - 1 @@ -649,8 +646,7 @@ static ngx_int_t ngx_http_find_location( } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "find location: ~ \"%s\"", - clcfp[i]->name.data); + "find location: ~ \"%V\"", &clcfp[i]->name); n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); @@ -661,8 +657,8 @@ static ngx_int_t ngx_http_find_location( if (n < 0) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_regex_exec_n - " failed: %d on \"%s\" using \"%s\"", - n, r->uri.data, clcfp[i]->name.data); + " failed: %d on \"%V\" using \"%V\"", + n, &r->uri, &clcfp[i]->name); return NGX_HTTP_INTERNAL_SERVER_ERROR; } @@ -809,14 +805,12 @@ ngx_int_t ngx_http_internal_redirect(ngx ngx_str_t *uri, ngx_str_t *args) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "internal redirect: \"%s\"", uri->data); + "internal redirect: \"%V\"", uri); - r->uri.len = uri->len; - r->uri.data = uri->data; + r->uri = *uri; if (args) { - r->args.len = args->len; - r->args.data = args->data; + r->args = *args; } if (ngx_http_set_exten(r) != NGX_OK) { @@ -1092,16 +1086,14 @@ static char *ngx_location_block(ngx_conf clcf->name = value[2]; #else ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "the using of the regex \"%s\" " - "requires PCRE library", - value[2].data); + "the using of the regex \"%V\" " + "requires PCRE library", &value[2]); return NGX_CONF_ERROR; #endif } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid location modifier \"%s\"", - value[1].data); + "invalid location modifier \"%V\"", &value[1]); return NGX_CONF_ERROR; } @@ -1123,9 +1115,9 @@ static char *ngx_location_block(ngx_conf if (pclcf->exact_match) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "location \"%s\" could not be inside " - "the exact location \"%s\"", - clcf->name.data, pclcf->name.data); + "location \"%V\" could not be inside " + "the exact location \"%V\"", + &clcf->name, &pclcf->name); return NGX_CONF_ERROR; } @@ -1139,8 +1131,8 @@ static char *ngx_location_block(ngx_conf #endif { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "location \"%s\" is outside location \"%s\"", - clcf->name.data, pclcf->name.data); + "location \"%V\" is outside location \"%V\"", + &clcf->name, &pclcf->name); return NGX_CONF_ERROR; } @@ -1301,7 +1293,7 @@ static char *ngx_http_core_merge_srv_con if (conf->listen.nelts == 0) { ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); l->addr = INADDR_ANY; -#if (WIN32) +#if (NGX_WIN32) l->port = 80; #else /* STUB: getuid() should be cached */ @@ -1561,9 +1553,9 @@ static char *ngx_http_listen(ngx_conf_t || (port < 1 || port > 65536)) { /* "listen 99999" */ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid port \"%s\" in \"%s\" directive, " + "invalid port \"%s\" in \"%V\" directive, " "it must be a number between 1 and 65535", - &addr[p], cmd->name.data); + &addr[p], &cmd->name); return NGX_CONF_ERROR; @@ -1583,7 +1575,7 @@ static char *ngx_http_listen(ngx_conf_t if (h == NULL || h->h_addr_list[0] == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "can not resolve host \"%s\" " - "in \"%s\" directive", addr, cmd->name.data); + "in \"%V\" directive", addr, &cmd->name); return NGX_CONF_ERROR; } @@ -1612,9 +1604,9 @@ static char *ngx_set_server_name(ngx_con for (i = 1; i < cf->args->nelts; i++) { if (value[i].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "server name \"%s\" is invalid " - "in \"%s\" directive", - value[i].data, cmd->name.data); + "server name \"%V\" is invalid " + "in \"%V\" directive", + &value[i], &cmd->name); return NGX_CONF_ERROR; } @@ -1659,13 +1651,13 @@ static char *ngx_set_root(ngx_conf_t *cf if ((ngx_uint_t) lcf->alias == alias) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" directive is duplicate", - cmd->name.data); + "\"%V\" directive is duplicate", + &cmd->name); } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"%s\" directive is duplicate, " + "\"%V\" directive is duplicate, " "\"%s\" directive is specified before", - cmd->name.data, lcf->alias ? "alias" : "root"); + &cmd->name, lcf->alias ? "alias" : "root"); } return NGX_CONF_ERROR; @@ -1708,7 +1700,7 @@ static char *ngx_set_error_page(ngx_conf if (value[i].data[0] == '=') { if (i == 1) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", &value[i]); return NGX_CONF_ERROR; } @@ -1716,7 +1708,7 @@ static char *ngx_set_error_page(ngx_conf if (overwrite == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", value[i]); return NGX_CONF_ERROR; } @@ -1735,14 +1727,14 @@ static char *ngx_set_error_page(ngx_conf err->status = ngx_atoi(value[i].data, value[i].len); if (err->status == NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid value \"%s\"", value[i].data); + "invalid value \"%V\"", &value[i]); return NGX_CONF_ERROR; } if (err->status < 400 || err->status > 599) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "value \"%s\" must be between 400 and 599", - value[i].data); + "value \"%V\" must be between 400 and 599", + &value[i]); return NGX_CONF_ERROR; } diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -168,7 +168,7 @@ int ngx_http_cache_update_file(ngx_http_ err = ngx_errno; -#if (WIN32) +#if (NGX_WIN32) if (err == NGX_EEXIST) { if (ngx_win32_rename_file(temp_file, &ctx->file.name, r->pool) == NGX_ERROR) diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -319,13 +319,6 @@ static ngx_int_t ngx_http_header_filter( if (r->headers_out.content_length_n >= 0) { b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF, r->headers_out.content_length_n); - -#if 0 - b->last += ngx_snprintf((char *) b->last, - sizeof("Content-Length: ") + NGX_OFF_T_LEN + 2, - "Content-Length: " OFF_T_FMT CRLF, - r->headers_out.content_length_n); -#endif } } @@ -396,12 +389,6 @@ static ngx_int_t ngx_http_header_filter( { b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF, clcf->keepalive_header); -#if 0 - b->last += ngx_snprintf((char *) b->last, - sizeof("Keep-Alive: timeout=") + TIME_T_LEN + 2, - "Keep-Alive: timeout=" TIME_T_FMT CRLF, - clcf->keepalive_header); -#endif } } else { diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c --- a/src/http/ngx_http_log_handler.c +++ b/src/http/ngx_http_log_handler.c @@ -133,7 +133,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_ ngx_http_log_t *log; ngx_http_log_op_t *op; ngx_http_log_loc_conf_t *lcf; -#if (WIN32) +#if (NGX_WIN32) u_long written; #endif @@ -160,7 +160,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_ } } -#if (WIN32) +#if (NGX_WIN32) len += 2; #else len++; @@ -186,7 +186,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_ } } -#if (WIN32) +#if (NGX_WIN32) *p++ = CR; *p++ = LF; WriteFile(log[l].file->fd, line, p - line, &written, NULL); #else @@ -211,12 +211,6 @@ static u_char *ngx_http_log_connection(n uintptr_t data) { return ngx_sprintf(buf, "%ui", r->connection->number); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_INT_T_LEN + 1, - "%" NGX_UINT_T_FMT, - r->connection->number); -#endif } @@ -249,11 +243,6 @@ static u_char *ngx_http_log_msec(ngx_htt ngx_gettimeofday(&tv); return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); - -#if 0 - return buf + ngx_snprintf((char *) buf, TIME_T_LEN + 5, "%ld.%03ld", - tv.tv_sec, tv.tv_usec / 1000); -#endif } @@ -274,11 +263,6 @@ static u_char *ngx_http_log_status(ngx_h { return ngx_sprintf(buf, "%ui", r->err_status ? r->err_status : r->headers_out.status); - -#if 0 - return buf + ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, - r->err_status ? r->err_status : r->headers_out.status); -#endif } @@ -286,11 +270,6 @@ static u_char *ngx_http_log_length(ngx_h uintptr_t data) { return ngx_sprintf(buf, "%O", r->connection->sent); - -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, - r->connection->sent); -#endif } @@ -298,10 +277,6 @@ static u_char *ngx_http_log_apache_lengt uintptr_t data) { return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size); -#if 0 - return buf + ngx_snprintf((char *) buf, NGX_OFF_T_LEN + 1, OFF_T_FMT, - r->connection->sent - r->header_size); -#endif } @@ -470,9 +445,7 @@ static u_char *ngx_http_log_header_out(n if (buf == NULL) { return (u_char *) NGX_OFF_T_LEN; } - return buf + ngx_snprintf((char *) buf, - NGX_OFF_T_LEN + 2, OFF_T_FMT, - r->headers_out.content_length_n); + return ngx_sprintf(buf, "%O", r->headers_out.content_length_n); } if (data == offsetof(ngx_http_headers_out_t, last_modified)) { diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -199,7 +199,7 @@ ngx_int_t ngx_http_parse_request_line(ng } break; - /* check "/.", "//", and "%" in URI */ + /* check "/.", "//", "%", and "\" (Win32) in URI */ case sw_after_slash_in_uri: switch (ch) { case CR: @@ -224,6 +224,11 @@ ngx_int_t ngx_http_parse_request_line(ng r->quoted_uri = 1; state = sw_uri; break; +#if (NGX_WIN32) + case '\\': + r->complex_uri = 1; + break; +#endif case '/': r->complex_uri = 1; break; @@ -237,7 +242,7 @@ ngx_int_t ngx_http_parse_request_line(ng } break; - /* check "/" and "%" in URI */ + /* check "/", "%" and "\" (Win32) in URI */ case sw_check_uri: switch (ch) { case CR: @@ -257,6 +262,12 @@ ngx_int_t ngx_http_parse_request_line(ng case '.': r->uri_ext = p; break; +#if (NGX_WIN32) + case '\\': + r->complex_uri = 1; + state = sw_after_slash_in_uri; + break; +#endif case '/': r->uri_ext = NULL; state = sw_after_slash_in_uri; @@ -657,7 +668,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx sw_slash, sw_dot, sw_dot_dot, -#if (WIN32) +#if (NGX_WIN32) sw_dot_dot_dot, #endif sw_quoted, @@ -671,17 +682,42 @@ ngx_int_t ngx_http_parse_complex_uri(ngx p = r->uri_start; u = r->uri.data; r->uri_ext = NULL; + r->args_start = NULL; ch = *p++; - while (p < r->uri_start + r->uri.len + 1) { + while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) { + + /* + * we use "ch = *p++" inside the cycle but this operation is safe + * because after the URI there is always at least one charcter: + * the line feed + */ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "s:%d in:'%x:%c', out:'%c'", state, ch, ch, *u); + "s:%d in:'%Xd:%c', out:'%c'", state, ch, ch, *u); switch (state) { case sw_usual: switch(ch) { +#if (NGX_WIN32) + case '\\': + r->uri_ext = NULL; + + if (p == r->uri_start + r->uri.len) { + + /* + * we omit the last "\" to cause redirect because + * the browsers do not treat "\" as "/" in relative URL path + */ + + break; + } + + state = sw_slash; + *u++ = '/'; + break; +#endif case '/': r->uri_ext = NULL; state = sw_slash; @@ -691,6 +727,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx quoted_state = state; state = sw_quoted; break; + case '?': + r->args_start = p; + break; case '.': r->uri_ext = u + 1; default: @@ -702,6 +741,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx case sw_slash: switch(ch) { +#if (NGX_WIN32) + case '\\': + break; +#endif case '/': break; case '.': @@ -722,6 +765,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx case sw_dot: switch(ch) { +#if (NGX_WIN32) + case '\\': + /* fall through */ +#endif case '/': state = sw_slash; u--; @@ -744,6 +791,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx case sw_dot_dot: switch(ch) { +#if (NGX_WIN32) + case '\\': + /* fall through */ +#endif case '/': state = sw_slash; u -= 4; @@ -758,7 +809,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx quoted_state = state; state = sw_quoted; break; -#if (WIN32) +#if (NGX_WIN32) case '.': state = sw_dot_dot_dot; *u++ = ch; @@ -772,9 +823,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx ch = *p++; break; -#if (WIN32) +#if (NGX_WIN32) case sw_dot_dot_dot: switch(ch) { + case '\\': case '/': state = sw_slash; u -= 5; @@ -857,12 +909,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx if (r->uri_ext) { r->exten.len = u - r->uri_ext; - - if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1); + r->exten.data = r->uri_ext; } r->uri_ext = NULL; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -34,24 +34,22 @@ static void ngx_http_lingering_close_han static void ngx_http_client_error(ngx_http_request_t *r, int client_error, int error); -static size_t ngx_http_log_error(void *data, char *buf, size_t len); +static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len); /* NGX_HTTP_PARSE_... errors */ static char *client_header_errors[] = { - "client %s sent invalid method", - "client %s sent invalid request", - "client %s sent too long URI", - "client %s sent invalid method in HTTP/0.9 request", - - "client %s sent invalid header, URL: %s", - "client %s sent too long header line, URL: %s", - "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", - "client %s sent invalid \"Content-Length\" header, URL: %s", - "client %s sent POST method without \"Content-Length\" header, URL: %s", - "client %s sent plain HTTP request to HTTPS port, URL: %s", - "client %s sent invalid \"Host\" header \"%s\", URL: %s" + "client %V sent invalid method \"%V\"", + "client %V sent invalid request \"%V\"", + "client %V sent too long URI in request \"%V\"", + "client %V sent invalid method in HTTP/0.9 request \"%V\"", + + "client %V sent invalid header, URL: \"%V\"", + "client %V sent too long header line, URL: \"%V\"", + "client %V sent HTTP/1.1 request without \"Host\" header, URL: \"%V\"", + "client %V sent invalid \"Content-Length\" header, URL: \"%V\"", + "client %V sent POST method without \"Content-Length\" header, URL: \"%V\"", }; @@ -105,14 +103,15 @@ void ngx_http_init_connection(ngx_connec ngx_event_t *rev; ngx_http_log_ctx_t *ctx; - if (!(ctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { + if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { ngx_http_close_connection(c); return; } ctx->connection = c->number; - ctx->client = c->addr_text.data; + ctx->client = &c->addr_text; ctx->action = "reading client request line"; + ctx->request = NULL; c->log->data = ctx; c->log->handler = ngx_http_log_error; c->log_error = NGX_ERROR_INFO; @@ -278,7 +277,7 @@ static void ngx_http_init_request(ngx_ev * AcceptEx() already gave this address. */ -#if (WIN32) +#if (NGX_WIN32) if (c->local_sockaddr) { r->in_addr = ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; @@ -295,7 +294,7 @@ static void ngx_http_init_request(ngx_ev r->in_addr = addr_in.sin_addr.s_addr; -#if (WIN32) +#if (NGX_WIN32) } #endif @@ -428,9 +427,9 @@ static void ngx_http_init_request(ngx_ev static void ngx_http_ssl_handshake(ngx_event_t *rev) { - int n; + u_char buf[1]; + ssize_t n; ngx_int_t rc; - u_char buf[1]; ngx_connection_t *c; ngx_http_request_t *r; @@ -454,7 +453,7 @@ static void ngx_http_ssl_handshake(ngx_e if (n == 1) { if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, - "https ssl handshake: 0x%X", buf[0]); + "https ssl handshake: 0x%02Xd", buf[0]); c->recv = ngx_ssl_recv; c->send_chain = ngx_ssl_send_chain; @@ -488,7 +487,6 @@ static void ngx_http_ssl_handshake(ngx_e static void ngx_http_process_request_line(ngx_event_t *rev) { - u_char *p; ssize_t n; ngx_int_t rc, rv; ngx_connection_t *c; @@ -524,21 +522,9 @@ static void ngx_http_process_request_lin /* the request line has been parsed successfully */ - /* copy unparsed URI */ - - r->unparsed_uri.len = r->uri_end - r->uri_start; - r->unparsed_uri.data = ngx_palloc(r->pool, r->unparsed_uri.len + 1); - if (r->unparsed_uri.data == NULL) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->unparsed_uri.data, r->uri_start, - r->unparsed_uri.len + 1); - - - /* copy URI */ + r->request_line.len = r->request_end - r->request_start; + r->request_line.data = r->request_start; + if (r->args_start) { r->uri.len = r->args_start - 1 - r->uri_start; @@ -546,13 +532,14 @@ static void ngx_http_process_request_lin r->uri.len = r->uri_end - r->uri_start; } - if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - if (r->complex_uri || r->quoted_uri) { + + if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { + ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + ngx_http_close_connection(c); + return; + } + rc = ngx_http_parse_complex_uri(r); if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { @@ -562,74 +549,55 @@ static void ngx_http_process_request_lin } if (rc != NGX_OK) { - r->request_line.len = r->request_end - r->request_start; - r->request_line.data = r->request_start; - ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); return; } } else { - ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); + r->uri.data = r->uri_start; } - - r->request_line.len = r->request_end - r->request_start; - r->request_line.data = r->request_start; - r->request_line.data[r->request_line.len] = '\0'; + r->unparsed_uri.len = r->uri_end - r->uri_start; + r->unparsed_uri.data = r->uri_start; + if (r->method == 0) { r->method_name.len = r->method_end - r->request_start + 1; r->method_name.data = r->request_line.data; } + if (r->uri_ext) { - - /* copy URI extention */ - if (r->args_start) { r->exten.len = r->args_start - 1 - r->uri_ext; } else { r->exten.len = r->uri_end - r->uri_ext; } - if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->exten.data, r->uri_ext, r->exten.len + 1); + r->exten.data = r->uri_ext; } + if (r->args_start && r->uri_end > r->args_start) { - - /* copy URI arguments */ - r->args.len = r->uri_end - r->args_start; - - if (!(r->args.data = ngx_palloc(r->pool, r->args.len + 1))) { - ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); - ngx_http_close_connection(c); - return; - } - - ngx_cpystrn(r->args.data, r->args_start, r->args.len + 1); + r->args.data = r->args_start; } + + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, + "http request line: \"%V\"", &r->request_line); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http request line: \"%s\"", r->request_line.data); - - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http uri: \"%s\"", r->uri.data); + "http uri: \"%V\"", &r->uri); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http args: \"%s\"", - r->args.data ? r->args.data : (u_char *) ""); + "http args: \"%V\"", &r->args); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http exten: \"%s\"", - r->exten.data ? r->exten.data : (u_char *) ""); + "http exten: \"%V\"", &r->exten); + + ctx = c->log->data; + ctx->request = r; if (r->http_version < NGX_HTTP_VERSION_10) { rev->event_handler = ngx_http_block_read; @@ -655,10 +623,7 @@ static void ngx_http_process_request_lin return; } - - ctx = c->log->data; ctx->action = "reading client request headers"; - ctx->url = r->unparsed_uri.data; rev->event_handler = ngx_http_process_request_headers; ngx_http_process_request_headers(rev); @@ -669,6 +634,9 @@ static void ngx_http_process_request_lin /* there was error while a request line parsing */ + ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST); + +#if 0 for (p = r->request_start; p < r->header_in->last; p++) { if (*p == CR || *p == LF) { break; @@ -686,6 +654,8 @@ static void ngx_http_process_request_lin (rc == NGX_HTTP_PARSE_INVALID_METHOD) ? NGX_HTTP_NOT_IMPLEMENTED: NGX_HTTP_BAD_REQUEST); +#endif + return; } @@ -811,8 +781,8 @@ static void ngx_http_process_request_hea } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http header: \"%s: %s\"", - h->key.data, h->value.data); + "http header: \"%V: %V\"", + &h->key, &h->value); continue; @@ -973,7 +943,7 @@ static ngx_int_t ngx_http_alloc_large_he b = hc->free[--hc->nfree]; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http large header free: " PTR_FMT " " SIZE_T_FMT, + "http large header free: %p %uz", b->pos, b->end - b->last); } else if (hc->nbusy < cscf->large_client_header_buffers.num) { @@ -993,7 +963,7 @@ static ngx_int_t ngx_http_alloc_large_he } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "http large header alloc: " PTR_FMT " " SIZE_T_FMT, + "http large header alloc: %p %uz", b->pos, b->end - b->last); } else { @@ -1095,7 +1065,7 @@ static ngx_int_t ngx_http_process_reques for (i = 0; i < r->virtual_names->nelts; i++) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "server name: %s", name[i].name.data); + "server name: %V", &name[i].name); if (name[i].wildcard) { if (r->headers_in.host_name_len <= name[i].name.len) { @@ -1579,7 +1549,7 @@ static void ngx_http_set_keepalive(ngx_h ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); - ctx = (ngx_http_log_ctx_t *) c->log->data; + ctx = c->log->data; ctx->action = "closing request"; hc = r->http_connection; @@ -1677,7 +1647,7 @@ static void ngx_http_set_keepalive(ngx_h b->last = b->start; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d", + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: %p %d", hc->free, hc->nfree); if (hc->free) { @@ -1689,7 +1659,7 @@ static void ngx_http_set_keepalive(ngx_h hc->nfree = 0; } - ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d", + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: %p %d", hc->busy, hc->nbusy); if (hc->busy) { @@ -1785,8 +1755,9 @@ static void ngx_http_keepalive_handler(n if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { if (rev->pending_eof) { + rev->log->handler = NULL; ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, - "kevent() reported that client %s closed " + "kevent() reported that client %V closed " "keepalive connection", ctx->client); ngx_http_close_connection(c); return; @@ -1841,7 +1812,7 @@ static void ngx_http_keepalive_handler(n if (n == 0) { ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, - "client %s closed keepalive connection", ctx->client); + "client %V closed keepalive connection", ctx->client); ngx_http_close_connection(c); return; } @@ -2055,7 +2026,7 @@ void ngx_http_close_request(ngx_http_req if (r->file.fd != NGX_INVALID_FILE) { if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - ngx_close_file_n " \"%s\" failed", r->file.name.data); + ngx_close_file_n " \"%V\" failed", &r->file.name); } } @@ -2067,8 +2038,8 @@ void ngx_http_close_request(ngx_http_req == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - ngx_close_file_n " deleted file \"%s\" failed", - r->request_body->temp_file->file.name.data); + ngx_close_file_n " deleted file \"%V\" failed", + &r->request_body->temp_file->file.name); } } @@ -2088,9 +2059,9 @@ void ngx_http_close_request(ngx_http_req } } - /* ctx->url was allocated from r->pool */ + /* the variuos request strings were allocated from r->pool */ ctx = log->data; - ctx->url = NULL; + ctx->request = NULL; r->request_line.len = 0; @@ -2148,6 +2119,7 @@ void ngx_http_close_connection(ngx_conne static void ngx_http_client_error(ngx_http_request_t *r, int client_error, int error) { + u_char *p; ngx_http_log_ctx_t *ctx; ngx_http_core_srv_conf_t *cscf; @@ -2164,13 +2136,15 @@ static void ngx_http_client_error(ngx_ht r->connection->log->handler = NULL; - if (ctx->url) { + if (ctx->request) { + switch (client_error) { case NGX_HTTP_PARSE_INVALID_HOST: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client, r->headers_in.host->value.data, ctx->url); + "client %V sent invalid \"Host\" header \"%V\", URL: \"%V\"", + ctx->client, &r->headers_in.host->value, + &ctx->request->unparsed_uri); error = NGX_HTTP_INVALID_HOST; @@ -2186,24 +2160,49 @@ static void ngx_http_client_error(ngx_ht case NGX_HTTP_PARSE_HTTP_TO_HTTPS: error = NGX_HTTP_TO_HTTPS; - - /* fall through */ + if (ctx->request->headers_in.referer) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "client %V sent plain HTTP request to HTTPS port, " + "URL: \"%V\", referrer \"%V\"", + ctx->client, &ctx->request->unparsed_uri, + &ctx->request->headers_in.referer->value); + + } else { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "client %V sent plain HTTP request to HTTPS port, " + "URL: \"%V\"", ctx->client, &ctx->request->unparsed_uri); + } + + break; default: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client, ctx->url); + ctx->client, &ctx->request->unparsed_uri); } } else { + if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { r->request_line.len = r->header_in->end - r->request_start; r->request_line.data = r->request_start; + + } else { + if (r->request_line.data == NULL) { + for (p = r->request_start; p < r->header_in->last; p++) { + if (*p == CR || *p == LF) { + break; + } + } + + r->request_line.len = p - r->request_start; + r->request_line.data = r->request_start; + } } ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], - ctx->client); + ctx->client, &r->request_line); } r->connection->log->handler = ngx_http_log_error; @@ -2212,20 +2211,35 @@ static void ngx_http_client_error(ngx_ht } -static size_t ngx_http_log_error(void *data, char *buf, size_t len) +static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len) { ngx_http_log_ctx_t *ctx = data; - if (ctx->action && ctx->url) { - return ngx_snprintf(buf, len, " while %s, client: %s, URL: %s", - ctx->action, ctx->client, ctx->url); - - } else if (ctx->action == NULL && ctx->url) { - return ngx_snprintf(buf, len, ", client: %s, URL: %s", - ctx->client, ctx->url); - - } else { - return ngx_snprintf(buf, len, " while %s, client: %s", - ctx->action, ctx->client); + u_char *p; + + p = buf; + + if (ctx->action) { + p = ngx_snprintf(p, len, " while %s", ctx->action); + len -= p - buf; + } + + p = ngx_snprintf(p, len, ", client: %V", ctx->client); + + if (ctx->request == NULL) { + return p; } + + len -= p - buf; + + p = ngx_snprintf(p, len, ", URL: \"%V\"", &ctx->request->unparsed_uri); + + if (ctx->request->headers_in.referer == NULL) { + return p; + } + + len -= p - buf; + + return ngx_snprintf(p, len, ", referrer: \"%V\"", + &ctx->request->headers_in.referer->value); } diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -41,8 +41,9 @@ #define NGX_HTTP_PARSE_NO_HOST_HEADER 16 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18 -#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 19 -#define NGX_HTTP_PARSE_INVALID_HOST 20 + +#define NGX_HTTP_PARSE_INVALID_HOST 19 +#define NGX_HTTP_PARSE_HTTP_TO_HTTPS 20 #define NGX_HTTP_OK 200 diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c --- a/src/http/ngx_http_request_body.c +++ b/src/http/ngx_http_request_body.c @@ -148,7 +148,7 @@ static ngx_int_t ngx_http_do_read_client n = c->recv(c, r->request_body->buf->last, size); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http client request body recv " SIZE_T_FMT, n); + "http client request body recv %z", n); if (n == NGX_AGAIN) { clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); @@ -184,7 +184,7 @@ static ngx_int_t ngx_http_do_read_client } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http client request body rest " SIZE_T_FMT, + "http client request body rest %uz", r->request_body->rest); if (r->request_body->rest) { diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -69,6 +69,12 @@ ngx_int_t ngx_http_write_filter(ngx_http for (cl = ctx->out; cl; cl = cl->next) { ll = &cl->next; +#if 1 + if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { + ngx_debug_point(); + } +#endif + size += ngx_buf_size(cl->buf); if (cl->buf->flush || cl->buf->recycled) { @@ -83,10 +89,20 @@ ngx_int_t ngx_http_write_filter(ngx_http /* add the new chain to the existent one */ for (ln = in; ln; ln = ln->next) { - ngx_alloc_link_and_set_buf(cl, ln->buf, r->pool, NGX_ERROR); + if (!(cl = ngx_alloc_chain_link(r->pool))) { + return NGX_ERROR; + } + + cl->buf = ln->buf; *ll = cl; ll = &cl->next; +#if 1 + if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) { + ngx_debug_point(); + } +#endif + size += ngx_buf_size(cl->buf); if (cl->buf->flush || cl->buf->recycled) { @@ -98,11 +114,12 @@ ngx_int_t ngx_http_write_filter(ngx_http } } + *ll = NULL; + c = r->connection; ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT, - last, flush, size); + "http write filter: l:%d f:%O s:%O", last, flush, size); clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, ngx_http_core_module); @@ -125,6 +142,9 @@ ngx_int_t ngx_http_write_filter(ngx_http if (!last) { ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, "the http output chain is empty"); + + ngx_debug_point(); + return NGX_ERROR; } return NGX_OK; @@ -136,7 +156,7 @@ ngx_int_t ngx_http_write_filter(ngx_http clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, - "http write filter %X", chain); + "http write filter %p", chain); if (clcf->limit_rate) { sent = c->sent - sent; diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c --- a/src/os/unix/ngx_aio_write_chain.c +++ b/src/os/unix/ngx_aio_write_chain.c @@ -13,11 +13,10 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { - int n; u_char *buf, *prev; off_t send, sent; size_t len; - ssize_t size; + ssize_t n, size; ngx_err_t err; ngx_chain_t *cl; @@ -63,7 +62,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con n = ngx_aio_write(c, buf, len); - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %d", n); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_write: %z", n); if (n == NGX_ERROR) { return NGX_CHAIN_ERROR; @@ -75,7 +74,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_con } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, - "aio_write sent: " OFF_T_FMT, c->sent); + "aio_write sent: %O", c->sent); for (cl = in; cl; cl = cl->next) { diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c --- a/src/os/unix/ngx_alloc.c +++ b/src/os/unix/ngx_alloc.c @@ -17,11 +17,10 @@ void *ngx_alloc(size_t size, ngx_log_t * if (!(p = malloc(size))) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "malloc() " SIZE_T_FMT " bytes failed", size); + "malloc() %uz bytes failed", size); } - ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, - "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size); + ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size); return p; } @@ -49,12 +48,12 @@ void *ngx_memalign(size_t alignment, siz if (posix_memalign(&p, alignment, size) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "posix_memalign() " SIZE_T_FMT " bytes aligned to " - SIZE_T_FMT " failed", size, alignment); + "posix_memalign() %uz bytes aligned to %uz failed", + size, alignment); } ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, - "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); + "posix_memalign: %p:%uz", p, size); return p; } @@ -67,12 +66,12 @@ void *ngx_memalign(size_t alignment, siz if (!(p = memalign(alignment, size))) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, - "memalign() " SIZE_T_FMT " bytes aligned to " - SIZE_T_FMT " failed", size, alignment); + "memalign() %uz bytes aligned to %uz failed", + size, alignment); } ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, - "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); + "memalign: %p:%uz", p, size); return p; } diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c --- a/src/os/unix/ngx_channel.c +++ b/src/os/unix/ngx_channel.c @@ -120,9 +120,14 @@ ngx_int_t ngx_read_channel(ngx_socket_t return NGX_ERROR; } + if (n == 0) { + ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "recvmsg() returned zero"); + return NGX_ERROR; + } + if ((size_t) n < sizeof(ngx_channel_t)) { ngx_log_error(NGX_LOG_ALERT, log, 0, - "recvmsg() returned not enough data"); + "recvmsg() returned not enough data: %uz", n); return NGX_ERROR; } diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c --- a/src/os/unix/ngx_errno.c +++ b/src/os/unix/ngx_errno.c @@ -10,32 +10,29 @@ #if (NGX_STRERROR_R) -ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size) +u_char *ngx_strerror_r(int err, u_char *errstr, size_t size) { - size_t len; - if (size == 0) { return 0; } errstr[0] = '\0'; - strerror_r(err, errstr, size); + strerror_r(err, (char *) errstr, size); - for (len = 0; len < size; len++) { - if (errstr[len] == '\0') { - break; - } + while (*errstr && size) { + errstr++; + size--; } - return len; + return errstr; } #elif (NGX_GNU_STRERROR_R) /* Linux strerror_r() */ -ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size) +u_char *ngx_strerror_r(int err, u_char *errstr, size_t size) { char *str; size_t len; @@ -46,20 +43,18 @@ ngx_int_t ngx_strerror_r(int err, char * errstr[0] = '\0'; - str = strerror_r(err, errstr, size); + str = strerror_r(err, (char *) errstr, size); - if (str != errstr) { - return ngx_cpystrn((u_char *) errstr, (u_char *) str, size) - - (u_char *) errstr; + if (str != (char *) errstr) { + return ngx_cpystrn(errstr, (u_char *) str, size); } - for (len = 0; len < size; len++) { - if (errstr[len] == '\0') { - break; - } + while (*errstr && size) { + errstr++; + size--; } - return len; + return errstr; } #endif diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -47,14 +47,14 @@ typedef int ngx_err_t; #if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R) -ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size); +u_char *ngx_strerror_r(int err, u_char *errstr, size_t size); #else /* Solaris has threads-safe strerror() */ #define ngx_strerror_r(err, errstr, size) \ - (char *) ngx_cpystrn(errstr, strerror(err), size) - (errstr) + ngx_cpystrn(errstr, (u_char *) strerror(err), size) #endif diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -13,7 +13,7 @@ ssize_t ngx_read_file(ngx_file_t *file, ssize_t n; ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, - "read: %d, %X, %d, " OFF_T_FMT, file->fd, buf, size, offset); + "read: %d, %p, %uz, %O", file->fd, buf, size, offset); #if (NGX_PREAD) @@ -57,6 +57,9 @@ ssize_t ngx_write_file(ngx_file_t *file, { ssize_t n; + ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, + "write: %d, %p, %uz, %O", file->fd, buf, size, offset); + #if (NGX_PWRITE) n = pwrite(file->fd, buf, size, offset); @@ -68,7 +71,7 @@ ssize_t ngx_write_file(ngx_file_t *file, if ((size_t) n != size) { ngx_log_error(NGX_LOG_CRIT, file->log, 0, - "pwrite() has written only %d of %d", n, size); + "pwrite() has written only %z of %uz", n, size); return NGX_ERROR; } @@ -92,7 +95,7 @@ ssize_t ngx_write_file(ngx_file_t *file, if ((size_t) n != size) { ngx_log_error(NGX_LOG_CRIT, file->log, 0, - "write() has written only %d of %d", n, size); + "write() has written only %z of %uz", n, size); return NGX_ERROR; } @@ -120,17 +123,19 @@ int ngx_open_tempfile(u_char *name, ngx_ } +#define NGX_IOVS 8 + ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, ngx_pool_t *pool) { u_char *prev; size_t size; ssize_t n; - struct iovec *iov; ngx_err_t err; - ngx_array_t io; + ngx_array_t vec; + struct iovec *iov, iovs[NGX_IOVS]; - /* use pwrite() if there's the only buf in a chain */ + /* use pwrite() if there is the only buf in a chain */ if (cl->next == NULL) { return ngx_write_file(file, cl->buf->pos, @@ -138,61 +143,74 @@ ssize_t ngx_write_chain_to_file(ngx_file offset); } - prev = NULL; - iov = NULL; - size = 0; + vec.elts = iovs; + vec.size = sizeof(struct iovec); + vec.nalloc = NGX_IOVS; + vec.pool = pool; - ngx_init_array(io, pool, 10, sizeof(struct iovec), NGX_ERROR); + do { + prev = NULL; + iov = NULL; + size = 0; - /* create the iovec and coalesce the neighbouring bufs */ + vec.nelts = 0; + + /* create the iovec and coalesce the neighbouring bufs */ - while (cl) { - if (prev == cl->buf->pos) { - iov->iov_len += cl->buf->last - cl->buf->pos; + while (cl && vec.nelts < IOV_MAX) { + if (prev == cl->buf->pos) { + iov->iov_len += cl->buf->last - cl->buf->pos; - } else { - ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); - iov->iov_base = (void *) cl->buf->pos; - iov->iov_len = cl->buf->last - cl->buf->pos; + } else { + if (!(iov = ngx_array_push(&vec))) { + return NGX_ERROR; + } + + iov->iov_base = (void *) cl->buf->pos; + iov->iov_len = cl->buf->last - cl->buf->pos; + } + + size += cl->buf->last - cl->buf->pos; + prev = cl->buf->last; + cl = cl->next; } - size += cl->buf->last - cl->buf->pos; - prev = cl->buf->last; - cl = cl->next; - } + /* use pwrite() if there is the only iovec buffer */ - /* use pwrite() if there's the only iovec buffer */ + if (vec.nelts == 1) { + iov = vec.elts; + return ngx_write_file(file, (u_char *) iov[0].iov_base, + iov[0].iov_len, offset); + } - if (io.nelts == 1) { - iov = io.elts; - return ngx_write_file(file, (u_char *) iov[0].iov_base, iov[0].iov_len, - offset); - } + if (file->sys_offset != offset) { + if (lseek(file->fd, offset, SEEK_SET) == -1) { + ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, + "lseek() failed"); + return NGX_ERROR; + } - if (file->sys_offset != offset) { - if (lseek(file->fd, offset, SEEK_SET) == -1) { - ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed"); + file->sys_offset = offset; + } + + n = writev(file->fd, vec.elts, vec.nelts); + + if (n == -1) { + ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, + "writev() failed"); return NGX_ERROR; } - file->sys_offset = offset; - } - - n = writev(file->fd, io.elts, io.nelts); + if ((size_t) n != size) { + ngx_log_error(NGX_LOG_CRIT, file->log, 0, + "writev() has written only %z of %uz", n, size); + return NGX_ERROR; + } - if (n == -1) { - ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "writev() failed"); - return NGX_ERROR; - } + file->sys_offset += n; + file->offset += n; - if ((size_t) n != size) { - ngx_log_error(NGX_LOG_CRIT, file->log, 0, - "writev() has written only %d of %d", n, size); - return NGX_ERROR; - } - - file->sys_offset += n; - file->offset += n; + } while (cl); return n; } diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -9,8 +9,8 @@ /* FreeBSD 3.0 at least */ -char ngx_freebsd_kern_ostype[20]; -char ngx_freebsd_kern_osrelease[20]; +char ngx_freebsd_kern_ostype[16]; +char ngx_freebsd_kern_osrelease[128]; int ngx_freebsd_kern_osreldate; int ngx_freebsd_hw_ncpu; int ngx_freebsd_net_inet_tcp_sendspace; @@ -95,7 +95,12 @@ ngx_int_t ngx_os_init(ngx_log_t *log) ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "sysctlbyname(kern.ostype) failed"); - return NGX_ERROR; + + if (ngx_errno != NGX_ENOMEM) { + return NGX_ERROR; + } + + ngx_freebsd_kern_ostype[size - 1] = '\0'; } size = sizeof(ngx_freebsd_kern_osrelease); @@ -103,7 +108,12 @@ ngx_int_t ngx_os_init(ngx_log_t *log) ngx_freebsd_kern_osrelease, &size, NULL, 0) == -1) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "sysctlbyname(kern.osrelease) failed"); - return NGX_ERROR; + + if (ngx_errno != NGX_ENOMEM) { + return NGX_ERROR; + } + + ngx_freebsd_kern_osrelease[size - 1] = '\0'; } diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -21,9 +21,10 @@ * The SysV semop() is a cheap syscall, particularly if it has little sembuf's * and does not use SEM_UNDO. * - * The condition variable implementation uses signal #64. The signal handler - * is SIG_IGN so the kill() is a cheap syscall. The thread waits a signal - * in kevent(). The use of the EVFILT_SIGNAL is safe since FreeBSD 4.7. + * The condition variable implementation uses the signal #64. + * The signal handler is SIG_IGN so the kill() is a cheap syscall. + * The thread waits a signal in kevent(). The use of the EVFILT_SIGNAL + * is safe since FreeBSD 4.10-STABLE. * * This threads implementation currently works on i386 (486+) and amd64 * platforms only. @@ -114,15 +115,16 @@ void _spinunlock(ngx_atomic_t *lock) #endif -int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log) +ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, + ngx_log_t *log) { - int id, err; - char *stack, *stack_top; + ngx_pid_t id; + ngx_err_t err; + char *stack, *stack_top; if (nthreads >= max_threads) { ngx_log_error(NGX_LOG_CRIT, log, 0, - "no more than %d threads can be created", max_threads); + "no more than %ui threads can be created", max_threads); return NGX_ERROR; } @@ -133,20 +135,21 @@ int ngx_create_thread(ngx_tid_t *tid, vo if (stack == MAP_FAILED) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - "mmap(" PTR_FMT ":" SIZE_T_FMT - ", MAP_STACK) thread stack failed", + "mmap(%p:%uz, MAP_STACK) thread stack failed", last_stack, usable_stack_size); return NGX_ERROR; } if (stack != last_stack) { - ngx_log_error(NGX_LOG_ALERT, log, 0, "stack address was changed"); + ngx_log_error(NGX_LOG_ALERT, log, 0, + "stack %p address was changed to %p", last_stack, stack); + return NGX_ERROR; } stack_top = stack + usable_stack_size; ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, - "thread stack: " PTR_FMT "-" PTR_FMT, stack, stack_top); + "thread stack: %p-%p", stack, stack_top); ngx_set_errno(0); @@ -164,7 +167,7 @@ int ngx_create_thread(ngx_tid_t *tid, vo / ngx_thread_stack_size; tids[nthreads] = id; - ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %d", id); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %P", id); } return err; @@ -205,30 +208,30 @@ ngx_int_t ngx_init_threads(int n, size_t red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "usrstack: " PTR_FMT " red zone: " PTR_FMT, + "usrstack: %p red zone: %p", ngx_freebsd_kern_usrstack, red_zone); zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); if (zone == MAP_FAILED) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - "mmap(" PTR_FMT ":" SIZE_T_FMT - ", PROT_NONE, MAP_ANON) red zone failed", + "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed", red_zone, rz_size); return NGX_ERROR; } if (zone != red_zone) { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "red zone address was changed"); + "red zone %p address was changed to %p", red_zone, zone); + return NGX_ERROR; } - /* create the threads errno's array */ + /* create the thread errno' array */ if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) { return NGX_ERROR; } - /* create the threads tids array */ + /* create the thread tids array */ if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) { return NGX_ERROR; @@ -236,7 +239,7 @@ ngx_int_t ngx_init_threads(int n, size_t tids[0] = ngx_pid; - /* create the threads tls's array */ + /* create the thread tls' array */ ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *), cycle->log); @@ -274,7 +277,7 @@ ngx_tid_t ngx_thread_self() } -ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key) +ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) { if (nkeys >= NGX_THREAD_KEYS_MAX) { return NGX_ENOMEM; @@ -286,7 +289,7 @@ ngx_int_t ngx_thread_key_create(ngx_tls_ } -ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) +ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) { if (key >= NGX_THREAD_KEYS_MAX) { return NGX_EINVAL; @@ -297,7 +300,7 @@ ngx_int_t ngx_thread_set_tls(ngx_tls_key } -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags) +ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) { ngx_mutex_t *m; union semun op; @@ -361,10 +364,10 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * #if (NGX_DEBUG) if (try) { ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "try lock mutex " PTR_FMT " lock:%X", m, m->lock); + "try lock mutex %p lock:%XD", m, m->lock); } else { ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "lock mutex " PTR_FMT " lock:%X", m, m->lock); + "lock mutex %p lock:%XD", m, m->lock); } #endif @@ -395,7 +398,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * } ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " lock:%X", m, m->lock); + "mutex %p lock:%XD", m, m->lock); /* * The mutex is locked so we increase a number @@ -406,8 +409,8 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, - "%d threads wait for mutex " PTR_FMT - ", while only %d threads are available", + "%D threads wait for mutex %p, " + "while only %ui threads are available", lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); return NGX_ERROR; } @@ -415,7 +418,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * if (ngx_atomic_cmp_set(&m->lock, old, lock)) { ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "wait mutex " PTR_FMT " lock:%X", m, m->lock); + "wait mutex %p lock:%XD", m, m->lock); /* * The number of the waiting threads has been increased @@ -430,14 +433,12 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * if (semop(m->semid, &op, 1) == -1) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, - "semop() failed while waiting " - "on mutex " PTR_FMT, m); + "semop() failed while waiting on mutex %p", m); return NGX_ERROR; } ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex waked up " PTR_FMT " lock:%X", - m, m->lock); + "mutex waked up %p lock:%XD", m, m->lock); tries = 0; old = m->lock; @@ -462,7 +463,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * if (tries++ > 1000) { ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is contested", m); + "mutex %p is contested", m); /* the mutex is probably contested so we are giving up now */ @@ -474,7 +475,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t * } ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is locked, lock:%X", m, m->lock); + "mutex %p is locked, lock:%XD", m, m->lock); return NGX_OK; } @@ -493,7 +494,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * if (!(old & NGX_MUTEX_LOCK_BUSY)) { ngx_log_error(NGX_LOG_ALERT, m->log, 0, - "trying to unlock the free mutex " PTR_FMT, m); + "trying to unlock the free mutex %p", m); return NGX_ERROR; } @@ -501,7 +502,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * #if 0 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "unlock mutex " PTR_FMT " lock:%X", m, old); + "unlock mutex %p lock:%XD", m, old); #endif for ( ;; ) { @@ -516,7 +517,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * if (m->semid == -1) { ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is unlocked", m); + "mutex %p is unlocked", m); return NGX_OK; } @@ -546,7 +547,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * /* wake up the thread that waits on semaphore */ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "wake up mutex " PTR_FMT "", m); + "wake up mutex %p", m); op.sem_num = 0; op.sem_op = 1; @@ -554,8 +555,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * if (semop(m->semid, &op, 1) == -1) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, - "semop() failed while waking up on mutex " - PTR_FMT, m); + "semop() failed while waking up on mutex %p", m); return NGX_ERROR; } @@ -566,7 +566,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is unlocked", m); + "mutex %p is unlocked", m); return NGX_OK; } @@ -647,21 +647,20 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, } ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " wait, kq:%d, signo:%d", - cv, cv->kq, cv->signo); + "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); for ( ;; ) { n = kevent(cv->kq, NULL, 0, &kev, 1, NULL); ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " kevent: %d", cv, n); + "cv %p kevent: %d", cv, n); if (n == -1) { err = ngx_errno; ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, cv->log, ngx_errno, - "kevent() failed while waiting condition variable " - PTR_FMT, cv); + "kevent() failed while waiting condition variable %p", + cv); if (err == NGX_EINTR) { break; @@ -673,7 +672,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, if (n == 0) { ngx_log_error(NGX_LOG_ALERT, cv->log, 0, "kevent() returned no events " - "while waiting condition variable " PTR_FMT, + "while waiting condition variable %p", cv); continue; } @@ -681,7 +680,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, if (kev.filter != EVFILT_SIGNAL) { ngx_log_error(NGX_LOG_ALERT, cv->log, 0, "kevent() returned unexpected events: %d " - "while waiting condition variable " PTR_FMT, + "while waiting condition variable %p", kev.filter, cv); continue; } @@ -689,7 +688,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, if (kev.ident != (uintptr_t) cv->signo) { ngx_log_error(NGX_LOG_ALERT, cv->log, 0, "kevent() returned unexpected signal: %d ", - "while waiting condition variable " PTR_FMT, + "while waiting condition variable %p", kev.ident, cv); continue; } @@ -697,8 +696,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, break; } - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " is waked up", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); if (ngx_mutex_lock(m) == NGX_ERROR) { return NGX_ERROR; @@ -713,7 +711,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv ngx_err_t err; ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " to signal " PID_T_FMT " %d", + "cv %p to signal %P %d", cv, cv->tid, cv->signo); if (kill(cv->tid, cv->signo) == -1) { @@ -721,8 +719,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv err = ngx_errno; ngx_log_error(NGX_LOG_ALERT, cv->log, err, - "kill() failed while signaling condition variable " - PTR_FMT, cv); + "kill() failed while signaling condition variable %p", cv); if (err == NGX_ESRCH) { cv->tid = -1; @@ -731,8 +728,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " is signaled", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv); return NGX_OK; } diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h --- a/src/os/unix/ngx_freebsd_rfork_thread.h +++ b/src/os/unix/ngx_freebsd_rfork_thread.h @@ -18,7 +18,7 @@ typedef pid_t ngx_tid_t; #define ngx_log_pid ngx_thread_self() #define ngx_log_tid 0 -#define TID_T_FMT PID_T_FMT +#define NGX_TID_T_FMT "%P" #define NGX_MUTEX_LIGHT 1 @@ -91,10 +91,10 @@ typedef ngx_uint_t ngx_tls extern void **ngx_tls; -ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key); +ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key); #define ngx_thread_key_create_n "the tls key creation" -ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value); +ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value); #define ngx_thread_set_tls_n "the tls key setting" diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -265,7 +265,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err, - "sendfile() sent only " OFF_T_FMT " bytes", + "sendfile() sent only %O bytes", sent); } else { @@ -290,14 +290,14 @@ ngx_chain_t *ngx_freebsd_sendfile_chain( } ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, - "sendfile: %d, @" OFF_T_FMT " " OFF_T_FMT ":%d", + "sendfile: %d, @%O %O:%uz", rc, file->file_pos, sent, fsize + hsize); } else { rc = writev(c->fd, header.elts, header.nelts); ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, - "writev: %d of " SIZE_T_FMT, rc, hsize); + "writev: %d of %uz", rc, hsize); if (rc == -1) { err = ngx_errno; diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -44,6 +44,7 @@ #include #include /* tzset() */ +#include /* memalign() */ #include #include diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -195,7 +195,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng sent = rc > 0 ? rc : 0; ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, - "sendfile: %d, @" OFF_T_FMT " %d:%d", + "sendfile: %d, @%O %z:%uz", rc, file->file_pos, sent, fsize); } else { @@ -221,7 +221,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ng sent = rc > 0 ? rc : 0; - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %d", sent); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %z", sent); } if (send - sprev == sent) { diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -134,7 +134,7 @@ ngx_int_t ngx_posix_init(ngx_log_t *log) void ngx_posix_status(ngx_log_t *log) { ngx_log_error(NGX_LOG_INFO, log, 0, - "getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT, + "getrlimit(RLIMIT_NOFILE): %r:%r", rlmt.rlim_cur, rlmt.rlim_max); } diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -143,7 +143,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t } ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "spawn %s: " PID_T_FMT, name, pid); + "spawn %s: %P", name, pid); ngx_processes[s].pid = pid; ngx_processes[s].exited = 0; @@ -282,22 +282,40 @@ void ngx_process_get_status() if (WTERMSIG(status)) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, - "%s " PID_T_FMT " exited on signal %d%s", + "%s %P exited on signal %d%s", process, pid, WTERMSIG(status), WCOREDUMP(status) ? " (core dumped)" : ""); } else { ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, - "%s " PID_T_FMT " exited with code %d", + "%s %P exited with code %d", process, pid, WEXITSTATUS(status)); } if (WEXITSTATUS(status) == 2 && ngx_processes[i].respawn) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, - "%s " PID_T_FMT - " exited with fatal code %d and could not respawn", - process, pid, WEXITSTATUS(status)); + "%s %P exited with fatal code %d and could not respawn", + process, pid, WEXITSTATUS(status)); ngx_processes[i].respawn = 0; } } } + + +void ngx_debug_point() +{ + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, + ngx_core_module); + + switch (ccf->debug_points) { + + case NGX_DEBUG_POINTS_STOP: + raise(SIGSTOP); + break; + + case NGX_DEBUG_POINTS_ABORT: + abort(); + } +} diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -53,6 +53,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t char *name, ngx_int_t respawn); ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx); void ngx_process_get_status(void); +void ngx_debug_point(void); #if (NGX_HAVE_SCHED_YIELD) diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -322,11 +322,10 @@ static void ngx_start_worker_processes(n } ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "pass channel s:%d pid:" PID_T_FMT - " fd:%d to s:%d pid:" PID_T_FMT " fd:%d", - ch.slot, ch.pid, ch.fd, - i, ngx_processes[i].pid, - ngx_processes[i].channel[0]); + "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d", + ch.slot, ch.pid, ch.fd, + i, ngx_processes[i].pid, + ngx_processes[i].channel[0]); /* TODO: NGX_AGAIN */ @@ -384,7 +383,7 @@ static void ngx_signal_worker_processes( for (i = 0; i < ngx_last_process; i++) { ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d", + "child: %d %P e:%d t:%d d:%d r:%d j:%d", i, ngx_processes[i].pid, ngx_processes[i].exiting, @@ -421,13 +420,12 @@ static void ngx_signal_worker_processes( } ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "kill (" PID_T_FMT ", %d)" , - ngx_processes[i].pid, signo); + "kill (%P, %d)" , ngx_processes[i].pid, signo); if (kill(ngx_processes[i].pid, signo) == -1) { err = ngx_errno; ngx_log_error(NGX_LOG_ALERT, cycle->log, err, - "kill(%d, %d) failed", + "kill(%P, %d) failed", ngx_processes[i].pid, signo); if (err == NGX_ESRCH) { @@ -459,7 +457,7 @@ static ngx_uint_t ngx_reap_childs(ngx_cy for (i = 0; i < ngx_last_process; i++) { ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d", + "child: %d %P e:%d t:%d d:%d r:%d j:%d", i, ngx_processes[i].pid, ngx_processes[i].exiting, @@ -492,8 +490,8 @@ static ngx_uint_t ngx_reap_childs(ngx_cy } ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "pass close channel s:%d pid:" PID_T_FMT - " to:" PID_T_FMT, ch.slot, ch.pid, ngx_processes[n].pid); + "pass close channel s:%i pid:%P to:%P", + ch.slot, ch.pid, ngx_processes[n].pid); /* TODO: NGX_AGAIN */ @@ -786,9 +784,19 @@ static void ngx_channel_handler(ngx_even n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log); - ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %d", n); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n); - if (n <= 0) { + if (n == NGX_ERROR) { + if (close(c->fd) == -1) { + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, + "close() channel failed"); + } + + c->fd = -1; + return; + } + + if (n == NGX_AGAIN) { return; } @@ -812,8 +820,7 @@ static void ngx_channel_handler(ngx_even case NGX_CMD_OPEN_CHANNEL: ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0, - "get channel s:%d pid:" PID_T_FMT " fd:%d", - ch.slot, ch.pid, ch.fd); + "get channel s:%i pid:%P fd:%d", ch.slot, ch.pid, ch.fd); ngx_processes[ch.slot].pid = ch.pid; ngx_processes[ch.slot].channel[0] = ch.fd; @@ -822,8 +829,7 @@ static void ngx_channel_handler(ngx_even case NGX_CMD_CLOSE_CHANNEL: ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0, - "close channel s:%d pid:" PID_T_FMT " our:" PID_T_FMT - " fd:%d", + "close channel s:%i pid:%P our:%P fd:%d", ch.slot, ch.pid, ngx_processes[ch.slot].pid, ngx_processes[ch.slot].channel[0]); @@ -882,7 +888,7 @@ static void ngx_wakeup_worker_threads(ng } -static void* ngx_worker_thread_cycle(void *data) +static void *ngx_worker_thread_cycle(void *data) { ngx_thread_t *thr = data; @@ -909,7 +915,7 @@ static void* ngx_worker_thread_cycle(voi } ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "thread " TID_T_FMT " started", ngx_thread_self()); + "thread " NGX_TID_T_FMT " started", ngx_thread_self()); ngx_setthrtitle("worker thread"); @@ -941,7 +947,8 @@ static void* ngx_worker_thread_cycle(voi ngx_mutex_unlock(ngx_posted_events_mutex); ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, - "thread %d is done", ngx_thread_self()); + "thread " NGX_TID_T_FMT " is done", + ngx_thread_self()); return (void *) 0; } diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c --- a/src/os/unix/ngx_pthread_thread.c +++ b/src/os/unix/ngx_pthread_thread.c @@ -15,14 +15,14 @@ static ngx_uint_t max_threads; static pthread_attr_t thr_attr; -int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log) +ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, + ngx_log_t *log) { int err; if (nthreads >= max_threads) { ngx_log_error(NGX_LOG_CRIT, log, 0, - "no more than %d threads can be created", max_threads); + "no more than %ui threads can be created", max_threads); return NGX_ERROR; } @@ -34,7 +34,7 @@ int ngx_create_thread(ngx_tid_t *tid, vo } ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, - "thread is created: " TID_T_FMT, *tid); + "thread is created: " NGX_TID_T_FMT, *tid); nthreads++; @@ -70,7 +70,7 @@ ngx_int_t ngx_init_threads(int n, size_t } -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags) +ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) { int err; ngx_mutex_t *m; @@ -101,7 +101,7 @@ void ngx_mutex_destroy(ngx_mutex_t *m) if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, - "pthread_mutex_destroy(" PTR_FMT ") failed", m); + "pthread_mutex_destroy(%p) failed", m); } ngx_free(m); @@ -116,18 +116,17 @@ ngx_int_t ngx_mutex_lock(ngx_mutex_t *m) return NGX_OK; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex " PTR_FMT, m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex %p", m); err = pthread_mutex_lock(&m->mutex); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, - "pthread_mutex_lock(" PTR_FMT ") failed", m); + "pthread_mutex_lock(%p) failed", m); return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is locked", m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); return NGX_OK; } @@ -141,8 +140,7 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t return NGX_OK; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "try lock mutex " PTR_FMT, m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "try lock mutex %p", m); err = pthread_mutex_trylock(&m->mutex); @@ -152,12 +150,11 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, - "pthread_mutex_trylock(" PTR_FMT ") failed", m); + "pthread_mutex_trylock(%p) failed", m); return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is locked", m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); return NGX_OK; } @@ -171,18 +168,17 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t * return NGX_OK; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex " PTR_FMT, m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex %p", m); err = pthread_mutex_unlock(&m->mutex); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, - "pthread_mutex_unlock(" PTR_FMT ") failed", m); + "pthread_mutex_unlock(%p) failed", m); return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is unlocked", m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m); return NGX_OK; } @@ -219,7 +215,7 @@ void ngx_cond_destroy(ngx_cond_t *cv) if (err != 0) { ngx_log_error(NGX_LOG_ALERT, cv->log, err, - "pthread_cond_destroy(" PTR_FMT ") failed", cv); + "pthread_cond_destroy(%p) failed", cv); } ngx_free(cv); @@ -230,22 +226,19 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, { int err; - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " wait", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p wait", cv); err = pthread_cond_wait(&cv->cond, &m->mutex); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, cv->log, err, - "pthread_cond_wait(" PTR_FMT ") failed", cv); + "pthread_cond_wait(%p) failed", cv); return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " is waked up", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); - ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, - "mutex " PTR_FMT " is locked", m); + ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); return NGX_OK; } @@ -255,19 +248,17 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv { int err; - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " to signal", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p to signal", cv); err = pthread_cond_signal(&cv->cond); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, cv->log, err, - "pthread_cond_signal(" PTR_FMT ") failed", cv); + "pthread_cond_signal(%p) failed", cv); return NGX_ERROR; } - ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, - "cv " PTR_FMT " is signaled", cv); + ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv); return NGX_OK; } diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c --- a/src/os/unix/ngx_shared.c +++ b/src/os/unix/ngx_shared.c @@ -18,8 +18,7 @@ void *ngx_create_shared_memory(size_t si if (p == MAP_FAILED) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - "mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed", - size); + "mmap(MAP_ANON|MAP_SHARED, %uz) failed", size); return NULL; } @@ -45,8 +44,7 @@ void *ngx_create_shared_memory(size_t si if (p == MAP_FAILED) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - "mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed", - size); + "mmap(/dev/zero, MAP_SHARED, %uz) failed", size); p = NULL; } @@ -72,7 +70,7 @@ void *ngx_create_shared_memory(size_t si if (id == -1) { ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, - "shmget(" SIZE_T_FMT ") failed", size); + "shmget(%uz) failed", size); return NULL; } diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h --- a/src/os/unix/ngx_socket.h +++ b/src/os/unix/ngx_socket.h @@ -15,7 +15,7 @@ typedef int ngx_socket_t; -#define ngx_socket(af, type, proto, flags) socket(af, type, proto) +#define ngx_socket socket #define ngx_socket_n "socket()" diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c --- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -136,8 +136,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain } ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err, - "sendfilev() sent only " SIZE_T_FMT " bytes", - sent); + "sendfilev() sent only %z bytes", sent); } else { wev->error = 1; @@ -147,7 +146,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain } ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, - "sendfilev: %d " SIZE_T_FMT, n, sent); + "sendfilev: %z %z", n, sent); if (send - sprev == sent) { complete = 1; diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h --- a/src/os/unix/ngx_thread.h +++ b/src/os/unix/ngx_thread.h @@ -29,9 +29,9 @@ typedef pthread_t ngx #define ngx_log_tid (int) ngx_thread_self() #if (NGX_FREEBSD) && !(NGX_LINUXTHREADS) -#define TID_T_FMT PTR_FMT +#define NGX_TID_T_FMT "%p" #else -#define TID_T_FMT "%d" +#define NGX_TID_T_FMT "%d" #endif @@ -92,11 +92,11 @@ extern volatile ngx_thread_t ngx_thread ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); -int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log); +ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, + ngx_log_t *log); -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags); +ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags); void ngx_mutex_destroy(ngx_mutex_t *m); @@ -110,8 +110,8 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv #define ngx_thread_volatile -#define ngx_log_tid 0 -#define TID_T_FMT "%d" +#define ngx_log_tid 0 +#define NGX_TID_T_FMT "%d" #define ngx_mutex_trylock(m) NGX_OK #define ngx_mutex_lock(m) NGX_OK diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c --- a/src/os/unix/ngx_writev_chain.c +++ b/src/os/unix/ngx_writev_chain.c @@ -9,14 +9,14 @@ #include -#define NGX_IOVS 8 +#define NGX_IOVS 16 ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) { u_char *prev; - ssize_t n, size; - off_t send, sprev, sent; + ssize_t n, size, sent; + off_t send, sprev; ngx_uint_t eintr, complete; ngx_err_t err; ngx_array_t vec; @@ -66,6 +66,12 @@ ngx_chain_t *ngx_writev_chain(ngx_connec continue; } +#if 1 + if (!ngx_buf_in_memory(cl->buf)) { + ngx_debug_point(); + } +#endif + size = cl->buf->last - cl->buf->pos; if (send + size > limit) { @@ -110,8 +116,7 @@ ngx_chain_t *ngx_writev_chain(ngx_connec sent = n > 0 ? n : 0; - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, - "writev: " OFF_T_FMT, sent); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %z", sent); if (send - sprev == sent) { complete = 1; @@ -119,7 +124,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connec c->sent += sent; - for (cl = in; cl && sent > 0; cl = cl->next) { + for (cl = in; cl; cl = cl->next) { + if (ngx_buf_special(cl->buf)) { continue; }