zsh-workers
 help / color / mirror / code / Atom feed
* Possible missing status info for builtins sysopen and sysseek in zsh/system module
@ 2022-04-28 13:18 Jim
  2022-04-28 13:50 ` Jim
  2022-04-28 14:07 ` ERRNO is unset until set Matthew Martin
  0 siblings, 2 replies; 12+ messages in thread
From: Jim @ 2022-04-28 13:18 UTC (permalink / raw)
  To: devs

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Hi,

Man page zshmodules(5.8) seems to be missing status information in module
zsh/system for builtins sysopen and sysseek.  All the other builtins have
some
kind of statement for return status. I believe status 0 is success and 1
would
be an error of some kind for both. Don't know if there are other error
numbers
or if the parameter ERRNO is used.

Should it be assumed 0 and 1 are the only status numbers if nothing is
stated?

Thanks,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 634 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Possible missing status info for builtins sysopen and sysseek in zsh/system module
  2022-04-28 13:18 Possible missing status info for builtins sysopen and sysseek in zsh/system module Jim
@ 2022-04-28 13:50 ` Jim
  2022-04-29  9:47   ` Jim
  2022-04-28 14:07 ` ERRNO is unset until set Matthew Martin
  1 sibling, 1 reply; 12+ messages in thread
From: Jim @ 2022-04-28 13:50 UTC (permalink / raw)
  To: devs

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

Hi again,

On Thu, Apr 28, 2022 at 8:18 AM Jim <linux.tech.guy@gmail.com> wrote:

> Hi,
>
> Man page zshmodules(5.8) seems to be missing status information in module
> zsh/system for builtins sysopen and sysseek.  All the other builtins have
> some
> kind of statement for return status. I believe status 0 is success and 1
> would
> be an error of some kind for both. Don't know if there are other error
> numbers
> or if the parameter ERRNO is used.
>
> Should it be assumed 0 and 1 are the only status numbers if nothing is
> stated?
>

Can't assume that at least for sysseek.  If fd isn't assigned it returns a
status of 2.

Thanks,
>
> Jim Murphy
>

Jim

[-- Attachment #2: Type: text/html, Size: 1334 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-28 13:18 Possible missing status info for builtins sysopen and sysseek in zsh/system module Jim
  2022-04-28 13:50 ` Jim
@ 2022-04-28 14:07 ` Matthew Martin
  2022-04-28 14:16   ` Matthew Martin
  1 sibling, 1 reply; 12+ messages in thread
From: Matthew Martin @ 2022-04-28 14:07 UTC (permalink / raw)
  To: zsh-workers

On Thu, Apr 28, 2022 at 08:18:58AM -0500, Jim wrote:
> Hi,
> 
> Man page zshmodules(5.8) seems to be missing status information in module
> zsh/system for builtins sysopen and sysseek.  All the other builtins have
> some
> kind of statement for return status. I believe status 0 is success and 1
> would
> be an error of some kind for both. Don't know if there are other error
> numbers
> or if the parameter ERRNO is used.

While looking at copying the text under syswrite for sysopen and
sysseek, I ran a short test for ERRNO.
    > zmodload zsh/system; syswrite -o 3 test; print $? $ERRNO
    2
As Mikael pointed out on IRC, setting ERRNO once is sufficient for ERRNO
to reflect errno. The patch below lets ERRNO reflect errno without
setting ERRNO first.

diff --git a/Src/params.c b/Src/params.c
index 27ea82298..c144c25c3 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -297,7 +297,7 @@ static initparam special_params[] ={
 #define NULL_GSU BR((GsuScalar)(void *)NULL)
 #define IPDEF1(A,B,C) {{NULL,A,PM_INTEGER|PM_SPECIAL|C},BR(NULL),GSU(B),10,0,NULL,NULL,NULL,0}
 IPDEF1("#", pound_gsu, PM_READONLY_SPECIAL),
-IPDEF1("ERRNO", errno_gsu, PM_UNSET),
+IPDEF1("ERRNO", errno_gsu, 0),
 IPDEF1("GID", gid_gsu, PM_DONTIMPORT | PM_RESTRICTED),
 IPDEF1("EGID", egid_gsu, PM_DONTIMPORT | PM_RESTRICTED),
 IPDEF1("HISTSIZE", histsize_gsu, PM_RESTRICTED),


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-28 14:07 ` ERRNO is unset until set Matthew Martin
@ 2022-04-28 14:16   ` Matthew Martin
  2022-04-29  6:44     ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Matthew Martin @ 2022-04-28 14:16 UTC (permalink / raw)
  To: zsh-workers

On Thu, Apr 28, 2022 at 09:07:07AM -0500, Matthew Martin wrote:
> On Thu, Apr 28, 2022 at 08:18:58AM -0500, Jim wrote:
> diff --git a/Src/params.c b/Src/params.c
> index 27ea82298..c144c25c3 100644
> --- a/Src/params.c
> +++ b/Src/params.c
> @@ -297,7 +297,7 @@ static initparam special_params[] ={
>  #define NULL_GSU BR((GsuScalar)(void *)NULL)
>  #define IPDEF1(A,B,C) {{NULL,A,PM_INTEGER|PM_SPECIAL|C},BR(NULL),GSU(B),10,0,NULL,NULL,NULL,0}
>  IPDEF1("#", pound_gsu, PM_READONLY_SPECIAL),
> -IPDEF1("ERRNO", errno_gsu, PM_UNSET),
> +IPDEF1("ERRNO", errno_gsu, 0),
>  IPDEF1("GID", gid_gsu, PM_DONTIMPORT | PM_RESTRICTED),
>  IPDEF1("EGID", egid_gsu, PM_DONTIMPORT | PM_RESTRICTED),
>  IPDEF1("HISTSIZE", histsize_gsu, PM_RESTRICTED),

Should have git blamed first. This was changed from 0 to PM_UNSET in
32337 for emulation compatibility. Perhaps the docs should be updated
instead?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-28 14:16   ` Matthew Martin
@ 2022-04-29  6:44     ` Bart Schaefer
  2022-04-29 10:00       ` Mikael Magnusson
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2022-04-29  6:44 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

On Thu, Apr 28, 2022 at 7:17 AM Matthew Martin <phy1729@gmail.com> wrote:
>
> Should have git blamed first. This was changed from 0 to PM_UNSET in
> 32337 for emulation compatibility. Perhaps the docs should be updated
> instead?

We should at least be consistent.

These code changes are pretty minor but perhaps shouldn't go in before
the pending release.

[-- Attachment #2: errnodoc.txt --]
[-- Type: text/plain, Size: 5020 bytes --]

diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo
index 884c3e753..e25201faa 100644
--- a/Doc/Zsh/mod_system.yo
+++ b/Doc/Zsh/mod_system.yo
@@ -74,6 +74,11 @@ truncate file to size 0
 )
 enditem()
 
+A return status of 0 indicates the descriptor was successfully opened,
+otherwise an error message is printed, and 1 is returned for an error
+in the parameters to the command, or 2 is returned for a system error.
+The parameter tt(ERRNO) is nonzero for system errors.
+
 To close the file, use one of the following:
 
 example(tt(exec {)var(fd)tt(}<&-)
@@ -123,11 +128,11 @@ error for which a message is printed to standard error.
 )
 item(2)(
 There was an error on the read, or on polling the input file descriptor
-for a timeout.  The parameter tt(ERRNO) gives the error.
+for a timeout.  The parameter tt(ERRNO) identifies the error.
 )
 item(3)(
 Data were successfully read, but there was an error writing them
-to var(outfd).  The parameter tt(ERRNO) gives the error.
+to var(outfd).  The parameter tt(ERRNO) identifies the error.
 )
 item(4)(
 The attempt to read timed out.  Note this does not set tt(ERRNO) as this
@@ -147,6 +152,11 @@ expression. The tt(-u) option allows the file descriptor to be specified. By
 default the offset is specified relative to the start or the file but, with the
 tt(-w) option, it is possible to specify that the offset should be relative to
 the current position or the end of the file.
+
+The return status may be 0 for success, 1 for an error in the parameters
+to the command, or 2 for an error on the seek; no error message is
+printed in the last case, but the parameter tt(ERRNO) reflects
+the error that occurred.
 )
 item(tt(syswrite) [ tt(-c) var(countvar) ] [ tt(-o) var(outfd) ] var(data))(
 The data (a single string of bytes) are written to the file descriptor
@@ -166,7 +176,7 @@ returning early.
 
 The return status may be 0 for success, 1 for an error in the parameters
 to the command, or 2 for an error on the write; no error message is
-printed in the last case, but the parameter tt(ERRNO) will reflect
+printed in the last case, but the parameter tt(ERRNO) reflects
 the error that occurred.
 )
 xitem(tt(zsystem flock) [ tt(-t) var(timeout) ] [ tt(-i) var(interval) ] [ tt(-f) var(var) ] [tt(-er)] var(file))
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 6d2d41b7a..b543d1c38 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -750,6 +750,9 @@ as set by the most recently failed system call.
 This value is system dependent and is intended for debugging
 purposes.  It is also useful with the tt(zsh/system) module which
 allows the number to be turned into a name or message.
+
+To use this parameter, it must first be assigned a value (typically
+0 (zero)).  It is initially unset for scripting compatibility.
 )
 vindex(FUNCNEST)
 item(tt(FUNCNEST) <S>)(
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index ea11ef037..929a8b002 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -74,6 +74,8 @@ bin_sysread(char *nam, char **args, Options ops, UNUSED(int func))
     int infd = 0, outfd = -1, bufsize = SYSREAD_BUFSIZE, count;
     char *outvar = NULL, *countvar = NULL, *inbuf;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -i: input file descriptor if not stdin */
     if (OPT_ISSET(ops, 'i')) {
 	infd = getposint(OPT_ARG(ops, 'i'), nam);
@@ -238,6 +240,8 @@ bin_syswrite(char *nam, char **args, Options ops, UNUSED(int func))
     int outfd = 1, len, count, totcount;
     char *countvar = NULL;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -o: output file descriptor if not stdout */
     if (OPT_ISSET(ops, 'o')) {
 	outfd = getposint(OPT_ARG(ops, 'o'), nam);
@@ -303,6 +307,13 @@ static struct { const char *name; int oflag; } openopts[] = {
     { "trunc", O_TRUNC }
 };
 
+/*
+ * Return values of bin_sysopen:
+ *	0	Success
+ *	1	Error in parameters to command
+ *	2	Error on open, ERRNO set by system
+ */
+
 /**/
 static int
 bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
@@ -319,6 +330,8 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
     int fdflags = 0;
 #endif
 
+    errno = 0;	/* Distinguish non-system errors */
+
     if (!OPT_ISSET(ops, 'u')) {
 	zwarnnam(nam, "file descriptor not specified");
 	return 1;
@@ -374,12 +387,12 @@ bin_sysopen(char *nam, char **args, Options ops, UNUSED(int func))
 
     if (fd == -1) {
 	zwarnnam(nam, "can't open file %s: %e", *args, errno);
-	return 1;
+	return 2;
     }
     moved_fd = (explicit > -1) ? redup(fd, explicit) : movefd(fd);
     if (moved_fd == -1) {
 	zwarnnam(nam, "can't open file %s", *args);
-	return 1;
+	return 2;
     }
 
 #ifdef FD_CLOEXEC
@@ -423,6 +436,8 @@ bin_sysseek(char *nam, char **args, Options ops, UNUSED(int func))
     char *whence;
     off_t pos;
 
+    errno = 0;	/* Distinguish non-system errors */
+
     /* -u:  file descriptor if not stdin */
     if (OPT_ISSET(ops, 'u')) {
 	fd = getposint(OPT_ARG(ops, 'u'), nam);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Possible missing status info for builtins sysopen and sysseek in zsh/system module
  2022-04-28 13:50 ` Jim
@ 2022-04-29  9:47   ` Jim
  0 siblings, 0 replies; 12+ messages in thread
From: Jim @ 2022-04-29  9:47 UTC (permalink / raw)
  To: devs

[-- Attachment #1: Type: text/plain, Size: 73 bytes --]

Moved to thread: 'ERRNO is unset until set'

See: 50130, 50131 and 50138

[-- Attachment #2: Type: text/html, Size: 141 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-29  6:44     ` Bart Schaefer
@ 2022-04-29 10:00       ` Mikael Magnusson
  2022-04-29 17:02         ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2022-04-29 10:00 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

On 4/29/22, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Thu, Apr 28, 2022 at 7:17 AM Matthew Martin <phy1729@gmail.com> wrote:
>>
>> Should have git blamed first. This was changed from 0 to PM_UNSET in
>> 32337 for emulation compatibility. Perhaps the docs should be updated
>> instead?
>
> We should at least be consistent.
>
> These code changes are pretty minor but perhaps shouldn't go in before
> the pending release.

Could you clarify how a script is helped by ERRNO not being listed,
but still being unusable for storing any data? eg,

% ARGV0=sh zsh
$ echo ${(t)ERRNO}

$ echo $ERRNO

$ ERRNO=hi
$ echo $ERRNO
0
$ echo ${(t)ERRNO}
integer-special

When is this good or useful?

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-29 10:00       ` Mikael Magnusson
@ 2022-04-29 17:02         ` Bart Schaefer
  2022-04-29 17:08           ` Daniel Shahaf
  2022-04-29 17:13           ` grepping the archives (was: Re: ERRNO is unset until set) Daniel Shahaf
  0 siblings, 2 replies; 12+ messages in thread
From: Bart Schaefer @ 2022-04-29 17:02 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zsh hackers list

On Fri, Apr 29, 2022 at 3:00 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> When is this good or useful?

I was wondering that myself.  The only thing I can think of is to make
${+ERRNO} show the "right" thing.

Archive search is still offline (and I'm not sure it would help
anyway) so I can't find the discussion that led up my patch from
32337, but it seems to me that was intended to be just a first step to
causing some of those variables to be non-special when zsh is started
in emulation mode.  The second step just never happened, or at least
not comprehensively.

I'm no longer even sure why ERRNO was included, there's no reference
to it in the POSIX shell specification.  Clash with some other shell?
But which one?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-29 17:02         ` Bart Schaefer
@ 2022-04-29 17:08           ` Daniel Shahaf
  2022-04-29 17:19             ` Bart Schaefer
  2022-04-29 17:13           ` grepping the archives (was: Re: ERRNO is unset until set) Daniel Shahaf
  1 sibling, 1 reply; 12+ messages in thread
From: Daniel Shahaf @ 2022-04-29 17:08 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Fri, 29 Apr 2022 17:02 +00:00:
> On Fri, Apr 29, 2022 at 3:00 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> When is this good or useful?
>
> I was wondering that myself.  The only thing I can think of is to make
> ${+ERRNO} show the "right" thing.
>
> Archive search is still offline (and I'm not sure it would help
> anyway) so I can't find the discussion that led up my patch from
> 32337,

https://zsh.org/workers/32157?

> but it seems to me that was intended to be just a first step to
> causing some of those variables to be non-special when zsh is started
> in emulation mode.  The second step just never happened, or at least
> not comprehensively.
>
> I'm no longer even sure why ERRNO was included, there's no reference
> to it in the POSIX shell specification.  Clash with some other shell?
> But which one?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* grepping the archives (was: Re: ERRNO is unset until set)
  2022-04-29 17:02         ` Bart Schaefer
  2022-04-29 17:08           ` Daniel Shahaf
@ 2022-04-29 17:13           ` Daniel Shahaf
  2022-04-30  0:45             ` Daniel Shahaf
  1 sibling, 1 reply; 12+ messages in thread
From: Daniel Shahaf @ 2022-04-29 17:13 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Fri, 29 Apr 2022 17:02 +00:00:
> On Fri, Apr 29, 2022 at 3:00 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> When is this good or useful?
>
> I was wondering that myself.  The only thing I can think of is to make
> ${+ERRNO} show the "right" thing.
>
> Archive search is still offline (and I'm not sure it would help
> anyway) so I can't find the discussion that led up my patch from
> 32337,

I don't think we ever set up search after the migration from primenet,
no.  I haven't even realized anybody would use that.

Instead, there is rsync://rsync.zsh.org/pub/mla.

Or you could ask -infra@ for SSH access to the host, and then access the
archives that way.  That's how I found 32157 for my other reply (using
«cd ${RSYNC_ROOT_DIR}/zsh-workers && mutt -f =(for 1 in <315-323>xx.tgz
; tar -O - -xf $1)» and search therein).  We'll need a preferred username and
a key we can trust (i.e., PGP sign it using a key we already know to be
yours, or upload it to sourceforge, etc.).

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: ERRNO is unset until set
  2022-04-29 17:08           ` Daniel Shahaf
@ 2022-04-29 17:19             ` Bart Schaefer
  0 siblings, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2022-04-29 17:19 UTC (permalink / raw)
  To: Zsh hackers list

On Fri, Apr 29, 2022 at 10:09 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Bart Schaefer wrote on Fri, 29 Apr 2022 17:02 +00:00:
> > I can't find the discussion that led up my patch from
> > 32337,
>
> https://zsh.org/workers/32157?

That does seem to be it; also interestingly,
https://zsh.org/workers/32161
"not worth untangling"


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: grepping the archives (was: Re: ERRNO is unset until set)
  2022-04-29 17:13           ` grepping the archives (was: Re: ERRNO is unset until set) Daniel Shahaf
@ 2022-04-30  0:45             ` Daniel Shahaf
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Shahaf @ 2022-04-30  0:45 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote on Fri, 29 Apr 2022 17:13 +00:00:
> Or you could ask -infra@ for SSH access to the host, and then access the
> archives that way.  That's how I found 32157 for my other reply (using
> «cd ${RSYNC_ROOT_DIR}/zsh-workers && mutt -f =(for 1 in <315-323>xx.tgz
> ; tar -O - -xf $1)» and search therein).  We'll need a preferred username and
> a key we can trust (i.e., PGP sign it using a key we already know to be
> yours, or upload it to sourceforge, etc.).

For avoidance of doubt:

s/^a key/an SSH public key/

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-04-30  0:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 13:18 Possible missing status info for builtins sysopen and sysseek in zsh/system module Jim
2022-04-28 13:50 ` Jim
2022-04-29  9:47   ` Jim
2022-04-28 14:07 ` ERRNO is unset until set Matthew Martin
2022-04-28 14:16   ` Matthew Martin
2022-04-29  6:44     ` Bart Schaefer
2022-04-29 10:00       ` Mikael Magnusson
2022-04-29 17:02         ` Bart Schaefer
2022-04-29 17:08           ` Daniel Shahaf
2022-04-29 17:19             ` Bart Schaefer
2022-04-29 17:13           ` grepping the archives (was: Re: ERRNO is unset until set) Daniel Shahaf
2022-04-30  0:45             ` Daniel Shahaf

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).