This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2][BZ #832][BZ #3266] Make ldd try_trace more robust and portable
- From: "Patrick 'P. J.' McDermott" <pj+sourceware-ml at pehjota dot net>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 10 Sep 2013 17:32:21 -0400
- Subject: Re: [PATCH v2][BZ #832][BZ #3266] Make ldd try_trace more robust and portable
- Authentication-results: sourceware.org; auth=none
- References: <522B4A29 dot 3060509 at pehjota dot net> <201309101702 dot 21701 dot vapier at gentoo dot org>
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/