Re: 'exec' runs shell functions and builtins

2017-07-25 Thread Thorsten Glaser
Robert Elz dixit:

>  | This specifically means that builtins MAY be made available
>  | to exec, and that thatbs an expected modus operandi.
>
>It means nothing of the kind.   The System Interfaces volume of POSIX.1-2008
>is the part that defines the system calls.

There’s no “exec” system call, so that’s the wrong part
you’re searching in for this.

>What the text you quoted is saying (if you had quoted it all) is that
>all of the built-in utilities (except the special built-ins) must be
>able to be accessed by execle(2) (and its sibling interfaces.)
>
>Note not may, must.

Yes, that *too*, but it also says that they *may* be builtins.

>Aside from the possibility that the sh exec special-builtin might be
>intended to make an exec*() system call (the spec does not say that)

Note that the exec built-in utility does not need to perfom
an exec*() system call.

>  | Heck, you can exec a function!
>
>That is where we started.   That is, that is the question.  Can you?

Of course you do, see the definition of “command” near the
top of the shell section.

bye,
//mirabilos
-- 
“ah that reminds me, thanks for the stellar entertainment that you and certain
other people provide on the Debian mailing lists │ sole reason I subscribed to
them (I'm not using Debian anywhere) is the entertainment factor │ Debian does
not strike me as a place for good humour, much less German admin-style humour”



Re: 'exec' runs shell functions and builtins

2017-07-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>And under what theory should 'exec' run a shell function?

Read up on what a “command” can be, pretty far up in
the Shell part.

Although I did not manage to get a pipeline or loop run.
Not sure if that’s a bug, but looking at the way statements
are parsed, probably not.

bye,
//mirabilos
-- 
18:47⎜ well channels… you see, I see everything in the
same window anyway  18:48⎜ i know, you have some kind of
telnet with automatic pong 18:48⎜ haha, yes :D
18:49⎜ though that's more tinyirc – sirc is more comfy


Re: 'exec' runs shell functions and builtins

2017-07-25 Thread Martijn Dekker
Op 25-07-17 om 23:41 schreef Thorsten Glaser:
> Martijn Dekker dixit:
> 
>> This behaviour also appears to be contrary to the documentation in
>> mksh(1) ("The command is executed without forking, replacing the shell
>> process"). The test script below demonstrates that neither "exec"
> 
> And this is utter nonsense, the builtin does replace the shell process,

And under what theory should 'exec' run a shell function?

- M.


Re: 'exec' runs shell functions and builtins

2017-07-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>to be a bug in POSIX terms; 'exec' is supposed to launch a program that
>overlays the current shell[2], implying the program launched by 'exec'
>is always external to the shell.

The built-in utility is “the program implementing command”,
and, with exec, it is not returning to the shell.

So, NO.

bye,
//mirabilos
-- 
11:56⎜«liwakura:#!/bin/mksh» also, i wanted to add mksh to my own distro │
i was disappointed that there is no makefile │ but somehow the Build.sh is
the least painful built system i've ever seen │ honours CC, {CPP,C,LD}FLAGS
properly │ looks cleary like done by someone who knows what they are doing


Re: 'exec' runs shell functions and builtins

2017-07-25 Thread Thorsten Glaser
Martijn Dekker dixit:

>This behaviour also appears to be contrary to the documentation in
>mksh(1) ("The command is executed without forking, replacing the shell
>process"). The test script below demonstrates that neither "exec"

And this is utter nonsense, the builtin does replace the shell process,

>replaces the shell process as the first executes a shell function and
>the second (within the function) executes a mksh builtin.

and you can even execute builtins by symlinking mksh to them,
try e.g. a symlink from mksh to print some day.

//mirabilos
-- 
(gnutls can also be used, but if you are compiling lynx for your own use,
there is no reason to consider using that package)
-- Thomas E. Dickey on the Lynx mailing list, about OpenSSL


[BUG] 'exec' runs shell functions and builtins

2017-07-25 Thread Martijn Dekker
In mksh (and pdksh), 'exec' looks up shell functions and builtins before
external commands, and if it finds one it appears to do the equivalent
of running the function or builtin followed by 'exit'. This turns out[1]
to be a bug in POSIX terms; 'exec' is supposed to launch a program that
overlays the current shell[2], implying the program launched by 'exec'
is always external to the shell.

This means that
(exec commandname arguments ...)
is a POSIXly correct way of guaranteeing the execution of an external
command without specifying the path.

In pdksh this is definitely a bug as this behaviour differs from ksh88
which pdksh is supposed to be a clone of. The POSIX spec is also based
on ksh88 behaviour.

This behaviour also appears to be contrary to the documentation in
mksh(1) ("The command is executed without forking, replacing the shell
process"). The test script below demonstrates that neither "exec"
replaces the shell process as the first executes a shell function and
the second (within the function) executes a mksh builtin.

testFn() {
exec print "this shell execs both functions and builtins"
}
PATH=/dev/null
exec testFn

Expected output: something like "testFn: not found".
Actual output: "this shell execs" etc.

- M.

[1] https://www.mail-archive.com/austin-group-l@opengroup.org/msg01469.html

[2]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_20_14