bug-autoconf
[Top][All Lists]
Advanced

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

Re: avoid mkdir/selinux failure when mknod is a shell built-in


From: Eric Blake
Subject: Re: avoid mkdir/selinux failure when mknod is a shell built-in
Date: Wed, 16 Apr 2008 16:14:35 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Jim Meyering <jim <at> meyering.net> writes:

> >
> > Ouch - this looks like a POSIX compliance bug in exec
> 
> This is on 3.9 GENERIC#617 i386 OpenBSD,
> and /bin/sh is a hard link to /bin/ksh.
> "strings" says it's PDKSH:
> 
>   PD KSH v5.2.14 99/07/13.2

Hmm - cygwin also has pdksh 5.2.14, but there, mknod is not builtin.  At any 
rate, I was able to reproduce this with other builtins, so here's what I'm 
considering adding to autoconf.  Any comments before I check it in?

>From 53403805c39ace610782a1b54c257b00844f61fd Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Wed, 16 Apr 2008 10:10:31 -0600
Subject: [PATCH] Document pdksh exec behavior.

* doc/autoconf.texi (Limitations of Builtins) <exec>: New
subsection.
Discovered by Jim Meyering.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog         |    7 ++++++
 doc/autoconf.texi |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b1d9a4e..9d9d04e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-16  Eric Blake  <address@hidden>
+
+       Document pdksh exec behavior.
+       * doc/autoconf.texi (Limitations of Builtins) <exec>: New
+       subsection.
+       Discovered by Jim Meyering.
+
 2008-04-14  Ralf Wildenhues  <address@hidden>
 
        * tests/autotest.at (AT_CHECK_AT): Allow to pass additional
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8b10387..9a381ee 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -13945,6 +13945,69 @@ but portable scripts should not rely on this.
 You should not rely on @code{LINENO} within @command{eval}.
 @xref{Special Shell Variables}.
 
address@hidden @command{exec}
address@hidden -----------------
address@hidden @command{exec}
+Posix divides the set of shell built-ins into two groups.  Special
+built-ins (such as @command{exit}) must impact the environment of the
+current shell, and need not be available through @command{exec}.
+Regular built-ins (such as @command{echo} or @command{cd}) must not
+propogate variable assignments to the environment of the current shell,
+and must also be available through @command{exec} (although the
+functionality may be pointless if not done in the context of the current
+shell).  According to this distinction, it should always be possible to
+use @command{exec} to invoke an actual executable rather than a regular
+built-in:
+
address@hidden
+$ @kbd{sh -c 'printf --version' | head -n1}
+sh: line 0: printf: --: invalid option
+printf: usage: printf [-v var] format [arguments]
+$ @kbd{sh -c 'exec printf --version' | head -n1}
+printf (GNU coreutils) 6.10
address@hidden example
+
+Many systems lack executable replacements for all of their regular
+built-ins (fortunately, the missing executables are usually the ones
+that make little sense to execute outside of the current shell
+environment):
+
address@hidden
+$ @kbd{sh -c 'exec cd /tmp'}
+sh: line 0: exec: cd: not found
address@hidden example
+
+On the other hand, @command{pdksh} 5.2.14 refuses to execute the
+executable replacement, using the built-in no matter what:
+
address@hidden
+$ @kbd{pdksh -c 'exec true --version'}
+$ @kbd{sh -c 'exec true --version'}
+true (GNU coreutils) 6.10
address@hidden example
+
address@hidden
+This has the interest effect that @command{pdksh} can use @command{exec}
+on special built-ins, even though Posix doesn't require it:
+
address@hidden
+$ @kbd{sh -c 'exec exit 2' || echo $?}
+sh: line 0: exec: exit: not found
+127
+$ @kbd{pdksh -c 'exec exit 2' || echo $?}
+2
address@hidden example
+
+When it is desired to avoid a regular shell built-in, the workaround is
+to use some other forwarding command, such as @command{nice}, that will
+ensure a path search:
+
address@hidden
+$ @kbd{pdksh -c 'exec true --version' | head -n1}
+$ @kbd{pdksh -c 'nice true --version' | head -n1}
+true (GNU coreutils) 6.10
address@hidden example
+
 @item @command{exit}
 @c -----------------
 @prindex @command{exit}
-- 
1.5.5








reply via email to

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