bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: noisy gnulib-tool on IRIX


From: Bruno Haible
Subject: Re: noisy gnulib-tool on IRIX
Date: Thu, 9 Sep 2010 11:41:56 +0200
User-agent: KMail/1.9.9

Ralf Wildenhues wrote:
> > (hmm, maybe autoconf should use that trick to reduce
> > forking at m4sh startup).
> 
>   exec 3>&2 2>/dev/null; command; exec 2>&3 3>&-
> 
> has the advantage of not forking, the disadvantage of using another file
> descriptor (which we should probably disallow the user from passing in).

And it has the drawback of leaving the file descriptors in a broken state
when a signal is caught and a 'trap' handler is run. Namely, when a signal
is caught between the two execs, and the trap handler does an
  echo '*** caught signal' 1>&2
the output is in fact redirected to /dev/null.

I conclude that it is bad practice to fiddle with file descriptors 0, 1, 2
in this way: It requires manual verification that no 'trap' handler is
installed that is subject to this problem, and will break the day someone
changes the effects of the trap handlers.

I'm therefore reverting to the "common idiom" of using a test in a subshell
  if (alias ...) >/dev/null 2>/dev/null; ...
I prefer maintainable reliable code, even if it costs one more 'fork'.

Bruno


2010-09-09  Bruno Haible  <address@hidden>

        gnulib-tool: Avoid stderr output on IRIX related to 'alias', 'unalias'.
        * gnulib-tool: Don't fiddle with file descriptors 0, 1, 2. Instead, use
        a reliable way to determine whether the 'alias' command works.

--- gnulib-tool.orig    Thu Sep  9 11:37:32 2010
+++ gnulib-tool Thu Sep  9 11:36:54 2010
@@ -836,28 +836,24 @@
 # that the top-level statement containing the test starts after the 'alias'
 # command.
 if test -z "$have_echo"; then
-bsd_echo ()
+  bsd_echo ()
 {
 cat <<EOF
 $*
 EOF
 }
-exec 3>&2
-exec 2>/dev/null
-alias echo=bsd_echo
-exec 2>&3
-exec 3>&-
+  if (alias echo=bsd_echo) 2>/dev/null; then
+    alias echo=bsd_echo 2>/dev/null
+  fi
 fi
 if test -z "$have_echo" \
    && echo '\t' | grep t > /dev/null; then
   have_echo=yes
 fi
 if test -z "$have_echo"; then
-  exec 3>&2
-  exec 2>/dev/null
-  unalias echo
-  exec 2>&3
-  exec 3>&-
+  if (alias echo=bsd_echo) 2>/dev/null; then
+    unalias echo 2>/dev/null
+  fi
 fi
 # For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
 if test -z "$have_echo" \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]