Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #1063345

Bug#990265: utilities and write errors

From Vincent Lefevre <vincent-opgr@vinc17.net>
Newsgroups linux.debian.bugs.dist
Subject Bug#990265: utilities and write errors
Date 2021-06-30 03:30 +0200
Message-ID <Cvxd7-42W-1@gated-at.bofh.it> (permalink)
References (7 earlier) <CvwK5-3F6-17@gated-at.bofh.it> <CvwK5-3F6-19@gated-at.bofh.it> <CvwK5-3F6-1@gated-at.bofh.it> <Ctujn-1ph-1@gated-at.bofh.it> <CvwK5-3F6-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 2021-06-30 00:46:00 +0000, mirabilos via austin-group-l at The Open Group wrote:
> Using the same shorthand, I changed mksh tonight to do pretty much
> what you described, in a second patch:
> 
> @@ pseudo @@
>  int
>  call_builtin(func_t builtinfunc, int argc, char *argv[])
>  {
>      int exitstatus;
> 
>      stdout = fdopen(1, "w");
>      exitstatus = (*builtinfunc)(argc, argv, environ);
>      fflush(stdout);
> +    if (ferror(stdout)) {
> +        fprintf(stderr, "%s: write: %s\n", argv[0], strerror(errno));
> +        if (exitstatus == 0)
> +            exitstatus = 1;
> +    }
>      return (exitstatus);
>  }
> 
> This handles pwd and (if compiled in) printf; I also added the same
> error message to the echo/print builtin for where it detects errors
> as it uses the write(2) syscall, not the stdio replacement, internally.

Thanks, I think that this is OK.

> We’ll see whether that breaks anything. Incidentally, if true encounters
> an error on stdout during operation now, it can return false — except it
> never accesses stdout, thus this cannot happen.
> 
> Vincent will probably see whether this solves his problem; he’s got to
> notify me if there are any other builtins to take care of.

There are "ulimit", "alias" and "type". But I don't know whether they
are also handled by call_builtin...

> Ugh. This is a “magic fix”… I don’t like this, but it’ll do, I think.
> If the builtin encountered other errors and already exited nōn-zero,
> that will be that, but otherwise, it runs on until the buffers are
> flushed as write errors may not be recognised before that. If that’s
> not enough, I don’t know. In that case I’d question the standard harder.

It seems that Coreutils has the same logic: the check is done only
at the end (except that it closes the stream instead of just flushing
it... which is OK because these are external commands).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Back to linux.debian.bugs.dist | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Bug#990265: mksh: output error is not checked for some builtins Vincent Lefevre <vincent@vinc17.net> - 2021-06-24 12:00 +0200
  Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Thorsten Glaser <tg@mirbsd.de> - 2021-06-24 16:00 +0200
    Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Vincent Lefevre <vincent@vinc17.net> - 2021-06-24 16:30 +0200
      Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Vincent Lefevre <vincent@vinc17.net> - 2021-06-24 16:40 +0200
      Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Thorsten Glaser <tg@mirbsd.de> - 2021-06-24 17:20 +0200
    Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Anuradha Weeraman <anuradha@debian.org> - 2021-06-27 18:20 +0200
      Bug#990264: Bug#990265: Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Thorsten Glaser <tg@mirbsd.de> - 2021-06-27 19:40 +0200
      Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Vincent Lefevre <vincent@vinc17.net> - 2021-06-27 23:30 +0200
        Bug#990264: Bug#990265: mksh: output error is not checked for some builtins when stdout is closed Thorsten Glaser <tg@mirbsd.de> - 2021-06-27 23:50 +0200
  Bug#990265: utilities and write errors mirabilos <tg+ml@mirbsd.org> - 2021-06-30 03:00 +0200
    Bug#990265: utilities and write errors Vincent Lefevre <vincent-opgr@vinc17.net> - 2021-06-30 03:30 +0200
      Bug#990265: utilities and write errors Thorsten Glaser <tg@mirbsd.de> - 2021-06-30 04:10 +0200

csiph-web