Move signal handler setup to C++ layer

See man pages for sigaction(2), sigemptyset(3):
http://man7.org/linux/man-pages/man2/sigaction.2.html
https://linux.die.net/man/3/sigemptyset

Code loosely based on
https://gist.github.com/azadkuh/a2ac6869661ebd3f8588 .
This commit is contained in:
Emil Lundberg 2019-11-26 14:02:37 +01:00
parent 99be0c8f91
commit 729339d2be
No known key found for this signature in database
GPG Key ID: D8588A5844E2A774
2 changed files with 18 additions and 7 deletions

View File

@ -2,14 +2,32 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <stdlib.h>
#include <signal.h>
#include <QtGlobal>
#include <QtWidgets>
#include <QQuickWindow>
#include <QQuickStyle>
#include "screenshot.h"
void handleExitSignal(int sig) {
printf("Exiting due to signal %d\n", sig);
QCoreApplication::quit();
}
void setupUnixSignals() {
struct sigaction sa;
sa.sa_handler = handleExitSignal;
sigset_t signal_mask;
sigemptyset(&signal_mask);
sa.sa_mask = signal_mask;
sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr);
}
int main(int argc, char *argv[])
{
setupUnixSignals();
// Don't write .pyc files.
qputenv("PYTHONDONTWRITEBYTECODE", "1");

View File

@ -23,7 +23,6 @@ from ykman.oath import (
from ykman.otp import OtpController
from ykman.settings import Settings
from qr import qrparse, qrdecode
import signal
logger = logging.getLogger(__name__)
@ -532,9 +531,3 @@ def init_with_logging(log_level, log_file=None):
def init():
global controller
controller = Controller()
try:
# TODO: We should probably do this in the C++/QML layer instead
signal.signal(signal.SIGINT, signal.SIG_DFL)
except Exception as e:
logger.error('Failed to set signal handlers', exc_info=e)