nginx-0.1.5-RELEASE import

*) 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.
This commit is contained in:
Igor Sysoev 2004-11-11 14:07:14 +00:00
parent d6f2495942
commit 1b73583ba2
132 changed files with 3036 additions and 1994 deletions

View File

@ -32,17 +32,31 @@ CFLAGS="$CFLAGS -w!"
# disable logo # disable logo
CFLAGS="$CFLAGS -q" CFLAGS="$CFLAGS -q"
# precompiled headers # precompiled headers
CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.csm" CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.csm"
NGX_PCH="$OBJS/ngx_config.csm" NGX_PCH="$OBJS/ngx_config.csm"
NGX_BUILD_PCH="-H=$OBJS/ngx_config.csm" NGX_BUILD_PCH="-H=$OBJS/ngx_config.csm"
NGX_USE_PCH="-Hu -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_include_opt="-I"
ngx_objout="-o" ngx_objout="-o"
ngx_binout="-e" ngx_binout="-e"
ngx_objext="obj" ngx_objext="obj"
ngx_binext=".exe" ngx_binext=".exe"
ngx_dirsep='\\'
ngx_regex_dirsep='\\'
ngx_dirsep="\\"

View File

@ -64,8 +64,8 @@ else
# . auto/cc/acc # . auto/cc/acc
# ;; # ;;
msvc) msvc*)
# MSVC 6.0 SP2 # MSVC++ 6.0 SP2, MSVC++ Toolkit 2003
. auto/cc/msvc . auto/cc/msvc
;; ;;
@ -93,6 +93,22 @@ CFLAGS="$CFLAGS $NGX_CC_OPT"
if [ "$PLATFORM" != win32 ]; then 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="gcc variadic macros"
ngx_feature_name=HAVE_GCC_VARIADIC_MACROS ngx_feature_name=HAVE_GCC_VARIADIC_MACROS
ngx_feature_run=yes ngx_feature_run=yes

View File

@ -104,6 +104,3 @@ if [ ".$CPP" = "." ]; then
fi fi
LINK="\$(CC)" LINK="\$(CC)"
CC_STRONG="-Wall -Werror"

View File

@ -64,6 +64,3 @@ CFLAGS="$CFLAGS -Werror"
CFLAGS="$CFLAGS -g" CFLAGS="$CFLAGS -g"
LINK="\$(CC)" LINK="\$(CC)"
CC_STRONG="-w1 -Werror"

View File

@ -2,7 +2,7 @@
# Copyright (C) Igor Sysoev # Copyright (C) Igor Sysoev
# MSVC 6.0 SP2 # MSVC 6.0 SP2, MSVC Toolkit 2003 (7.1)
# optimizations # optimizations
@ -31,8 +31,8 @@ case $CPU in
;; ;;
pentium4) pentium4)
# optimize for Pentium 4 # optimize for Pentium 4, MSVC 7
#CPU_OPT="-G7" CPU_OPT="-G7"
;; ;;
esac esac
@ -47,30 +47,48 @@ CFLAGS="$CFLAGS -W4"
# stop on warning # stop on warning
CFLAGS="$CFLAGS -WX" CFLAGS="$CFLAGS -WX"
# link with libcmt.lib, multithreaded
#LIBC="-MT"
# link with msvcrt.dll
LIBC="-MD"
CFLAGS="$CFLAGS $LIBC"
# disable logo # disable logo
CFLAGS="$CFLAGS -nologo" CFLAGS="$CFLAGS -nologo"
LINK="\$(CC)" LINK="\$(CC)"
# link flags # the link flags
CORE_LINK="$CORE_LINK -link -verbose:lib" 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"
# Win32 GUI mode application
CORE_LIBS="$CORE_LIBS kernel32.lib user32.lib"
CORE_LINK="$CORE_LINK -subsystem:windows -entry:mainCRTStartup"
# debug # debug
CFLAGS="$CFLAGS -Yd" CFLAGS="$CFLAGS -Yd"
CORE_LINK="$CORE_LINK -debug -debugtype:coff" CORE_LINK="$CORE_LINK -debug -debugtype:coff"
# precompiled headers # precompiled headers
CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch" if [ $NGX_CC_NAME != msvc7 ]; then
NGX_PCH="$OBJS/ngx_config.pch" CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch" NGX_PCH="$OBJS/ngx_config.pch"
NGX_USE_PCH="-Yungx_config.h -Fp$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_objout="-Fo"
ngx_binout="-Fe" ngx_binout="-Fe"

View File

@ -6,8 +6,17 @@ echo $ngx_n "checking for C compiler ...$ngx_c"
if [ $CC = cl ]; then if [ $CC = cl ]; then
NGX_CC_NAME=msvc if `$NGX_WINE $CC -v 2>&1 \
echo " using Microsoft Visual C compiler" | 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 else
if [ $CC = wcl386 ]; then if [ $CC = wcl386 ]; then

View File

@ -59,18 +59,25 @@ CFLAGS="$CFLAGS -d2"
CFLAGS="$CFLAGS -zq" CFLAGS="$CFLAGS -zq"
# Open Watcom C 1.2 # 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" CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
NGX_PCH="$OBJS/ngx_config.pch" NGX_PCH="$OBJS/ngx_config.pch"
NGX_BUILD_PCH="-fhq=$OBJS/ngx_config.pch" NGX_BUILD_PCH="-fhq=$OBJS/ngx_config.pch"
NGX_USE_PCH="-fh=$OBJS/ngx_config.pch" NGX_USE_PCH="-fh=$OBJS/ngx_config.pch"
LINK="\$(CC)" LINK="\$(CC)"
# link flags # the link flags, built target is NT GUI mode application
CORE_LINK="$CORE_LINK -l=nt" 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_include_opt="-i="
ngx_objout="-fo" ngx_objout="-fo"

View File

@ -35,6 +35,7 @@ END
ngx_test="$CC $CC_TEST_FLAGS $CC_WARN $CC_AUX_FLAGS \ ngx_test="$CC $CC_TEST_FLAGS $CC_WARN $CC_AUX_FLAGS \
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs" -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"

View File

@ -17,12 +17,12 @@ if [ $MD5 != NONE ]; then
case "$NGX_CC_NAME" in case "$NGX_CC_NAME" in
msvc | owc | bcc) msvc* | owc* | bcc)
LINK_DEPS="$LINK_DEPS $MD5/md5.lib" LINK_DEPS="$LINK_DEPS $MD5/md5.lib"
CORE_LIBS="$CORE_LIBS $MD5/md5.lib" CORE_LIBS="$CORE_LIBS $MD5/md5.lib"
;; ;;
icc) icc*)
LINK_DEPS="$LINK_DEPS $MD5/libmd5.a" LINK_DEPS="$LINK_DEPS $MD5/libmd5.a"
# to allow -ipo optimization we link with the *.o but not library # to allow -ipo optimization we link with the *.o but not library

View File

@ -9,7 +9,7 @@ if [ $PCRE != NONE ]; then
case "$NGX_CC_NAME" in case "$NGX_CC_NAME" in
msvc | owc | bcc) msvc* | owc* | bcc)
have=NGX_PCRE . auto/have have=NGX_PCRE . auto/have
have=PCRE_STATIC . auto/have have=PCRE_STATIC . auto/have
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h" CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
@ -17,7 +17,7 @@ if [ $PCRE != NONE ]; then
CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib" CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib"
;; ;;
icc) icc*)
have=NGX_PCRE . auto/have have=NGX_PCRE . auto/have
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h" CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"

View File

@ -7,12 +7,12 @@ if [ $ZLIB != NONE ]; then
case "$NGX_CC_NAME" in case "$NGX_CC_NAME" in
msvc | owc | bcc) msvc* | owc* | bcc)
LINK_DEPS="$LINK_DEPS $ZLIB/zlib.lib" LINK_DEPS="$LINK_DEPS $ZLIB/zlib.lib"
CORE_LIBS="$CORE_LIBS $ZLIB/zlib.lib" CORE_LIBS="$CORE_LIBS $ZLIB/zlib.lib"
;; ;;
icc) icc*)
LINK_DEPS="$LINK_DEPS $ZLIB/libz.a" LINK_DEPS="$LINK_DEPS $ZLIB/libz.a"
# to allow -ipo optimization we link with the *.o but not library # to allow -ipo optimization we link with the *.o but not library

View File

@ -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_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" \ | sed -e "s/ *\([^ ][^ ]*\)/$ngx_regex_cont\1/g" \
-e "s/\//$ngx_regex_dirsep/g"` -e "s/\//$ngx_regex_dirsep/g"`
@ -146,10 +154,12 @@ ngx_libs=${CORE_LIBS:+`echo $NGX_LD_OPT $CORE_LIBS \
ngx_link=${CORE_LINK:+`echo $CORE_LINK \ ngx_link=${CORE_LINK:+`echo $CORE_LINK \
| sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_regex_cont/"`} | sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_regex_cont/"`}
cat << END >> $NGX_MAKEFILE cat << END >> $NGX_MAKEFILE
$NGX_OBJS${ngx_dirsep}nginx${ngx_binext}: $ngx_deps$ngx_spacer $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 \$(LINK) ${ngx_binout}$NGX_OBJS${ngx_dirsep}nginx$ngx_cont$ngx_objs$ngx_libs$ngx_link
$ngx_rcc
END END
@ -256,6 +266,24 @@ END
fi 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 # the precompiled headers
if test -n "$NGX_PCH"; then if test -n "$NGX_PCH"; then

View File

@ -154,9 +154,14 @@ if [ $IMAP = YES ]; then
fi fi
echo "#include <ngx_config.h>" > $NGX_MODULES_C cat << END > $NGX_MODULES_C
echo "#include <ngx_core.h>" >> $NGX_MODULES_C
echo >> $NGX_MODULES_C #include <ngx_config.h>
#include <ngx_core.h>
$NGX_PRAGMA
END
for mod in $modules for mod in $modules
do do
@ -171,5 +176,8 @@ do
echo " &$mod," >> $NGX_MODULES_C echo " &$mod," >> $NGX_MODULES_C
done done
echo " NULL" >> $NGX_MODULES_C cat << END >> $NGX_MODULES_C
echo "};" >> $NGX_MODULES_C NULL
};
END

View File

@ -26,6 +26,9 @@ TEST_BUILD_DEVPOLL=NO
TEST_BUILD_EPOLL=NO TEST_BUILD_EPOLL=NO
TEST_BUILD_RTSIG=NO TEST_BUILD_RTSIG=NO
PLATFORM=
NGX_WINE=
EVENT_FOUND=NO EVENT_FOUND=NO
EVENT_RTSIG=NO EVENT_RTSIG=NO
@ -195,9 +198,8 @@ if [ $HTTP = NO ]; then
fi fi
if [ ".$PLATFORM" = ".win32" -a $EVENT_POLL = YES ]; then if [ ".$PLATFORM" = ".win32" ]; then
EVENT_POLL=NO NGX_WINE=$WINE
echo "$0: warning: --with-poll_module option is ignored for win32"
fi fi
@ -211,12 +213,6 @@ if test -z "$NGX_GROUP"; then
fi fi
if test -z "$NGX_USER"; then
NGX_USER=nobody
NGX_GROUP=nobody
fi
case ".$SBIN_PATH" in case ".$SBIN_PATH" in
./*) ./*)
;; ;;

View File

@ -45,6 +45,12 @@ esac
if [ $PLATFORM != win32 ]; then if [ $PLATFORM != win32 ]; then
if test -z "$NGX_USER"; then
NGX_USER=nobody
NGX_GROUP=nobody
fi
ngx_feature="/dev/poll" ngx_feature="/dev/poll"
ngx_feature_name="devpoll" ngx_feature_name="devpoll"
ngx_feature_run=no ngx_feature_run=no

View File

@ -20,6 +20,13 @@ ngx_spacer='
CC_AUX_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64" 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 # Linux kernel version
version=`grep "#define LINUX_VERSION_CODE" /usr/include/linux/version.h \ version=`grep "#define LINUX_VERSION_CODE" /usr/include/linux/version.h \

View File

@ -15,7 +15,8 @@ CORE_INCS="$WIN32_INCS"
CORE_DEPS="$WIN32_DEPS" CORE_DEPS="$WIN32_DEPS"
CORE_SRCS="$WIN32_SRCS $IOCP_SRCS" CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
OS_CONFIG="$WIN32_CONFIG" 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_MODULES="$EVENT_MODULES $IOCP_MODULE"
EVENT_FOUND=YES EVENT_FOUND=YES

View File

@ -175,8 +175,10 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
src/os/win32/ngx_shared.h \ src/os/win32/ngx_shared.h \
src/os/win32/ngx_process.h \ src/os/win32/ngx_process.h \
src/os/win32/ngx_atomic.h \ src/os/win32/ngx_atomic.h \
src/os/win32/ngx_thread.h \
src/os/win32/ngx_socket.h \ src/os/win32/ngx_socket.h \
src/os/win32/ngx_os.h \ src/os/win32/ngx_os.h \
src/os/win32/ngx_gui.h \
src/os/win32/ngx_process_cycle.h" src/os/win32/ngx_process_cycle.h"
WIN32_CONFIG=src/os/win32/ngx_win32_config.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_files.c \
src/os/win32/ngx_time.c \ src/os/win32/ngx_time.c \
src/os/win32/ngx_process.c \ src/os/win32/ngx_process.c \
src/os/win32/ngx_thread.c \
src/os/win32/ngx_socket.c \ src/os/win32/ngx_socket.c \
src/os/win32/ngx_wsarecv.c \ src/os/win32/ngx_wsarecv.c \
src/os/win32/ngx_wsarecv_chain.c \ src/os/win32/ngx_wsarecv_chain.c \
src/os/win32/ngx_wsasend_chain.c \ src/os/win32/ngx_wsasend_chain.c \
src/os/win32/ngx_win32_init.c \ src/os/win32/ngx_win32_init.c \
src/os/win32/ngx_gui.c \
src/os/win32/ngx_process_cycle.c \ src/os/win32/ngx_process_cycle.c \
src/event/ngx_event_acceptex.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 \ HTTP_MODULES="ngx_http_module \
ngx_http_core_module \ ngx_http_core_module \

View File

@ -8,17 +8,17 @@ ngx_fmt_collect=yes
# C types # C types
ngx_type="int"; . auto/types/sizeof 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_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_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_type="void *"; . auto/types/sizeof; ngx_ptr_size=$ngx_size
ngx_fmt_name=PTR_FMT; #ngx_fmt_name=PTR_FMT;
eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt #eval ngx_formats=\${ngx_${ngx_ptr_size}_fmt}; . auto/fmt/ptrfmt
# POSIX types # POSIX types
@ -46,28 +46,28 @@ ngx_type="rlim_t"; ngx_types="int"; . auto/types/typedef
# printf() formats # printf() formats
CC_WARN=$CC_STRONG #CC_WARN=$CC_STRONG
ngx_fmt_collect=no #ngx_fmt_collect=no
#
ngx_fmt_name=OFF_T_FMT; ngx_type="off_t"; . auto/types/sizeof #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 ngx_param=OFF_T_MAX_VALUE; ngx_value=$ngx_max_value; . auto/types/value
eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt #eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
#
ngx_fmt_name=TIME_T_FMT; ngx_type="time_t"; . auto/types/sizeof #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_SIZE; ngx_value=$ngx_size; . auto/types/value
ngx_param=TIME_T_LEN; ngx_value=$ngx_max_len; . 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 #eval ngx_formats=\${ngx_${ngx_size}_fmt}; . auto/fmt/fmt
#
ngx_fmt_name=SIZE_T_FMT; ngx_type="size_t"; . auto/types/sizeof #ngx_fmt_name=SIZE_T_FMT; ngx_type="size_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_X_FMT; . auto/fmt/xfmt #ngx_fmt_name=SIZE_T_X_FMT; . auto/fmt/xfmt
#
ngx_fmt_name=PID_T_FMT; ngx_type="pid_t"; . auto/types/sizeof #ngx_fmt_name=PID_T_FMT; ngx_type="pid_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=RLIM_T_FMT; ngx_type="rlim_t"; . auto/types/sizeof #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
# syscalls, libc calls and some features # syscalls, libc calls and some features
@ -93,19 +93,23 @@ ngx_feature_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0)"
ngx_feature="strerror_r()" ngx_feature="strerror_r()"
ngx_feature_name="strerror_r" ngx_feature_name="strerror_r"
ngx_feature_run=no ngx_feature_run=yes
ngx_feature_incs="#include <string.h>" ngx_feature_incs="#include <string.h>"
ngx_feature_libs= 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 . 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_name="gnu_strerror_r"
ngx_feature_run=no ngx_feature_run=yes
ngx_feature_incs="#include <string.h>" ngx_feature_incs="#include <string.h>"
ngx_feature_libs= 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 . auto/feature
@ -184,16 +188,6 @@ ngx_feature_test="int id;
. auto/feature . auto/feature
ngx_feature="struct sockaddr_in.sin_len"
ngx_feature_name="sin_len"
ngx_feature_run=no
ngx_feature_incs="#include <sys/socket.h>
#include <netinet/in.h>"
ngx_feature_libs=
ngx_feature_test="struct sockaddr_in sa; sa.sin_len = 5"
. auto/feature
ngx_feature="struct msghdr.msg_control" ngx_feature="struct msghdr.msg_control"
ngx_feature_name="msghdr_msg_control" ngx_feature_name="msghdr_msg_control"
ngx_feature_run=no ngx_feature_run=no

View File

@ -6,6 +6,92 @@
title="nginx"> title="nginx">
<changes ver="0.1.5" date="11.11.2004">
<change type="bugfix">
<para lang="ru">
ÎÁ Solaris É Linux ÍÏÇÌÏ ÂÙÔØ ÏÞÅÎØ ÍÎÏÇÏ ÓÏÏÂÝÅÎÉÊ "recvmsg() returned
not enough data".
</para>
<para lang="en">
on Solaris and Linux there may be too many "recvmsg() returned not enough data"
alerts.
</para>
</change>
<change type="bugfix">
<para lang="ru">
× ÒÅÖÉÍÅ ÐÒÏËÓÉ ÂÅÚ ÉÓÐÏÌØÚÏ×ÁÎÉÑ sendfile ÎÁ Solaris ×ÏÚÎÉËÁÌÁ
ÏÛÉÂËÁ "writev() failed (22: Invalid argument)". îÁ ÄÒÕÇÉÈ ÐÌÁÔÆÏÒÍÁÈ,
ÎÅ ÐÏÄÄÅÒÖÉ×ÁÀÝÉÈ sendfile, ÐÒÏÃÅÓÓ ÚÁÃÉËÌÉ×ÁÌÓÑ.
</para>
<para lang="en">
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.
</para>
</change>
<change type="bugfix">
<para lang="ru">
ÐÒÉ ÉÓÐÏÌØÚÏ×ÁÎÉÉ sendfile × ÒÅÖÉÍÅ ÐÒÏËÓÉ ÎÁ Solaris ×ÏÚÎÉËÁÌ
segmentation fault.
</para>
<para lang="en">
segmentation fault on Solaris in proxy mode and using sendfile.
</para>
</change>
<change type="bugfix">
<para lang="ru">
segmentation fault ÎÁ Solaris.
</para>
<para lang="en">
segmentation fault on Solaris.
</para>
</change>
<change type="bugfix">
<para lang="ru">
ÏÂÎÏ×ÌÅÎÉÅ ÉÓÐÏÌÎÑÅÍÏÇÏ ÆÁÊÌÁ ÎÁ ÌÅÔÕ ÎÅ ÒÁÂÏÔÁÌÏ ÎÁ Linux.
</para>
<para lang="en">
on-line upgrade did not work on Linux.
</para>
</change>
<change type="bugfix">
<para lang="ru">
× ÓÐÉÓËÅ ÆÁÊÌÏ×, ×ÙÄÁ×ÁÅÍÏÍ ÍÏÄÕÌÅÍ ngx_http_autoindex_module,
ÎÅ ÐÅÒÅËÏÄÉÒÏ×ÁÌÉÓØ ÐÒÏÂÅÌÙ, ËÁ×ÙÞËÉ É ÚÎÁËÉ ÐÒÏÃÅÎÔÁ.
</para>
<para lang="en">
the ngx_http_autoindex_module module did not escape the spaces,
the quotes, and the percent signs in the directory listing.
</para>
</change>
<change type="change">
<para lang="ru">
ÕÍÅÎØÛÅÎÉÅ ÏÐÅÒÁÃÉÊ ËÏÐÉÒÏ×ÁÎÉÑ.
</para>
<para lang="en">
the decrease of the copy operations.
</para>
</change>
<change type="feature">
<para lang="ru">
ÄÉÒÅËÔÉ×Á userid_p3p.
</para>
<para lang="en">
the userid_p3p directive.
</para>
</change>
</changes>
<changes ver="0.1.4" date="26.10.2004"> <changes ver="0.1.4" date="26.10.2004">
<change type="bugfix"> <change type="bugfix">

View File

@ -18,6 +18,13 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 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[] = { static ngx_command_t ngx_core_commands[] = {
{ ngx_string("daemon"), { ngx_string("daemon"),
@ -41,6 +48,13 @@ static ngx_command_t ngx_core_commands[] = {
offsetof(ngx_core_conf_t, worker_processes), offsetof(ngx_core_conf_t, worker_processes),
NULL }, 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) #if (NGX_THREADS)
{ ngx_string("worker_threads"), { ngx_string("worker_threads"),
@ -97,6 +111,7 @@ ngx_module_t ngx_core_module = {
ngx_uint_t ngx_max_module; ngx_uint_t ngx_max_module;
int main(int argc, char *const *argv, char *const *envp) int main(int argc, char *const *argv, char *const *envp)
{ {
ngx_int_t i; ngx_int_t i;
@ -118,7 +133,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_pid = ngx_getpid(); ngx_pid = ngx_getpid();
if (!(log = ngx_log_init_stderr())) { if (!(log = ngx_log_init())) {
return 1; return 1;
} }
@ -165,7 +180,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (cycle == NULL) { if (cycle == NULL) {
if (ngx_test_config) { if (ngx_test_config) {
ngx_log_error(NGX_LOG_EMERG, log, 0, 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); init_cycle.conf_file.data);
} }
@ -174,7 +189,7 @@ int main(int argc, char *const *argv, char *const *envp)
if (ngx_test_config) { if (ngx_test_config) {
ngx_log_error(NGX_LOG_INFO, log, 0, 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); cycle->conf_file.data);
return 0; return 0;
} }
@ -187,7 +202,7 @@ int main(int argc, char *const *argv, char *const *envp)
ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE;
#if (WIN32) #if (NGX_WIN32)
#if 0 #if 0
@ -241,11 +256,14 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
return NGX_OK; 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); "using inherited sockets from \"%s\"", inherited);
ngx_init_array(cycle->listening, cycle->pool, if (ngx_array_init(&cycle->listening, cycle->pool, 10,
10, sizeof(ngx_listening_t), NGX_ERROR); sizeof(ngx_listening_t)) == NGX_ERROR)
{
return NGX_ERROR;
}
for (p = inherited, v = p; *p; p++) { for (p = inherited, v = p; *p; p++) {
if (*p == ':' || *p == ';') { if (*p == ':' || *p == ';') {
@ -260,7 +278,7 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
v = p + 1; v = p + 1;
if (!(ls = ngx_push_array(&cycle->listening))) { if (!(ls = ngx_array_push(&cycle->listening))) {
return NGX_ERROR; return NGX_ERROR;
} }
@ -276,7 +294,8 @@ static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) 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_uint_t i;
ngx_pid_t pid; ngx_pid_t pid;
ngx_exec_ctx_t ctx; ngx_exec_ctx_t ctx;
@ -290,20 +309,22 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
+ cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
cycle->log); 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; ls = cycle->listening.elts;
for (i = 0; i < cycle->listening.nelts; i++) { 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); ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, "inherited: %s", var);
env[0] = var; env[0] = var;
#if (NGX_SETPROCTITLE_USES_ENV) #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" env[1] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@ -430,12 +451,13 @@ static void *ngx_core_module_create_conf(ngx_cycle_t *cycle)
ccf->daemon = NGX_CONF_UNSET; ccf->daemon = NGX_CONF_UNSET;
ccf->master = NGX_CONF_UNSET; ccf->master = NGX_CONF_UNSET;
ccf->worker_processes = NGX_CONF_UNSET; ccf->worker_processes = NGX_CONF_UNSET;
#if (NGX_THREADS) ccf->debug_points = NGX_CONF_UNSET;
ccf->worker_threads = NGX_CONF_UNSET;
ccf->thread_stack_size = NGX_CONF_UNSET;
#endif
ccf->user = (ngx_uid_t) NGX_CONF_UNSET; ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
ccf->group = (ngx_gid_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_SIZE;
#endif
return ccf; return ccf;
} }
@ -445,7 +467,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{ {
ngx_core_conf_t *ccf = conf; ngx_core_conf_t *ccf = conf;
#if !(WIN32) #if !(NGX_WIN32)
struct passwd *pwd; struct passwd *pwd;
struct group *grp; struct group *grp;
#endif #endif
@ -453,6 +475,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_value(ccf->daemon, 1); ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1); ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->worker_processes, 1); ngx_conf_init_value(ccf->worker_processes, 1);
ngx_conf_init_value(ccf->debug_points, 0);
#if (NGX_THREADS) #if (NGX_THREADS)
ngx_conf_init_value(ccf->worker_threads, 0); ngx_conf_init_value(ccf->worker_threads, 0);
@ -460,9 +483,9 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024);
#endif #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); pwd = getpwnam(NGX_USER);
if (pwd == NULL) { if (pwd == NULL) {
@ -509,7 +532,7 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 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, ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
"\"user\" is not supported, ignored"); "\"user\" is not supported, ignored");

View File

@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_ #define _NGINX_H_INCLUDED_
#define NGINX_VER "nginx/0.1.4" #define NGINX_VER "nginx/0.1.5"
#define NGINX_VAR "NGINX" #define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin" #define NGX_NEWPID_EXT ".newbin"

View File

@ -73,7 +73,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN); fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
if (fd == NGX_INVALID_FILE) { if (fd == NGX_INVALID_FILE) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, 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; return NGX_CONF_ERROR;
} }
@ -84,7 +84,7 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) {
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, 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))) { 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_str_t *filename)
rc = ngx_conf_read_token(cf); rc = ngx_conf_read_token(cf);
/* /*
* ngx_conf_read_token() returns NGX_OK, NGX_ERROR, * ngx_conf_read_token() may return
* NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE * 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 #if 0
@ -115,13 +119,16 @@ ngx_log_debug(cf->log, "token %d" _ rc);
break; break;
} }
if (rc != NGX_OK) { if (rc != NGX_OK && rc != NGX_CONF_BLOCK_START) {
break; break;
} }
if (cf->handler) { 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); rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) { if (rv == NGX_CONF_OK) {
@ -182,6 +189,31 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
break; 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 ? */ /* is the directive's argument count right ? */
if (cmd->type & NGX_CONF_ANY) { if (cmd->type & NGX_CONF_ANY) {
@ -396,10 +428,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
continue; continue;
} }
if (ch == ';' || ch == '{') { if (ch == ';') {
return NGX_OK; return NGX_OK;
} }
if (ch == '{') {
return NGX_CONF_BLOCK_START;
}
ngx_log_error(NGX_LOG_EMERG, cf->log, 0, ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"unexpected '%c' in %s:%d", "unexpected '%c' in %s:%d",
ch, cf->conf_file->file.name.data, ch, cf->conf_file->file.name.data,
@ -427,6 +463,10 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
return NGX_ERROR; return NGX_ERROR;
} }
if (ch == '{') {
return NGX_CONF_BLOCK_START;
}
return NGX_OK; return NGX_OK;
case '}': case '}':
@ -538,10 +578,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
#endif #endif
if (ch == ';' || ch == '{') { if (ch == ';') {
return NGX_OK; return NGX_OK;
} }
if (ch == '{') {
return NGX_CONF_BLOCK_START;
}
found = 0; found = 0;
} }
} }
@ -575,6 +619,18 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
return NGX_OK; 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; old = *name;
name->len = cycle->root.len + old.len; name->len = cycle->root.len + old.len;
@ -664,20 +720,22 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...) char *fmt, ...)
{ {
int len; u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
char errstr[NGX_MAX_CONF_ERRSTR];
va_list args; va_list args;
last = errstr + NGX_MAX_CONF_ERRSTR;
va_start(args, fmt); va_start(args, fmt);
len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args); buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
va_end(args); va_end(args);
*buf = '\0';
if (err) { if (err) {
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1, buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
" (%d: ", err); buf = ngx_strerror_r(err, buf, last - buf - 1);
len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1); *buf++ = ')';
errstr[len++] = ')'; *buf = '\0';
errstr[len] = '\0';
} }
ngx_log_error(level, cf->log, 0, "%s in %s:%d", ngx_log_error(level, cf->log, 0, "%s in %s:%d",

View File

@ -59,8 +59,9 @@
#define NGX_CONF_OK NULL #define NGX_CONF_OK NULL
#define NGX_CONF_ERROR (char *) -1 #define NGX_CONF_ERROR (char *) -1
#define NGX_CONF_BLOCK_DONE 1 #define NGX_CONF_BLOCK_START 1
#define NGX_CONF_FILE_DONE 2 #define NGX_CONF_BLOCK_DONE 2
#define NGX_CONF_FILE_DONE 3
#define NGX_MODULE 0, 0 #define NGX_MODULE 0, 0

View File

@ -39,7 +39,7 @@
#endif #endif
#if !(WIN32) #if !(NGX_WIN32)
#define ngx_signal_helper(n) SIG##n #define ngx_signal_helper(n) SIG##n
#define ngx_signal_value(n) ngx_signal_helper(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 u_int ngx_uint_t;
typedef int ngx_flag_t; typedef int ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-2147483648") - 1 #define NGX_INT_T_LEN sizeof("-2147483648") - 1
#define NGX_INT_T_FMT "d"
#define NGX_UINT_T_FMT "u"
#else #else
@ -81,8 +79,6 @@ typedef long ngx_int_t;
typedef u_long ngx_uint_t; typedef u_long ngx_uint_t;
typedef long ngx_flag_t; typedef long ngx_flag_t;
#define NGX_INT_T_LEN sizeof("-9223372036854775808") - 1 #define NGX_INT_T_LEN sizeof("-9223372036854775808") - 1
#define NGX_INT_T_FMT "lld"
#define NGX_UINT_T_FMT "llu"
#endif #endif
@ -131,5 +127,12 @@ typedef long ngx_flag_t;
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN #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_ */ #endif /* _NGX_CONFIG_H_INCLUDED_ */

View File

@ -30,28 +30,27 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
return NULL; return NULL;
} }
#if (HAVE_SIN_LEN)
addr_in->sin_len = sizeof(struct sockaddr_in);
#endif
addr_in->sin_family = AF_INET; addr_in->sin_family = AF_INET;
addr_in->sin_addr.s_addr = addr; addr_in->sin_addr.s_addr = addr;
addr_in->sin_port = htons(port); 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; return NULL;
} }
len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, INET_ADDRSTRLEN); 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->fd = (ngx_socket_t) -1;
ls->family = AF_INET; ls->family = AF_INET;
ls->type = SOCK_STREAM; ls->type = SOCK_STREAM;
ls->protocol = IPPROTO_IP; ls->protocol = IPPROTO_IP;
#if (WIN32)
ls->flags = WSA_FLAG_OVERLAPPED;
#endif
ls->sockaddr = (struct sockaddr *) addr_in; ls->sockaddr = (struct sockaddr *) addr_in;
ls->socklen = sizeof(struct sockaddr_in); ls->socklen = sizeof(struct sockaddr_in);
ls->addr = offsetof(struct sockaddr_in, sin_addr); ls->addr = offsetof(struct sockaddr_in, sin_addr);
@ -63,6 +62,7 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle) ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
{ {
size_t len;
ngx_uint_t i; ngx_uint_t i;
ngx_listening_t *ls; ngx_listening_t *ls;
struct sockaddr_in *addr_in; struct sockaddr_in *addr_in;
@ -95,20 +95,26 @@ ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
ls[i].ignore = 1; ls[i].ignore = 1;
continue; continue;
} }
ls[i].addr_text_max_len = INET_ADDRSTRLEN; 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) { if (ls[i].addr_text.data == NULL) {
return NGX_ERROR; return NGX_ERROR;
} }
ls[i].family = addr_in->sin_family; ls[i].family = addr_in->sin_family;
ls[i].addr_text.len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr, len = ngx_sock_ntop(ls[i].family, ls[i].sockaddr,
ls[i].addr_text.data, ls[i].addr_text.data, INET_ADDRSTRLEN);
ls[i].addr_text_max_len); if (len == 0) {
if (ls[i].addr_text.len == 0) {
return NGX_ERROR; 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; return NGX_OK;
@ -157,16 +163,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
continue; continue;
} }
s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol, s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol);
ls[i].flags);
if (s == -1) { if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, 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; return NGX_ERROR;
} }
#if (WIN32) #if (NGX_WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number 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_cycle_t *cycle)
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(const void *) &reuseaddr, sizeof(int)) == -1) { (const void *) &reuseaddr, sizeof(int)) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
"setsockopt(SO_REUSEADDR) %s failed", "setsockopt(SO_REUSEADDR) %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
return NGX_ERROR; return NGX_ERROR;
} }
@ -192,8 +197,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) { if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
if (ngx_nonblocking(s) == -1) { if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_nonblocking_n " %s failed", ngx_nonblocking_n " %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
return NGX_ERROR; return NGX_ERROR;
} }
} }
@ -202,8 +207,8 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (ls[i].nonblocking) { if (ls[i].nonblocking) {
if (ngx_nonblocking(s) == -1) { if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_nonblocking_n " %s failed", ngx_nonblocking_n " %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
return NGX_ERROR; return NGX_ERROR;
} }
} }
@ -212,15 +217,15 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) { if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) {
err = ngx_socket_errno; err = ngx_socket_errno;
ngx_log_error(NGX_LOG_EMERG, log, err, 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) if (err != NGX_EADDRINUSE)
return NGX_ERROR; return NGX_ERROR;
if (ngx_close_socket(s) == -1) if (ngx_close_socket(s) == -1)
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_close_socket_n " %s failed", ngx_close_socket_n " %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
failed = 1; failed = 1;
continue; continue;
@ -228,7 +233,7 @@ ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
if (listen(s, ls[i].backlog) == -1) { if (listen(s, ls[i].backlog) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, 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; return NGX_ERROR;
} }
@ -273,7 +278,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
for (i = 0; i < cycle->listening.nelts; i++) { for (i = 0; i < cycle->listening.nelts; i++) {
fd = ls[i].fd; fd = ls[i].fd;
#if (WIN32) #if (NGX_WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number by 4. * so to find a connection we divide a socket number by 4.
@ -296,8 +301,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
if (ngx_close_socket(ls[i].fd) == -1) { if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
ngx_close_socket_n " %s failed", ngx_close_socket_n " %V failed", &ls[i].addr_text);
ls[i].addr_text.data);
} }
cycle->connections[fd].fd = (ngx_socket_t) -1; cycle->connections[fd].fd = (ngx_socket_t) -1;
@ -408,7 +412,7 @@ ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
} }
if (err == NGX_ECONNRESET if (err == NGX_ECONNRESET
#if !(WIN32) #if !(NGX_WIN32)
|| err == NGX_EPIPE || err == NGX_EPIPE
#endif #endif
|| err == NGX_ENOTCONN || err == NGX_ENOTCONN

View File

@ -24,7 +24,6 @@ typedef struct {
int family; int family;
int type; int type;
int protocol; int protocol;
int flags; /* Winsock2 flags */
void (*handler)(ngx_connection_t *c); /* handler of accepted void (*handler)(ngx_connection_t *c); /* handler of accepted
connection */ connection */
@ -48,9 +47,6 @@ typedef struct {
unsigned inherited:1; /* inherited from previous process */ unsigned inherited:1; /* inherited from previous process */
unsigned nonblocking_accept:1; unsigned nonblocking_accept:1;
unsigned nonblocking:1; unsigned nonblocking:1;
#if 0
unsigned overlapped:1; /* Winsock2 overlapped */
#endif
unsigned shared:1; /* shared between threads or processes */ unsigned shared:1; /* shared between threads or processes */
#if (HAVE_DEFERRED_ACCEPT) #if (HAVE_DEFERRED_ACCEPT)
unsigned deferred_accept:1; unsigned deferred_accept:1;

View File

@ -9,6 +9,7 @@
#include <ngx_event.h> #include <ngx_event.h>
static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *s1, struct sockaddr *s2);
static void ngx_clean_old_cycles(ngx_event_t *ev); static void ngx_clean_old_cycles(ngx_event_t *ev);
@ -195,7 +196,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
failed = 0; failed = 0;
#if !(WIN32) #if !(NGX_WIN32)
if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) { if (ngx_create_pidfile(cycle, old_cycle) == NGX_ERROR) {
failed = 1; failed = 1;
} }
@ -204,6 +205,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (!failed) { if (!failed) {
/* open the new files */
part = &cycle->open_files.part; part = &cycle->open_files.part;
file = part->elts; file = part->elts;
@ -227,7 +230,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, 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); &file[i], file[i].fd, file[i].name.data);
if (file[i].fd == NGX_INVALID_FILE) { if (file[i].fd == NGX_INVALID_FILE) {
@ -238,7 +241,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
break; break;
} }
#if (WIN32) #if (NGX_WIN32)
if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) { if (ngx_file_append_mode(file[i].fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
ngx_file_append_mode_n " \"%s\" failed", ngx_file_append_mode_n " \"%s\" failed",
@ -266,6 +269,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
} }
if (!failed) { if (!failed) {
/* handle the listening sockets */
if (old_cycle->listening.nelts) { if (old_cycle->listening.nelts) {
ls = old_cycle->listening.elts; ls = old_cycle->listening.elts;
for (i = 0; i < old_cycle->listening.nelts; i++) { for (i = 0; i < old_cycle->listening.nelts; i++) {
@ -274,16 +280,17 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
nls = cycle->listening.elts; nls = cycle->listening.elts;
for (n = 0; n < cycle->listening.nelts; n++) { for (n = 0; n < cycle->listening.nelts; n++) {
for (i = 0; i < old_cycle->listening.nelts; i++) { for (i = 0; i < old_cycle->listening.nelts; i++) {
if (ls[i].ignore) { if (ls[i].ignore) {
continue; continue;
} }
if (ngx_memcmp(nls[n].sockaddr, if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr)
ls[i].sockaddr, ls[i].socklen) == 0) == NGX_OK)
{ {
fd = ls[i].fd; fd = ls[i].fd;
#if (WIN32) #if (NGX_WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 so * Winsock assignes a socket number divisible by 4 so
* to find a connection we divide a socket number by 4. * to find a connection we divide a socket number by 4.
@ -294,10 +301,10 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (fd >= (ngx_socket_t) cycle->connection_n) { if (fd >= (ngx_socket_t) cycle->connection_n) {
ngx_log_error(NGX_LOG_EMERG, log, 0, ngx_log_error(NGX_LOG_EMERG, log, 0,
"%d connections is not enough to hold " "%d connections is not enough to hold "
"an open listening socket on %s, " "an open listening socket on %V, "
"required at least %d connections", "required at least %d connections",
cycle->connection_n, cycle->connection_n,
ls[i].addr_text.data, fd); &ls[i].addr_text, fd);
failed = 1; failed = 1;
break; break;
} }
@ -372,8 +379,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) { if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_close_socket_n " %s failed", ngx_close_socket_n " %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
} }
} }
@ -384,12 +391,12 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* commit the new cycle configuration */ /* commit the new cycle configuration */
#if !(WIN32) #if !(NGX_WIN32)
if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) { if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0, ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
"dup2: %0X %d \"%s\"", "dup2: %p %d \"%s\"",
cycle->log->file, cycle->log->file,
cycle->log->file->fd, cycle->log->file->name.data); cycle->log->file->fd, cycle->log->file->name.data);
@ -426,8 +433,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
if (ngx_close_socket(ls[i].fd) == -1) { if (ngx_close_socket(ls[i].fd) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_close_socket_n " %s failed", ngx_close_socket_n " %V failed",
ls[i].addr_text.data); &ls[i].addr_text);
} }
} }
@ -512,13 +519,38 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
} }
#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_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
{ {
ngx_uint_t trunc; ngx_uint_t trunc;
size_t len; size_t len;
u_char *name, pid[NGX_INT64_LEN + 1]; u_char *name, pid[NGX_INT64_LEN];
ngx_file_t file; ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf; ngx_core_conf_t *ccf, *old_ccf;
@ -548,8 +580,6 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
} }
} }
len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid);
ngx_memzero(&file, sizeof(ngx_file_t)); ngx_memzero(&file, sizeof(ngx_file_t));
file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid; file.name = (ngx_inherited && getppid() > 1) ? ccf->newpid : ccf->pid;
file.log = cycle->log; file.log = cycle->log;
@ -566,6 +596,8 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
} }
if (!ngx_test_config) { if (!ngx_test_config) {
len = ngx_sprintf(pid, "%P", ngx_pid) - pid;
if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) { if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
} }
@ -615,7 +647,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
ngx_uint_t i; ngx_uint_t i;
ngx_list_part_t *part; ngx_list_part_t *part;
ngx_open_file_t *file; ngx_open_file_t *file;
#if !(WIN32) #if !(NGX_WIN32)
ngx_file_info_t fi; ngx_file_info_t fi;
#endif #endif
@ -649,7 +681,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
continue; continue;
} }
#if (WIN32) #if (NGX_WIN32)
if (ngx_file_append_mode(fd) == NGX_ERROR) { if (ngx_file_append_mode(fd) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
ngx_file_append_mode_n " \"%s\" failed", ngx_file_append_mode_n " \"%s\" failed",
@ -730,7 +762,7 @@ void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
file[i].fd = fd; file[i].fd = fd;
} }
#if !(WIN32) #if !(NGX_WIN32)
if (cycle->log->file->fd != STDERR_FILENO) { if (cycle->log->file->fd != STDERR_FILENO) {
if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) { if (dup2(cycle->log->file->fd, STDERR_FILENO) == -1) {

View File

@ -12,6 +12,10 @@
#include <ngx_core.h> #include <ngx_core.h>
#define NGX_DEBUG_POINTS_STOP 1
#define NGX_DEBUG_POINTS_ABORT 2
struct ngx_cycle_s { struct ngx_cycle_s {
void ****conf_ctx; void ****conf_ctx;
ngx_pool_t *pool; ngx_pool_t *pool;
@ -40,6 +44,7 @@ typedef struct {
ngx_flag_t master; ngx_flag_t master;
ngx_int_t worker_processes; ngx_int_t worker_processes;
ngx_int_t debug_points;
ngx_uid_t user; ngx_uid_t user;
ngx_gid_t group; ngx_gid_t group;

View File

@ -55,9 +55,8 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
num = ngx_next_temp_number(0); num = ngx_next_temp_number(0);
for ( ;; ) { for ( ;; ) {
ngx_snprintf((char *) ngx_sprintf(file->name.data + path->name.len + 1 + path->len,
(file->name.data + path->name.len + 1 + path->len), "%010ud%Z", num);
11, "%010u", num);
ngx_create_hashed_filename(file, path); ngx_create_hashed_filename(file, path);
@ -83,7 +82,7 @@ int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
if ((path->level[0] == 0) if ((path->level[0] == 0)
|| (err != NGX_ENOENT || (err != NGX_ENOENT
#if (WIN32) #if (NGX_WIN32)
&& err != NGX_ENOTDIR && err != NGX_ENOTDIR
#endif #endif
)) { )) {

View File

@ -9,6 +9,17 @@
#include <ngx_core.h> #include <ngx_core.h>
/*
* 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) ngx_inline static size_t ngx_sprint_uchar(u_char *text, u_char c, size_t len)
{ {
size_t n; size_t n;
@ -105,15 +116,8 @@ size_t ngx_sock_ntop(int family, struct sockaddr *addr, u_char *text,
text[n] = '\0'; text[n] = '\0';
return n; 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) size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
{ {
u_char *p; u_char *p;
@ -163,12 +167,6 @@ size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
text[n] = '\0'; text[n] = '\0';
return n; 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
} }

View File

@ -8,7 +8,7 @@
#include <ngx_core.h> #include <ngx_core.h>
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); 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_errlog_commands, /* module directives */
NGX_CORE_MODULE, /* module type */ NGX_CORE_MODULE, /* module type */
NULL, /* init module */ NULL, /* init module */
NULL /* init child */ NULL /* init process */
}; };
@ -65,121 +65,104 @@ void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args) const char *fmt, va_list args)
#endif #endif
{ {
char errstr[MAX_ERROR_STR];
size_t len, max;
#if (NGX_HAVE_VARIADIC_MACROS) #if (NGX_HAVE_VARIADIC_MACROS)
va_list args; va_list args;
#endif #endif
u_char errstr[NGX_MAX_ERROR_STR], *p, *last;
if (log->file->fd == NGX_INVALID_FILE) { if (log->file->fd == NGX_INVALID_FILE) {
return; return;
} }
last = errstr + NGX_MAX_ERROR_STR;
ngx_memcpy(errstr, ngx_cached_err_log_time.data, ngx_memcpy(errstr, ngx_cached_err_log_time.data,
ngx_cached_err_log_time.len); ngx_cached_err_log_time.len);
#if (WIN32) p = errstr + ngx_cached_err_log_time.len;
max = MAX_ERROR_STR - 2;
#else
max = MAX_ERROR_STR - 1;
#endif
len = ngx_cached_err_log_time.len; p = ngx_sprintf(p, " [%s] ", err_levels[level]);
len += ngx_snprintf(errstr + len, max - len, " [%s] ", err_levels[level]);
/* pid#tid */ /* pid#tid */
len += ngx_snprintf(errstr + len, max - len, p = ngx_sprintf(p, "%P#" NGX_TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
PID_T_FMT "#" TID_T_FMT ": ", ngx_log_pid, ngx_log_tid);
if (log->data && *(int *) log->data != -1) { if (log->data && *(int *) log->data != -1) {
len += ngx_snprintf(errstr + len, max - len, p = ngx_sprintf(p, "*%ud ", *(u_int *) log->data);
"*%u ", *(u_int *) log->data);
} }
#if (NGX_HAVE_VARIADIC_MACROS) #if (NGX_HAVE_VARIADIC_MACROS)
va_start(args, fmt); va_start(args, fmt);
len += ngx_vsnprintf(errstr + len, max - len, fmt, args); p = ngx_vsnprintf(p, last - p, fmt, args);
va_end(args); va_end(args);
#else #else
len += ngx_vsnprintf(errstr + len, max - len, fmt, args); p = ngx_vsnprintf(p, last - p, fmt, args);
#endif #endif
if (err) { if (err) {
if (len > max - 50) { if (p > last - 50) {
/* leave a space for an error code */ /* leave a space for an error code */
len = max - 50; p = last - 50;
errstr[len++] = '.'; *p++ = '.';
errstr[len++] = '.'; *p++ = '.';
errstr[len++] = '.'; *p++ = '.';
} }
#if (WIN32) #if (NGX_WIN32)
if ((unsigned) err >= 0x80000000) { if ((unsigned) err >= 0x80000000) {
len += ngx_snprintf(errstr + len, max - len, " (%X: ", err); p = ngx_snprintf(p, last - p, " (%Xd: ", err);
} else { } else {
len += ngx_snprintf(errstr + len, max - len, " (%d: ", err); p = ngx_snprintf(p, last - p, " (%d: ", err);
} }
#else #else
len += ngx_snprintf(errstr + len, max - len, " (%d: ", err);
p = ngx_snprintf(p, last - p, " (%d: ", err);
#endif #endif
if (len >= max) { p = ngx_strerror_r(err, p, last - p);
ngx_log_write(log, errstr, max);
return;
}
len += ngx_strerror_r(err, errstr + len, max - len); if (p < last) {
*p++ = ')';
if (len >= max) {
ngx_log_write(log, errstr, max);
return;
}
errstr[len++] = ')';
if (len >= max) {
ngx_log_write(log, errstr, max);
return;
}
} else {
if (len >= max) {
ngx_log_write(log, errstr, max);
return;
} }
} }
if (level != NGX_LOG_DEBUG && log->handler) { if (level != NGX_LOG_DEBUG && log->handler) {
len += log->handler(log->data, errstr + len, max - len); p = log->handler(log->data, p, last - p);
if (len >= max) {
len = max;
}
} }
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; u_long written;
if (len >= NGX_MAX_ERROR_STR - 1) {
len = NGX_MAX_ERROR_STR - 2;
}
errstr[len++] = CR; errstr[len++] = CR;
errstr[len++] = LF; errstr[len++] = LF;
WriteFile(log->file->fd, errstr, len, &written, NULL); WriteFile(log->file->fd, errstr, len, &written, NULL);
#else #else
if (len == NGX_MAX_ERROR_STR) {
len--;
}
errstr[len++] = LF; errstr[len++] = LF;
write(log->file->fd, errstr, len); write(log->file->fd, errstr, len);
@ -192,7 +175,7 @@ static void ngx_log_write(ngx_log_t *log, char *errstr, size_t len)
void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list args; va_list args;
if (log->log_level >= level) { if (log->log_level >= level) {
va_start(args, fmt); va_start(args, fmt);
@ -204,46 +187,39 @@ void ngx_log_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...) 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); va_start(args, fmt);
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args); ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args);
va_end(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 #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); #if (NGX_WIN32)
ngx_stderr.fd = ngx_stderr_fileno;
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; return NULL;
}
} else if (ngx_stderr_fileno == NULL) { if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) {
ngx_message_box("nginx", MB_OK, ngx_errno,
/* there are no associated standard handles */ "Could not open error log file: "
ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
/* TODO: where can we can log possible errors ? */ "\" failed");
return NULL;
ngx_stderr.fd = NGX_INVALID_FILE;
} }
#else #else
@ -252,61 +228,10 @@ ngx_log_t *ngx_log_init_stderr()
#endif #endif
ngx_log.file = &ngx_stderr;
ngx_log.log_level = NGX_LOG_NOTICE;
return &ngx_log; 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 *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
{ {
ngx_log_t *log; ngx_log_t *log;

View File

@ -40,7 +40,7 @@
#define NGX_LOG_DEBUG_ALL 0x7ffffff0 #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 { struct ngx_log_s {
@ -50,7 +50,8 @@ struct ngx_log_s {
ngx_log_handler_pt handler; 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_log_t *log, ngx_err_t err,
void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, va_list args); const char *fmt, va_list args);
void ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...); 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 */ #endif /* VARIADIC MACROS */
@ -195,10 +195,7 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#define ngx_log_alloc_log(pool, log) ngx_palloc(pool, log, sizeof(ngx_log_t)) #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)) #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
ngx_log_t *ngx_log_init_stderr(); ngx_log_t *ngx_log_init();
#if 0
ngx_int_t ngx_log_init_error_log();
#endif
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args); 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); char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);

View File

@ -162,7 +162,11 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
ctx->in = ctx->in->next; 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;
last_out = &cl->next; last_out = &cl->next;
ctx->buf = NULL; ctx->buf = NULL;
@ -266,7 +270,7 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
if ((size_t) n != size) { if ((size_t) n != size) {
ngx_log_error(NGX_LOG_ALERT, src->file->log, 0, 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); n, size);
if (n == 0) { if (n == 0) {
return NGX_ERROR; return NGX_ERROR;
@ -306,20 +310,24 @@ ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in)
for (/* void */; in; in = in->next) { for (/* void */; in; in = in->next) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 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;
ctx->last = &cl->next; ctx->last = &cl->next;
} }
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 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); ctx->out = ngx_send_chain(ctx->connection, ctx->out, ctx->limit);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0, 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) { if (ctx->out == NGX_CHAIN_ERROR) {
return NGX_ERROR; return NGX_ERROR;

View File

@ -33,8 +33,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
for (l = pool->large; l; l = l->next) { for (l = pool->large; l; l = l->next) {
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc);
"free: " PTR_FMT, l->alloc);
if (l->alloc) { if (l->alloc) {
free(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) { for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
"free: " PTR_FMT ", unused: " SIZE_T_FMT, "free: %p, unused: %uz", p, p->end - p->last);
p, p->end - p->last);
if (n == NULL) { if (n == NULL) {
break; break;
@ -164,7 +162,7 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
for (l = pool->large; l; l = l->next) { for (l = pool->large; l; l = l->next) {
if (p == l->alloc) { if (p == l->alloc) {
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
"free: " PTR_FMT, l->alloc); "free: %p", l->alloc);
free(l->alloc); free(l->alloc);
l->alloc = NULL; l->alloc = NULL;

View File

@ -53,11 +53,11 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
if (re == NULL) { if (re == NULL) {
if ((size_t) erroff == pattern->len) { 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\"", "pcre_compile() failed: %s in \"%s\"",
errstr, pattern->data); errstr, pattern->data);
} else { } else {
ngx_snprintf((char *) err->data, err->len - 1, ngx_snprintf(err->data, err->len - 1,
"pcre_compile() failed: %s in \"%s\" at \"%s\"", "pcre_compile() failed: %s in \"%s\" at \"%s\"",
errstr, pattern->data, pattern->data + erroff); errstr, pattern->data, pattern->data + erroff);
} }

View File

@ -30,42 +30,92 @@ u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n)
/* /*
* supported formats: * supported formats:
* %[0][width]O off_t * %[0][width]O off_t
* %[0][width]T time_t * %[0][width]T time_t
* %[0][width]S ssize_t * %[0][width][u][x|X]z ssize_t/size_t
* %[0][width]uS size_t * %[0][width][u][x|X]d int/u_int
* %[0][width]uxS size_t in hex * %[0][width][u][x|X]l long
* %[0][width]l long * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t
* %[0][width]d int * %[0][width][u][x|X]D int32_t/uint32_t
* %[0][width]i ngx_int_t * %[0][width][u][x|X]L int64_t/uint64_t
* %[0][width]ui ngx_uint_t * %P ngx_pid_t
* %[0][width]uxi ngx_uint_t in hex * %r rlim_t
* %s null-terminated string * %p pointer
* %c char * %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, c, temp[NGX_MAX_INT_LEN]; u_char *p;
int d; va_list args;
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";
va_start(arg, fmt); 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;
va_list args;
va_start(args, fmt);
p = ngx_vsnprintf(buf, max, fmt, args);
va_end(args);
return p;
}
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";
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
*/
while (*fmt) {
if (*fmt == '%') { if (*fmt == '%') {
zero = (*++fmt == '0') ? 1 : 0; i64 = 0;
ui64 = 0;
zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0; width = 0;
sign = 1; sign = 1;
hexadecimal = 0; hexadecimal = 0;
@ -85,8 +135,15 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
fmt++; fmt++;
continue; continue;
case 'X':
hexadecimal = 2;
sign = 0;
fmt++;
continue;
case 'x': case 'x':
hexadecimal = 1; hexadecimal = 1;
sign = 0;
fmt++; fmt++;
continue; continue;
@ -100,137 +157,116 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
switch (*fmt) { switch (*fmt) {
case 'O': case 'V':
offset = va_arg(arg, off_t); s = va_arg(args, ngx_str_t *);
if (offset < 0) { len = (buf + s->len < last) ? s->len : (size_t) (last - buf);
*buf++ = '-'; buf = ngx_cpymem(buf, s->data, len);
offset = -offset; fmt++;
}
do { continue;
*--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 '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;
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;
case 's': case 's':
p = va_arg(arg, u_char *); p = va_arg(args, u_char *);
while (*p) { while (*p && buf < last) {
*buf++ = *p++; *buf++ = *p++;
} }
fmt++; fmt++;
continue; 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': case 'c':
d = va_arg(arg, int); d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff); *buf++ = (u_char) (d & 0xff);
fmt++; fmt++;
continue; continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case '%': case '%':
*buf++ = '%'; *buf++ = '%';
fmt++; fmt++;
@ -243,15 +279,71 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
continue; continue;
} }
len = (temp + NGX_MAX_INT_LEN) - p; if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
c = (u_char) (zero ? '0' : ' '); } else {
ui64 = (uint64_t) i64;
while (len++ < width) { }
*buf++ = c;
} }
buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p)); 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;
while (len++ < width && buf < last) {
*buf++ = zero;
}
len = (temp + NGX_MAX_INT_LEN) - p;
if (buf + len > last) {
len = last - buf;
}
buf = ngx_cpymem(buf, p, len);
fmt++; fmt++;
@ -260,10 +352,6 @@ u_char *ngx_sprintf(u_char *buf, char *fmt, ...)
} }
} }
va_end(arg);
*buf = '\0';
return buf; return buf;
} }
@ -505,12 +593,14 @@ 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) 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, n;
ngx_uint_t i; uint32_t *escape;
static u_char hex[] = "0123456789abcdef"; static u_char hex[] = "0123456789abcdef";
static uint32_t escape[] =
static uint32_t uri[] =
{ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
@ -527,6 +617,31 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
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 */ };
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) { if (dst == NULL) {
/* find the number of the characters to be escaped */ /* find the number of the characters to be escaped */
@ -555,5 +670,5 @@ ngx_int_t ngx_escape_uri(u_char *dst, u_char *src, size_t size)
} }
} }
return NGX_OK; return 0;
} }

View File

@ -22,16 +22,13 @@ typedef struct {
#define ngx_null_string { 0, NULL } #define ngx_null_string { 0, NULL }
#if (WIN32) #if (NGX_WIN32)
#define ngx_strncasecmp(s1, s2, n) \ #define ngx_strncasecmp(s1, s2, n) \
strnicmp((const char *) s1, (const char *) s2, n) strnicmp((const char *) s1, (const char *) s2, n)
#define ngx_strcasecmp(s1, s2) \ #define ngx_strcasecmp(s1, s2) \
stricmp((const char *) s1, (const char *) s2) stricmp((const char *) s1, (const char *) s2)
#define ngx_snprintf _snprintf
#define ngx_vsnprintf _vsnprintf
#else #else
#define ngx_strncasecmp(s1, s2, n) \ #define ngx_strncasecmp(s1, s2, n) \
@ -39,21 +36,20 @@ typedef struct {
#define ngx_strcasecmp(s1, s2) \ #define ngx_strcasecmp(s1, s2) \
strcasecmp((const char *) s1, (const char *) s2) strcasecmp((const char *) s1, (const char *) s2)
#define ngx_snprintf snprintf
#define ngx_vsnprintf vsnprintf
#endif #endif
#define ngx_strncmp(s1, s2, n) \ #define ngx_strncmp(s1, s2, n) strncmp((const char *) s1, (const char *) s2, n)
strncmp((const char *) s1, (const char *) s2, n)
/* msvc and icc compile strcmp() to inline loop */ /* msvc and icc compile strcmp() to inline loop */
#define ngx_strcmp(s1, s2) strcmp((const char *) s1, (const char *) s2) #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_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
#define ngx_strlen(s) strlen((const char *) s) #define ngx_strlen(s) strlen((const char *) s)
/* /*
* msvc and icc compile memset() to the inline "rep stos" * msvc and icc compile memset() to the inline "rep stos"
* while ZeroMemory() and bzero() are the calls. * while ZeroMemory() and bzero() are the calls.
@ -62,15 +58,20 @@ typedef struct {
#define ngx_memzero(buf, n) memset(buf, 0, n) #define ngx_memzero(buf, n) memset(buf, 0, n)
#define ngx_memset(buf, c, n) memset(buf, c, n) #define ngx_memset(buf, c, n) memset(buf, c, n)
/* msvc and icc compile memcpy() to the inline "rep movs" */ /* msvc and icc compile memcpy() to the inline "rep movs" */
#define ngx_memcpy(dst, src, n) memcpy(dst, src, n) #define ngx_memcpy(dst, src, n) memcpy(dst, src, n)
#define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + n #define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + n
/* msvc and icc compile memcmp() to the inline loop */ /* msvc and icc compile memcmp() to the inline loop */
#define ngx_memcmp memcmp #define ngx_memcmp memcmp
u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n); 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_rstrncmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_rstrncasecmp(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 *md5);
void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src); 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_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 #define ngx_qsort qsort

View File

@ -94,7 +94,7 @@ void ngx_time_init()
ngx_old_elapsed_msec = 0; ngx_old_elapsed_msec = 0;
ngx_elapsed_msec = 0; ngx_elapsed_msec = 0;
#if !(WIN32) #if !(NGX_WIN32)
tzset(); tzset();
#endif #endif
@ -150,15 +150,14 @@ void ngx_time_update(time_t s)
p = cached_http_time[slot]; p = cached_http_time[slot];
ngx_snprintf((char *) p, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), ngx_sprintf(p, "%s, %02d %s %4d %02d:%02d:%02d GMT",
"%s, %02d %s %4d %02d:%02d:%02d GMT", week[ngx_cached_gmtime.ngx_tm_wday],
week[ngx_cached_gmtime.ngx_tm_wday], ngx_cached_gmtime.ngx_tm_mday,
ngx_cached_gmtime.ngx_tm_mday, months[ngx_cached_gmtime.ngx_tm_mon - 1],
months[ngx_cached_gmtime.ngx_tm_mon - 1], ngx_cached_gmtime.ngx_tm_year,
ngx_cached_gmtime.ngx_tm_year, ngx_cached_gmtime.ngx_tm_hour,
ngx_cached_gmtime.ngx_tm_hour, ngx_cached_gmtime.ngx_tm_min,
ngx_cached_gmtime.ngx_tm_min, ngx_cached_gmtime.ngx_tm_sec);
ngx_cached_gmtime.ngx_tm_sec);
ngx_cached_http_time.data = p; ngx_cached_http_time.data = p;
@ -183,24 +182,22 @@ void ngx_time_update(time_t s)
p = cached_err_log_time[slot]; p = cached_err_log_time[slot];
ngx_snprintf((char *) p, sizeof("1970/09/28 12:00:00"), ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d",
"%4d/%02d/%02d %02d:%02d:%02d", tm.ngx_tm_year, tm.ngx_tm_mon,
tm.ngx_tm_year, tm.ngx_tm_mon, tm.ngx_tm_mday, tm.ngx_tm_hour,
tm.ngx_tm_mday, tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
tm.ngx_tm_min, tm.ngx_tm_sec);
ngx_cached_err_log_time.data = p; ngx_cached_err_log_time.data = p;
p = cached_http_log_time[slot]; p = cached_http_log_time[slot];
ngx_snprintf((char *) p, sizeof("28/Sep/1970:12:00:00 +0600"), ngx_sprintf(p, "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
"%02d/%s/%d:%02d:%02d:%02d %c%02d%02d", tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1], tm.ngx_tm_year, tm.ngx_tm_hour,
tm.ngx_tm_year, tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec,
tm.ngx_tm_min, tm.ngx_tm_sec, ngx_gmtoff < 0 ? '-' : '+',
ngx_gmtoff < 0 ? '-' : '+', abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
abs(ngx_gmtoff / 60), abs(ngx_gmtoff % 60));
ngx_cached_http_log_time.data = p; 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) 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; ngx_tm_t tm;
@ -229,25 +223,10 @@ size_t ngx_http_time(u_char *buf, time_t t)
tm.ngx_tm_hour, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_min,
tm.ngx_tm_sec); 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) 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; ngx_tm_t tm;
@ -270,32 +249,6 @@ size_t ngx_http_cookie_time(u_char *buf, time_t t)
tm.ngx_tm_hour, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_min,
tm.ngx_tm_sec); 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
} }

View File

@ -110,6 +110,10 @@ static int ngx_aio_del_connection(ngx_connection_t *c, u_int flags)
return NGX_OK; return NGX_OK;
} }
if (flags & NGX_CLOSE_EVENT) {
return NGX_OK;
}
rc = aio_cancel(c->fd, NULL); rc = aio_cancel(c->fd, NULL);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc); ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc);

View File

@ -208,7 +208,7 @@ static int ngx_devpoll_add_event(ngx_event_t *ev, int event, u_int flags)
#if (NGX_DEBUG) #if (NGX_DEBUG)
c = ev->data; c = ev->data;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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 #endif
ev->active = 1; ev->active = 1;
@ -229,7 +229,7 @@ static int ngx_devpoll_del_event(ngx_event_t *ev, int event, u_int flags)
#endif #endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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) { if (ngx_devpoll_set_event(ev, POLLREMOVE, flags) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
@ -268,7 +268,7 @@ static int ngx_devpoll_set_event(ngx_event_t *ev, int event, u_int flags)
c = ev->data; c = ev->data;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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) { if (nchanges >= max_changes) {
ngx_log_error(NGX_LOG_WARN, ev->log, 0, ngx_log_error(NGX_LOG_WARN, ev->log, 0,
@ -453,13 +453,13 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
} }
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 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].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) { if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 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].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }
@ -468,7 +468,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
{ {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"strange ioctl(DP_POLL) events " "strange ioctl(DP_POLL) events "
"fd:%d ev:%04X rev:%04X", "fd:%d ev:%04Xd rev:%04Xd",
event_list[i].fd, event_list[i].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }

View File

@ -232,7 +232,7 @@ static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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); c->fd, op, ee.events);
if (epoll_ctl(ep, op, c->fd, &ee) == -1) { if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
@ -291,7 +291,7 @@ static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags)
} }
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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); c->fd, op, ee.events);
if (epoll_ctl(ep, op, c->fd, &ee) == -1) { if (epoll_ctl(ep, op, c->fd, &ee) == -1) {
@ -314,7 +314,7 @@ static int ngx_epoll_add_connection(ngx_connection_t *c)
ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance); ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 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) { if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@ -513,7 +513,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
*/ */
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"epoll: stale event " PTR_FMT, c); "epoll: stale event %p", c);
continue; continue;
} }
@ -522,18 +522,18 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
#endif #endif
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, 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); c->fd, event_list[i].events, event_list[i].data);
if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, 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); c->fd, event_list[i].events);
} }
if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
ngx_log_error(NGX_LOG_ALERT, log, 0, 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); c->fd, event_list[i].events);
} }

View File

@ -82,7 +82,7 @@ ngx_os_io_t ngx_iocp_io = {
ngx_overlapped_wsarecv, ngx_overlapped_wsarecv,
NULL, NULL,
NULL, NULL,
ngx_wsasend_chain, ngx_overlapped_wsasend_chain,
0 0
}; };
@ -138,7 +138,7 @@ static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
c->write->active = 1; c->write->active = 1;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"iocp add: fd:%d k:%d ov:" PTR_FMT, c->fd, key, &ev->ovlp); "iocp add: fd:%d k:%d ov:%p", c->fd, key, &ev->ovlp);
if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) { if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@ -152,10 +152,16 @@ static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags) static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags)
{ {
#if 0
if (flags & NGX_CLOSE_EVENT) {
return NGX_OK;
}
if (CancelIo((HANDLE) c->fd) == 0) { if (CancelIo((HANDLE) c->fd) == 0) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed"); ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed");
return NGX_ERROR; return NGX_ERROR;
} }
#endif
return NGX_OK; return NGX_OK;
} }
@ -195,12 +201,19 @@ static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
ngx_time_update(tv.tv_sec); ngx_time_update(tv.tv_sec);
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp: %d b:%d k:%d ov:" PTR_FMT, rc, bytes, key, ovlp); "iocp: %d b:%d k:%d ov:%p", rc, bytes, key, ovlp);
delta = ngx_elapsed_msec; delta = ngx_elapsed_msec;
ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000 ngx_elapsed_msec = (ngx_epoch_msec_t) tv.tv_sec * 1000
+ tv.tv_usec / 1000 - ngx_start_msec; + tv.tv_usec / 1000 - ngx_start_msec;
if (timer != INFINITE) {
delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp timer: %d, delta: %d", timer, (int) delta);
}
if (err) { if (err) {
if (ovlp == NULL) { if (ovlp == NULL) {
if (err != WAIT_TIMEOUT) { if (err != WAIT_TIMEOUT) {
@ -210,49 +223,76 @@ static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
return NGX_ERROR; return NGX_ERROR;
} }
} else { if (timer != INFINITE && delta) {
ovlp->error = err; ngx_event_expire_timers((ngx_msec_t) delta);
}
}
if (timer != INFINITE) {
delta = ngx_elapsed_msec - delta;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp timer: %d, delta: %d", timer, (int) delta);
}
if (ovlp) {
ev = ovlp->event;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp event:" PTR_FMT, ev);
switch (key) {
case NGX_IOCP_ACCEPT:
if (bytes) {
ev->ready = 1;
} }
break;
case NGX_IOCP_IO: return NGX_OK;
ev->complete = 1;
ev->ready = 1;
break;
case NGX_IOCP_CONNECT:
ev->ready = 1;
} }
ev->available = bytes; ovlp->error = err;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp event handler: " PTR_FMT, ev->event_handler);
ev->event_handler(ev);
} }
if (ovlp == NULL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"GetQueuedCompletionStatus() returned no operation");
return NGX_ERROR;
}
ev = ovlp->event;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, err, "iocp event:%p", ev);
if (err == ERROR_NETNAME_DELETED /* the socket was closed */
|| err == ERROR_OPERATION_ABORTED /* the operation was canceled */)
{
/*
* the WSA_OPERATION_ABORTED completion notification
* for a file descriptor that was closed
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, err,
"iocp: aborted event %p", ev);
if (timer != INFINITE && delta) {
ngx_event_expire_timers((ngx_msec_t) delta);
}
return NGX_OK;
}
if (err) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
"GetQueuedCompletionStatus() returned operation error");
}
switch (key) {
case NGX_IOCP_ACCEPT:
if (bytes) {
ev->ready = 1;
}
break;
case NGX_IOCP_IO:
ev->complete = 1;
ev->ready = 1;
break;
case NGX_IOCP_CONNECT:
ev->ready = 1;
}
ev->available = bytes;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"iocp event handler: %p", ev->event_handler);
ev->event_handler(ev);
if (timer != INFINITE && delta) { if (timer != INFINITE && delta) {
ngx_event_expire_timers((ngx_msec_t) delta); ngx_event_expire_timers((ngx_msec_t) delta);
} }

View File

@ -367,7 +367,7 @@ static ngx_int_t ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
c = ev->data; c = ev->data;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 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); c->fd, filter, flags);
if (nchanges >= max_changes) { if (nchanges >= max_changes) {
@ -599,7 +599,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle)
*/ */
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"kevent: stale event " PTR_FMT, ev); "kevent: stale event %p", ev);
continue; continue;
} }
@ -776,9 +776,8 @@ static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, struct kevent *kev)
{ {
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0, ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0,
(kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ? (kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ?
"kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" "kevent: %p: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p":
PTR_FMT: "kevent: %d: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p",
"kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT,
kev->ident, kev->filter, kev->ident, kev->filter,
kev->flags, kev->fflags, kev->flags, kev->fflags,
kev->data, kev->udata); kev->data, kev->udata);

View File

@ -302,7 +302,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) { if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) {
for (i = 0; i < nevents; i++) { for (i = 0; i < nevents; i++) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 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); i, event_list[i].fd, event_list[i].events);
} }
} }
@ -380,13 +380,13 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
#if 0 #if 0
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 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, i, event_list[i].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
#else #else
if (event_list[i].revents) { if (event_list[i].revents) {
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 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, i, event_list[i].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }
@ -394,7 +394,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (event_list[i].revents & POLLNVAL) { if (event_list[i].revents & POLLNVAL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 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].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }
@ -402,7 +402,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL))
{ {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 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].fd,
event_list[i].events, event_list[i].revents); event_list[i].events, event_list[i].revents);
} }
@ -529,7 +529,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
for ( ;; ) { for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"accept event " PTR_FMT, ev); "accept event %p", ev);
if (ev == NULL) { if (ev == NULL) {
break; break;

View File

@ -383,7 +383,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle)
} else { } else {
err = 0; err = 0;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 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); signo, si.si_fd, si.si_band);
} }
@ -434,7 +434,7 @@ ngx_int_t ngx_rtsig_process_events(ngx_cycle_t *cycle)
ngx_accept_mutex_unlock(); ngx_accept_mutex_unlock();
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"rtsig: stale event " PTR_FMT, c); "rtsig: stale event %p", c);
return NGX_OK; return NGX_OK;
} }

View File

@ -23,7 +23,7 @@ static fd_set master_write_fd_set;
static fd_set work_read_fd_set; static fd_set work_read_fd_set;
static fd_set work_write_fd_set; static fd_set work_write_fd_set;
#if (WIN32) #if (NGX_WIN32)
static int max_read; static int max_read;
static int max_write; static int max_write;
#else #else
@ -114,7 +114,7 @@ static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_ONESHOT_EVENT; ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_ONESHOT_EVENT;
#if (WIN32) #if (NGX_WIN32)
max_read = max_write = 0; max_read = max_write = 0;
#else #else
max_fd = -1; max_fd = -1;
@ -150,7 +150,7 @@ static ngx_int_t ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
return NGX_OK; return NGX_OK;
} }
#if (WIN32) #if (NGX_WIN32)
if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE) if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE)
|| (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE)) || (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE))
@ -211,7 +211,7 @@ static ngx_int_t ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"select del event fd:%d ev:%d", c->fd, event); "select del event fd:%d ev:%d", c->fd, event);
#if (WIN32) #if (NGX_WIN32)
if (event == NGX_READ_EVENT) { if (event == NGX_READ_EVENT) {
FD_CLR(c->fd, &master_read_fd_set); FD_CLR(c->fd, &master_read_fd_set);
@ -280,7 +280,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
expire = 1; expire = 1;
#if !(WIN32) #if !(NGX_WIN32)
if (ngx_accept_mutex) { if (ngx_accept_mutex) {
if (ngx_accept_disabled > 0) { if (ngx_accept_disabled > 0) {
@ -324,7 +324,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
"select event: fd:%d wr:%d", c->fd, ev->write); "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, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"max_fd: %d", max_fd); "max_fd: %d", max_fd);
#endif #endif
@ -348,9 +348,9 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
work_write_fd_set = master_write_fd_set; work_write_fd_set = master_write_fd_set;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 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); ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
#else #else
ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp); 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_events(ngx_cycle_t *cycle)
"select ready %d", ready); "select ready %d", ready);
if (err) { if (err) {
#if (WIN32) #if (NGX_WIN32)
ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed"); ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "select() failed");
#else #else
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
@ -534,7 +534,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
for ( ;; ) { for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"accept event " PTR_FMT, ev); "accept event %p", ev);
if (ev == NULL) { if (ev == NULL) {
break; break;
@ -597,7 +597,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
/* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */ /* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */
#if !(WIN32) #if !(NGX_WIN32)
if ((unsigned) ecf->connections > FD_SETSIZE) { if ((unsigned) ecf->connections > FD_SETSIZE) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"the maximum number of files " "the maximum number of files "
@ -606,7 +606,7 @@ static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
} }
#endif #endif
#if (NGX_THREADS) #if (NGX_THREADS) && !(NGX_WIN32)
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
"select() is not supported in the threaded mode"); "select() is not supported in the threaded mode");
return NGX_CONF_ERROR; return NGX_CONF_ERROR;

View File

@ -191,7 +191,7 @@ ngx_module_t ngx_event_core_module = {
static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
{ {
#if !(WIN32) #if !(NGX_WIN32)
size_t size; size_t size;
char *shared; char *shared;
@ -240,7 +240,7 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
#endif #endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"counter: " PTR_FMT ", %d", "counter: %p, %d",
ngx_connection_counter, *ngx_connection_counter); ngx_connection_counter, *ngx_connection_counter);
#endif #endif
@ -259,7 +259,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
ngx_core_conf_t *ccf; ngx_core_conf_t *ccf;
ngx_event_conf_t *ecf; ngx_event_conf_t *ecf;
ngx_event_module_t *module; ngx_event_module_t *module;
#if (WIN32) #if (NGX_WIN32)
ngx_iocp_conf_t *iocpcf; ngx_iocp_conf_t *iocpcf;
#endif #endif
@ -352,7 +352,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
fd = s[i].fd; fd = s[i].fd;
#if (WIN32) #if (NGX_WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number 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(ngx_cycle_t *cycle)
} }
} }
#if (WIN32) #if (NGX_WIN32)
if (ngx_event_flags & NGX_USE_IOCP_EVENT) { 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) { if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
@ -429,7 +429,8 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
} }
} else { } else {
rev->event_handler = &ngx_event_accept; rev->event_handler = ngx_event_accept;
if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
} }
@ -437,7 +438,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
#else #else
rev->event_handler = &ngx_event_accept; rev->event_handler = ngx_event_accept;
if (ngx_accept_mutex) { if (ngx_accept_mutex) {
continue; continue;
@ -580,7 +581,7 @@ static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd,
ecf->connections = ngx_atoi(value[1].data, value[1].len); ecf->connections = ngx_atoi(value[1].data, value[1].len);
if (ecf->connections == (ngx_uint_t) NGX_ERROR) { if (ecf->connections == (ngx_uint_t) NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid number \"%s\"", value[1].data); "invalid number \"%V\"", &value[1]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -631,12 +632,12 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{ {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"when the server runs without a master process " "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\" " "in previous configuration - \"%s\" "
"and it can not be changed on the fly, " "and it can not be changed on the fly, "
"to change it you need to stop server " "to change it you need to stop server "
"and start it again", "and start it again",
value[1].data, old_ecf->name); &value[1], old_ecf->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -647,7 +648,7 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} }
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 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; return NGX_CONF_ERROR;
} }
@ -681,7 +682,7 @@ static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd,
if (h == NULL || h->h_addr_list[0] == NULL) { if (h == NULL || h->h_addr_list[0] == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 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; return NGX_CONF_ERROR;
} }
@ -755,7 +756,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#elif (HAVE_SELECT) #elif (HAVE_SELECT)
#if (WIN32) #if (NGX_WIN32)
ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS); ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
#else #else
ngx_conf_init_unsigned_value(ecf->connections, ngx_conf_init_unsigned_value(ecf->connections,

View File

@ -81,7 +81,7 @@ struct ngx_event_s {
unsigned posted_ready:1; unsigned posted_ready:1;
#endif #endif
#if (WIN32) #if (NGX_WIN32)
/* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */ /* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */
unsigned accept_context_updated:1; unsigned accept_context_updated:1;
#endif #endif
@ -473,7 +473,7 @@ ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle);
ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle); ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle);
#if (WIN32) #if (NGX_WIN32)
void ngx_event_acceptex(ngx_event_t *ev); void ngx_event_acceptex(ngx_event_t *ev);
int ngx_event_post_acceptex(ngx_listening_t *ls, int n); int ngx_event_post_acceptex(ngx_listening_t *ls, int n);
#endif #endif
@ -490,7 +490,7 @@ ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat);
#include <ngx_event_posted.h> #include <ngx_event_posted.h>
#include <ngx_event_busy_lock.h> #include <ngx_event_busy_lock.h>
#if (WIN32) #if (NGX_WIN32)
#include <ngx_iocp_module.h> #include <ngx_iocp_module.h>
#endif #endif

View File

@ -11,13 +11,13 @@
typedef struct { typedef struct {
int flag; int flag;
u_char *name; ngx_str_t *name;
} ngx_accept_log_ctx_t; } ngx_accept_log_ctx_t;
static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log); 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) void ngx_event_accept(ngx_event_t *ev)
@ -46,8 +46,8 @@ void ngx_event_accept(ngx_event_t *ev)
ls = ev->data; ls = ev->data;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"accept on %s, ready: %d", "accept on %V, ready: %d",
ls->listening->addr_text.data, ev->available); &ls->listening->addr_text, ev->available);
ev->ready = 0; ev->ready = 0;
accepted = 0; accepted = 0;
@ -88,7 +88,7 @@ void ngx_event_accept(ngx_event_t *ev)
/* -1 disables the connection number logging */ /* -1 disables the connection number logging */
ctx->flag = -1; ctx->flag = -1;
ctx->name = ls->listening->addr_text.data; ctx->name = &ls->listening->addr_text;
log->data = ctx; log->data = ctx;
log->handler = ngx_accept_log_error; 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, ngx_log_error(NGX_LOG_ALERT, ev->log, err,
"accept() on %s failed", "accept() on %V failed", &ls->listening->addr_text);
ls->listening->addr_text.data);
if (err == NGX_ECONNABORTED) { if (err == NGX_ECONNABORTED) {
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 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) { if ((ngx_uint_t) s >= ecf->connections) {
ngx_log_error(NGX_LOG_ALERT, ev->log, 0, 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, " "only %d connections was configured, "
"closing the connection", "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_close_accepted_socket(s, log);
ngx_destroy_pool(pool); 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 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number 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) { if (s % 4) {
ngx_log_error(NGX_LOG_EMERG, ev->log, 0, 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", "not divisible by 4",
ls->listening->addr_text.data, s); &ls->listening->addr_text, s);
exit(1); exit(1);
} }
@ -467,9 +466,9 @@ 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)
{ {
ngx_accept_log_ctx_t *ctx = data; 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);
} }

View File

@ -14,22 +14,24 @@ void ngx_event_acceptex(ngx_event_t *rev)
{ {
ngx_connection_t *c; ngx_connection_t *c;
c = (ngx_connection_t *) rev->data; c = rev->data;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "AcceptEx: %d", c->fd);
if (rev->ovlp.error) { if (rev->ovlp.error) {
ngx_log_error(NGX_LOG_CRIT, c->log, rev->ovlp.error, ngx_log_error(NGX_LOG_CRIT, c->log, rev->ovlp.error,
"AcceptEx() %s failed", c->listening->addr_text.data); "AcceptEx() %V failed", &c->listening->addr_text);
return; return;
} }
/* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */ /* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
(char *)&c->listening->fd, sizeof(ngx_socket_t)) == -1) (char *) &c->listening->fd, sizeof(ngx_socket_t)) == -1)
{ {
ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno, ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
"setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %s", "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %V",
c->addr_text.data); &c->addr_text);
} else { } else {
c->accept_context_updated = 1; c->accept_context_updated = 1;
} }
@ -49,6 +51,23 @@ void ngx_event_acceptex(ngx_event_t *rev)
c->buffer = NULL; c->buffer = NULL;
} }
if (c->listening->addr_ntop) {
c->addr_text.data = ngx_palloc(c->pool,
c->listening->addr_text_max_len);
if (c->addr_text.data == NULL) {
/* TODO: close socket */
return;
}
c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr,
c->addr_text.data,
c->listening->addr_text_max_len);
if (c->addr_text.len == 0) {
/* TODO: close socket */
return;
}
}
ngx_event_post_acceptex(c->listening, 1); ngx_event_post_acceptex(c->listening, 1);
c->number = ngx_atomic_inc(ngx_connection_counter); c->number = ngx_atomic_inc(ngx_connection_counter);
@ -73,10 +92,10 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
/* TODO: look up reused sockets */ /* TODO: look up reused sockets */
s = ngx_socket(ls->family, ls->type, ls->protocol, ls->flags); s = ngx_socket(ls->family, ls->type, ls->protocol);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ls->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ls->log, 0,
ngx_socket_n " s:%d fl:%d", s, ls->flags); ngx_socket_n " s:%d", s);
if (s == -1) { if (s == -1) {
ngx_log_error(NGX_LOG_ALERT, ls->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, ls->log, ngx_socket_errno,
@ -107,49 +126,60 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
ngx_memzero(rev, sizeof(ngx_event_t)); ngx_memzero(rev, sizeof(ngx_event_t));
ngx_memzero(wev, sizeof(ngx_event_t)); ngx_memzero(wev, sizeof(ngx_event_t));
rev->index = wev->index = NGX_INVALID_INDEX; c->listening = ls;
rev->index = NGX_INVALID_INDEX;
wev->index = NGX_INVALID_INDEX;
rev->ovlp.event = rev; rev->ovlp.event = rev;
wev->ovlp.event = wev; wev->ovlp.event = wev;
rev->event_handler = ngx_event_acceptex;
rev->data = c;
wev->data = c;
rev->data = wev->data = c;
c->read = rev; c->read = rev;
c->write = wev; c->write = wev;
c->listening = ls;
c->fd = s; c->fd = s;
c->unexpected_eof = 1;
rev->ready = 1;
wev->write = 1;
wev->ready = 1;
c->ctx = ls->ctx; c->ctx = ls->ctx;
c->servers = ls->servers; c->servers = ls->servers;
c->unexpected_eof = 1; c->recv = ngx_recv;
wev->write = 1; c->send_chain = ngx_send_chain;
rev->event_handler = ngx_event_acceptex;
rev->ready = 1; if (!(c->pool = ngx_create_pool(ls->pool_size, ls->log))) {
wev->ready = 1; return NGX_ERROR;
}
ngx_test_null(c->pool, c->buffer = ngx_create_temp_buf(c->pool,
ngx_create_pool(ls->pool_size, ls->log), ls->post_accept_buffer_size
NGX_ERROR); + 2 * (c->listening->socklen + 16));
if (c->buffer == NULL) {
return NGX_ERROR;
}
ngx_test_null(c->buffer, if (!(c->local_sockaddr = ngx_palloc(c->pool, ls->socklen))) {
ngx_create_temp_buf(c->pool, return NGX_ERROR;
ls->post_accept_buffer_size }
+ 2 * (c->listening->socklen + 16)),
NGX_ERROR);
ngx_test_null(c->local_sockaddr, ngx_palloc(c->pool, ls->socklen), if (!(c->sockaddr = ngx_palloc(c->pool, ls->socklen))) {
NGX_ERROR); return NGX_ERROR;
}
ngx_test_null(c->sockaddr, ngx_palloc(c->pool, ls->socklen), if (!(c->log = ngx_palloc(c->pool, sizeof(ngx_log_t)))) {
NGX_ERROR); return NGX_ERROR;
}
ngx_test_null(c->log, ngx_palloc(c->pool, sizeof(ngx_log_t)),
NGX_ERROR);
ngx_memcpy(c->log, ls->log, sizeof(ngx_log_t)); ngx_memcpy(c->log, ls->log, sizeof(ngx_log_t));
c->read->log = c->write->log = c->log; c->read->log = c->log;
c->write->log = c->log;
if (ngx_add_event(rev, 0, NGX_IOCP_IO) == NGX_ERROR) { if (ngx_add_event(rev, 0, NGX_IOCP_IO) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;

View File

@ -13,7 +13,7 @@
/* AF_INET only */ /* 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; int rc;
ngx_uint_t instance; ngx_uint_t instance;
@ -107,7 +107,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
/* ngx_unlock_mutex(pc->peers->mutex); */ /* 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) { if (s == -1) {
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
@ -165,7 +165,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
return NGX_ERROR; return NGX_ERROR;
} }
#if (WIN32) #if (NGX_WIN32)
/* /*
* Winsock assignes a socket number divisible by 4 * Winsock assignes a socket number divisible by 4
* so to find a connection we divide a socket number 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_connection_t *pc)
addr.sin_addr.s_addr = peer->addr; addr.sin_addr.s_addr = peer->addr;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, 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)); rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));

View File

@ -60,7 +60,7 @@ typedef struct {
} ngx_peer_connection_t; } 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); void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc);

View File

@ -199,7 +199,7 @@ void ngx_iocp_wait_events(int main)
ngx_log_error(NGX_LOG_ALERT, c[n].log, 0, ngx_log_error(NGX_LOG_ALERT, c[n].log, 0,
"WSAWaitForMultipleEvents() " "WSAWaitForMultipleEvents() "
"returned unexpected network event %lu", "returned unexpected network event %ul",
ne.lNetworkEvents); ne.lNetworkEvents);
} }
} }

View File

@ -13,7 +13,7 @@ ngx_int_t ngx_event_mutex_timedlock(ngx_event_mutex_t *m, ngx_msec_t timer,
ngx_event_t *ev) ngx_event_t *ev)
{ {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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) { if (m->lock) {
@ -48,13 +48,12 @@ ngx_int_t ngx_event_mutex_unlock(ngx_event_mutex_t *m, ngx_log_t *log)
if (m->lock == 0) { if (m->lock == 0) {
ngx_log_error(NGX_LOG_ALERT, log, 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; return NGX_ERROR;
} }
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
"unlock event mutex " PTR_FMT ", next event: " PTR_FMT, "unlock event mutex %p, next event: %p", m, m->events);
m, m->events);
m->lock = 0; m->lock = 0;

View File

@ -73,7 +73,7 @@ ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
} }
if (!SSL_is_init_finished(c->ssl->ssl)) { if (!SSL_is_init_finished(c->ssl->ssl)) {
handshake = "in SSL handshake"; handshake = " in SSL handshake";
} else { } else {
handshake = ""; handshake = "";
@ -269,7 +269,7 @@ static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
if (sslerr == SSL_ERROR_WANT_READ) { if (sslerr == SSL_ERROR_WANT_READ) {
if (!SSL_is_init_finished(c->ssl->ssl)) { if (!SSL_is_init_finished(c->ssl->ssl)) {
handshake = "in SSL handshake"; handshake = " in SSL handshake";
} else { } else {
handshake = ""; handshake = "";
@ -310,6 +310,9 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
} }
again = 0; again = 0;
#if (NGX_SUPPRESS_WARN)
sslerr = 0;
#endif
for ( ;; ) { for ( ;; ) {
n = SSL_shutdown(c->ssl->ssl); n = SSL_shutdown(c->ssl->ssl);
@ -366,23 +369,18 @@ ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c)
void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
char *fmt, ...) char *fmt, ...)
{ {
int len; u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
char errstr[NGX_MAX_CONF_ERRSTR]; va_list args;
va_list args;
last = errstr + NGX_MAX_CONF_ERRSTR;
va_start(args, fmt); 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); va_end(args);
errstr[len++] = ' '; p = ngx_cpystrn(p, " (SSL: ", last - p);
errstr[len++] = '(';
errstr[len++] = 'S';
errstr[len++] = 'S';
errstr[len++] = 'L';
errstr[len++] = ':';
errstr[len++] = ' ';
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); ngx_log_error(level, log, err, "%s)", errstr);
} }

View File

@ -79,7 +79,8 @@ ngx_int_t ngx_event_pipe(ngx_event_pipe_t *p, int do_write)
ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) 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_buf_t *b;
ngx_chain_t *chain, *cl, *tl; ngx_chain_t *chain, *cl, *tl;
@ -109,7 +110,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
n = p->preread_size; n = p->preread_size;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe preread: %d", n); "pipe preread: %z", n);
if (n) { if (n) {
p->read = 1; p->read = 1;
@ -197,7 +198,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
rc = ngx_event_pipe_write_chain_to_temp_file(p); rc = ngx_event_pipe_write_chain_to_temp_file(p);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 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 (rc == NGX_AGAIN) {
if (ngx_event_flags & NGX_USE_LEVEL_EVENT if (ngx_event_flags & NGX_USE_LEVEL_EVENT
@ -237,7 +238,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
n = ngx_recv_chain(p->upstream, chain); n = ngx_recv_chain(p->upstream, chain);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 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) { if (p->free_raw_bufs) {
chain->next = p->free_raw_bufs; chain->next = p->free_raw_bufs;
@ -303,7 +304,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->busy; cl; cl = cl->next) { for (cl = p->busy; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, 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->start, cl->buf->pos,
cl->buf->last - cl->buf->pos); cl->buf->last - cl->buf->pos);
} }
@ -311,9 +312,8 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->out; cl; cl = cl->next) { for (cl = p->out; cl; cl = cl->next) {
if (cl->buf->in_file && cl->buf->temporary) { if (cl->buf->in_file && cl->buf->temporary) {
ngx_log_debug5(NGX_LOG_DEBUG_EVENT, p->log, 0, ngx_log_debug5(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe buf out shadow " "pipe buf out shadow %p, pos %p, size: %z "
PTR_FMT ", pos " PTR_FMT ", size: %d " "file: %O, size: %z",
"file: " OFF_T_FMT ", size: %d",
cl->buf->start, cl->buf->pos, cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos, cl->buf->last - cl->buf->pos,
cl->buf->file_pos, cl->buf->file_pos,
@ -321,13 +321,12 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
} else if (cl->buf->in_file) { } else if (cl->buf->in_file) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, 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_pos,
cl->buf->file_last - cl->buf->file_pos); cl->buf->file_last - cl->buf->file_pos);
} else { } else {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe buf out " PTR_FMT ", pos " PTR_FMT "pipe buf out %p, pos %p, size: %z",
", size: %d",
cl->buf->start, cl->buf->pos, cl->buf->start, cl->buf->pos,
cl->buf->last - cl->buf->pos); cl->buf->last - cl->buf->pos);
} }
@ -335,14 +334,14 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
for (cl = p->in; cl; cl = cl->next) { for (cl = p->in; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, 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->start, cl->buf->pos,
cl->buf->last - cl->buf->pos); cl->buf->last - cl->buf->pos);
} }
for (cl = p->free_raw_bufs; cl; cl = cl->next) { for (cl = p->free_raw_bufs; cl; cl = cl->next) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, 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->start, cl->buf->last,
cl->buf->end - cl->buf->last); cl->buf->end - cl->buf->last);
} }
@ -443,7 +442,7 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe write busy: " SIZE_T_FMT, bsize); "pipe write busy: %uz", bsize);
out = NULL; out = NULL;
ll = NULL; ll = NULL;
@ -482,7 +481,7 @@ ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
} }
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0, 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) { if (out == NULL && !flush) {
break; break;
@ -553,13 +552,13 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
ll = NULL; ll = NULL;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 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 { do {
bsize = cl->buf->last - cl->buf->pos; bsize = cl->buf->last - cl->buf->pos;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0, 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); cl->buf->start, cl->buf->pos, bsize);
if ((size + bsize > p->temp_file_write_size) if ((size + bsize > p->temp_file_write_size)
@ -574,7 +573,7 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
} while (cl); } 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) { if (cl) {
p->in = cl; p->in = cl;

View File

@ -25,7 +25,7 @@ void ngx_event_process_posted(ngx_cycle_t *cycle)
ev = (ngx_event_t *) ngx_posted_events; ev = (ngx_event_t *) ngx_posted_events;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT, ev); "posted event %p", ev);
if (ev == NULL) { if (ev == NULL) {
return; return;
@ -38,7 +38,7 @@ void ngx_event_process_posted(ngx_cycle_t *cycle)
} }
#if (NGX_THREADS) #if (NGX_THREADS) && !(NGX_WIN32)
void ngx_wakeup_worker_thread(ngx_cycle_t *cycle) void ngx_wakeup_worker_thread(ngx_cycle_t *cycle)
{ {
@ -87,7 +87,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
for ( ;; ) { for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT, ev); "posted event %p", ev);
if (ev == NULL) { if (ev == NULL) {
return NGX_OK; return NGX_OK;
@ -96,7 +96,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
if (ngx_trylock(ev->lock) == 0) { if (ngx_trylock(ev->lock) == 0) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 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; ev = ev->next;
continue; continue;
@ -105,8 +105,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
if (ev->lock != ev->own_lock) { if (ev->lock != ev->own_lock) {
if (*(ev->own_lock)) { if (*(ev->own_lock)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"the own lock of the posted event " "the own lock of the posted event %p is busy", ev);
PTR_FMT " is busy", ev);
ngx_unlock(ev->lock); ngx_unlock(ev->lock);
ev = ev->next; ev = ev->next;
continue; continue;
@ -153,7 +152,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT " is done", ev); "posted event %p is done", ev);
break; break;
} }

View File

@ -22,10 +22,10 @@
ev->next->prev = &ev->next; \ ev->next->prev = &ev->next; \
} \ } \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \
"post event " PTR_FMT, ev); \ "post event %p", ev); \
} else { \ } else { \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ 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) \ #define ngx_delete_posted_event(ev) \
@ -35,7 +35,7 @@
} \ } \
ev->prev = NULL; \ ev->prev = NULL; \
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, \
"delete posted event " PTR_FMT, ev); "delete posted event %p", ev);

View File

@ -110,14 +110,13 @@ void ngx_event_expire_timers(ngx_msec_t timer)
*/ */
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
"event " PTR_FMT " is busy in expire timers", "event %p is busy in expire timers", ev);
ev);
break; break;
} }
#endif #endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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_event_ident(ev->data), ev->rbtree_key);
ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree, ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree,

View File

@ -89,7 +89,7 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
if (abs(key - ev->rbtree_key) < 100 / NGX_TIMER_RESOLUTION) { if (abs(key - ev->rbtree_key) < 100 / NGX_TIMER_RESOLUTION) {
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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); ngx_event_ident(ev->data), ev->rbtree_key, key);
return; return;
} }
@ -100,7 +100,7 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
ev->rbtree_key = key; ev->rbtree_key = key;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, 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); ngx_event_ident(ev->data), ev->rbtree_key);
if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) {

View File

@ -97,8 +97,9 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
rule = alcf->rules->elts; rule = alcf->rules->elts;
for (i = 0; i < alcf->rules->nelts; i++) { for (i = 0; i < alcf->rules->nelts; i++) {
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%08X %08X %08X", ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
addr_in->sin_addr.s_addr, rule[i].mask, rule[i].addr); "%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 ((addr_in->sin_addr.s_addr & rule[i].mask) == rule[i].addr) {
if (rule[i].deny) { if (rule[i].deny) {
@ -157,8 +158,8 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
} }
if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) { if (ngx_ptocidr(&value[1], &in_cidr) == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%s\"", ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid paramter \"%V\"",
value[1].data); &value[1]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }

View File

@ -24,6 +24,7 @@ typedef struct {
typedef struct { typedef struct {
ngx_str_t name; ngx_str_t name;
ngx_uint_t escape;
ngx_uint_t dir; ngx_uint_t dir;
time_t mtime; time_t mtime;
off_t size; off_t size;
@ -269,10 +270,13 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
} }
entry->name.len = len; 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); return ngx_http_autoindex_error(r, &dir, dname.data);
} }
ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1); ngx_cpystrn(entry->name.data, ngx_de_name(&dir), len + 1);
entry->dir = ngx_de_is_dir(&dir); entry->dir = ngx_de_is_dir(&dir);
@ -298,7 +302,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
for (i = 0; i < entries.nelts; i++) { for (i = 0; i < entries.nelts; i++) {
len += sizeof("<a href=\"") - 1 len += sizeof("<a href=\"") - 1
+ 1 /* 1 is for "/" */ + 1 /* 1 is for "/" */
+ entry[i].name.len + entry[i].name.len + entry[i].escape
+ sizeof("\">") - 1 + sizeof("\">") - 1
+ NGX_HTTP_AUTOINDEX_NAME_LEN + NGX_HTTP_AUTOINDEX_NAME_LEN
+ sizeof("</a>") - 1 + sizeof("</a>") - 1
@ -329,7 +333,17 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
for (i = 0; i < entries.nelts; i++) { for (i = 0; i < entries.nelts; i++) {
b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1); b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1);
b->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) { if (entry[i].dir) {
*b->last++ = '/'; *b->last++ = '/';
@ -375,7 +389,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
} else { } else {
length = entry[i].size; length = entry[i].size;
if (length > 1024 * 1024 * 1024) { if (length > 1024 * 1024 * 1024 - 1) {
size = (ngx_int_t) (length / (1024 * 1024 * 1024)); size = (ngx_int_t) (length / (1024 * 1024 * 1024));
if ((length % (1024 * 1024 * 1024)) if ((length % (1024 * 1024 * 1024))
> (1024 * 1024 * 1024 / 2 - 1)) > (1024 * 1024 * 1024 / 2 - 1))
@ -384,7 +398,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
} }
scale = 'G'; scale = 'G';
} else if (length > 1024 * 1024) { } else if (length > 1024 * 1024 - 1) {
size = (ngx_int_t) (length / (1024 * 1024)); size = (ngx_int_t) (length / (1024 * 1024));
if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) { if ((length % (1024 * 1024)) > (1024 * 1024 / 2 - 1)) {
size++; size++;

View File

@ -125,7 +125,7 @@ ngx_module_t ngx_http_charset_filter_module = {
ngx_http_charset_filter_commands, /* module directives */ ngx_http_charset_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */ NGX_HTTP_MODULE, /* module type */
ngx_http_charset_filter_init, /* init module */ ngx_http_charset_filter_init, /* init module */
NULL /* init child */ NULL /* init process */
}; };
@ -287,8 +287,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
if (src == dst) { if (src == dst) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"charset_map\" between the same charsets " "\"charset_map\" between the same charsets "
"\"%s\" and \"%s\"", "\"%V\" and \"%V\"", &value[1], &value[2]);
value[1].data, value[2].data);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -299,8 +298,7 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
{ {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate \"charset_map\" between " "duplicate \"charset_map\" between "
"\"%s\" and \"%s\"", "\"%V\" and \"%V\"", &value[1], &value[2]);
value[1].data, value[2].data);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
} }
@ -357,14 +355,14 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
src = ngx_hextoi(value[0].data, value[0].len); src = ngx_hextoi(value[0].data, value[0].len);
if (src == NGX_ERROR || src > 255) { if (src == NGX_ERROR || src > 255) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%s\"", value[0].data); "invalid value \"%V\"", &value[0]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
dst = ngx_hextoi(value[1].data, value[1].len); dst = ngx_hextoi(value[1].data, value[1].len);
if (dst == NGX_ERROR || dst > 255) { if (dst == NGX_ERROR || dst > 255) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%s\"", value[1].data); "invalid value \"%V\"", &value[1]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -525,8 +523,8 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
ngx_log_error(NGX_LOG_EMERG, cf->log, 0, ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
" no \"charset_map\" between the charsets " " no \"charset_map\" between the charsets "
"\"%s\" and \"%s\"", "\"%V\" and \"%V\"",
charset[i].name.data, charset[n].name.data); &charset[i].name, &charset[n].name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
} }

View File

@ -32,7 +32,7 @@ ngx_module_t ngx_http_chunked_filter_module = {
NULL, /* module directives */ NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */ NGX_HTTP_MODULE, /* module type */
ngx_http_chunked_filter_init, /* init module */ 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_filter(ngx_http_request_t *r,
size += ngx_buf_size(cl->buf); size += ngx_buf_size(cl->buf);
if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) { 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; tl->buf = cl->buf;
*ll = tl; *ll = tl;
ll = &tl->next; ll = &tl->next;
@ -102,30 +106,22 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return NGX_ERROR; return NGX_ERROR;
} }
if (!(chunk = ngx_palloc(r->pool, 11))) { if (!(chunk = ngx_palloc(r->pool, sizeof("00000000" CRLF) - 1))) {
return NGX_ERROR; return NGX_ERROR;
} }
b->temporary = 1; b->temporary = 1;
b->pos = chunk; b->pos = chunk;
b->last = ngx_sprintf(chunk, "%uxS" CRLF, size); b->last = ngx_sprintf(chunk, "%xz" CRLF, size);
out.buf = b; 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) { 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->memory = 1;
b->last_buf = 1; b->last_buf = 1;
b->pos = (u_char *) CRLF "0" CRLF CRLF; b->pos = (u_char *) CRLF "0" CRLF CRLF;
@ -147,7 +143,10 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return ngx_http_next_body_filter(r, out.next); 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->memory = 1;
b->pos = (u_char *) CRLF; b->pos = (u_char *) CRLF;
b->last = b->pos + 2; b->last = b->pos + 2;

View File

@ -80,7 +80,7 @@ static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r,
static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
u_int size); u_int size);
static void ngx_http_gzip_filter_free(void *opaque, void *address); 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, static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
uintptr_t data); uintptr_t data);
@ -507,7 +507,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
b->pos = gzheader; b->pos = gzheader;
b->last = b->pos + 10; 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->out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
@ -534,7 +538,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
&& !ctx->redo) && !ctx->redo)
{ {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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) { if (ctx->in == NULL) {
break; break;
@ -547,7 +551,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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->in_buf,
ctx->zstream.next_in, ctx->zstream.avail_in); ctx->zstream.next_in, ctx->zstream.avail_in);
@ -608,10 +612,10 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
} }
ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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", "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
ctx->zstream.next_in, ctx->zstream.next_out, ctx->zstream.next_in, ctx->zstream.next_out,
ctx->zstream.avail_in, ctx->zstream.avail_out, ctx->zstream.avail_in, ctx->zstream.avail_out,
ctx->flush, ctx->redo); ctx->flush, ctx->redo);
rc = deflate(&ctx->zstream, ctx->flush); rc = deflate(&ctx->zstream, ctx->flush);
@ -622,13 +626,13 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
} }
ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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.next_in, ctx->zstream.next_out,
ctx->zstream.avail_in, ctx->zstream.avail_out, ctx->zstream.avail_in, ctx->zstream.avail_out,
rc); rc);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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); ctx->in_buf, ctx->in_buf->pos);
@ -646,8 +650,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
/* zlib wants to output some more gzipped data */ /* zlib wants to output some more gzipped data */
ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, if (!(cl = ngx_alloc_chain_link(r->pool))) {
ngx_http_gzip_error(ctx)); return ngx_http_gzip_error(ctx);
}
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl; *ctx->last_out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
@ -663,8 +670,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ctx->out_buf->flush = 0; ctx->out_buf->flush = 0;
ctx->flush = Z_NO_FLUSH; ctx->flush = Z_NO_FLUSH;
ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, if (!(cl = ngx_alloc_chain_link(r->pool))) {
ngx_http_gzip_error(ctx)); return ngx_http_gzip_error(ctx);
}
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl; *ctx->last_out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
@ -686,8 +696,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
ngx_pfree(r->pool, ctx->preallocated); ngx_pfree(r->pool, ctx->preallocated);
ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, if (!(cl = ngx_alloc_chain_link(r->pool))) {
ngx_http_gzip_error(ctx)); return ngx_http_gzip_error(ctx);
}
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl; *ctx->last_out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
@ -703,8 +716,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
b->last_buf = 1; b->last_buf = 1;
ngx_alloc_link_and_set_buf(cl, b, r->pool, if (!(cl = ngx_alloc_chain_link(r->pool))) {
ngx_http_gzip_error(ctx)); return ngx_http_gzip_error(ctx);
}
cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl; *ctx->last_out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
trailer = (struct gztrailer *) b->pos; trailer = (struct gztrailer *) b->pos;
@ -735,8 +751,11 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
} }
if (conf->no_buffer && ctx->in == NULL) { if (conf->no_buffer && ctx->in == NULL) {
ngx_alloc_link_and_set_buf(cl, ctx->out_buf, r->pool, if (!(cl = ngx_alloc_chain_link(r->pool))) {
ngx_http_gzip_error(ctx)); return ngx_http_gzip_error(ctx);
}
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl; *ctx->last_out = cl;
ctx->last_out = &cl->next; ctx->last_out = &cl->next;
@ -782,10 +801,12 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
ngx_uint_t alloc; ngx_uint_t alloc;
alloc = items * size; alloc = items * size;
if (alloc % 512 != 0) { 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); alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1);
@ -797,14 +818,14 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
ctx->allocated -= alloc; ctx->allocated -= alloc;
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, 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); items, size, alloc, p);
return p; return p;
} }
ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, 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); items * size, ctx->allocated);
p = ngx_palloc(ctx->request->pool, items * size); p = ngx_palloc(ctx->request->pool, items * size);
@ -819,7 +840,7 @@ static void ngx_http_gzip_filter_free(void *opaque, void *address)
ngx_http_gzip_ctx_t *ctx = opaque; ngx_http_gzip_ctx_t *ctx = opaque;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
"gzip free: %X", address); "gzip free: %p", address);
#endif #endif
} }
@ -837,8 +858,6 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
return buf + 1; return buf + 1;
} }
/* we prefer do not use the FPU */
zint = (ngx_uint_t) (ctx->zin / ctx->zout); zint = (ngx_uint_t) (ctx->zin / ctx->zout);
zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100);
@ -855,16 +874,10 @@ static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf,
} }
return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); 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); deflateEnd(&ctx->zstream);

View File

@ -138,12 +138,6 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
conf->expires) conf->expires)
- cc->value.data; - 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
} }
} }
} }

View File

@ -143,7 +143,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
&r->uri, &crc); &r->uri, &crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, 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) { if (ctx->cache && !ctx->cache->expired) {
@ -251,7 +251,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
err = ngx_errno; err = ngx_errno;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err, 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) { if (err == NGX_ENOTDIR) {
return ngx_http_index_error(r, ctx, err); return ngx_http_index_error(r, ctx, err);
@ -275,7 +275,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
} }
ngx_log_error(NGX_LOG_ERR, log, err, 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; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@ -331,7 +331,7 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
ctx->redirect.len--; ctx->redirect.len--;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, 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) { if (ctx->cache) {
ctx->cache->fd = NGX_INVALID_FILE; ctx->cache->fd = NGX_INVALID_FILE;
@ -373,7 +373,7 @@ static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
} }
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err, 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; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@ -502,17 +502,17 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) { if (value[1].data[0] == '/' && ilcf->indices.nelts == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 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", "must not be absolute",
value[1].data, cmd->name.data); &value[1], &cmd->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
for (i = 1; i < cf->args->nelts; i++) { for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) { if (value[i].len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"index \"%s\" in \"%s\" directive is invalid", "index \"%V\" in \"%V\" directive is invalid",
value[1].data, cmd->name.data); &value[1], &cmd->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }

View File

@ -33,7 +33,7 @@ ngx_module_t ngx_http_not_modified_filter_module = {
NULL, /* module directives */ NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */ NGX_HTTP_MODULE, /* module type */
ngx_http_not_modified_filter_init, /* init module */ ngx_http_not_modified_filter_init, /* init module */
NULL /* init child */ NULL /* init process */
}; };

View File

@ -107,11 +107,13 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) 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; u_char *p;
size_t len; size_t len;
off_t start, end; 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_t *range;
ngx_http_range_filter_ctx_t *ctx; ngx_http_range_filter_ctx_t *ctx;
@ -141,8 +143,11 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r); return ngx_http_next_header_filter(r);
} }
ngx_init_array(r->headers_out.ranges, r->pool, 5, sizeof(ngx_http_range_t), if (ngx_array_init(&r->headers_out.ranges, r->pool, 5,
NGX_ERROR); sizeof(ngx_http_range_t)) == NGX_ERROR)
{
return NGX_ERROR;
}
rc = 0; rc = 0;
range = NULL; range = NULL;
@ -180,8 +185,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
while (*p == ' ') { p++; } while (*p == ' ') { p++; }
if (*p == ',' || *p == '\0') { if (*p == ',' || *p == '\0') {
ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), if (!(range = ngx_array_push(&r->headers_out.ranges))) {
NGX_ERROR); return NGX_ERROR;
}
range->start = start; range->start = start;
range->end = r->headers_out.content_length_n; range->end = r->headers_out.content_length_n;
@ -223,7 +230,10 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
break; 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; range->start = start;
if (end >= r->headers_out.content_length_n) { if (end >= r->headers_out.content_length_n) {
@ -249,29 +259,26 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.status = rc; r->headers_out.status = rc;
r->headers_out.ranges.nelts = 0; r->headers_out.ranges.nelts = 0;
r->headers_out.content_range = ngx_list_push(&r->headers_out.headers); if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
if (r->headers_out.content_range == NULL) {
return NGX_ERROR; return NGX_ERROR;
} }
r->headers_out.content_range->key.len = sizeof("Content-Range") - 1; r->headers_out.content_range = content_range;
r->headers_out.content_range->key.data = (u_char *) "Content-Range";
r->headers_out.content_range->value.data = content_range->key.len = sizeof("Content-Range") - 1;
ngx_palloc(r->pool, 8 + 20 + 1); content_range->key.data = (u_char *) "Content-Range";
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; return NGX_ERROR;
} }
r->headers_out.content_range->value.len = content_range->value.len = ngx_sprintf(content_range->value.data,
ngx_sprintf(r->headers_out.content_range->value.data, "bytes */%O",
"bytes */%O", r->headers_out.content_length_n) r->headers_out.content_length_n)
- r->headers_out.content_range->value.data; - 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
r->headers_out.content_length_n = -1; r->headers_out.content_length_n = -1;
if (r->headers_out.content_length) { if (r->headers_out.content_length) {
@ -280,177 +287,135 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
} }
return rc; 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 { } else {
r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data,
CRLF "--%010ud" CRLF
if (r->headers_out.ranges.nelts == 1) { "Content-Type: %V" CRLF
"Content-Range: bytes ",
r->headers_out.content_range = boundary,
ngx_list_push(&r->headers_out.headers); &r->headers_out.content_type->value)
if (r->headers_out.content_range == NULL) { - ctx->boundary_header.data;
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
r->headers_out.content_length_n = range->end - range->start;
} else {
#if 0
/* TODO: what if no content_type ?? */
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);
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);
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 "--%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;
} 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;
#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);
#endif
}
ngx_test_null(r->headers_out.content_type->value.data,
ngx_palloc(r->pool, 31 + 10 + 1),
NGX_ERROR);
/* "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);
/* 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;
#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);
}
r->headers_out.content_length_n = len;
r->headers_out.content_length = NULL;
}
} }
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->value.data == NULL) {
return NGX_ERROR;
}
/* "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=%010ud",
boundary)
- r->headers_out.content_type->value.data;
/* the size of the last boundary CRLF "--0123456789--" CRLF */
len = sizeof(CRLF "--0123456789--" CRLF) - 1;
range = r->headers_out.ranges.elts;
for (i = 0; i < r->headers_out.ranges.nelts; i++) {
/* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */
range[i].content_range.data =
ngx_palloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4);
if (range[i].content_range.data == NULL) {
return NGX_ERROR;
}
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;
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;
return ngx_http_next_header_filter(r); return ngx_http_next_header_filter(r);
} }
@ -496,33 +461,54 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
* "Content-Range: bytes " * "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->memory = 1;
b->pos = ctx->boundary_header.data; b->pos = ctx->boundary_header.data;
b->last = ctx->boundary_header.data + ctx->boundary_header.len; 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; hcl->buf = b;
/* "SSSS-EEEE/TTTT" CRLF CRLF */ /* "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->temporary = 1;
b->pos = range[i].content_range.data; b->pos = range[i].content_range.data;
b->last = range[i].content_range.data + range[i].content_range.len; 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; rcl->buf = b;
/* the range data */ /* 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->in_file = 1;
b->file_pos = range[i].start; b->file_pos = range[i].start;
b->file_last = range[i].end; b->file_last = range[i].end;
b->file = in->buf->file; 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; *ll = hcl;
hcl->next = rcl; hcl->next = rcl;
@ -532,15 +518,29 @@ static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
/* the last boundary CRLF "--0123456789--" CRLF */ /* 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->temporary = 1;
b->last_buf = 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 = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10);
*b->last++ = '-'; *b->last++ = '-'; *b->last++ = '-'; *b->last++ = '-';
*b->last++ = CR; *b->last++ = LF; *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; *ll = hcl;
return ngx_http_next_body_filter(r, out); return ngx_http_next_body_filter(r, out);

View File

@ -146,8 +146,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
if (rc == NGX_DECLINED) { if (rc == NGX_DECLINED) {
if (scf->log) { if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"\"%s\" does not match \"%s\"", "\"%V\" does not match \"%V\"",
rule[i].re_name.data, r->uri.data); &rule[i].re_name, &r->uri);
} }
continue; continue;
@ -156,15 +156,15 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
if (rc < 0) { if (rc < 0) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ngx_regex_exec_n ngx_regex_exec_n
" failed: %d on \"%s\" using \"%s\"", " failed: %d on \"%V\" using \"%V\"",
rc, r->uri.data, rule[i].re_name.data); rc, &r->uri, &rule[i].re_name);
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
if (scf->log) { if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"\"%s\" matches \"%s\"", "\"%V\" matches \"%V\"",
rule[i].re_name.data, r->uri.data); &rule[i].re_name, &r->uri);
} }
if (rule[i].status) { if (rule[i].status) {
@ -177,7 +177,7 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
uri.len += matches[2 * n + 1] - matches[2 * n]; 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; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@ -203,11 +203,9 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
} }
} }
*p = '\0';
if (scf->log) { if (scf->log) {
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"rewritten uri: \"%s\"", uri.data); "rewritten uri: \"%V\"", &uri);
} }
r->uri = uri; r->uri = uri;
@ -353,7 +351,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
} }
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%s\"", value[3].data); "invalid parameter \"%V\"", &value[3]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -427,7 +425,7 @@ static char *ngx_http_rewrite_rule(ngx_conf_t *cf, ngx_command_t *cmd,
} else { } else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter \"%s\"", value[3].data); "invalid parameter \"%V\"", &value[3]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
} }

View File

@ -197,7 +197,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
&name, &file_crc); &name, &file_crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, 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) { if (file && !file->expired) {
r->cache = file; r->cache = file;
@ -216,7 +216,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
&name, &redirect_crc); &name, &redirect_crc);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, 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) { if (redirect && !redirect->expired) {
@ -247,7 +247,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
/* open file */ /* open file */
#if (WIN9X) #if (NGX_WIN9X)
/* TODO: redirect cache */ /* TODO: redirect cache */
@ -276,7 +276,8 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
} }
if (ngx_is_dir(&fi)) { 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 = if (!(r->headers_out.location =
ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
@ -384,7 +385,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
location.len--; location.len--;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
"http redirect cache alloc: " PTR_FMT, redirect); "http redirect cache alloc: %p", redirect);
if (redirect) { if (redirect) {
redirect->fd = NGX_INVALID_FILE; redirect->fd = NGX_INVALID_FILE;
@ -403,11 +404,11 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
return NGX_HTTP_MOVED_PERMANENTLY; 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)) { if (!ngx_is_file(&fi)) {
ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, 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) { if (ngx_close_file(fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
@ -459,7 +460,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
#endif #endif
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, 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) { if (file) {
file->fd = fd; file->fd = fd;

View File

@ -171,10 +171,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
return NGX_ERROR; return NGX_ERROR;
} }
b->last += ngx_snprintf((char *) b->last, b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i);
/* STUB: should be NGX_PID_T_LEN */
NGX_INT64_LEN + NGX_INT32_LEN,
PID_T_FMT " %4u", ngx_pid, i);
switch (r->http_state) { switch (r->http_state) {
case NGX_HTTP_INITING_REQUEST_STATE: case NGX_HTTP_INITING_REQUEST_STATE:
@ -250,10 +247,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
return NGX_ERROR; return NGX_ERROR;
} }
b->last += ngx_snprintf((char *) b->last, b->last = ngx_sprintf(b->last, "%P %5ui", ngx_pid, i);
/* STUB: should be NGX_PID_T_LEN */
NGX_INT64_LEN + NGX_INT32_LEN,
PID_T_FMT " %4u", ngx_pid, i);
*(b->last++) = ' '; *(b->last++) = ' ';
*(b->last++) = 's'; *(b->last++) = 's';

View File

@ -27,15 +27,13 @@ typedef struct {
ngx_str_t domain; ngx_str_t domain;
ngx_str_t path; ngx_str_t path;
time_t expires; time_t expires;
ngx_str_t p3p;
ngx_int_t p3p;
ngx_str_t p3p_string;
} ngx_http_userid_conf_t; } ngx_http_userid_conf_t;
typedef struct { typedef struct {
uint32_t uid_got[4]; uint32_t uid_got[4];
uint32_t uid_set[4]; uint32_t uid_set[4];
} ngx_http_userid_ctx_t; } ngx_http_userid_ctx_t;
@ -56,8 +54,10 @@ static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
void *child); 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_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; static uint32_t sequencer_v1 = 1;
@ -79,8 +79,11 @@ static ngx_conf_enum_t ngx_http_userid_state[] = {
}; };
static ngx_conf_post_handler_pt ngx_conf_check_domain_p = static ngx_conf_post_handler_pt ngx_http_userid_domain_p =
ngx_conf_check_domain; 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[] = { static ngx_command_t ngx_http_userid_commands[] = {
@ -111,14 +114,14 @@ static ngx_command_t ngx_http_userid_commands[] = {
ngx_conf_set_str_slot, ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, domain), offsetof(ngx_http_userid_conf_t, domain),
&ngx_conf_check_domain_p }, &ngx_http_userid_domain_p },
{ ngx_string("userid_path"), { ngx_string("userid_path"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_str_slot, ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_userid_conf_t, path), offsetof(ngx_http_userid_conf_t, path),
NULL }, &ngx_http_userid_path_p },
{ ngx_string("userid_expires"), { ngx_string("userid_expires"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 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_commands[] = {
0, 0,
NULL }, 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 ngx_null_command
}; };
@ -210,40 +220,44 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
for (i = 0; i < r->headers_in.cookies.nelts; i++) { for (i = 0; i < r->headers_in.cookies.nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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; end = cookies[i]->value.data + cookies[i]->value.len;
for (start = cookies[i]->value.data; start < end; /* void */) { while (start < end) {
if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) {
if (conf->name.len >= cookies[i]->value.len
|| ngx_strncmp(start, conf->name.data, conf->name.len) != 0)
{
start += conf->name.len;
while (start < end && *start++ != ';') { /* void */ } while (start < end && *start++ != ';') { /* void */ }
while (start < end && *start == ' ') { start++; }
for (/* void */; start < end && *start == ' '; start++) { /**/ }
continue; continue;
} }
for (start += conf->name.len; start < end && *start == ' '; start++) start += conf->name.len;
{
/* void */
}
if (*start != '=') { while (start < end && *start == ' ') { start++; }
if (start == end || *start++ != '=') {
/* the invalid "Cookie" header */
break; 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) { if (last - start < 22) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client sent too short userid cookie \"%s\"", "client sent too short userid cookie \"%V\"",
cookies[i]->value.data); &cookies[i]->value);
break; break;
} }
@ -259,13 +273,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client sent invalid userid cookie \"%s\"", "client sent invalid userid cookie \"%V\"",
cookies[i]->value.data); &cookies[i]->value);
break; break;
} }
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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[0], ctx->uid_got[1],
ctx->uid_got[2], ctx->uid_got[3]); ctx->uid_got[2], ctx->uid_got[3]);
@ -280,14 +294,13 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
ngx_http_userid_ctx_t *ctx, ngx_http_userid_ctx_t *ctx,
ngx_http_userid_conf_t *conf) ngx_http_userid_conf_t *conf)
{ {
u_char *cookie, *p; u_char *cookie, *p;
size_t len; size_t len;
socklen_t slen; socklen_t slen;
struct sockaddr_in addr_in; struct sockaddr_in addr_in;
ngx_str_t src, dst; ngx_str_t src, dst;
ngx_table_elt_t *set_cookie; ngx_table_elt_t *set_cookie, *p3p;
/* TODO: mutex for sequencers */ /* TODO: mutex for sequencers */
@ -333,18 +346,14 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
} }
} }
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) { if (conf->expires) {
len += sizeof(expires) - 1 + 2; len += sizeof(expires) - 1 + 2;
} }
if (conf->domain.len > 1) { if (conf->domain.len > 1) {
len += sizeof("; domain=") - 1 + conf->domain.len; len += conf->domain.len;
}
if (conf->path.len) {
len += sizeof("; path=") - 1 + conf->path.len;
} }
if (!(cookie = ngx_palloc(r->pool, len))) { if (!(cookie = ngx_palloc(r->pool, len))) {
@ -371,19 +380,10 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
} }
if (conf->domain.len > 1) { if (conf->domain.len > 1) {
p = ngx_cpymem(p, "; domain=", sizeof("; domain=") - 1);
p = ngx_cpymem(p, conf->domain.data, conf->domain.len); p = ngx_cpymem(p, conf->domain.data, conf->domain.len);
} }
if (conf->path.len) { p = ngx_cpymem(p, conf->path.data, 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);
if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) { if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
return NGX_ERROR; return NGX_ERROR;
@ -394,6 +394,21 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
set_cookie->value.len = p - cookie; set_cookie->value.len = p - cookie;
set_cookie->value.data = 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; return NGX_OK;
} }
@ -425,9 +440,9 @@ static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
*buf++ = '='; *buf++ = '=';
return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
ctx->uid_got[0], ctx->uid_got[1], ctx->uid_got[0], ctx->uid_got[1],
ctx->uid_got[2], ctx->uid_got[3]); ctx->uid_got[2], ctx->uid_got[3]);
} }
@ -458,9 +473,9 @@ static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
*buf++ = '='; *buf++ = '=';
return buf + ngx_snprintf((char *) buf, 33, "%08X%08X%08X%08X", return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
ctx->uid_set[0], ctx->uid_set[1], ctx->uid_set[0], ctx->uid_set[1],
ctx->uid_set[2], ctx->uid_set[3]); ctx->uid_set[2], ctx->uid_set[3]);
} }
@ -510,6 +525,8 @@ static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
conf->domain.date = NULL; conf->domain.date = NULL;
conf->path.len = 0; conf->path.len = 0;
conf->path.date = NULL; 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_t *cf, void *parent,
ngx_conf_merge_str_value(conf->name, prev->name, "uid"); 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->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_value(conf->service, prev->service, NGX_CONF_UNSET);
ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); ngx_conf_merge_sec_value(conf->expires, prev->expires, 0);
@ -540,15 +558,49 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
} }
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; ngx_str_t *domain = data;
u_char *p, *new;
if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
domain->len = 1; domain->len = 1;
domain->data = (u_char *) "."; 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; return NGX_CONF_OK;
} }
@ -586,3 +638,16 @@ char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK; 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;
}

View File

@ -173,8 +173,8 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p)
ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1); 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, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http cache status %d \"%s\"", "http cache status %ui \"%V\"",
c->status, c->status_line.data); c->status, &c->status_line);
/* TODO: ngx_init_table */ /* TODO: ngx_init_table */
c->headers_in.headers = ngx_create_table(r->pool, 20); c->headers_in.headers = ngx_create_table(r->pool, 20);
@ -219,8 +219,7 @@ static int ngx_http_proxy_process_cached_header(ngx_http_proxy_ctx_t *p)
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http cache header: \"%s: %s\"", "http cache header: \"%V: %V\"", &h->key, &h->value);
h->key.data, h->value.data);
continue; continue;
@ -614,7 +613,7 @@ int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p)
ep = p->upstream->event_pipe; ep = p->upstream->event_pipe;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, 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); p->cache->ctx.length, ep->read_length);
if (p->cache->ctx.length == -1) { if (p->cache->ctx.length == -1) {

View File

@ -710,26 +710,75 @@ void ngx_http_proxy_close_connection(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)
{ {
ngx_http_proxy_log_ctx_t *ctx = data; ngx_http_proxy_log_ctx_t *ctx = data;
ngx_http_request_t *r; u_char *p;
ngx_peer_connection_t *peer; 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; r = ctx->proxy->request;
uc = ctx->proxy->lcf->upstream;
peer = &ctx->proxy->upstream->peer; peer = &ctx->proxy->upstream->peer;
return ngx_snprintf(buf, len, p = ngx_snprintf(buf, len,
" while %s, client: %s, URL: %s, upstream: %s%s%s%s%s", " while %s, client: %V, URL: %V, upstream: %V%V",
ctx->proxy->action, ctx->proxy->action,
r->connection->addr_text.data, &r->connection->addr_text,
r->unparsed_uri.data, &r->unparsed_uri,
peer->peers->peers[peer->cur_peer].addr_port_text.data, &peer->peers->peers[peer->cur_peer].addr_port_text,
ctx->proxy->lcf->upstream->uri.data, &ctx->proxy->lcf->upstream->uri);
r->uri.data + ctx->proxy->lcf->upstream->location->len, len -= p - buf;
r->args.len ? "?" : "", buf = p;
r->args.len ? r->args.data : (u_char *) "");
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_state(ngx_http_request_t *r,
*buf++ = '-'; *buf++ = '-';
} else { } else {
buf += ngx_snprintf((char *) buf, TIME_T_LEN, buf = ngx_sprintf(buf, "%T", p->state->expired);
TIME_T_FMT, p->state->expired);
} }
*buf++ = '/'; *buf++ = '/';
@ -769,8 +817,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-'; *buf++ = '-';
} else { } else {
buf += ngx_snprintf((char *) buf, TIME_T_LEN, buf = ngx_sprintf(buf, "%T", p->state->bl_time);
TIME_T_FMT, p->state->bl_time);
} }
*buf++ = '/'; *buf++ = '/';
@ -783,8 +830,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-'; *buf++ = '-';
} else { } else {
buf += ngx_snprintf((char *) buf, 4, "%" NGX_UINT_T_FMT, buf = ngx_sprintf(buf, "%ui", p->state->status);
p->state->status);
} }
*buf++ = '/'; *buf++ = '/';
@ -803,8 +849,7 @@ static u_char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r,
*buf++ = '-'; *buf++ = '-';
} else { } else {
buf += ngx_snprintf((char *) buf, TIME_T_LEN, buf = ngx_sprintf(buf, "%T", p->state->expires);
TIME_T_FMT, p->state->expires);
} }
*buf++ = ' '; *buf++ = ' ';
@ -1166,7 +1211,7 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]); lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]);
lcf->peers->peers[i].port = lcf->upstream->port; 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 = lcf->peers->peers[i].addr_port_text.data =
ngx_palloc(cf->pool, len); ngx_palloc(cf->pool, len);
@ -1181,12 +1226,12 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[i].addr_port_text.data[len++] = ':'; lcf->peers->peers[i].addr_port_text.data[len++] = ':';
ngx_cpystrn(lcf->peers->peers[i].addr_port_text.data + len, ngx_memcpy(lcf->peers->peers[i].addr_port_text.data + len,
lcf->upstream->port_text.data, lcf->upstream->port_text.data,
lcf->upstream->port_text.len + 1); lcf->upstream->port_text.len);
lcf->peers->peers[i].addr_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 { } else {
@ -1204,10 +1249,11 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[0].addr = addr; lcf->peers->peers[0].addr = addr;
lcf->peers->peers[0].port = lcf->upstream->port; 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 = lcf->peers->peers[0].addr_port_text.len = len;
ngx_palloc(cf->pool, len + 1);
lcf->peers->peers[0].addr_port_text.data = ngx_palloc(cf->pool, len);
if (lcf->peers->peers[0].addr_port_text.data == NULL) { if (lcf->peers->peers[0].addr_port_text.data == NULL) {
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1219,9 +1265,9 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
lcf->peers->peers[0].addr_port_text.data[len++] = ':'; lcf->peers->peers[0].addr_port_text.data[len++] = ':';
ngx_cpystrn(lcf->peers->peers[0].addr_port_text.data + len, ngx_memcpy(lcf->peers->peers[0].addr_port_text.data + len,
lcf->upstream->port_text.data, lcf->upstream->port_text.data,
lcf->upstream->port_text.len + 1); lcf->upstream->port_text.len);
} }
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

View File

@ -245,7 +245,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev);
void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev); void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev);
void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p); 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_finalize_request(ngx_http_proxy_ctx_t *p, int rc);
void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p); void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p);

View File

@ -25,7 +25,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); 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_send_response(ngx_http_proxy_ctx_t *p);
static void ngx_http_proxy_process_body(ngx_event_t *ev); 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[] = { static ngx_str_t http_methods[] = {
@ -137,7 +138,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (r->quoted_uri) { if (r->quoted_uri) {
escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, 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 { } else {
escape = 0; escape = 0;
} }
@ -246,7 +248,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (escape) { if (escape) {
ngx_escape_uri(b->last, r->uri.data + uc->location->len, 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; b->last += r->uri.len - uc->location->len + escape;
} else { } else {
@ -409,8 +411,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
*(b->last++) = CR; *(b->last++) = LF; *(b->last++) = CR; *(b->last++) = LF;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http proxy header: \"%s: %s\"", "http proxy header: \"%V: %V\"",
header[i].key.data, header[i].value.data); &header[i].key, &header[i].value);
} }
/* add "\r\n" at the header end */ /* add "\r\n" at the header end */
@ -670,7 +672,7 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
{ {
int rc; ngx_int_t rc;
ngx_connection_t *c; ngx_connection_t *c;
ngx_http_request_t *r; ngx_http_request_t *r;
ngx_output_chain_ctx_t *output; ngx_output_chain_ctx_t *output;
@ -683,7 +685,7 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
rc = ngx_event_connect_peer(&p->upstream->peer); rc = ngx_event_connect_peer(&p->upstream->peer);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, 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) { if (rc == NGX_ERROR) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
@ -705,6 +707,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
c->write->event_handler = ngx_http_proxy_send_request_handler; c->write->event_handler = ngx_http_proxy_send_request_handler;
c->read->event_handler = ngx_http_proxy_process_upstream_status_line; c->read->event_handler = ngx_http_proxy_process_upstream_status_line;
c->sendfile = r->connection->sendfile;
c->pool = r->pool; c->pool = r->pool;
c->read->log = c->write->log = c->log = r->connection->log; c->read->log = c->write->log = c->log = r->connection->log;
@ -1028,8 +1032,8 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
p->upstream->status_line.len + 1); p->upstream->status_line.len + 1);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
"http proxy status %d \"%s\"", "http proxy status %ui \"%V\"",
p->upstream->status, p->upstream->status_line.data); p->upstream->status, &p->upstream->status_line);
/* init or reinit the p->upstream->headers_in.headers table */ /* init or reinit the p->upstream->headers_in.headers table */
@ -1143,8 +1147,7 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http proxy header: \"%s: %s\"", "http proxy header: \"%V: %V\"", &h->key, &h->value);
h->key.data, h->value.data);
continue; continue;
@ -1467,7 +1470,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) { if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, 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_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
ngx_http_proxy_finalize_request(p, 0); ngx_http_proxy_finalize_request(p, 0);
return; return;
@ -1484,12 +1487,13 @@ 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)
{ {
int status; ngx_uint_t status;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0, 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); ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);

View File

@ -83,7 +83,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_core_srv_conf_t **cscfp, *cscf; ngx_http_core_srv_conf_t **cscfp, *cscf;
ngx_http_core_loc_conf_t *clcf; ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf; ngx_http_core_main_conf_t *cmcf;
#if (WIN32) #if (NGX_WIN32)
ngx_iocp_conf_t *iocpcf; ngx_iocp_conf_t *iocpcf;
#endif #endif
@ -343,9 +343,8 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (in_addr[a].default_server) { if (in_addr[a].default_server) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0, ngx_log_error(NGX_LOG_ERR, cf->log, 0,
"the duplicate default server in %s:%d", "the duplicate default server in %V:%d",
lscf[l].file_name.data, &lscf[l].file_name, lscf[l].line);
lscf[l].line);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -516,7 +515,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index]; clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
ls->log = clcf->err_log; ls->log = clcf->err_log;
#if (WIN32) #if (NGX_WIN32)
iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module); iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
if (iocpcf->acceptex_read) { if (iocpcf->acceptex_read) {
ls->post_accept_buffer_size = cscf->client_header_buffer_size; ls->post_accept_buffer_size = cscf->client_header_buffer_size;
@ -582,18 +581,18 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_port = in_ports.elts; in_port = in_ports.elts;
for (p = 0; p < in_ports.nelts; p++) { for (p = 0; p < in_ports.nelts; p++) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, 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; in_addr = in_port[p].addrs.elts;
for (a = 0; a < in_port[p].addrs.nelts; a++) { for (a = 0; a < in_port[p].addrs.nelts; a++) {
ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20); ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20);
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0, 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); address, in_port[p].port, in_addr[a].core_srv_conf);
s_name = in_addr[a].names.elts; s_name = in_addr[a].names.elts;
for (n = 0; n < in_addr[a].names.nelts; n++) { for (n = 0; n < in_addr[a].names.nelts; n++) {
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0, ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0,
"%s:%d %s %08x", "%s:%d %V %p",
address, in_port[p].port, s_name[n].name.data, address, in_port[p].port, &s_name[n].name,
s_name[n].core_srv_conf); s_name[n].core_srv_conf);
} }
} }
@ -671,7 +670,7 @@ static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,
for (i = 0; i < cscf->server_names.nelts; i++) { for (i = 0; i < cscf->server_names.nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, 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 */ /* TODO: duplicate names can be checked here */

View File

@ -33,7 +33,7 @@ typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
typedef struct { typedef struct {
u_int connection; u_int connection;
/* /*
* we declare "action" as "char *" because the actions are usually * we declare "action" as "char *" because the actions are usually
@ -41,9 +41,9 @@ typedef struct {
* all the time their types * all the time their types
*/ */
char *action; char *action;
u_char *client; ngx_str_t *client;
u_char *url; ngx_http_request_t *request;
} ngx_http_log_ctx_t; } ngx_http_log_ctx_t;

View File

@ -10,7 +10,7 @@
#include <ngx_http.h> #include <ngx_http.h>
#include <nginx.h> #include <nginx.h>
/* STUB */
#define NGX_HTTP_LOCATION_EXACT 1 #define NGX_HTTP_LOCATION_EXACT 1
#define NGX_HTTP_LOCATION_AUTO_REDIRECT 2 #define NGX_HTTP_LOCATION_AUTO_REDIRECT 2
#define NGX_HTTP_LOCATION_REGEX 3 #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) 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; r->connection->unexpected_eof = 0;
lcx = r->connection->log->data; ctx = r->connection->log->data;
lcx->action = NULL; ctx->action = NULL;
switch (r->headers_in.connection_type) { switch (r->headers_in.connection_type) {
case 0: case 0:
@ -526,17 +526,15 @@ ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, "http cl:%z max:%uz",
r->headers_in.content_length_n, r->headers_in.content_length_n, clcf->client_max_body_size);
clcf->client_max_body_size);
if (r->headers_in.content_length_n != -1 if (r->headers_in.content_length_n != -1
&& clcf->client_max_body_size && clcf->client_max_body_size
&& clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n)
{ {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client intented to send too large body: " "client intented to send too large body: %z bytes",
SIZE_T_FMT " bytes",
r->headers_in.content_length_n); r->headers_in.content_length_n);
return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
@ -583,9 +581,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
#endif #endif
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"find location: %s\"%s\"", "find location: %s\"%V\"",
clcfp[i]->exact_match ? "= " : "", clcfp[i]->exact_match ? "= " : "", &clcfp[i]->name);
clcfp[i]->name.data);
if (clcfp[i]->auto_redirect if (clcfp[i]->auto_redirect
&& r->uri.len == clcfp[i]->name.len - 1 && r->uri.len == clcfp[i]->name.len - 1
@ -649,8 +646,7 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
} }
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"find location: ~ \"%s\"", "find location: ~ \"%V\"", &clcfp[i]->name);
clcfp[i]->name.data);
n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); n = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0);
@ -661,8 +657,8 @@ static ngx_int_t ngx_http_find_location(ngx_http_request_t *r,
if (n < 0) { if (n < 0) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ngx_regex_exec_n ngx_regex_exec_n
" failed: %d on \"%s\" using \"%s\"", " failed: %d on \"%V\" using \"%V\"",
n, r->uri.data, clcfp[i]->name.data); n, &r->uri, &clcfp[i]->name);
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@ -809,14 +805,12 @@ ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args) ngx_str_t *uri, ngx_str_t *args)
{ {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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 = *uri;
r->uri.data = uri->data;
if (args) { if (args) {
r->args.len = args->len; r->args = *args;
r->args.data = args->data;
} }
if (ngx_http_set_exten(r) != NGX_OK) { if (ngx_http_set_exten(r) != NGX_OK) {
@ -1092,16 +1086,14 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
clcf->name = value[2]; clcf->name = value[2];
#else #else
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"the using of the regex \"%s\" " "the using of the regex \"%V\" "
"requires PCRE library", "requires PCRE library", &value[2]);
value[2].data);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
#endif #endif
} else { } else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid location modifier \"%s\"", "invalid location modifier \"%V\"", &value[1]);
value[1].data);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1123,9 +1115,9 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
if (pclcf->exact_match) { if (pclcf->exact_match) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"location \"%s\" could not be inside " "location \"%V\" could not be inside "
"the exact location \"%s\"", "the exact location \"%V\"",
clcf->name.data, pclcf->name.data); &clcf->name, &pclcf->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1139,8 +1131,8 @@ static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
#endif #endif
{ {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"location \"%s\" is outside location \"%s\"", "location \"%V\" is outside location \"%V\"",
clcf->name.data, pclcf->name.data); &clcf->name, &pclcf->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1301,7 +1293,7 @@ static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf,
if (conf->listen.nelts == 0) { if (conf->listen.nelts == 0) {
ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
l->addr = INADDR_ANY; l->addr = INADDR_ANY;
#if (WIN32) #if (NGX_WIN32)
l->port = 80; l->port = 80;
#else #else
/* STUB: getuid() should be cached */ /* STUB: getuid() should be cached */
@ -1561,9 +1553,9 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|| (port < 1 || port > 65536)) { /* "listen 99999" */ || (port < 1 || port > 65536)) { /* "listen 99999" */
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 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", "it must be a number between 1 and 65535",
&addr[p], cmd->name.data); &addr[p], &cmd->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
@ -1583,7 +1575,7 @@ static char *ngx_http_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (h == NULL || h->h_addr_list[0] == NULL) { if (h == NULL || h->h_addr_list[0] == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"can not resolve host \"%s\" " "can not resolve host \"%s\" "
"in \"%s\" directive", addr, cmd->name.data); "in \"%V\" directive", addr, &cmd->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1612,9 +1604,9 @@ static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 1; i < cf->args->nelts; i++) { for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 0) { if (value[i].len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"server name \"%s\" is invalid " "server name \"%V\" is invalid "
"in \"%s\" directive", "in \"%V\" directive",
value[i].data, cmd->name.data); &value[i], &cmd->name);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1659,13 +1651,13 @@ static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if ((ngx_uint_t) lcf->alias == alias) { if ((ngx_uint_t) lcf->alias == alias) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"%s\" directive is duplicate", "\"%V\" directive is duplicate",
cmd->name.data); &cmd->name);
} else { } else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"%s\" directive is duplicate, " "\"%V\" directive is duplicate, "
"\"%s\" directive is specified before", "\"%s\" directive is specified before",
cmd->name.data, lcf->alias ? "alias" : "root"); &cmd->name, lcf->alias ? "alias" : "root");
} }
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
@ -1708,7 +1700,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (value[i].data[0] == '=') { if (value[i].data[0] == '=') {
if (i == 1) { if (i == 1) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%s\"", value[i].data); "invalid value \"%V\"", &value[i]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1716,7 +1708,7 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (overwrite == NGX_ERROR) { if (overwrite == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%s\"", value[i].data); "invalid value \"%V\"", value[i]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
@ -1735,14 +1727,14 @@ static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
err->status = ngx_atoi(value[i].data, value[i].len); err->status = ngx_atoi(value[i].data, value[i].len);
if (err->status == NGX_ERROR) { if (err->status == NGX_ERROR) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid value \"%s\"", value[i].data); "invalid value \"%V\"", &value[i]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }
if (err->status < 400 || err->status > 599) { if (err->status < 400 || err->status > 599) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"value \"%s\" must be between 400 and 599", "value \"%V\" must be between 400 and 599",
value[i].data); &value[i]);
return NGX_CONF_ERROR; return NGX_CONF_ERROR;
} }

View File

@ -168,7 +168,7 @@ int ngx_http_cache_update_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx,
err = ngx_errno; err = ngx_errno;
#if (WIN32) #if (NGX_WIN32)
if (err == NGX_EEXIST) { if (err == NGX_EEXIST) {
if (ngx_win32_rename_file(temp_file, &ctx->file.name, r->pool) if (ngx_win32_rename_file(temp_file, &ctx->file.name, r->pool)
== NGX_ERROR) == NGX_ERROR)

View File

@ -319,13 +319,6 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
if (r->headers_out.content_length_n >= 0) { if (r->headers_out.content_length_n >= 0) {
b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF, b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,
r->headers_out.content_length_n); 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(ngx_http_request_t *r)
{ {
b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF, b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,
clcf->keepalive_header); 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 { } else {

View File

@ -133,7 +133,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
ngx_http_log_t *log; ngx_http_log_t *log;
ngx_http_log_op_t *op; ngx_http_log_op_t *op;
ngx_http_log_loc_conf_t *lcf; ngx_http_log_loc_conf_t *lcf;
#if (WIN32) #if (NGX_WIN32)
u_long written; u_long written;
#endif #endif
@ -160,7 +160,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
} }
} }
#if (WIN32) #if (NGX_WIN32)
len += 2; len += 2;
#else #else
len++; len++;
@ -186,7 +186,7 @@ ngx_int_t ngx_http_log_handler(ngx_http_request_t *r)
} }
} }
#if (WIN32) #if (NGX_WIN32)
*p++ = CR; *p++ = LF; *p++ = CR; *p++ = LF;
WriteFile(log[l].file->fd, line, p - line, &written, NULL); WriteFile(log[l].file->fd, line, p - line, &written, NULL);
#else #else
@ -211,12 +211,6 @@ static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf,
uintptr_t data) uintptr_t data)
{ {
return ngx_sprintf(buf, "%ui", r->connection->number); 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_http_request_t *r, u_char *buf,
ngx_gettimeofday(&tv); ngx_gettimeofday(&tv);
return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); 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_http_request_t *r, u_char *buf,
{ {
return ngx_sprintf(buf, "%ui", return ngx_sprintf(buf, "%ui",
r->err_status ? r->err_status : r->headers_out.status); 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_http_request_t *r, u_char *buf,
uintptr_t data) uintptr_t data)
{ {
return ngx_sprintf(buf, "%O", r->connection->sent); 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_length(ngx_http_request_t *r, u_char *buf,
uintptr_t data) uintptr_t data)
{ {
return ngx_sprintf(buf, "%O", r->connection->sent - r->header_size); 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(ngx_http_request_t *r, u_char *buf,
if (buf == NULL) { if (buf == NULL) {
return (u_char *) NGX_OFF_T_LEN; return (u_char *) NGX_OFF_T_LEN;
} }
return buf + ngx_snprintf((char *) buf, return ngx_sprintf(buf, "%O", r->headers_out.content_length_n);
NGX_OFF_T_LEN + 2, OFF_T_FMT,
r->headers_out.content_length_n);
} }
if (data == offsetof(ngx_http_headers_out_t, last_modified)) { if (data == offsetof(ngx_http_headers_out_t, last_modified)) {

View File

@ -199,7 +199,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
} }
break; break;
/* check "/.", "//", and "%" in URI */ /* check "/.", "//", "%", and "\" (Win32) in URI */
case sw_after_slash_in_uri: case sw_after_slash_in_uri:
switch (ch) { switch (ch) {
case CR: case CR:
@ -224,6 +224,11 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
r->quoted_uri = 1; r->quoted_uri = 1;
state = sw_uri; state = sw_uri;
break; break;
#if (NGX_WIN32)
case '\\':
r->complex_uri = 1;
break;
#endif
case '/': case '/':
r->complex_uri = 1; r->complex_uri = 1;
break; break;
@ -237,7 +242,7 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
} }
break; break;
/* check "/" and "%" in URI */ /* check "/", "%" and "\" (Win32) in URI */
case sw_check_uri: case sw_check_uri:
switch (ch) { switch (ch) {
case CR: case CR:
@ -257,6 +262,12 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
case '.': case '.':
r->uri_ext = p; r->uri_ext = p;
break; break;
#if (NGX_WIN32)
case '\\':
r->complex_uri = 1;
state = sw_after_slash_in_uri;
break;
#endif
case '/': case '/':
r->uri_ext = NULL; r->uri_ext = NULL;
state = sw_after_slash_in_uri; state = sw_after_slash_in_uri;
@ -657,7 +668,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
sw_slash, sw_slash,
sw_dot, sw_dot,
sw_dot_dot, sw_dot_dot,
#if (WIN32) #if (NGX_WIN32)
sw_dot_dot_dot, sw_dot_dot_dot,
#endif #endif
sw_quoted, sw_quoted,
@ -671,17 +682,42 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
p = r->uri_start; p = r->uri_start;
u = r->uri.data; u = r->uri.data;
r->uri_ext = NULL; r->uri_ext = NULL;
r->args_start = NULL;
ch = *p++; 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, 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) { switch (state) {
case sw_usual: case sw_usual:
switch(ch) { 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 '/': case '/':
r->uri_ext = NULL; r->uri_ext = NULL;
state = sw_slash; state = sw_slash;
@ -691,6 +727,9 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
quoted_state = state; quoted_state = state;
state = sw_quoted; state = sw_quoted;
break; break;
case '?':
r->args_start = p;
break;
case '.': case '.':
r->uri_ext = u + 1; r->uri_ext = u + 1;
default: default:
@ -702,6 +741,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_slash: case sw_slash:
switch(ch) { switch(ch) {
#if (NGX_WIN32)
case '\\':
break;
#endif
case '/': case '/':
break; break;
case '.': case '.':
@ -722,6 +765,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_dot: case sw_dot:
switch(ch) { switch(ch) {
#if (NGX_WIN32)
case '\\':
/* fall through */
#endif
case '/': case '/':
state = sw_slash; state = sw_slash;
u--; u--;
@ -744,6 +791,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
case sw_dot_dot: case sw_dot_dot:
switch(ch) { switch(ch) {
#if (NGX_WIN32)
case '\\':
/* fall through */
#endif
case '/': case '/':
state = sw_slash; state = sw_slash;
u -= 4; u -= 4;
@ -758,7 +809,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
quoted_state = state; quoted_state = state;
state = sw_quoted; state = sw_quoted;
break; break;
#if (WIN32) #if (NGX_WIN32)
case '.': case '.':
state = sw_dot_dot_dot; state = sw_dot_dot_dot;
*u++ = ch; *u++ = ch;
@ -772,9 +823,10 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
ch = *p++; ch = *p++;
break; break;
#if (WIN32) #if (NGX_WIN32)
case sw_dot_dot_dot: case sw_dot_dot_dot:
switch(ch) { switch(ch) {
case '\\':
case '/': case '/':
state = sw_slash; state = sw_slash;
u -= 5; u -= 5;
@ -857,12 +909,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r)
if (r->uri_ext) { if (r->uri_ext) {
r->exten.len = u - r->uri_ext; r->exten.len = u - r->uri_ext;
r->exten.data = 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->uri_ext = NULL; r->uri_ext = NULL;

View File

@ -34,24 +34,22 @@ static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static void ngx_http_client_error(ngx_http_request_t *r, static void ngx_http_client_error(ngx_http_request_t *r,
int client_error, int error); 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 */ /* NGX_HTTP_PARSE_... errors */
static char *client_header_errors[] = { static char *client_header_errors[] = {
"client %s sent invalid method", "client %V sent invalid method \"%V\"",
"client %s sent invalid request", "client %V sent invalid request \"%V\"",
"client %s sent too long URI", "client %V sent too long URI in request \"%V\"",
"client %s sent invalid method in HTTP/0.9 request", "client %V sent invalid method in HTTP/0.9 request \"%V\"",
"client %s sent invalid header, URL: %s", "client %V sent invalid header, URL: \"%V\"",
"client %s sent too long header line, URL: %s", "client %V sent too long header line, URL: \"%V\"",
"client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", "client %V sent HTTP/1.1 request without \"Host\" header, URL: \"%V\"",
"client %s sent invalid \"Content-Length\" header, URL: %s", "client %V sent invalid \"Content-Length\" header, URL: \"%V\"",
"client %s sent POST method without \"Content-Length\" header, URL: %s", "client %V sent POST method without \"Content-Length\" header, URL: \"%V\"",
"client %s sent plain HTTP request to HTTPS port, URL: %s",
"client %s sent invalid \"Host\" header \"%s\", URL: %s"
}; };
@ -105,14 +103,15 @@ void ngx_http_init_connection(ngx_connection_t *c)
ngx_event_t *rev; ngx_event_t *rev;
ngx_http_log_ctx_t *ctx; 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); ngx_http_close_connection(c);
return; return;
} }
ctx->connection = c->number; ctx->connection = c->number;
ctx->client = c->addr_text.data; ctx->client = &c->addr_text;
ctx->action = "reading client request line"; ctx->action = "reading client request line";
ctx->request = NULL;
c->log->data = ctx; c->log->data = ctx;
c->log->handler = ngx_http_log_error; c->log->handler = ngx_http_log_error;
c->log_error = NGX_ERROR_INFO; c->log_error = NGX_ERROR_INFO;
@ -278,7 +277,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
* AcceptEx() already gave this address. * AcceptEx() already gave this address.
*/ */
#if (WIN32) #if (NGX_WIN32)
if (c->local_sockaddr) { if (c->local_sockaddr) {
r->in_addr = r->in_addr =
((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr;
@ -295,7 +294,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->in_addr = addr_in.sin_addr.s_addr; r->in_addr = addr_in.sin_addr.s_addr;
#if (WIN32) #if (NGX_WIN32)
} }
#endif #endif
@ -428,9 +427,9 @@ static void ngx_http_init_request(ngx_event_t *rev)
static void ngx_http_ssl_handshake(ngx_event_t *rev) static void ngx_http_ssl_handshake(ngx_event_t *rev)
{ {
int n;
ngx_int_t rc;
u_char buf[1]; u_char buf[1];
ssize_t n;
ngx_int_t rc;
ngx_connection_t *c; ngx_connection_t *c;
ngx_http_request_t *r; ngx_http_request_t *r;
@ -454,7 +453,7 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
if (n == 1) { if (n == 1) {
if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) { if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0, 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->recv = ngx_ssl_recv;
c->send_chain = ngx_ssl_send_chain; c->send_chain = ngx_ssl_send_chain;
@ -488,7 +487,6 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
static void ngx_http_process_request_line(ngx_event_t *rev) static void ngx_http_process_request_line(ngx_event_t *rev)
{ {
u_char *p;
ssize_t n; ssize_t n;
ngx_int_t rc, rv; ngx_int_t rc, rv;
ngx_connection_t *c; ngx_connection_t *c;
@ -524,21 +522,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* the request line has been parsed successfully */ /* the request line has been parsed successfully */
/* copy unparsed URI */ r->request_line.len = r->request_end - r->request_start;
r->request_line.data = r->request_start;
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 */
if (r->args_start) { if (r->args_start) {
r->uri.len = r->args_start - 1 - r->uri_start; r->uri.len = r->args_start - 1 - r->uri_start;
@ -546,13 +532,14 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
r->uri.len = r->uri_end - r->uri_start; 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->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); rc = ngx_http_parse_complex_uri(r);
if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) { if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
@ -562,74 +549,55 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
} }
if (rc != NGX_OK) { 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); ngx_http_client_error(r, rc, NGX_HTTP_BAD_REQUEST);
return; return;
} }
} else { } else {
ngx_cpystrn(r->uri.data, r->uri_start, r->uri.len + 1); r->uri.data = r->uri_start;
} }
r->unparsed_uri.len = r->uri_end - r->uri_start;
r->unparsed_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';
if (r->method == 0) { if (r->method == 0) {
r->method_name.len = r->method_end - r->request_start + 1; r->method_name.len = r->method_end - r->request_start + 1;
r->method_name.data = r->request_line.data; r->method_name.data = r->request_line.data;
} }
if (r->uri_ext) { if (r->uri_ext) {
/* copy URI extention */
if (r->args_start) { if (r->args_start) {
r->exten.len = r->args_start - 1 - r->uri_ext; r->exten.len = r->args_start - 1 - r->uri_ext;
} else { } else {
r->exten.len = r->uri_end - r->uri_ext; r->exten.len = r->uri_end - r->uri_ext;
} }
if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { r->exten.data = r->uri_ext;
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);
} }
if (r->args_start && r->uri_end > r->args_start) { if (r->args_start && r->uri_end > r->args_start) {
/* copy URI arguments */
r->args.len = r->uri_end - r->args_start; r->args.len = r->uri_end - r->args_start;
r->args.data = 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);
} }
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, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http uri: \"%s\"", r->uri.data); "http request line: \"%V\"", &r->request_line);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http args: \"%s\"", "http uri: \"%V\"", &r->uri);
r->args.data ? r->args.data : (u_char *) "");
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http exten: \"%s\"", "http args: \"%V\"", &r->args);
r->exten.data ? r->exten.data : (u_char *) "");
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http exten: \"%V\"", &r->exten);
ctx = c->log->data;
ctx->request = r;
if (r->http_version < NGX_HTTP_VERSION_10) { if (r->http_version < NGX_HTTP_VERSION_10) {
rev->event_handler = ngx_http_block_read; rev->event_handler = ngx_http_block_read;
@ -655,10 +623,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
return; return;
} }
ctx = c->log->data;
ctx->action = "reading client request headers"; ctx->action = "reading client request headers";
ctx->url = r->unparsed_uri.data;
rev->event_handler = ngx_http_process_request_headers; rev->event_handler = ngx_http_process_request_headers;
ngx_http_process_request_headers(rev); ngx_http_process_request_headers(rev);
@ -669,6 +634,9 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* there was error while a request line parsing */ /* 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++) { for (p = r->request_start; p < r->header_in->last; p++) {
if (*p == CR || *p == LF) { if (*p == CR || *p == LF) {
break; break;
@ -686,6 +654,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
(rc == NGX_HTTP_PARSE_INVALID_METHOD) ? (rc == NGX_HTTP_PARSE_INVALID_METHOD) ?
NGX_HTTP_NOT_IMPLEMENTED: NGX_HTTP_NOT_IMPLEMENTED:
NGX_HTTP_BAD_REQUEST); NGX_HTTP_BAD_REQUEST);
#endif
return; return;
} }
@ -811,8 +781,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http header: \"%s: %s\"", "http header: \"%V: %V\"",
h->key.data, h->value.data); &h->key, &h->value);
continue; continue;
@ -973,7 +943,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
b = hc->free[--hc->nfree]; b = hc->free[--hc->nfree];
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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); b->pos, b->end - b->last);
} else if (hc->nbusy < cscf->large_client_header_buffers.num) { } else if (hc->nbusy < cscf->large_client_header_buffers.num) {
@ -993,7 +963,7 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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); b->pos, b->end - b->last);
} else { } else {
@ -1095,7 +1065,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
for (i = 0; i < r->virtual_names->nelts; i++) { for (i = 0; i < r->virtual_names->nelts; i++) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 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 (name[i].wildcard) {
if (r->headers_in.host_name_len <= name[i].name.len) { if (r->headers_in.host_name_len <= name[i].name.len) {
@ -1579,7 +1549,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); 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"; ctx->action = "closing request";
hc = r->http_connection; hc = r->http_connection;
@ -1677,7 +1647,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
b->last = b->start; 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); hc->free, hc->nfree);
if (hc->free) { if (hc->free) {
@ -1689,7 +1659,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
hc->nfree = 0; 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); hc->busy, hc->nbusy);
if (hc->busy) { if (hc->busy) {
@ -1785,8 +1755,9 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
if (rev->pending_eof) { if (rev->pending_eof) {
rev->log->handler = NULL;
ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, 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); "keepalive connection", ctx->client);
ngx_http_close_connection(c); ngx_http_close_connection(c);
return; return;
@ -1841,7 +1812,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
if (n == 0) { if (n == 0) {
ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, 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); ngx_http_close_connection(c);
return; return;
} }
@ -2055,7 +2026,7 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
if (r->file.fd != NGX_INVALID_FILE) { if (r->file.fd != NGX_INVALID_FILE) {
if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) { if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 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_request_t *r, int error)
== NGX_FILE_ERROR) == NGX_FILE_ERROR)
{ {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
ngx_close_file_n " deleted file \"%s\" failed", ngx_close_file_n " deleted file \"%V\" failed",
r->request_body->temp_file->file.name.data); &r->request_body->temp_file->file.name);
} }
} }
@ -2088,9 +2059,9 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
} }
} }
/* ctx->url was allocated from r->pool */ /* the variuos request strings were allocated from r->pool */
ctx = log->data; ctx = log->data;
ctx->url = NULL; ctx->request = NULL;
r->request_line.len = 0; r->request_line.len = 0;
@ -2148,6 +2119,7 @@ void ngx_http_close_connection(ngx_connection_t *c)
static void ngx_http_client_error(ngx_http_request_t *r, static void ngx_http_client_error(ngx_http_request_t *r,
int client_error, int error) int client_error, int error)
{ {
u_char *p;
ngx_http_log_ctx_t *ctx; ngx_http_log_ctx_t *ctx;
ngx_http_core_srv_conf_t *cscf; ngx_http_core_srv_conf_t *cscf;
@ -2164,13 +2136,15 @@ static void ngx_http_client_error(ngx_http_request_t *r,
r->connection->log->handler = NULL; r->connection->log->handler = NULL;
if (ctx->url) { if (ctx->request) {
switch (client_error) { switch (client_error) {
case NGX_HTTP_PARSE_INVALID_HOST: case NGX_HTTP_PARSE_INVALID_HOST:
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], "client %V sent invalid \"Host\" header \"%V\", URL: \"%V\"",
ctx->client, r->headers_in.host->value.data, ctx->url); ctx->client, &r->headers_in.host->value,
&ctx->request->unparsed_uri);
error = NGX_HTTP_INVALID_HOST; error = NGX_HTTP_INVALID_HOST;
@ -2186,24 +2160,49 @@ static void ngx_http_client_error(ngx_http_request_t *r,
case NGX_HTTP_PARSE_HTTP_TO_HTTPS: case NGX_HTTP_PARSE_HTTP_TO_HTTPS:
error = NGX_HTTP_TO_HTTPS; error = NGX_HTTP_TO_HTTPS;
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);
/* fall through */ } 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: default:
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
ctx->client, ctx->url); ctx->client, &ctx->request->unparsed_uri);
} }
} else { } else {
if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) { if (error == NGX_HTTP_REQUEST_URI_TOO_LARGE) {
r->request_line.len = r->header_in->end - r->request_start; r->request_line.len = r->header_in->end - r->request_start;
r->request_line.data = 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, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
ctx->client); ctx->client, &r->request_line);
} }
r->connection->log->handler = ngx_http_log_error; r->connection->log->handler = ngx_http_log_error;
@ -2212,20 +2211,35 @@ static void ngx_http_client_error(ngx_http_request_t *r,
} }
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; ngx_http_log_ctx_t *ctx = data;
if (ctx->action && ctx->url) { u_char *p;
return ngx_snprintf(buf, len, " while %s, client: %s, URL: %s",
ctx->action, ctx->client, ctx->url);
} else if (ctx->action == NULL && ctx->url) { p = buf;
return ngx_snprintf(buf, len, ", client: %s, URL: %s",
ctx->client, ctx->url);
} else { if (ctx->action) {
return ngx_snprintf(buf, len, " while %s, client: %s", p = ngx_snprintf(p, len, " while %s", ctx->action);
ctx->action, ctx->client); 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);
} }

View File

@ -41,8 +41,9 @@
#define NGX_HTTP_PARSE_NO_HOST_HEADER 16 #define NGX_HTTP_PARSE_NO_HOST_HEADER 16
#define NGX_HTTP_PARSE_INVALID_CL_HEADER 17 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 17
#define NGX_HTTP_PARSE_POST_WO_CL_HEADER 18 #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 #define NGX_HTTP_OK 200

View File

@ -148,7 +148,7 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r)
n = c->recv(c, r->request_body->buf->last, size); n = c->recv(c, r->request_body->buf->last, size);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 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) { if (n == NGX_AGAIN) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 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_request_body(ngx_http_request_t *r)
} }
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 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); r->request_body->rest);
if (r->request_body->rest) { if (r->request_body->rest) {

View File

@ -40,15 +40,11 @@ char *ngx_http_script_request_line(ngx_http_request_t *r, char *p, size_t len)
char *ngx_http_script_status(ngx_http_request_t *r, char *p, size_t len) char *ngx_http_script_status(ngx_http_request_t *r, char *p, size_t len)
{ {
p += ngx_snprintf(p, len, "%d", r->headers_out.status); return ngx_snprintf(p, len, "%d", r->headers_out.status);
return p;
} }
char *ngx_http_script_sent(ngx_http_request_t *r, char *p, size_t len) char *ngx_http_script_sent(ngx_http_request_t *r, char *p, size_t len)
{ {
p += ngx_snprintf(p, len, OFF_FMT, r->connection->sent); return ngx_sprintf(p, "%O", r->connection->sent);
return p;
} }

View File

@ -69,6 +69,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
for (cl = ctx->out; cl; cl = cl->next) { for (cl = ctx->out; cl; cl = cl->next) {
ll = &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); size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) { if (cl->buf->flush || cl->buf->recycled) {
@ -83,10 +89,20 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* add the new chain to the existent one */ /* add the new chain to the existent one */
for (ln = in; ln; ln = ln->next) { 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;
ll = &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); size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) { if (cl->buf->flush || cl->buf->recycled) {
@ -98,11 +114,12 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
} }
} }
*ll = NULL;
c = r->connection; c = r->connection;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT, "http write filter: l:%d f:%O s:%O", last, flush, size);
last, flush, size);
clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module); ngx_http_core_module);
@ -125,6 +142,9 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
if (!last) { if (!last) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"the http output chain is empty"); "the http output chain is empty");
ngx_debug_point();
return NGX_ERROR; return NGX_ERROR;
} }
return NGX_OK; return NGX_OK;
@ -136,7 +156,7 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE); clcf->limit_rate ? clcf->limit_rate: OFF_T_MAX_VALUE);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http write filter %X", chain); "http write filter %p", chain);
if (clcf->limit_rate) { if (clcf->limit_rate) {
sent = c->sent - sent; sent = c->sent - sent;

View File

@ -13,11 +13,10 @@
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in, ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit) off_t limit)
{ {
int n;
u_char *buf, *prev; u_char *buf, *prev;
off_t send, sent; off_t send, sent;
size_t len; size_t len;
ssize_t size; ssize_t n, size;
ngx_err_t err; ngx_err_t err;
ngx_chain_t *cl; ngx_chain_t *cl;
@ -63,7 +62,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
n = ngx_aio_write(c, buf, len); 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) { if (n == NGX_ERROR) {
return NGX_CHAIN_ERROR; return NGX_CHAIN_ERROR;
@ -75,7 +74,7 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 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) { for (cl = in; cl; cl = cl->next) {

View File

@ -17,11 +17,10 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
if (!(p = malloc(size))) { if (!(p = malloc(size))) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 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, ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size);
"malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
return p; return p;
} }
@ -49,12 +48,12 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
if (posix_memalign(&p, alignment, size) == -1) { if (posix_memalign(&p, alignment, size) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"posix_memalign() " SIZE_T_FMT " bytes aligned to " "posix_memalign() %uz bytes aligned to %uz failed",
SIZE_T_FMT " failed", size, alignment); size, alignment);
} }
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, 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; return p;
} }
@ -67,12 +66,12 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
if (!(p = memalign(alignment, size))) { if (!(p = memalign(alignment, size))) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"memalign() " SIZE_T_FMT " bytes aligned to " "memalign() %uz bytes aligned to %uz failed",
SIZE_T_FMT " failed", size, alignment); size, alignment);
} }
ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
"memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); "memalign: %p:%uz", p, size);
return p; return p;
} }

View File

@ -120,9 +120,14 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
return NGX_ERROR; 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)) { if ((size_t) n < sizeof(ngx_channel_t)) {
ngx_log_error(NGX_LOG_ALERT, log, 0, ngx_log_error(NGX_LOG_ALERT, log, 0,
"recvmsg() returned not enough data"); "recvmsg() returned not enough data: %uz", n);
return NGX_ERROR; return NGX_ERROR;
} }

View File

@ -10,32 +10,29 @@
#if (NGX_STRERROR_R) #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) { if (size == 0) {
return 0; return 0;
} }
errstr[0] = '\0'; errstr[0] = '\0';
strerror_r(err, errstr, size); strerror_r(err, (char *) errstr, size);
for (len = 0; len < size; len++) { while (*errstr && size) {
if (errstr[len] == '\0') { errstr++;
break; size--;
}
} }
return len; return errstr;
} }
#elif (NGX_GNU_STRERROR_R) #elif (NGX_GNU_STRERROR_R)
/* Linux 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; char *str;
size_t len; size_t len;
@ -46,20 +43,18 @@ ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
errstr[0] = '\0'; errstr[0] = '\0';
str = strerror_r(err, errstr, size); str = strerror_r(err, (char *) errstr, size);
if (str != errstr) { if (str != (char *) errstr) {
return ngx_cpystrn((u_char *) errstr, (u_char *) str, size) return ngx_cpystrn(errstr, (u_char *) str, size);
- (u_char *) errstr;
} }
for (len = 0; len < size; len++) { while (*errstr && size) {
if (errstr[len] == '\0') { errstr++;
break; size--;
}
} }
return len; return errstr;
} }
#endif #endif

View File

@ -47,14 +47,14 @@ typedef int ngx_err_t;
#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R) #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 #else
/* Solaris has threads-safe strerror() */ /* Solaris has threads-safe strerror() */
#define ngx_strerror_r(err, errstr, size) \ #define ngx_strerror_r(err, errstr, size) \
(char *) ngx_cpystrn(errstr, strerror(err), size) - (errstr) ngx_cpystrn(errstr, (u_char *) strerror(err), size)
#endif #endif

View File

@ -13,7 +13,7 @@ ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
ssize_t n; ssize_t n;
ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, 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) #if (NGX_PREAD)
@ -57,6 +57,9 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
{ {
ssize_t n; 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) #if (NGX_PWRITE)
n = pwrite(file->fd, buf, size, offset); n = pwrite(file->fd, buf, size, offset);
@ -68,7 +71,7 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if ((size_t) n != size) { if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0, 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; return NGX_ERROR;
} }
@ -92,7 +95,7 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
if ((size_t) n != size) { if ((size_t) n != size) {
ngx_log_error(NGX_LOG_CRIT, file->log, 0, 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; return NGX_ERROR;
} }
@ -120,17 +123,19 @@ int ngx_open_tempfile(u_char *name, ngx_uint_t persistent)
} }
#define NGX_IOVS 8
ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
off_t offset, ngx_pool_t *pool) off_t offset, ngx_pool_t *pool)
{ {
u_char *prev; u_char *prev;
size_t size; size_t size;
ssize_t n; ssize_t n;
struct iovec *iov;
ngx_err_t err; 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) { if (cl->next == NULL) {
return ngx_write_file(file, cl->buf->pos, return ngx_write_file(file, cl->buf->pos,
@ -138,61 +143,74 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
offset); offset);
} }
prev = NULL; vec.elts = iovs;
iov = NULL; vec.size = sizeof(struct iovec);
size = 0; 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;
while (cl) { /* create the iovec and coalesce the neighbouring bufs */
if (prev == cl->buf->pos) {
iov->iov_len += cl->buf->last - cl->buf->pos;
} else { while (cl && vec.nelts < IOV_MAX) {
ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); if (prev == cl->buf->pos) {
iov->iov_base = (void *) cl->buf->pos; iov->iov_len += cl->buf->last - 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; /* use pwrite() if there is the only iovec buffer */
prev = cl->buf->last;
cl = cl->next;
}
/* 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) { if (file->sys_offset != offset) {
iov = io.elts; if (lseek(file->fd, offset, SEEK_SET) == -1) {
return ngx_write_file(file, (u_char *) iov[0].iov_base, iov[0].iov_len, ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
offset); "lseek() failed");
} return NGX_ERROR;
}
if (file->sys_offset != offset) { file->sys_offset = offset;
if (lseek(file->fd, offset, SEEK_SET) == -1) { }
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed");
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; return NGX_ERROR;
} }
file->sys_offset = offset; 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;
}
n = writev(file->fd, io.elts, io.nelts); file->sys_offset += n;
file->offset += n;
if (n == -1) { } while (cl);
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "writev() failed");
return NGX_ERROR;
}
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;
return n; return n;
} }

View File

@ -9,8 +9,8 @@
/* FreeBSD 3.0 at least */ /* FreeBSD 3.0 at least */
char ngx_freebsd_kern_ostype[20]; char ngx_freebsd_kern_ostype[16];
char ngx_freebsd_kern_osrelease[20]; char ngx_freebsd_kern_osrelease[128];
int ngx_freebsd_kern_osreldate; int ngx_freebsd_kern_osreldate;
int ngx_freebsd_hw_ncpu; int ngx_freebsd_hw_ncpu;
int ngx_freebsd_net_inet_tcp_sendspace; 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_freebsd_kern_ostype, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"sysctlbyname(kern.ostype) failed"); "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); 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_freebsd_kern_osrelease, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"sysctlbyname(kern.osrelease) failed"); "sysctlbyname(kern.osrelease) failed");
return NGX_ERROR;
if (ngx_errno != NGX_ENOMEM) {
return NGX_ERROR;
}
ngx_freebsd_kern_osrelease[size - 1] = '\0';
} }

View File

@ -21,9 +21,10 @@
* The SysV semop() is a cheap syscall, particularly if it has little sembuf's * The SysV semop() is a cheap syscall, particularly if it has little sembuf's
* and does not use SEM_UNDO. * and does not use SEM_UNDO.
* *
* The condition variable implementation uses signal #64. The signal handler * The condition variable implementation uses the signal #64.
* is SIG_IGN so the kill() is a cheap syscall. The thread waits a signal * The signal handler is SIG_IGN so the kill() is a cheap syscall.
* in kevent(). The use of the EVFILT_SIGNAL is safe since FreeBSD 4.7. * 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 * This threads implementation currently works on i386 (486+) and amd64
* platforms only. * platforms only.
@ -114,15 +115,16 @@ void _spinunlock(ngx_atomic_t *lock)
#endif #endif
int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
ngx_log_t *log) ngx_log_t *log)
{ {
int id, err; ngx_pid_t id;
char *stack, *stack_top; ngx_err_t err;
char *stack, *stack_top;
if (nthreads >= max_threads) { if (nthreads >= max_threads) {
ngx_log_error(NGX_LOG_CRIT, log, 0, 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; return NGX_ERROR;
} }
@ -133,20 +135,21 @@ int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
if (stack == MAP_FAILED) { if (stack == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
"mmap(" PTR_FMT ":" SIZE_T_FMT "mmap(%p:%uz, MAP_STACK) thread stack failed",
", MAP_STACK) thread stack failed",
last_stack, usable_stack_size); last_stack, usable_stack_size);
return NGX_ERROR; return NGX_ERROR;
} }
if (stack != last_stack) { 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; stack_top = stack + usable_stack_size;
ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, 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); ngx_set_errno(0);
@ -164,7 +167,7 @@ int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
/ ngx_thread_stack_size; / ngx_thread_stack_size;
tids[nthreads] = id; 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; return err;
@ -205,30 +208,30 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); red_zone = ngx_freebsd_kern_usrstack - (size + rz_size);
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, 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); ngx_freebsd_kern_usrstack, red_zone);
zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0);
if (zone == MAP_FAILED) { if (zone == MAP_FAILED) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"mmap(" PTR_FMT ":" SIZE_T_FMT "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed",
", PROT_NONE, MAP_ANON) red zone failed",
red_zone, rz_size); red_zone, rz_size);
return NGX_ERROR; return NGX_ERROR;
} }
if (zone != red_zone) { if (zone != red_zone) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 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))) { if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) {
return NGX_ERROR; 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))) { if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) {
return NGX_ERROR; return NGX_ERROR;
@ -236,7 +239,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
tids[0] = ngx_pid; 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 *), ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *),
cycle->log); 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) { if (nkeys >= NGX_THREAD_KEYS_MAX) {
return NGX_ENOMEM; return NGX_ENOMEM;
@ -286,7 +289,7 @@ ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key)
} }
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) { if (key >= NGX_THREAD_KEYS_MAX) {
return NGX_EINVAL; return NGX_EINVAL;
@ -297,7 +300,7 @@ ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value)
} }
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; ngx_mutex_t *m;
union semun op; union semun op;
@ -361,10 +364,10 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
#if (NGX_DEBUG) #if (NGX_DEBUG)
if (try) { if (try) {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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 { } else {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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 #endif
@ -395,7 +398,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
} }
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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 * The mutex is locked so we increase a number
@ -406,8 +409,8 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
"%d threads wait for mutex " PTR_FMT "%D threads wait for mutex %p, "
", while only %d threads are available", "while only %ui threads are available",
lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads);
return NGX_ERROR; return NGX_ERROR;
} }
@ -415,7 +418,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (ngx_atomic_cmp_set(&m->lock, old, lock)) { if (ngx_atomic_cmp_set(&m->lock, old, lock)) {
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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 * The number of the waiting threads has been increased
@ -430,14 +433,12 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (semop(m->semid, &op, 1) == -1) { if (semop(m->semid, &op, 1) == -1) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
"semop() failed while waiting " "semop() failed while waiting on mutex %p", m);
"on mutex " PTR_FMT, m);
return NGX_ERROR; return NGX_ERROR;
} }
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex waked up " PTR_FMT " lock:%X", "mutex waked up %p lock:%XD", m, m->lock);
m, m->lock);
tries = 0; tries = 0;
old = m->lock; old = m->lock;
@ -462,7 +463,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (tries++ > 1000) { if (tries++ > 1000) {
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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 */ /* the mutex is probably contested so we are giving up now */
@ -474,7 +475,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
} }
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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; return NGX_OK;
} }
@ -493,7 +494,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (!(old & NGX_MUTEX_LOCK_BUSY)) { if (!(old & NGX_MUTEX_LOCK_BUSY)) {
ngx_log_error(NGX_LOG_ALERT, m->log, 0, 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; return NGX_ERROR;
} }
@ -501,7 +502,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
#if 0 #if 0
ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 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 #endif
for ( ;; ) { for ( ;; ) {
@ -516,7 +517,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (m->semid == -1) { if (m->semid == -1) {
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is unlocked", m); "mutex %p is unlocked", m);
return NGX_OK; return NGX_OK;
} }
@ -546,7 +547,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
/* wake up the thread that waits on semaphore */ /* wake up the thread that waits on semaphore */
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, 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_num = 0;
op.sem_op = 1; op.sem_op = 1;
@ -554,8 +555,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
if (semop(m->semid, &op, 1) == -1) { if (semop(m->semid, &op, 1) == -1) {
ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno,
"semop() failed while waking up on mutex " "semop() failed while waking up on mutex %p", m);
PTR_FMT, m);
return NGX_ERROR; return NGX_ERROR;
} }
@ -566,7 +566,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
} }
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is unlocked", m); "mutex %p is unlocked", m);
return NGX_OK; return NGX_OK;
} }
@ -647,21 +647,20 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
} }
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0,
"cv " PTR_FMT " wait, kq:%d, signo:%d", "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo);
cv, cv->kq, cv->signo);
for ( ;; ) { for ( ;; ) {
n = kevent(cv->kq, NULL, 0, &kev, 1, NULL); n = kevent(cv->kq, NULL, 0, &kev, 1, NULL);
ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, 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) { if (n == -1) {
err = ngx_errno; err = ngx_errno;
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
cv->log, ngx_errno, cv->log, ngx_errno,
"kevent() failed while waiting condition variable " "kevent() failed while waiting condition variable %p",
PTR_FMT, cv); cv);
if (err == NGX_EINTR) { if (err == NGX_EINTR) {
break; break;
@ -673,7 +672,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (n == 0) { if (n == 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0, ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned no events " "kevent() returned no events "
"while waiting condition variable " PTR_FMT, "while waiting condition variable %p",
cv); cv);
continue; continue;
} }
@ -681,7 +680,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (kev.filter != EVFILT_SIGNAL) { if (kev.filter != EVFILT_SIGNAL) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0, ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned unexpected events: %d " "kevent() returned unexpected events: %d "
"while waiting condition variable " PTR_FMT, "while waiting condition variable %p",
kev.filter, cv); kev.filter, cv);
continue; continue;
} }
@ -689,7 +688,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
if (kev.ident != (uintptr_t) cv->signo) { if (kev.ident != (uintptr_t) cv->signo) {
ngx_log_error(NGX_LOG_ALERT, cv->log, 0, ngx_log_error(NGX_LOG_ALERT, cv->log, 0,
"kevent() returned unexpected signal: %d ", "kevent() returned unexpected signal: %d ",
"while waiting condition variable " PTR_FMT, "while waiting condition variable %p",
kev.ident, cv); kev.ident, cv);
continue; continue;
} }
@ -697,8 +696,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
break; break;
} }
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv);
"cv " PTR_FMT " is waked up", cv);
if (ngx_mutex_lock(m) == NGX_ERROR) { if (ngx_mutex_lock(m) == NGX_ERROR) {
return NGX_ERROR; return NGX_ERROR;
@ -713,7 +711,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
ngx_err_t err; ngx_err_t err;
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, 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); cv, cv->tid, cv->signo);
if (kill(cv->tid, cv->signo) == -1) { if (kill(cv->tid, cv->signo) == -1) {
@ -721,8 +719,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
err = ngx_errno; err = ngx_errno;
ngx_log_error(NGX_LOG_ALERT, cv->log, err, ngx_log_error(NGX_LOG_ALERT, cv->log, err,
"kill() failed while signaling condition variable " "kill() failed while signaling condition variable %p", cv);
PTR_FMT, cv);
if (err == NGX_ESRCH) { if (err == NGX_ESRCH) {
cv->tid = -1; cv->tid = -1;
@ -731,8 +728,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv)
return NGX_ERROR; return NGX_ERROR;
} }
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv);
"cv " PTR_FMT " is signaled", cv);
return NGX_OK; return NGX_OK;
} }

View File

@ -18,7 +18,7 @@ typedef pid_t ngx_tid_t;
#define ngx_log_pid ngx_thread_self() #define ngx_log_pid ngx_thread_self()
#define ngx_log_tid 0 #define ngx_log_tid 0
#define TID_T_FMT PID_T_FMT #define NGX_TID_T_FMT "%P"
#define NGX_MUTEX_LIGHT 1 #define NGX_MUTEX_LIGHT 1
@ -91,10 +91,10 @@ typedef ngx_uint_t ngx_tls_key_t;
extern void **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" #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" #define ngx_thread_set_tls_n "the tls key setting"

View File

@ -265,7 +265,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
} }
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err, ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, err,
"sendfile() sent only " OFF_T_FMT " bytes", "sendfile() sent only %O bytes",
sent); sent);
} else { } else {
@ -290,14 +290,14 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
} }
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, 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); rc, file->file_pos, sent, fsize + hsize);
} else { } else {
rc = writev(c->fd, header.elts, header.nelts); rc = writev(c->fd, header.elts, header.nelts);
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 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) { if (rc == -1) {
err = ngx_errno; err = ngx_errno;

Some files were not shown because too many files have changed in this diff Show More