From: Rich Felker <dalias@libc.org>
To: Markus Wichmann <nullplan@gmx.net>
Cc: musl@lists.openwall.com,
"Jef STEELANT (EXT)" <jef.steelant_ext@softathome.com>
Subject: Re: [musl] syslog does not detect a closed file descriptor
Date: Wed, 9 Oct 2024 16:36:27 -0400 [thread overview]
Message-ID: <20241009203626.GL10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <ZvWO7L-nGBBg0U0s@voyager>
On Thu, Sep 26, 2024 at 06:42:20PM +0200, Markus Wichmann wrote:
> Am Thu, Sep 26, 2024 at 09:08:59AM +0000 schrieb Jef STEELANT (EXT):
> > The syslog implementation does not detect if the file descriptor of
> > /dev/log is closed, and keeps on logging to an invalid fd.
> > This happens for instance when using lxc with musl libc ( see issue
> > https://github.com/lxc/lxc/issues/4485). LXC will at a certain point
> > close the fd of /dev/log, in the assumption that a next call to syslog
> > will detect an EBADF when writing data, and that the log will be
> > reopened. glibc does this, but musl does not. It would be better if
> > syslog would either stop logging to the invalid fd, or reopen the log
> > when s send returns EBADF.
>
> This is why you do not close FDs you do not own. The application does
> not own the socket FD for the syslog; it belongs to libc. And the
> application can portably request the FD be closed by calling closelog().
> And it should, because that will restore the initial state in that file,
> and cause the log to be opened again.
>
> Using EBADF for anything is a bad idea in the lib, since the lib must
> work with multiple threads, and in a multi-threaded process EBADF means
> "you could have sent this data to the wrong FD". I think the simplest
> solution is for lxc to just call closelog() before closing the other
> FDs.
Yes, if you close or replace any fds belonging to the implementation
behind its back, very bad things can happen. This is an application
bug. Any attempt to mitigate it by catching EBADF here would only bury
the bug, making it so you detect it only on fairly rare race
conditions rather than always seeing it (and thereby realizing it
needs to be fixed and fixing it).
prev parent reply other threads:[~2024-10-09 20:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 9:08 Jef STEELANT (EXT)
2024-09-26 16:42 ` Markus Wichmann
2024-10-09 20:36 ` Rich Felker [this message]
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=20241009203626.GL10433@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=jef.steelant_ext@softathome.com \
--cc=musl@lists.openwall.com \
--cc=nullplan@gmx.net \
/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).