mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Cc: "Jef STEELANT (EXT)" <jef.steelant_ext@softathome.com>
Subject: Re: [musl] syslog does not detect a closed file descriptor
Date: Thu, 26 Sep 2024 18:42:20 +0200	[thread overview]
Message-ID: <ZvWO7L-nGBBg0U0s@voyager> (raw)
In-Reply-To: <MR1P264MB2481E332F0FB7A51B6A7FD7BC06A2@MR1P264MB2481.FRAP264.PROD.OUTLOOK.COM>

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.

Ciao,
Markus

  reply	other threads:[~2024-09-26 16:42 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 [this message]
2024-10-09 20:36   ` 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=ZvWO7L-nGBBg0U0s@voyager \
    --to=nullplan@gmx.net \
    --cc=jef.steelant_ext@softathome.com \
    --cc=musl@lists.openwall.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).