All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: Sean Anderson <seanga2@gmail.com>
Cc: "Steve Bennett" <steveb@workware.net.au>,
	"Rasmus Villemoes" <rasmus.villemoes@prevas.dk>,
	u-boot@lists.denx.de, "Tom Rini" <trini@konsulko.com>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Simon Glass" <sjg@chromium.org>,
	"Roland Gaudig" <roland.gaudig-oss@weidmueller.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Kostas Michalopoulos" <badsector@runtimeterror.com>
Subject: Re: [RFC PATCH 03/28] cli: lil: Replace strclone with strdup
Date: Thu, 08 Jul 2021 18:13:19 +0200	[thread overview]
Message-ID: <132363.1625760799@gemini.denx.de> (raw)
In-Reply-To: <4aa7ff19-b774-0d67-b96a-9c0c9290a708@gmail.com>

Dear Sean,

In message <4aa7ff19-b774-0d67-b96a-9c0c9290a708@gmail.com> you wrote:
>
> Without pipes, how do bourne-style shells communicate? Sure you can
> transfer data into functions using arguments, but what about the other
> way around? Numeric return values? Global variables? I think these are
> rather anemic compared to proper return values.

Pipes are basically just a shortcut to avoid buffer space and to
make scripting easier and more elegant.

For example:

	$ ps aux | grep foo | grep -v grep | awk '{print $2}' | xargs kill

can be written without use of pipes as:

	$ ps aux >/tmp/$$.1 ; \
	  grep foo </tmp/$$.1 >/tmp/$$.2 ; \
	  grep -v grep </tmp/$$.2 >/tmp/$$.1 ; \
	  awk '{print $2}' </tmp/$$.1 >/tmp/$$.2  ; \
	  xargs kill </tmp/$$.2 ; \
	  rm -f /tmp/$$.1 /tmp/$$.2

[and of course this could be done in many other ways, too, cleaner
and more efficient]

The point is:   Pipes are just a shortcut.  You can do all the same
using files - of course with different performance and resource
usage.

> The point here is that many Hush features were written with fork. For
> example, to create a new scope (such as for a subshell), Hush just
> fork()s. When parsing, if it encounters a construct like $(), it fork()s

Yes, of course I am fully aware of this.  This is one of the reasons
why command substitution was excluded from the inital port of hush
to U-Boot - but again: command sustitution is just a shortcut; it is
simple enough to write scripts without it, and it is certainly
possible to implent this feature in a U-Boot context as well.

The reason it was not done 18 years ago is 1) typical systems at
that time did not have the resources (especially not enough ROM for
a bigger U-Boot image), and 2) having a shell with basic scripting
capabilities was sheer extravagance in a boot loader.

Yes, the situation has changed since then; today a U-Boot image is
as big as a v2.2 Linux kernel image was then, and nobody cares.

> and then modifies the map variable, (correctly) assuming that the
> "original" map will remain unmodified. These things are all over and
> make doing a port difficult; especially when they crop up as unforseen
> bugs. Though I suppose the real issue here is a lack of virtual memory.

Not really.  At the time of the port the concern was about code size
(size of the text segment).

> IMO "everything is a file" is more of an API thing than a shell thing.
> E.g. the idea that you can use open/read/write/close to access any
> resource. But without pipes, I don't think such an abstraction is very
> useful.

Pipes are just a notation to allow for a convenient use of
coroutines, even from a command line interface.  They make you think
of concurrent processing, but (on single core machines - which was
all they had at the time this was invented) it was just an emulation
of concurrency on a strictly sequential system.

Nothing really fancy at all, once you have the idea.  And nothing
that could not be emulated in a U-Boot environment, either.

The question is: how urgently do we need it?

My experience is that if anything is _really_ needed, someone will
show up and implement it, probably funded by some customer who needs
this feature for some product.  I have yet to see any such urgent
need for pipes in U-Boot.


> > Expect the output of every program to become the input to another, as
> > yet unknown, program. Don't clutter output with extraneous
> > information. Avoid stringently columnar or binary input formats.

That's the theory, yes.  In reality, things are a bit different.
Look at the output format of classic Unix commands: ls, ps, df, ...

> I don't know about that. I think making U-Boot commands emit output
> designed for machine consumption would require substantial effort.

Unix commands usually have NOT been designed for "machine
consumption", on contrary.  Even network protocols, log files atc.
were intentionally designed to be humanly readable.

It's the flexibility of the tools which allows for clever usage.


In U-Boot, commands could be cleaned up for better use in pipes -
assuming we had those.  But there would be no need to do this ina
single huge action - it could be done step by step, one command at
a time when somebody needs to use it in such a way.

> >> * Tools such as grep, cut, tr, sed, sort, uniq, etc. which are extremely
> >>     useful when working with streams are not present in U-Boot.
> > 
> > You are talking about OS environments here.  But we are a boot
> > loader.
>
> These programs are just as much part of the shell as the builtin
> commands.

Sorry, but they are definitely NOT part of the _shell_.

They are part of the standard Unix toolbox for basic text
processing, but for many good reasons each of these is a separate
program, and the shell knows nothing of these.

> > In which way do you think "a new language" needs to be ported when
> > switching from an old to a new version of hush?  It would be still a
> > (mostly) POSIX compatible shell, with some restrictions.
>
> Modern Hush is completely unrecognizable compared to what we have in
> U-Boot today. Any "updating" effort would be akin to going over the
> entire upstream codebase and porting it from scratch.

Agreed. But this means porting some code, which still implements the
very same language (i. e. "shell"). There would be no new language in
this case - just a bigger subset, less restrictions, more options,
probably.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
God made machine language; all the rest is the work of man.

  reply	other threads:[~2021-07-08 16:13 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01  6:15 [RFC PATCH 00/28] cli: Add a new shell Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 01/28] Add Zlib License Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-01  6:15 ` [RFC PATCH 02/28] cli: Add LIL shell Sean Anderson
2021-07-02 11:03   ` Wolfgang Denk
2021-07-02 13:33     ` Sean Anderson
2021-07-03  2:12       ` Sean Anderson
2021-07-03 19:33         ` Wolfgang Denk
2021-07-05 15:29           ` Simon Glass
2021-07-05 19:10           ` Tom Rini
2021-07-05 19:47             ` Sean Anderson
2021-07-05 19:53               ` Tom Rini
2021-07-05 19:55                 ` Sean Anderson
2021-07-06  7:46               ` Wolfgang Denk
2021-07-06  7:52                 ` Michael Nazzareno Trimarchi
2021-07-06 14:57                   ` Simon Glass
2021-07-06 15:48                     ` Tom Rini
2021-07-07  8:22                     ` Michael Nazzareno Trimarchi
2021-07-06 14:54                 ` Tom Rini
2021-07-07  8:15                   ` Wolfgang Denk
2021-07-07 13:58                     ` Tom Rini
2021-07-07 14:10                       ` Wolfgang Denk
2021-07-07 14:14                         ` Tom Rini
2021-07-07 14:23                           ` Wolfgang Denk
2021-07-06  7:44             ` Wolfgang Denk
2021-07-06 15:43               ` Tom Rini
2021-07-06 16:09                 ` Kostas Michalopoulos
2021-07-07 13:32                   ` Sean Anderson
2021-07-07  8:15                 ` Wolfgang Denk
2021-07-07 13:46                   ` Sean Anderson
2021-07-07 13:51                     ` Tom Rini
2021-07-07 13:58                   ` Tom Rini
2021-07-07 14:48                   ` Marek Behun
2021-07-08  5:19                     ` Michael Nazzareno Trimarchi
2021-07-08 15:33                       ` Tom Rini
2021-07-08  4:56               ` Sean Anderson
2021-07-08 17:00                 ` Wolfgang Denk
2021-07-03 19:23       ` Wolfgang Denk
2021-07-01  6:15 ` [RFC PATCH 03/28] cli: lil: Replace strclone with strdup Sean Anderson
2021-07-02  8:36   ` Rasmus Villemoes
2021-07-02 11:38     ` Wolfgang Denk
2021-07-02 13:38     ` Sean Anderson
2021-07-02 14:28       ` Tom Rini
2021-07-02 22:18       ` Kostas Michalopoulos
2021-07-03  2:28         ` Sean Anderson
2021-07-03 19:26       ` Wolfgang Denk
2021-07-05  5:07         ` Steve Bennett
2021-07-05 14:42           ` Sean Anderson
2021-07-05 15:29             ` Simon Glass
2021-07-05 15:42               ` Sean Anderson
2021-07-05 17:50             ` Wolfgang Denk
2021-07-08  4:37               ` Sean Anderson
2021-07-08 16:13                 ` Wolfgang Denk [this message]
2021-07-01  6:15 ` [RFC PATCH 04/28] cli: lil: Remove most functions by default Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-01  6:15 ` [RFC PATCH 05/28] cli: lil: Rename some functions to be more like TCL Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-05 15:54     ` Sean Anderson
2021-07-05 17:58       ` Wolfgang Denk
2021-07-05 18:51         ` Tom Rini
2021-07-05 21:02           ` Simon Glass
2021-07-05 21:36             ` Tom Rini
2021-07-06  7:52           ` Wolfgang Denk
2021-07-06 15:21             ` Simon Glass
2021-07-06 15:33             ` Tom Rini
2021-07-06 16:00               ` Kostas Michalopoulos
2021-07-07  8:16               ` Wolfgang Denk
2021-07-07 13:58                 ` Tom Rini
2021-07-05 19:46         ` Sean Anderson
2021-07-06  7:50           ` Wolfgang Denk
2021-07-08  4:47             ` Sean Anderson
2021-07-08 16:21               ` Wolfgang Denk
2021-07-01  6:15 ` [RFC PATCH 06/28] cli: lil: Convert some defines to enums Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 07/28] cli: lil: Simplify callbacks Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 08/28] cli: lil: Handle commands with dots Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 09/28] cli: lil: Use error codes Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 10/28] cli: lil: Add printf-style format helper for errors Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 11/28] cli: lil: Add several helper functions " Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 12/28] cli: lil: Check for ctrl-c Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-01  6:15 ` [RFC PATCH 13/28] cli: lil: Wire up LIL to the rest of U-Boot Sean Anderson
2021-07-02  8:18   ` Rasmus Villemoes
2021-07-02 13:40     ` Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-01  6:15 ` [RFC PATCH 14/28] cli: lil: Document structures Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 15/28] cli: lil: Convert LIL_ENABLE_POOLS to Kconfig Sean Anderson
2021-07-01  6:15 ` [RFC PATCH 16/28] cli: lil: Convert LIL_ENABLE_RECLIMIT to KConfig Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 17/28] test: Add tests for LIL Sean Anderson
2021-07-05 15:29   ` Simon Glass
2021-07-01  6:16 ` [RFC PATCH 18/28] cli: lil: Remove duplicate function bodies Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 19/28] cli: lil: Add "symbol" structure Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 20/28] cli: lil: Add config to enable debug output Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 21/28] cli: lil: Add a distinct parsing step Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 22/28] env: Add a priv pointer to hwalk_r Sean Anderson
2021-07-01 20:10   ` Tom Rini
2021-07-01  6:16 ` [RFC PATCH 23/28] cli: lil: Handle OOM for hm_put Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 24/28] cli: lil: Make proc always take 3 arguments Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 25/28] cli: lil: Always quote items in lil_list_to_value Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 26/28] cli: lil: Allocate len even when str is NULL in alloc_value_len Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 27/28] cli: lil: Add a function to quote values Sean Anderson
2021-07-01  6:16 ` [RFC PATCH 28/28] cli: lil: Load procs from the environment Sean Anderson
2021-07-01 20:21 ` [RFC PATCH 00/28] cli: Add a new shell Tom Rini
2021-07-02 11:30   ` Wolfgang Denk
2021-07-02 13:56     ` Sean Anderson
2021-07-02 14:07   ` Sean Anderson
2021-07-08  3:49 ` Heiko Schocher
2021-07-08  4:26   ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=132363.1625760799@gemini.denx.de \
    --to=wd@denx.de \
    --cc=badsector@runtimeterror.com \
    --cc=marek.behun@nic.cz \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=roland.gaudig-oss@weidmueller.com \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=steveb@workware.net.au \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.