From feed52d242f5f4fb2c7beacbbd27aac32bf6dd39 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 15 Aug 2020 13:00:06 -0700 Subject: [PATCH] shlib.sh: provide git_ulimit function and var_xfsz_err In order to implement the new $Girocco::Config::max_file_size512 setting, it's necessary to run git using the ulimit512 utility. Provide a new git_ulimit function that does so if the max_file_size512 variable has been set to a non-zero value (otherwise just run git normally). While it would certainly be possible to always run git with the limit in place, it's only needed during fetching/receiving of new objects and it's better to avoid setting it during other operations (especially gc) that could, perhaps, be adversely affected by such a limit. When a command fails because it receives SIGXFSZ (and it does not have a signal handler for it installed), the shell will report that as an exit status of 128+. Unfortunately, the actual signal number assigned to SIGXFSZ is not standardized by POSIX (although it's likely 25 on many systems). Therefore, test the actual failure at install time and set a new "var_xfsz_err" variable to the exit code the shell will report for a SIGXFSZ termination on the current system. This makes it possible to reliably test for such a failure later. Signed-off-by: Kyle J. McKay --- shlib.sh | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/shlib.sh b/shlib.sh index 93a090d..171dadc 100644 --- a/shlib.sh +++ b/shlib.sh @@ -110,6 +110,7 @@ get_girocco_config_var_list() ( # var_xargs_r A "-r" if xargs needs it to behave correctly # var_du_exclude Option to exclude PATTERN from du if available # var_du_follow Option to follow command line sym links if available + # var_xfsz_err Shell error code when child dies from SIGXFSZ _cfg_vars="$(get_girocco_config_pm_var_list)" eval "$_cfg_vars" printf '%s\n' "$_cfg_vars" @@ -182,6 +183,23 @@ get_girocco_config_var_list() ( printf 'var_du_follow=%s\n' "-H" break fi + ul512bin="$inc_basedir/bin/ulimit512" + if [ ! -x "$ul512bin" ] && [ -x "$inc_basedir/src/ulimit512" ]; then + ul512bin="$inc_basedir/src/ulimit512" + fi + ebin="/bin/echo" + if [ ! -x "$ebin" ] && [ -x "/usr/bin/echo" ]; then + ebin="/usr/bin/echo" + fi + if [ -x "$ul512bin" ]; then + tmpfile="$(mktemp /tmp/ul512-$$-XXXXXX)" + ec=999 + { "$ul512bin" -f 0 "$ebin" test >"$tmpfile" || ec=$?; } >/dev/null 2>&1 + rm -f "$tmpfile" + if [ "$ec" != 999 ] && [ "$ec" -gt 0 ]; then + printf 'var_xfsz_err=%s\n' "$ec" + fi + fi ) # If basedir has been replaced, and shlib_vars.sh exists, get the config @@ -320,15 +338,31 @@ clean_git_env() { # have to beware and explicitly unset any variables that should not persist # beyond the function call itself. +_setexport_gitvars() { + [ z"${GIT_DIR+set}" != z"set" ] || export GIT_DIR + [ z"${GIT_SSL_NO_VERIFY+set}" != z"set" ] || export GIT_SSL_NO_VERIFY + [ z"${GIT_TRACE_PACKET+set}" != z"set" ] || export GIT_TRACE_PACKET + [ z"${GIT_USER_AGENT+set}" != z"set" ] || export GIT_USER_AGENT + [ z"${GIT_HTTP_USER_AGENT+set}" != z"set" ] || export GIT_HTTP_USER_AGENT +} + git() ( - [ z"${GIT_DIR+set}" != z"set" ] || export GIT_DIR - [ z"${GIT_SSL_NO_VERIFY+set}" != z"set" ] || export GIT_SSL_NO_VERIFY - [ z"${GIT_TRACE_PACKET+set}" != z"set" ] || export GIT_TRACE_PACKET - [ z"${GIT_USER_AGENT+set}" != z"set" ] || export GIT_USER_AGENT - [ z"${GIT_HTTP_USER_AGENT+set}" != z"set" ] || export GIT_HTTP_USER_AGENT + _setexport_gitvars exec "$cfg_git_bin" "$@" ) +# git_ulimit behaves the same as git except that it runs git using ulimit512 +# with the value of $cfg_max_file_size512 if that is set and greater than 0 + +git_ulimit() ( + _setexport_gitvars + if [ "${cfg_max_file_size512:-0}" = "0" ]; then + exec "$cfg_git_bin" "$@" + else + exec "$cfg_basedir/bin/ulimit512" -i -f "$cfg_max_file_size512" -- "$cfg_git_bin" "$@" + fi +) + # Since we do not yet require at least Git 1.8.5 this is a compatibility function # that allows us to use git update-ref --stdin where supported and the slow shell # script where not, but only the "delete" operation is currently supported. -- 2.11.4.GIT