git: d94d94e2c06b - main - libusb(3): Ignore SIGPIPE when initializing the LibUSB v1.0 API.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Wed, 02 Mar 2022 11:34:56 UTC
The branch main has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=d94d94e2c06b4331f706a3b4eca058041294ea05

commit d94d94e2c06b4331f706a3b4eca058041294ea05
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-03-02 11:31:27 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-03-02 11:33:40 +0000

    libusb(3): Ignore SIGPIPE when initializing the LibUSB v1.0 API.
    
    The LibUSB v1.0 emulation layer uses pipes internally to signal between
    threads. When USB devices are reset, as part of loading firmware, SIGPIPE
    may happen, and that is expected and should be ignored.
    
    PR:             261891
    MFC after:      1 week
    Sponsored by:   NVIDIA Networking
---
 lib/libusb/libusb10.c            | 3 +++
 lib/libusb/libusb_global_linux.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index ffe0cf3f366a..ecfffde555aa 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <poll.h>
 #include <pthread.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -226,6 +227,8 @@ libusb_init(libusb_context **context)
 
 	DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_init complete");
 
+	signal(SIGPIPE, SIG_IGN);
+
 	return (0);
 }
 
diff --git a/lib/libusb/libusb_global_linux.h b/lib/libusb/libusb_global_linux.h
index 9886bd4486f5..3e83bb2a6ea4 100644
--- a/lib/libusb/libusb_global_linux.h
+++ b/lib/libusb/libusb_global_linux.h
@@ -50,6 +50,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <setjmp.h>
+#include <signal.h>
 #include <pthread.h>
 #include <sys/queue.h>
 #include <sys/ioctl.h>