[PATCH v2][BZ #832][BZ #3266] Make ldd try_trace more robust and portable
Patrick 'P. J.' McDermott
pj+sourceware-ml@pehjota.net
Tue Sep 10 21:32:00 GMT 2013
On 2013-09-10 17:02, Mike Frysinger wrote:
> On Saturday 07 September 2013 11:45:45 Patrick "P. J." McDermott wrote:
>> +# The following command substitution is needed to make ldd work in
>> +# SELinux environments where the executed program might not have
>> +# permissions to write to the console/tty. The extra "x" character
>> +# prevents the shell from trimming trailing newlines from command
>> +# substitution results.
>> +try_trace() {
>> + output=$(eval $add_env '"$@"'; rc=$?; printf 'x'; exit $rc)
>> + rc=$?
>> + printf '%s' "${output%x}"
>> + return $rc
>> +}
>
> not really a new issue, but doesn't this also need to handle stderr ?
>
> simply adding 2>&1 for the eval statement seems sufficient
Ah yes, stderr is of course also affected by the permissions issue.
I'll fix that.
> i dislike the missing `local` decls for output and rc. but those aren't
> exactly specified in POSIX (even if every reasonable shell supports it). maybe
> do a double sub-shell instead ?
>
> try_trace() {
> (
> output=$(.....)
> rc=$?
> printf ....
> exit $rc
> )
> }
I discussed this in the original thread [1]. There are shells that
don't support local, so I'd rather avoid using it. I proposed using a
subshell as you've suggested (though the outside curly braces aren't
necessary on any shell, as far as I know â either way the function is
defined as a compound list of commands). At the time, though, no one
indicated any preferences. So I think I'll adjust this to use a
subshell.
[1]: https://sourceware.org/ml/libc-alpha/2013-06/msg01155.html
Thanks,
--
Patrick "P. J." McDermott
http://www.pehjota.net/
Lead Developer, ProteanOS
http://www.proteanos.com/
More information about the Libc-alpha
mailing list