mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 09:56:23 +03:00
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:
parent
99be0c8f91
commit
729339d2be
18
main.cpp
18
main.cpp
@ -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");
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user