This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[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: libc-alpha at sourceware dot org
- Date: Sat, 07 Sep 2013 11:45:45 -0400
- Subject: [PATCH v2][BZ #832][BZ #3266] Make ldd try_trace more robust and portable
- Authentication-results: sourceware.org; auth=none
This is a second version of my previous ldd try_trace patch [1], with
feedback from Dmitry V. Levin [2][3].
[1]: http://sourceware.org/ml/libc-alpha/2012-11/msg00663.html
[2]: http://sourceware.org/ml/libc-alpha/2012-11/msg00736.html
[3]: http://sourceware.org/ml/libc-alpha/2013-06/msg01155.html
2013-09-07 P. J. McDermott <pj@pehjota.net>
[BZ #832]
[BZ #3266]
* elf/ldd.bash.in (try_trace): More robustly and portably work around
SELinux console/tty write permissions by using a command substitution
instead of a pipeline and pipefail option.
---
elf/ldd.bash.in | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in
index 39aeca2..112a350 100644
--- a/elf/ldd.bash.in
+++ b/elf/ldd.bash.in
@@ -106,19 +106,17 @@ if test "$unused" = yes; then
add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
fi
-# The following use of cat is needed to make ldd work in SELinux
-# environments where the executed program might not have permissions
-# to write to the console/tty. But only bash 3.x supports the pipefail
-# option, and we don't bother to handle the case for older bash versions.
-if set -o pipefail 2> /dev/null; then
- try_trace() {
- eval $add_env '"$@"' | cat
- }
-else
- try_trace() {
- eval $add_env '"$@"'
- }
-fi
+# 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
+}
case $# in
0)
--
Patrick "P. J." McDermott
http://www.pehjota.net/
Lead Developer, ProteanOS
http://www.proteanos.com/