From 10db8f6d73cb9c83ad9e53c78c7569d06472c997 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 18 Jul 2013 10:51:32 -0700 Subject: [PATCH] git-http-backend-verify: suppress git-http-backend errors The git-http-backend routinely emits messages to standard error about things that don't exist or requests that are not supported. Unfortunately these errors end up cluttering up the server error log and in almost all cases are uninteresting spam. Discard these errors by default unless the environment variable GIT_HTTP_BACKEND_SHOW_ERRORS is set to a non-empty value. At the same time, make sure any "Internal Server Error" results do end up in the server error log. --- bin/git-http-backend-verify | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/bin/git-http-backend-verify b/bin/git-http-backend-verify index a7d43e3..40ec010 100755 --- a/bin/git-http-backend-verify +++ b/bin/git-http-backend-verify @@ -8,6 +8,9 @@ # of "/usr/lib/git-core/git-http-backend") # # Note that GIT_PROJECT_ROOT must be set to use this script. +# +# Also prevent standard error output from git-http-backend cluttering up the +# server's log unless GIT_HTTP_BACKEND_SHOW_ERRORS is set to a non-empty value. set -e @@ -58,8 +61,13 @@ internalerr() errorhdrs 500 "Internal Server Error" if [ $# -eq 0 ]; then msglines "Internal Server Error" + echo "Internal Server Error" >&2 else msglines "$@" + while [ $# -gt 0 ]; do + echo "$1" >&2 + shift + done fi exit 0 } @@ -105,8 +113,15 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then esac fi -[ -n "$needscheck" ] || - { exec "$cfg_git_http_backend_bin" "$@"; forbidden "exec failed: $cfg_git_http_backend_bin"; exit 1; } +if [ -z "$needscheck" ]; then + if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then + exec "$cfg_git_http_backend_bin" "$@" + else + exec "$cfg_git_http_backend_bin" "$@" 2>/dev/null + fi + internalerr "exec failed: $cfg_git_http_backend_bin" + exit 1 +fi # add a missing trailing .git case "$proj" in @@ -156,6 +171,10 @@ EOT exit 1 fi -exec "$cfg_git_http_backend_bin" "$@" -forbidden "exec failed: $cfg_git_http_backend_bin" +if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then + exec "$cfg_git_http_backend_bin" "$@" +else + exec "$cfg_git_http_backend_bin" "$@" 2>/dev/null +fi +internalerr "exec failed: $cfg_git_http_backend_bin" exit 1 -- 2.11.4.GIT