dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Parke <parke.nexus@gmail.com>
To: "dash@vger.kernel.org" <dash@vger.kernel.org>
Subject: Re: why does dash save, dup, and restore redirected descriptor in the parent, rather than redirect in the child?
Date: Tue, 31 Jan 2017 18:27:00 -0800	[thread overview]
Message-ID: <CAPxz1+au53RAak7Goisz7QKrzUSvtZidLFZ4b7sgV1QR_JeK5Q@mail.gmail.com> (raw)
In-Reply-To: <2132582962.805179.1485892834849@mail.yahoo.com>

On Tue, Jan 31, 2017 at 12:00 PM, Mark Galeck <mark_galeck@pacbell.net> wrote:
> This is strange. Why save, dup and dup again to restore, descriptors in the parent, when it would be much simpler to just dup in the child, and not have to save and restore. This is simpler and I checked it works the same:

> I am sure there must be a good reason and I am not understanding something deeper. What is it?

I am not a dash developer, but one reason to make system calls in the
parent is that it is much simpler to handle errors in the parent.

In your example:

> if (!fork()) {
>     fd = open64("foobar.txt", O_WRONLY|O_CREAT);
>     dup2(fd, 1);
>     execl("/bin/date", "date", (char *)NULL);
> }

What happens if open64 fails?  How should the child inform the parent
of this specific error?


  parent reply	other threads:[~2017-02-01  2:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2132582962.805179.1485892834849.ref@mail.yahoo.com>
2017-01-31 20:00 ` Mark Galeck
2017-01-31 20:30   ` Harald van Dijk
2017-02-01  2:27   ` Parke [this message]
2017-02-03 22:37     ` Jilles Tjoelker
2017-02-02 18:17   ` Mark Galeck

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:

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

  git send-email \
    --in-reply-to=CAPxz1+au53RAak7Goisz7QKrzUSvtZidLFZ4b7sgV1QR_JeK5Q@mail.gmail.com \
    --to=parke.nexus@gmail.com \
    --cc=dash@vger.kernel.org \
    --subject='Re: why does dash save, dup, and restore redirected descriptor in the parent, rather than redirect in the child?' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).