• Vladimir Davydov's avatar
    Bluetooth: never linger on process exit · 07dd3b62
    Vladimir Davydov authored
    commit 093facf3 upstream.
    
    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: default avatarVladimir Davydov <vdavydov@parallels.com>
    Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    07dd3b62
sock.c 22.1 KB