This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2][BZ #832][BZ #3266] Make ldd try_trace more robust and portable


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]