mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-04-09 08:21:23 -04:00
Use sigsetjmp to continue cleanup after SIGTERM/SIGINT
This uses the non-local goto sigsetjmp function to continue cleaning up after a SIGINT or SIGTERM has been caught. Normally, SIGINT or SIGTERM signal the end of the program and cannot be ignored. We jump to the cleanup in the signal handler.
This commit is contained in:
parent
6eb693c05b
commit
70ecdcb02e
1 changed files with 15 additions and 9 deletions
24
cage.c
24
cage.c
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -162,6 +163,8 @@ drop_permissions(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
sigjmp_buf end_mark;
|
||||
|
||||
static int
|
||||
handle_signal(int signal, void *data)
|
||||
{
|
||||
|
|
@ -172,6 +175,7 @@ handle_signal(int signal, void *data)
|
|||
/* Fallthrough */
|
||||
case SIGTERM:
|
||||
wl_display_terminate(display);
|
||||
siglongjmp(end_mark, -1);
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -474,17 +478,19 @@ main(int argc, char *argv[])
|
|||
wlr_xwayland_set_seat(xwayland, server.seat->seat);
|
||||
#endif
|
||||
|
||||
if (!spawn_primary_client(server.wl_display, argv + optind, &pid, &sigchld_source)) {
|
||||
ret = 1;
|
||||
goto end;
|
||||
if (sigsetjmp(end_mark, 0) == 0) {
|
||||
if (!spawn_primary_client(server.wl_display, argv + optind, &pid, &sigchld_source)) {
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Place the cursor in the center of the output layout. */
|
||||
struct wlr_box *layout_box = wlr_output_layout_get_box(server.output_layout, NULL);
|
||||
wlr_cursor_warp(server.seat->cursor, NULL, layout_box->width / 2, layout_box->height / 2);
|
||||
|
||||
wl_display_run(server.wl_display);
|
||||
}
|
||||
|
||||
/* Place the cursor in the center of the output layout. */
|
||||
struct wlr_box *layout_box = wlr_output_layout_get_box(server.output_layout, NULL);
|
||||
wlr_cursor_warp(server.seat->cursor, NULL, layout_box->width / 2, layout_box->height / 2);
|
||||
|
||||
wl_display_run(server.wl_display);
|
||||
|
||||
#if CAGE_HAS_XWAYLAND
|
||||
wlr_xwayland_destroy(xwayland);
|
||||
wlr_xcursor_manager_destroy(xcursor_manager);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue