fix: handle SIGTERM for graceful graphical shutdown

Sending SIGTERM to X.org is necessary to avoid graphical lock-up.
This commit is contained in:
grialion
2026-01-17 12:33:25 +01:00
parent e615968a17
commit d07395c325
4 changed files with 35 additions and 2 deletions

View File

@@ -17,10 +17,10 @@ LDFLAGS?=-Wl,--gc-sections
LIBS=-lpam
_DEPS = version.h log.h util.h ui.h ui_state.h config.h pam.h desktop.h desktop_exec.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h
_DEPS = version.h log.h util.h ui.h ui_state.h config.h pam.h desktop.h desktop_exec.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h signal_handler.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = main.o log.o util.o ui.o ui_state.o config.o pam.o desktop.o desktop_exec.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o
_OBJ = main.o log.o util.o ui.o ui_state.o config.o pam.o desktop.o desktop_exec.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o signal_handler.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
INFO_GIT_REV?=$$(git describe --long --tags --always || echo '?')

3
include/signal_handler.h Normal file
View File

@@ -0,0 +1,3 @@
// handle SIGTERM by sending SIGTERM to all children, resulting
// in a graceful graphical shutdown
void setup_sigterm();

View File

@@ -12,12 +12,14 @@
#include "log.h"
#include "macros.h"
#include "sessions.h"
#include "signal_handler.h"
#include "ui.h"
#include "users.h"
#include "util.h"
#include "version.h"
#define DATESTR_MAXBUFSIZE 0x20
int main(int argc, char* argv[]) {
// Logger
char* log_output = getenv("LIDM_LOG");
@@ -85,6 +87,8 @@ int main(int argc, char* argv[]) {
struct Vector users = get_human_users();
struct Vector sessions = get_avaliable_sessions();
setup_sigterm();
int ret = load(&users, &sessions);
if (ret == 0) execl(argv[0], argv[0], NULL);
}

26
src/signal_handler.c Normal file
View File

@@ -0,0 +1,26 @@
#include <errno.h>
#include <stddef.h>
#include <sys/wait.h>
#include <unistd.h>
static void handle_sigterm(int) {
signal(SIGTERM, SIG_IGN);
kill(-getpgrp(), SIGTERM);
int status;
while (waitpid(-1, &status, 0) > 0 || errno == EINTR) {
}
_exit(0);
}
void setup_sigterm() {
setpgid(0, 0);
struct sigaction sa;
sa.sa_handler = handle_sigterm;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL);
}