Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[usb transport] Establish SIGUSR1 handler even when running as a plugin

The I/O thread management relies on sending SIGUSR1 to wake up
threads that are blocked on I/O. This only works if a handler has
been established in the receiving thread, otherwise it'll just
kill the process.
  • Loading branch information...
commit 62b53df916ed598029a8ce03eed002a0a6673c05 1 parent ccefcb7
@amtep amtep authored
Showing with 20 additions and 4 deletions.
  1. +20 −0 mts/transport/usb/mtptransporterusb.cpp
  2. +0 −4 service/service.cpp
View
20 mts/transport/usb/mtptransporterusb.cpp
@@ -29,6 +29,7 @@
*
*/
+#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -45,6 +46,24 @@
using namespace meegomtp1dot0;
+static void signalHandler(int signum)
+{
+ return; // This handler just exists to make blocking I/O return with EINTR
+}
+
+static void catchUserSignal()
+{
+ struct sigaction action;
+
+ memset(&action, 0, sizeof(action));
+ action.sa_handler = signalHandler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+
+ if (sigaction(SIGUSR1, &action, NULL) < 0)
+ MTP_LOG_WARNING("Could not establish SIGUSR1 signal handler");
+}
+
MTPTransporterUSB::MTPTransporterUSB() : m_ioState(SUSPENDED), m_containerReadLen(0),
m_ctrlFd(-1), m_intrFd(-1), m_inFd(-1), m_outFd(-1), m_writer_busy(false)
{
@@ -85,6 +104,7 @@ bool MTPTransporterUSB::activate()
}
if(success) {
+ catchUserSignal();
openDevices(); // TODO: trigger with Bind?
m_ctrl.setFd(m_ctrlFd);
QObject::connect(&m_ctrl, SIGNAL(startIO()),
View
4 service/service.cpp
@@ -37,9 +37,6 @@ using namespace meegomtp1dot0;
void signalHandler(int signum, siginfo_t *info, void *context)
{
- if(signum == SIGUSR1)
- return;
-
// Is this async safe?
Mts::destroyInstance();
_exit(0);
@@ -57,7 +54,6 @@ int main(int argc, char** argv)
if (sigaction(SIGINT, &action, NULL) < 0) return(-1);
if (sigaction(SIGALRM, &action, NULL) < 0) return(-1);
- if (sigaction(SIGUSR1, &action, NULL) < 0) return(-1);
QObject::connect(&app,SIGNAL(aboutToQuit()),Mts::getInstance(),SLOT(destroyInstance()));
Please sign in to comment.
Something went wrong with that request. Please try again.