public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zackw@panix.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: "Arsen Arsenović" <arsen@aarsen.me>,
	"GNU C Library" <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2] Ensure standard file descriptors are open on start
Date: Thu, 27 Aug 2020 11:56:47 -0400	[thread overview]
Message-ID: <CAKCAbMiGeimxoMQGdq5BRpkD7QOj8njcNM6g2FDGAv_dLffYDw@mail.gmail.com> (raw)
In-Reply-To: <e9402d52-f83c-b33d-120d-349214df7293@cs.ucla.edu>

On Thu, Aug 20, 2020 at 6:00 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
> Arsen Arsenović wrote:
>  > And considering the hint, and that the edge case of stdin being closed
>  > seems to have been missed even by the autotools developers (I noticed this
>  > when running autoconf-1.64s ./configure from an automation tool that closed
>  > fd 0)
>
> If Autoconf doesn't operate well when file descriptor 0 is closed then it
> might be worth changing Autoconf, if it's not too much trouble.

I looked into making that change.  However, it is very difficult to
detect and handle closed fds 0,1,2 reliably in a shell script.  In C
it's easy (just call fcntl([012], F_GETFL, 0)) but shell programs
cannot make that system call directly, and all of the alternatives
have significant limitations (e.g. not being able to tell whether a fd
is open for *writing*), run foul of bugs (e.g. `exec 3>&0` will
succeed with Solaris /bin/sh, regardless of whether fd 0 was open), or
are not portable enough to use as the sole method (e.g. Linux's
/proc/<pid>/fdinfo/<fd> virtual files).  If you're curious what I did,
see https://lists.gnu.org/archive/html/autoconf-patches/2020-08/msg00025.html
and msg00026.html, but right now I am inclined *not* to put those
changes into the upcoming Autoconf 2.70.

After the experience of writing those patches, I'm definitely in favor
of GNU libc making a guarantee that fds 0,1,2 are open when
application code starts executing, for all processes, regardless of
what POSIX does or does not say.

zw

  parent reply	other threads:[~2020-08-27 15:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19 12:41 Arsen Arsenović
2020-08-19 16:28 ` Joseph Myers
2020-08-19 17:46   ` Zack Weinberg
2020-08-19 17:50     ` Joseph Myers
2020-08-19 18:20     ` Adhemerval Zanella
2020-08-19 19:13       ` Florian Weimer
2020-08-19 19:25         ` Adhemerval Zanella
2020-08-19 19:27           ` Florian Weimer
2020-08-19 19:35             ` Adhemerval Zanella
2020-08-19 19:40   ` Arsen Arsenović
2020-08-19 21:04     ` Michael Morrell
2020-08-19 22:32     ` Joseph Myers
2020-08-19 23:45       ` Arsen Arsenović
2020-08-20 22:00         ` Paul Eggert
2020-08-20 23:25           ` Arsen Arsenović
2020-08-27 15:56           ` Zack Weinberg [this message]
2020-08-27 18:21             ` Paul Eggert
2020-08-28  0:12               ` Arsen Arsenović
2020-09-04 17:49                 ` Arsen Arsenović
2020-09-11  7:47                 ` ping^2 " Arsen Arsenović
2020-08-19 23:16     ` Rich Felker

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=CAKCAbMiGeimxoMQGdq5BRpkD7QOj8njcNM6g2FDGAv_dLffYDw@mail.gmail.com \
    --to=zackw@panix.com \
    --cc=arsen@aarsen.me \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).