linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] gatt: Ignore SIGPIPE
@ 2018-11-15  8:38 Gal
  2018-11-15 10:12 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 9+ messages in thread
From: Gal @ 2018-11-15  8:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gal

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.

Ignoring the SIGPIPE will cause the write operation to return a
"io_send: Broken pipe" error which will be logged.
---
 src/gatt-client.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index 234f46ed7..236f38ad5 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -1137,6 +1137,9 @@ static DBusMessage *characteristic_create_pipe(struct characteristic *chrc,
 	if (pipe2(pipefd, O_DIRECT | O_NONBLOCK | O_CLOEXEC) < 0)
 		return btd_error_failed(msg, strerror(errno));
 
+	/* Ignore SIGPIPE, a broken pipe error will be returned if the pipe has no readers */
+	signal(SIGPIPE, SIG_IGN);
+
 	dir = dbus_message_has_member(msg, "AcquireWrite");
 
 	io = io_new(pipefd[!dir]);
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15  8:38 [PATCH BlueZ] gatt: Ignore SIGPIPE Gal
@ 2018-11-15 10:12 ` Luiz Augusto von Dentz
  2018-11-15 10:16   ` Gal Ben Haim
  0 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2018-11-15 10:12 UTC (permalink / raw)
  To: gbenhaim; +Cc: linux-bluetooth

Hi,
On Thu, Nov 15, 2018 at 10:41 AM Gal <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.
>
> Ignoring the SIGPIPE will cause the write operation to return a
> "io_send: Broken pipe" error which will be logged.
> ---
>  src/gatt-client.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/gatt-client.c b/src/gatt-client.c
> index 234f46ed7..236f38ad5 100644
> --- a/src/gatt-client.c
> +++ b/src/gatt-client.c
> @@ -1137,6 +1137,9 @@ static DBusMessage *characteristic_create_pipe(struct characteristic *chrc,
>         if (pipe2(pipefd, O_DIRECT | O_NONBLOCK | O_CLOEXEC) < 0)
>                 return btd_error_failed(msg, strerror(errno));
>
> +       /* Ignore SIGPIPE, a broken pipe error will be returned if the pipe has no readers */
> +       signal(SIGPIPE, SIG_IGN);
> +
>         dir = dbus_message_has_member(msg, "AcquireWrite");
>
>         io = io_new(pipefd[!dir]);
> --
> 2.19.1

I wonder if there is a way to detect that on bluetoothd actually, that
way even if the client don't set it properly it would not make
bluetoothd to exit.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 10:12 ` Luiz Augusto von Dentz
@ 2018-11-15 10:16   ` Gal Ben Haim
  2018-11-15 10:18     ` Marcel Holtmann
  0 siblings, 1 reply; 9+ messages in thread
From: Gal Ben Haim @ 2018-11-15 10:16 UTC (permalink / raw)
  To: luiz.dentz; +Cc: linux-bluetooth

io_send can use poll and check for POLLOUT and POLLRDHUP before
writing to the pipe

On Thu, Nov 15, 2018 at 12:12 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi,
> On Thu, Nov 15, 2018 at 10:41 AM Gal <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.
> >
> > Ignoring the SIGPIPE will cause the write operation to return a
> > "io_send: Broken pipe" error which will be logged.
> > ---
> >  src/gatt-client.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/src/gatt-client.c b/src/gatt-client.c
> > index 234f46ed7..236f38ad5 100644
> > --- a/src/gatt-client.c
> > +++ b/src/gatt-client.c
> > @@ -1137,6 +1137,9 @@ static DBusMessage *characteristic_create_pipe(struct characteristic *chrc,
> >         if (pipe2(pipefd, O_DIRECT | O_NONBLOCK | O_CLOEXEC) < 0)
> >                 return btd_error_failed(msg, strerror(errno));
> >
> > +       /* Ignore SIGPIPE, a broken pipe error will be returned if the pipe has no readers */
> > +       signal(SIGPIPE, SIG_IGN);
> > +
> >         dir = dbus_message_has_member(msg, "AcquireWrite");
> >
> >         io = io_new(pipefd[!dir]);
> > --
> > 2.19.1
>
> I wonder if there is a way to detect that on bluetoothd actually, that
> way even if the client don't set it properly it would not make
> bluetoothd to exit.
>
>
> --
> Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 10:16   ` Gal Ben Haim
@ 2018-11-15 10:18     ` Marcel Holtmann
  2018-11-15 10:20       ` Gal Ben Haim
  0 siblings, 1 reply; 9+ messages in thread
From: Marcel Holtmann @ 2018-11-15 10:18 UTC (permalink / raw)
  To: Gal Ben Haim; +Cc: Luiz Augusto von Dentz, linux-bluetooth

Hi Gal,

> io_send can use poll and check for POLLOUT and POLLRDHUP before
> writing to the pipe

that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.

Regards

Marcel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 10:18     ` Marcel Holtmann
@ 2018-11-15 10:20       ` Gal Ben Haim
  2018-11-15 11:55         ` Gal Ben Haim
  0 siblings, 1 reply; 9+ messages in thread
From: Gal Ben Haim @ 2018-11-15 10:20 UTC (permalink / raw)
  To: marcel; +Cc: luiz.dentz, linux-bluetooth

I can try to create another patch for it

On Thu, Nov 15, 2018 at 12:18 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Gal,
>
> > io_send can use poll and check for POLLOUT and POLLRDHUP before
> > writing to the pipe
>
> that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.
>
> Regards
>
> Marcel
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 10:20       ` Gal Ben Haim
@ 2018-11-15 11:55         ` Gal Ben Haim
  2018-11-15 12:56           ` Emil Lenngren
  0 siblings, 1 reply; 9+ messages in thread
From: Gal Ben Haim @ 2018-11-15 11:55 UTC (permalink / raw)
  To: marcel; +Cc: luiz.dentz, linux-bluetooth

I submitted a different patch -
https://marc.info/?l=linux-bluetooth&m=154228281730667&w=2
On Thu, Nov 15, 2018 at 12:20 PM Gal Ben Haim <gbenhaim@augury.com> wrote:
>
> I can try to create another patch for it
>
> On Thu, Nov 15, 2018 at 12:18 PM Marcel Holtmann <marcel@holtmann.org> wrote:
> >
> > Hi Gal,
> >
> > > io_send can use poll and check for POLLOUT and POLLRDHUP before
> > > writing to the pipe
> >
> > that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.
> >
> > Regards
> >
> > Marcel
> >

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 11:55         ` Gal Ben Haim
@ 2018-11-15 12:56           ` Emil Lenngren
  2018-11-15 15:43             ` Gal Ben Haim
  0 siblings, 1 reply; 9+ messages in thread
From: Emil Lenngren @ 2018-11-15 12:56 UTC (permalink / raw)
  To: gbenhaim; +Cc: Marcel Holtmann, Luiz Augusto von Dentz, Bluez mailing list

Den tors 15 nov. 2018 kl 12:55 skrev Gal Ben Haim <gbenhaim@augury.com>:
>
> I submitted a different patch -
> https://marc.info/?l=linux-bluetooth&m=154228281730667&w=2
> On Thu, Nov 15, 2018 at 12:20 PM Gal Ben Haim <gbenhaim@augury.com> wrote:
> >
> > I can try to create another patch for it
> >
> > On Thu, Nov 15, 2018 at 12:18 PM Marcel Holtmann <marcel@holtmann.org> wrote:
> > >
> > > Hi Gal,
> > >
> > > > io_send can use poll and check for POLLOUT and POLLRDHUP before
> > > > writing to the pipe
> > >
> > > that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.
> > >
> > > Regards
> > >
> > > Marcel
> > >

Even if you first check for writability with poll, you still need to
also ignore the SIGPIPE signal, since the connection could be reset
after the check is made but before the write is executed, I guess. But
the "signal(SIGPIPE, SIG_IGN)" should usually be made once at
application initialization.

/Emil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 12:56           ` Emil Lenngren
@ 2018-11-15 15:43             ` Gal Ben Haim
  2018-11-16 19:18               ` Gal Ben Haim
  0 siblings, 1 reply; 9+ messages in thread
From: Gal Ben Haim @ 2018-11-15 15:43 UTC (permalink / raw)
  To: emil.lenngren; +Cc: Marcel Holtmann, Luiz Augusto von Dentz, linux-bluetooth

should it be added to setup_signalfd in main.c ?

On Thu, Nov 15, 2018 at 2:56 PM Emil Lenngren <emil.lenngren@gmail.com> wrote:
>
> Den tors 15 nov. 2018 kl 12:55 skrev Gal Ben Haim <gbenhaim@augury.com>:
> >
> > I submitted a different patch -
> > https://marc.info/?l=linux-bluetooth&m=154228281730667&w=2
> > On Thu, Nov 15, 2018 at 12:20 PM Gal Ben Haim <gbenhaim@augury.com> wrote:
> > >
> > > I can try to create another patch for it
> > >
> > > On Thu, Nov 15, 2018 at 12:18 PM Marcel Holtmann <marcel@holtmann.org> wrote:
> > > >
> > > > Hi Gal,
> > > >
> > > > > io_send can use poll and check for POLLOUT and POLLRDHUP before
> > > > > writing to the pipe
> > > >
> > > > that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.
> > > >
> > > > Regards
> > > >
> > > > Marcel
> > > >
>
> Even if you first check for writability with poll, you still need to
> also ignore the SIGPIPE signal, since the connection could be reset
> after the check is made but before the write is executed, I guess. But
> the "signal(SIGPIPE, SIG_IGN)" should usually be made once at
> application initialization.
>
> /Emil

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ] gatt: Ignore SIGPIPE
  2018-11-15 15:43             ` Gal Ben Haim
@ 2018-11-16 19:18               ` Gal Ben Haim
  0 siblings, 0 replies; 9+ messages in thread
From: Gal Ben Haim @ 2018-11-16 19:18 UTC (permalink / raw)
  To: Emil Lenngren; +Cc: Marcel Holtmann, Luiz Augusto von Dentz, linux-bluetooth

I submitted another patch that does it in src/main.c -
https://marc.info/?l=linux-bluetooth&m=154239570400752&w=2
On Thu, Nov 15, 2018 at 5:43 PM Gal Ben Haim <gbenhaim@augury.com> wrote:
>
> should it be added to setup_signalfd in main.c ?
>
> On Thu, Nov 15, 2018 at 2:56 PM Emil Lenngren <emil.lenngren@gmail.com> wrote:
> >
> > Den tors 15 nov. 2018 kl 12:55 skrev Gal Ben Haim <gbenhaim@augury.com>:
> > >
> > > I submitted a different patch -
> > > https://marc.info/?l=linux-bluetooth&m=154228281730667&w=2
> > > On Thu, Nov 15, 2018 at 12:20 PM Gal Ben Haim <gbenhaim@augury.com> wrote:
> > > >
> > > > I can try to create another patch for it
> > > >
> > > > On Thu, Nov 15, 2018 at 12:18 PM Marcel Holtmann <marcel@holtmann.org> wrote:
> > > > >
> > > > > Hi Gal,
> > > > >
> > > > > > io_send can use poll and check for POLLOUT and POLLRDHUP before
> > > > > > writing to the pipe
> > > > >
> > > > > that should be done anyway since code that writes to a pipe descriptor (or socket for that matter) without checking that it is still valid is broken code.
> > > > >
> > > > > Regards
> > > > >
> > > > > Marcel
> > > > >
> >
> > Even if you first check for writability with poll, you still need to
> > also ignore the SIGPIPE signal, since the connection could be reset
> > after the check is made but before the write is executed, I guess. But
> > the "signal(SIGPIPE, SIG_IGN)" should usually be made once at
> > application initialization.
> >
> > /Emil

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-16 19:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-15  8:38 [PATCH BlueZ] gatt: Ignore SIGPIPE Gal
2018-11-15 10:12 ` Luiz Augusto von Dentz
2018-11-15 10:16   ` Gal Ben Haim
2018-11-15 10:18     ` Marcel Holtmann
2018-11-15 10:20       ` Gal Ben Haim
2018-11-15 11:55         ` Gal Ben Haim
2018-11-15 12:56           ` Emil Lenngren
2018-11-15 15:43             ` Gal Ben Haim
2018-11-16 19:18               ` Gal Ben Haim

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