mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Cc: Nick Peng <pymumu@gmail.com>
Subject: Re: [musl] BUG: Calling readdir/dirfd after vfork will cause deadlock.
Date: Mon, 27 Jun 2022 16:29:11 +0200	[thread overview]
Message-ID: <20220627142911.GC2408@voyager> (raw)
In-Reply-To: <CALkM5nttiPx75y3SZeGfh65LG_e7vngPNnY4KyHttO0qR-R3og@mail.gmail.com>

On Mon, Jun 27, 2022 at 12:05:41PM +0800, Nick Peng wrote:
> The feature I want to achieve is to close all file handles after fork to
> avoid file handles being inherited to child processes.
>

The normal solution to that problem is FD_CLOEXEC. I have started just
opening all FDs with FD_CLOEXEC set. If I want to bestow it upon a child
process, I can always dup() it (which clears FD_CLOEXEC from the
destination FD).

> In order to avoid file handles inheriting from child processes, we
> implemented a API like system,close all file handles after vfork.

That wouldn't be conforming to the vfork() spec either, since close() is
neither _exit() nor in the exec* family.

> The component is based on glibc, currently this program runs for about 10
> years without deadlock.
> Recently, this component is used in musl-based embedded systems, and it
> hangs often.
>

Congratulations, you found a way to make undefined behavior break your
setup only a decade after its inception. Such is the nature of the
beast. Sometimes it will work for you. Until something changes, that may
be out of your control.

Ciao,
Markus

  parent reply	other threads:[~2022-06-27 14:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-25  3:40 Nick Peng
2022-06-25 12:51 ` Szabolcs Nagy
2022-06-27  4:05   ` Nick Peng
2022-06-27 10:38     ` Laurent Bercot
2022-06-27 14:21     ` Rich Felker
2022-06-27 14:29     ` Markus Wichmann [this message]
2022-06-27  7:42   ` Florian Weimer
2022-06-27  8:37     ` Szabolcs Nagy
2022-06-27  9:23       ` Florian Weimer
2022-06-27 17:33         ` Szabolcs Nagy
2022-06-25 12:56 ` Alex Xu (Hello71)
2022-06-27  7:44   ` Florian Weimer
2022-06-27 12:28     ` Alex Xu (Hello71)

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=20220627142911.GC2408@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    --cc=pymumu@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

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

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