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: Jim Meyering
Subject: Re: avoid mkdir/selinux failure when mknod is a shell built-in
Date: Wed, 16 Apr 2008 16:27:26 +0200

Eric Blake <address@hidden> wrote:

> According to Jim Meyering on 4/16/2008 6:57 AM:
> |   $ PATH=. /bin/sh -c 'exec mknod --version'|head -1
> |   /bin/sh: mknod: --: unknown option
>
> Ouch - this looks like a POSIX compliance bug in exec; I'm adding
> bug-autoconf to the distribution in case we want to document this corner
> case bug in the shell portability section.  POSIX states that exec is
> supposed to bypass shell builtins (and while special shell builtins, like
> 'exit', give undefined behavior when passed to exec, regular shell
> builtins, like 'fg', are required to exist in PATH even if they can't
> quite do as much work as their builtin counterpart).  Do you know which
> shell heritage the OpenBSD /bin/sh derives from?
>
> |   $ PATH=. /bin/sh -c 'nice mknod --version' | head -1
> |   mknod (GNU coreutils) 6.10.188-7cb24
>
> | So I'll go with nice.
>
> Sounds nice to me (sorry, couldn't resist :)

Here's the patch I've just pushed:

>From 57ae7da07593ab0134e120ea79819fdd069563a1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 16 Apr 2008 15:28:33 +0200
Subject: [PATCH] tests: accommodate built-in mknod more cleanly

* tests/mkdir/selinux: Undo most of previous change,
bc22dbbf844f31ddaf2e68b167d0128a985d73ab, and instead
invoke the command via "nice".  Using "exec" should be
enough, but isn't with OpenBSD's PD KSH v5.2.14 99/07/13.2.
Eric Blake suggested using nice.

Signed-off-by: Jim Meyering <address@hidden>
---
 tests/mkdir/selinux |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/tests/mkdir/selinux b/tests/mkdir/selinux
index 4363275..45c2399 100755
--- a/tests/mkdir/selinux
+++ b/tests/mkdir/selinux
@@ -34,16 +34,12 @@ fi
 c=invalid-selinux-context
 msg="failed to set default file creation context to \`$c':"

-# In OpenBSD's /bin/sh, mknod is a shell built-in.
-# In that case, just skip the mknod test.
-( mknod --version 2>&1 ) | grep 'GNU coreutils' \
-    && mknod='mknod b p' \
-    || mknod='mkdir dir'
-
 # Test each of mkdir, mknod, mkfifo with "-Z invalid-context".

-for cmd_w_arg in 'mkdir dir' "$mknod" 'mkfifo f'; do
-  $cmd_w_arg -Z $c 2> out && fail=1
+for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+  # In OpenBSD's /bin/sh, mknod is a shell built-in.
+  # Running via "nice" ensures we run our program and not the built-in.
+  nice -- $cmd_w_arg -Z $c 2> out && fail=1
   set $cmd_w_arg; cmd=$1
   echo "$cmd: $msg" > exp || fail=1

--
1.5.5.56.gbcf7f




reply via email to

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