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@xxxxxxxxx> wrote: > > Hi, > On Thu, Nov 15, 2018 at 10:41 AM Gal <gbenhaim@xxxxxxxxxx> 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