[PATCH] Detect location of ldconfig before use

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Sun Feb 5 08:08:14 PST 2017


On Sun, 5 Feb 2017, Robert Helling wrote:
> > On 05 Feb 2017, at 15:21, Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com> wrote:
> > 
> > I have an idea ;)
> > 
> > Why not error handle those the code that produces those "warnings" (as
> > you call them) on that particular architecture, instead of
> > ignoring/hiding the errors (exit status failure) for everyone?  That
> > kind of thing can bite you later in various ways, leading to bug
> > reports saying "I tried that but it doesn't work :/  The build script
> > exits with success, but...  Could you fix it for me?  I can't tell you
> > where to start looking :(".
> > 
> > 'errexit' was not invented to punish people, but to help coding robust
> > scripts.  In my experience, error handling is one of the most
> > neglected areas.
> 
> ok, took up the challenge. My memory was wrong. It wasn’t Qt. It was 
> the construct
> 
>                 echo $NAME | grep / > /dev/null 2>&1
>                 if [ $? -eq 1 ] ; then
>                         install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME"
>                 fi
> 
> (this appears twice, you find it by searching for $?). Problem is, 
> when I run it, grep returns non-zero and this is then where the 
> script silently stops.

So, I read that as:

	* if there is a '/' in $NAME, do nothing
	* otherwise install $NAME

> Fixing this is beyond my bash abilities. If you want -e, please 
> rewrite these two occurrences so that the script does not silently 
> fail.

To even avoid the `grep' fork and the pipe, I would write that as:

	case $NAME in
		*/*)
			:
			;;
		*)
			install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME"
			;;
	esac

If you insist on using `grep':

	echo $NAME | grep -q / ||
		install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME"

and if it _must_ be done using an if/fi block:

	if ! echo $NAME | grep -q /; then
		install_name_tool -id "$INSTALL_ROOT/lib/$NAME" "$INSTALL_ROOT/lib/$NAME"
	fi


Cheers,

-- 
Cristian


More information about the subsurface mailing list