Skip to content

Commit

Permalink
mask all signals in libhackrf transfer_threadproc (#1330)
Browse files Browse the repository at this point in the history
* mask all signals in libhackrf transfer_threadproc

hackrf_transfer uses pause() and SIGALRM to print statistics and POSIX doesn't
specify which thread must recieve the signal, block all signals here, so we
don't interrupt their reception by hackrf_transfer or any other app which uses
the library (#1323)

* fix windows build and remove empty line
  • Loading branch information
bsdmp authored Sep 13, 2023
1 parent dab548b commit ed8a1a6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions host/libhackrf/src/hackrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#include <signal.h>
#endif
#include <libusb.h>

Expand Down Expand Up @@ -1763,6 +1764,20 @@ static void* transfer_threadproc(void* arg)
int error;
struct timeval timeout = {0, 500000};

/*
* hackrf_transfer uses pause() and SIGALRM to print statistics and
* POSIX doesn't specify which thread must recieve the signal, block all
* signals here, so we don't interrupt their reception by
* hackrf_transfer or any other app which uses the library (#1323)
*/
#ifndef _WIN32
sigset_t signal_mask;
sigfillset(&signal_mask);
if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0) {
return NULL;
}
#endif

while (device->do_exit == false) {
error = libusb_handle_events_timeout(g_libusb_context, &timeout);
if ((error != 0) && (error != LIBUSB_ERROR_INTERRUPTED)) {
Expand Down

0 comments on commit ed8a1a6

Please sign in to comment.