public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Cupertino Miranda via Libc-alpha <libc-alpha@sourceware.org>
Cc: Cupertino Miranda <cupertino.miranda@oracle.com>,
	 "Jose E. Marchesi" <jose.marchesi@oracle.com>,
	 Elena Zannoni <elena.zannoni@oracle.com>
Subject: Re: [PING] [PATCH v2] Resolve-flockfile-funlockfile-differences
Date: Mon, 04 Sep 2023 18:40:23 +0200	[thread overview]
Message-ID: <87ledluc20.fsf@oldenburg3.str.redhat.com> (raw)
In-Reply-To: <87ilhj3bsp.fsf@oracle.com> (Cupertino Miranda via Libc-alpha's message of "Fri, 06 Jan 2023 15:47:18 +0000")

* Cupertino Miranda via Libc-alpha:

> This is a request for review of the patch sent by Patrick McGehearty
> based on an inconsistency in flockfile and funlockfile definitions
> (macro/function) when used in glibc code.

It finally clicked to for me what is going on here.  Sorry for taking so
long.  It's a basic C problem.

_IO_funlockfile is defined as a macro and as a function.  The function
definition in stdio-common/funlockfile.c unlocks the stream
unconditionally.  The macro version checks if FSETLOCKING_BYCALLER is
active and skips the unlocking in that case.  Same for _IO_flockfile.

With &_IO_funlockfile, we get the unconditional unlock, but with
_IO_flockfile (S), we get the conditionalized lock.

The current code is clearly buggy.  It should be possible to write a
test for this, using ftrylockfile.  The direction of the change seems
right, too.

> Should both the macro/function definitions be coherent such that they should be
> used interchangeably in glibc code?

The external flockfile/funlockfile needs to be unconditional because I
think it is expected that these functions can be used to implement the
locking that is required if FSETLOCKING_BYCALLER is used.

Despite the recursive internal lock, checking for FSETLOCKING_BYCALLER
is probably more than a performance optimization because the unexpected
locking might introduce deadlocks.  So skipping the locking, as you did,
seems correct.

So I think we need the different internal and external behavior.  What
is clearly not okay though is that we use the same identifier for those
two different operations.  We cannot rename the external symbol, but we
really should rename the internal identifier.

Thanks,
Florian


  parent reply	other threads:[~2023-09-04 16:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 15:47 Cupertino Miranda
2023-01-12 15:04 ` Cupertino Miranda
2023-02-13 13:30 ` Florian Weimer
2023-09-04 16:40 ` Florian Weimer [this message]
2023-09-05  8:42 ` Florian Weimer

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=87ledluc20.fsf@oldenburg3.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=cupertino.miranda@oracle.com \
    --cc=elena.zannoni@oracle.com \
    --cc=jose.marchesi@oracle.com \
    --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).