Thread (1 message) 1 message, 1 author, 2014-07-17

Re: [PATCH] bluetooth: never linger on process exit

From: Marcel Holtmann <marcel@holtmann.org>
Date: 2014-07-17 10:05:12
Also in: lkml, netdev

Hi Vladimir,

please always include linux-bluetooth@vger.kernel.org since otherwise it might be missed in the massive amount of emails that is LKML.
quoted hunk
If the current process is exiting, lingering on socket close will make
it unkillable, so we should avoid it.

Reproducer:

 #include <sys/types.h>
 #include <sys/socket.h>

 #define BTPROTO_L2CAP   0
 #define BTPROTO_SCO     2
 #define BTPROTO_RFCOMM  3

 int main()
 {
         int fd;
         struct linger ling;

         fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
         //or: fd = socket(PF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP);
         //or: fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);

         ling.l_onoff = 1;
         ling.l_linger = 1000000000;
         setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));

         return 0;
 }

Signed-off-by: Vladimir Davydov <redacted>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <redacted>
Cc: Johan Hedberg <redacted>
---
net/bluetooth/l2cap_sock.c  |    3 ++-
net/bluetooth/rfcomm/sock.c |    3 ++-
net/bluetooth/sco.c         |    6 ++++--
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index e1378693cc90..d0fd8b04f2e6 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1111,7 +1111,8 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
		l2cap_chan_close(chan, 0);
		lock_sock(sk);

-		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
+		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+		    !(current->flags & PF_EXITING))
			err = bt_sock_wait_state(sk, BT_CLOSED,
						 sk->sk_lingertime);
	}
The only other example of using PF_EXITING I found is net/ipv4/af_inet.c and if this is the preferred way of handling this, the patch looks fine to me.

Regards

Marcel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help