From e666896b70d518934690fe2c6ad4dd75f73a0c65 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 24 Apr 2015 15:34:44 -0700 Subject: [PATCH] shlib.sh: provide xargs wrapper to compensate for broken behavior On some platforms running the following: xargs --- install.sh | 2 +- shlib.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index bc5628e..3b8de02 100755 --- a/install.sh +++ b/install.sh @@ -178,7 +178,7 @@ fi chown_make() { if [ "$LOGNAME" = root -a -n "$SUDO_USER" -a "$SUDO_USER" != root ]; then find "$@" -user root -print0 2>/dev/null | \ - xargs $(: | xargs echo -r) -0 chown "$SUDO_USER:$(id -gn "$SUDO_USER")" + xargs -0 chown "$SUDO_USER:$(id -gn "$SUDO_USER")" elif [ "$LOGNAME" = root -a -z "$SUDO_USER" -o "$SUDO_USER" = root ]; then echo "*** WARNING: running make as root w/o sudo may leave root-owned: $*" fi diff --git a/shlib.sh b/shlib.sh index 8ecfde3..a8eb512 100644 --- a/shlib.sh +++ b/shlib.sh @@ -64,6 +64,7 @@ get_girocco_config_var_list() ( # var_window_memory Value to use for repack --window-memory= # var_log_window_size Value to use for git-svn --log-window-size= # var_utf8_locale Value to use for a UTF-8 locale if available + # var_xargs_r A "-r" if xargs needs it to behave correctly _cfg_vars="$(get_girocco_config_pm_var_list)" eval "$_cfg_vars" printf '%s\n' "$_cfg_vars" @@ -84,6 +85,8 @@ get_girocco_config_var_list() ( sed -e '/en_US/ s/^/0 /; /en_US/ !s/^/1 /' | LC_ALL=C sort | \ head -n 1 | cut -d ' ' -f 2)" [ -z "$_guess_locale" ] || printf 'var_utf8_locale=%s.UTF-8\n' "$_guess_locale" + # On some broken platforms running xargs without -r and empty input runs the command + printf 'var_xargs_r=%s\n' "$(: | command xargs echo -r)" ) # If basedir has been replaced, and shlib_vars.sh exists, get the config @@ -154,6 +157,11 @@ git() ( nc_openbsd() { "$cfg_nc_openbsd_bin" "$@"; } +# Some platforms' broken xargs runs the command always at least once even if +# there's no input unless given a special option. Automatically supply the +# option on those platforms by providing an xargs function. +xargs() { command xargs $var_xargs_r "$@"; } + _addrlist() { _list= for _addr in "$@"; do -- 2.11.4.GIT