Re: [PATCH v2 3/3] script(1): fix exit status wording, use 125 for general failure

2022-01-29 Thread наб
On Fri, Jan 28, 2022 at 06:32:07PM -0800, Philip Guenther wrote:
> On Fri, Jan 28, 2022 at 5:28 AM наб 
> wrote:
> > This is a base-line attempt at separating errors from the child from the
> > ones from script itself ‒ 125 is the general-purpose code in POSIX
> > utilities that exec() (with 126 being ENOEXEC and 127 ‒ ENOENT)
> >
> 
> I just checked the draft of the next revision of the POSIX spec and can
> find no reference to 125 being either recommended or required as the status
> for general exec failures.  For example, the spec for xargs includes this:
> 
> EXIT STATUS
> The following exit values shall be returned:
>  0All invocations of utility returned exit
> status zero.
>  1-125 A command line meeting the specified
> requirements could
>not be assembled, one or more of the
> invocations of utility
>returned a non-zero exit status, or some
> other error occurred.
>  126The utility specified by utility was found but
> could not be invoked.
>  127The utility specified by utility could not be
> found.
> 
> I'm confident that this isn't a change from previous versions.  Where is
> this proposed use of 125 documented?
I guess I overconstrained that ‒ all utilities that explicitly note a
general failure (xargs, as you mentioned, env, time, ) do note
"1-125 An error occurred in the env utility.".

I think it'd be Nice to return 125 (since we already exit 126/127 when
forwarding sh(1)) to enforce a better separation of the child exit
codes from the script exit codes, but if you don't feel like that's
a good reason to deviate from the status quo so far then that's fair
enough, too, and I don't feel /too/ strongly about it either way.

> Philip Guenther
Best,
наб


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] script(1): fix exit status wording, use 125 for general failure

2022-01-28 Thread Philip Guenther
On Fri, Jan 28, 2022 at 5:28 AM наб 
wrote:

> This is a base-line attempt at separating errors from the child from the
> ones from script itself ‒ 125 is the general-purpose code in POSIX
> utilities that exec() (with 126 being ENOEXEC and 127 ‒ ENOENT)
>

I just checked the draft of the next revision of the POSIX spec and can
find no reference to 125 being either recommended or required as the status
for general exec failures.  For example, the spec for xargs includes this:

EXIT STATUS
The following exit values shall be returned:
 0All invocations of utility returned exit
status zero.
 1-125 A command line meeting the specified
requirements could
   not be assembled, one or more of the
invocations of utility
   returned a non-zero exit status, or some
other error occurred.
 126The utility specified by utility was found but
could not be invoked.
 127The utility specified by utility could not be
found.

I'm confident that this isn't a change from previous versions.  Where is
this proposed use of 125 documented?

Philip Guenther


[PATCH v2 3/3] script(1): fix exit status wording, use 125 for general failure

2022-01-28 Thread наб
This is a base-line attempt at separating errors from the child from the
ones from script itself ‒ 125 is the general-purpose code in POSIX
utilities that exec() (with 126 being ENOEXEC and 127 ‒ ENOENT)
---
Please keep me in CC, as I'm not subscribed.

 usr.bin/script/script.1 | 6 ++
 usr.bin/script/script.c | 6 +++---
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1
index aa8bb2790..2ce483b97 100644
--- a/usr.bin/script/script.1
+++ b/usr.bin/script/script.1
@@ -80,10 +80,8 @@ or control-D
 .Pq Ql ^D
 will exit most interactive shells).
 .Nm
-will exit with the status of 0 unless any of its child
-processes fail, in which case,
-.Nm
-will return 1.
+will exit with the status of the shell,
+or 125 if it couldn't execute it.
 .Pp
 Certain interactive commands, such as
 .Xr vi 1 ,
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c
index fd2829033..1c2db608d 100644
--- a/usr.bin/script/script.c
+++ b/usr.bin/script/script.c
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
default:
fprintf(stderr, "usage: %s [-a] [-c command] [file]\n",
__progname);
-   exit(1);
+   exit(125);
}
argc -= optind;
argv += optind;
@@ -206,7 +206,7 @@ void
 finish(int signo)
 {
int save_errno = errno;
-   int status, e = 1;
+   int status, e = 125;
pid_t pid;
 
while ((pid = wait3(, WNOHANG, 0)) > 0) {
@@ -335,7 +335,7 @@ fail(void)
 {
 
(void)kill(0, SIGTERM);
-   done(1);
+   done(125);
 }
 
 void
-- 
2.30.2


signature.asc
Description: PGP signature