[elbe-devel] /bin/sh

Torben Hohn torben.hohn at linutronix.de
Thu Jan 26 16:39:05 CET 2017


On Thu, Jan 26, 2017 at 03:52:01PM +0100, John Ogness wrote:
> Hi Ralf,
> 
> On 2017-01-26, Ralf Schlatterbeck <rsc at runtux.com> wrote:
> >> If there are no disagreements, I would provide a patch to remove all
> >> use of /bin/sh for executing commands. And in particular, removing
> >> its use for such simple tasks as writing text files. A quick
> >> recursive search for "sh -c" shows some bizarre usages.
> >
> > From what I understood so far, some of it is due to running chrooted.
> > But there is an undocumented raw_cmd-Feature that doesn't use a shell
> > on the target (it *does* seem to use a shell for calling the chroot
> > command, though afair and that usage of the shell could be removed).
> >
> > I'm using this for a busybox-based system to create the busybox links
> > like so:
> >
> >     <finetuning>
> >           <raw_cmd>/install_bb.sh</raw_cmd>
> >
> > And the install_bb has
> > #!/bin/busybox sh
> > ...
> > for i in $(busybox --list)
> >     do something
> >
> > Contrary to the original busybox example we don't need to temporarily
> > copy a shell with associated libs to the target and remove it later.
> 
> Agreed. The install_bb.sh script can even be avoided with:
> 
> <finetuning>
>     <raw_cmd>/bin/busybox mkdir -p /bin /sbin /usr/bin /usr/sbin</raw_cmd>
>     <raw_cmd>/bin/busybox --install -s</raw_cmd>
> </finetuning>
> 
> > So I guess sometimes it is very convenient to be able to use
> > shell-commands with pipelines, redirection etc and resort to raw_cmd
> > if you don't want a shell.
> 
> Thanks. I forgot that <command> is often used with shell expression,
> pipes, redirections, etc.
> 
> But there are still many places where "sh -c" are used and I don't see
> the need. For example, <ln> uses "sh -c". So if there is no /bin/sh, I
> cannot create any symbolic links.

Some "sh -c" occurences are there for historical reasons.
The original code was running in a post-install pressed hook.

The finetuning step was a generated shell script.
We basically took the old sh code, and made it work.

Some "sh -c" occurences have been added, because the old code suggested,
that it would be fine to implement things in sh.

The only place, i see where it must stay, is <command> because that
needs to support redirection etc...


> 
> > The raw_cmd feature should be (better?)  documented, I've found it by
> > accident.
> 
> Agreed. It should be better documented. In my opinion it would be enough
> to include it in the minimal-cpio example, since most people probably
> use that as a reference when creating a rootfs with no /bin/sh. (I
> assume you did as well, since you are also using the install_bb.sh
> script.)
> 
> So let me rephrase my initial question... is there any reason why we are
> using "sh -c" for things like <ln>? These kinds of things can be done
> without a chroot into the target rootfs.

i dont think, there are real reasons, other than historic.


-- 
Mit freundlichen Grüßen
Torben Hohn

Linutronix GmbH

Standort: Bremen

Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806

Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner

Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20170126/aac714b7/attachment.sig>


More information about the elbe-devel mailing list