linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gal Ben Haim <gbenhaim@augury.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ] shared/io-mainloop: Try to write to the pipe only if there are readers
Date: Thu, 15 Nov 2018 21:34:23 +0200	[thread overview]
Message-ID: <CAHotPr9A7A6Rf0+JgQN6nAiXYDGp6QiaPeXP6vyomXeR4F57Cw@mail.gmail.com> (raw)
In-Reply-To: <CABBYNZKkrddaFypEA0FGW8CHAH3bf-atNKh2+6scLKC3ZPSfQQ@mail.gmail.com>

doesn't my first patch of ignoring SIGPIPE simplify this? errno of the
write op will be EPIPE..
I can move it to main.c
On Thu, Nov 15, 2018 at 2:38 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Gal,
> On Thu, Nov 15, 2018 at 1:55 PM Gal Ben-Haim <gbenhaim@augury.com> wrote:
> >
> > bluetoothd receives a SIGPIPE and terminates if writing to a pipe that
> > was acquired by AcquireNotify and there are no readers. it can be
> > reproduced by terminating the reader process without closing the reader
> > end of the pipe.
> >
> > poll is used to check for a POLLRDHUP event before write and an EPIPE
> > error is returned if the peer closed its end of the pipe.
> > ---
> >  src/shared/io-mainloop.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c
> > index 2306c3479..4a70449fc 100644
> > --- a/src/shared/io-mainloop.c
> > +++ b/src/shared/io-mainloop.c
> > @@ -27,6 +27,7 @@
> >
> >  #include <unistd.h>
> >  #include <errno.h>
> > +#include <poll.h>
> >  #include <sys/socket.h>
> >
> >  #include "src/shared/mainloop.h"
> > @@ -305,7 +306,14 @@ ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt)
> >         if (!io || io->fd < 0)
> >                 return -ENOTCONN;
> >
> > +       struct pollfd fds[1];
> > +       fds[0].fd = io->fd;
> > +       fds[0].events = POLLRDHUP;
> >         do {
> > +               if (poll(fds, 1, 0) > 0 && fds[0].revents & POLLRDHUP > 0) {
> > +                       return -EPIPE;
> > +               }
> > +
> >                 ret = writev(io->fd, iov, iovcnt);
> >         } while (ret < 0 && errno == EINTR);
> >
> > --
> > 2.19.1
>
> We normally do it a bit differently, we setup a write handler using
> io_set_write_handler which informs when the fd is writable, otherwise
> we maybe polling twice here since the user of the io may already be
> using that mechanism. That said you are actually checking for HUP
> which is something done io_set_disconnect_handler, which is already in
> use. I suspect to really get this done cleanly we should perhaps use
> MSG_NOSIGNAL when trying to write.
>
> --
> Luiz Augusto von Dentz

      reply	other threads:[~2018-11-15 19:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15 11:53 [PATCH BlueZ] shared/io-mainloop: Try to write to the pipe only if there are readers Gal Ben-Haim
2018-11-15 12:37 ` Luiz Augusto von Dentz
2018-11-15 19:34   ` Gal Ben Haim [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=CAHotPr9A7A6Rf0+JgQN6nAiXYDGp6QiaPeXP6vyomXeR4F57Cw@mail.gmail.com \
    --to=gbenhaim@augury.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@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.
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).