handle SIGUSR1 signal to run/stop the capture, UNIX only

This commit is contained in:
Mickael Bosch 2020-10-09 15:49:16 +02:00 committed by Soeren Apel
parent d1b479f74c
commit f1e9295aa5
5 changed files with 17 additions and 5 deletions

View File

@ -350,10 +350,9 @@ int main(int argc, char *argv[])
#ifdef ENABLE_SIGNALS
if (SignalHandler::prepare_signals()) {
SignalHandler *const handler = new SignalHandler(&w);
QObject::connect(handler, SIGNAL(int_received()),
&w, SLOT(close()));
QObject::connect(handler, SIGNAL(term_received()),
&w, SLOT(close()));
QObject::connect(handler, SIGNAL(int_received()), &w, SLOT(close()));
QObject::connect(handler, SIGNAL(term_received()), &w, SLOT(close()));
QObject::connect(handler, SIGNAL(usr1_received()), &w, SLOT(on_run_stop_clicked()));
} else
qWarning() << "Could not prepare signal handler.";
#endif

View File

@ -728,6 +728,11 @@ void MainWindow::on_run_stop_clicked()
}
}
void MainWindow::on_external_trigger()
{
on_run_stop_clicked();
}
void MainWindow::on_settings_clicked()
{
dialogs::Settings dlg(device_manager_);

View File

@ -145,6 +145,9 @@ private Q_SLOTS:
void on_close_current_tab();
public Q_SLOTS:
void on_external_trigger();
private:
DeviceManager &device_manager_;

View File

@ -43,7 +43,8 @@ bool SignalHandler::prepare_signals()
sig_action.sa_flags = SA_RESTART;
if (sigaction(SIGINT, &sig_action, nullptr) != 0 ||
sigaction(SIGTERM, &sig_action, nullptr) != 0) {
sigaction(SIGTERM, &sig_action, nullptr) != 0 ||
sigaction(SIGUSR1, &sig_action, nullptr) != 0) {
close(sockets_[0]);
close(sockets_[1]);
return false;
@ -78,6 +79,9 @@ void SignalHandler::on_socket_notifier_activated()
case SIGTERM:
Q_EMIT term_received();
break;
case SIGUSR1:
Q_EMIT usr1_received();
break;
}
socket_notifier_->setEnabled(true);

View File

@ -37,6 +37,7 @@ public:
Q_SIGNALS:
void int_received();
void term_received();
void usr1_received();
private Q_SLOTS:
void on_socket_notifier_activated();