René J.V. Bertin
2018-10-15 09:15:20 UTC
rjvbb created this revision.
rjvbb added a reviewer: KDevelop.
rjvbb added a project: KDevelop.
rjvbb requested review of this revision.
REVISION SUMMARY
This is a work-in-progress change inspired by BKO ticket #399473
Goals:
1- make signal handling safe, i.e. make only async-signal safe calls in the actual signal handler, like `write()` or `sem_post()`.
2- be as cross-platform as possible. ANSI/C signals do exist on MS Windows but I cannot be the judge of whether they'd ever be encountered there.
Bonus goal:
- give users an option to quit a remote session as cleanly as possible if the remote display is inaccessible (whatever the reason).
Goal 1:
Two alternative implementations, both using a static CorePrivate member variable to store the received signal number
a- Use a pair of file descriptors connected via a pipe and a QSocketNotifier. In the signal handler, `write()` to the pipe; this will cause the `CorePrivate::shutdownGracefully` slot to be activated which does the actual work (basically unchanged from the current implementation) outside the signal handler context.
b- Use a semaphore and a monitor started through `QtConcurrent::run`. In the signal handler, `sem_post()` the semaphore which triggers the monitor which then calls `CorePrivate::shutdownGracefully()`.
Goal 2:
Creating a pipe with `pipe()` is Unix-specific; MS Windows has a dedicated call the result of which can (probably) not be fed to QSocketNotifier.
Unnamed semaphores are platform-specific too (note the use of Mach semaphores on Mac which doesn't have unnamed POSIX semaphores) but it should be straightforward to adapt the implementation.
The actual graceful shutdown routine has been modified slightly: it will call `Core::shutdown()` when a 2nd signal is received, before raising that signal again. I propose to make this the only action when a SIGHUP is received, in order to speed up the exit procedure and reduce the chances of getting stuck in the normal exit procedure. This seems more in line with the nature of the signal.
BUG: 399473
TEST PLAN
Launch KDevelop, send it a HUP, INT or TERM signal when it has document(s) with unsaved change open or not. Also test on a remote server.
Tested on Linux, Mac OS and FreeBSD.
REPOSITORY
R32 KDevelop
REVISION DETAIL
https://phabricator.kde.org/D16218
AFFECTED FILES
kdevplatform/shell/CMakeLists.txt
kdevplatform/shell/core.cpp
kdevplatform/shell/core_p.h
To: rjvbb, #kdevelop
Cc: kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
rjvbb added a reviewer: KDevelop.
rjvbb added a project: KDevelop.
rjvbb requested review of this revision.
REVISION SUMMARY
This is a work-in-progress change inspired by BKO ticket #399473
Goals:
1- make signal handling safe, i.e. make only async-signal safe calls in the actual signal handler, like `write()` or `sem_post()`.
2- be as cross-platform as possible. ANSI/C signals do exist on MS Windows but I cannot be the judge of whether they'd ever be encountered there.
Bonus goal:
- give users an option to quit a remote session as cleanly as possible if the remote display is inaccessible (whatever the reason).
Goal 1:
Two alternative implementations, both using a static CorePrivate member variable to store the received signal number
a- Use a pair of file descriptors connected via a pipe and a QSocketNotifier. In the signal handler, `write()` to the pipe; this will cause the `CorePrivate::shutdownGracefully` slot to be activated which does the actual work (basically unchanged from the current implementation) outside the signal handler context.
b- Use a semaphore and a monitor started through `QtConcurrent::run`. In the signal handler, `sem_post()` the semaphore which triggers the monitor which then calls `CorePrivate::shutdownGracefully()`.
Goal 2:
Creating a pipe with `pipe()` is Unix-specific; MS Windows has a dedicated call the result of which can (probably) not be fed to QSocketNotifier.
Unnamed semaphores are platform-specific too (note the use of Mach semaphores on Mac which doesn't have unnamed POSIX semaphores) but it should be straightforward to adapt the implementation.
The actual graceful shutdown routine has been modified slightly: it will call `Core::shutdown()` when a 2nd signal is received, before raising that signal again. I propose to make this the only action when a SIGHUP is received, in order to speed up the exit procedure and reduce the chances of getting stuck in the normal exit procedure. This seems more in line with the nature of the signal.
BUG: 399473
TEST PLAN
Launch KDevelop, send it a HUP, INT or TERM signal when it has document(s) with unsaved change open or not. Also test on a remote server.
Tested on Linux, Mac OS and FreeBSD.
REPOSITORY
R32 KDevelop
REVISION DETAIL
https://phabricator.kde.org/D16218
AFFECTED FILES
kdevplatform/shell/CMakeLists.txt
kdevplatform/shell/core.cpp
kdevplatform/shell/core_p.h
To: rjvbb, #kdevelop
Cc: kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd