mirror of
https://github.com/javalsai/lidm.git
synced 2026-02-27 12:00:44 +01:00
fix: handle SIGTERM for graceful graphical shutdown
Sending SIGTERM to X.org is necessary to avoid graphical lock-up.
This commit is contained in:
4
Makefile
4
Makefile
@@ -17,10 +17,10 @@ LDFLAGS?=-Wl,--gc-sections
|
|||||||
|
|
||||||
LIBS=-lpam
|
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))
|
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))
|
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
|
||||||
|
|
||||||
INFO_GIT_REV?=$$(git describe --long --tags --always || echo '?')
|
INFO_GIT_REV?=$$(git describe --long --tags --always || echo '?')
|
||||||
|
|||||||
3
include/signal_handler.h
Normal file
3
include/signal_handler.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// handle SIGTERM by sending SIGTERM to all children, resulting
|
||||||
|
// in a graceful graphical shutdown
|
||||||
|
void setup_sigterm();
|
||||||
@@ -12,12 +12,14 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "sessions.h"
|
#include "sessions.h"
|
||||||
|
#include "signal_handler.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#define DATESTR_MAXBUFSIZE 0x20
|
#define DATESTR_MAXBUFSIZE 0x20
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// Logger
|
// Logger
|
||||||
char* log_output = getenv("LIDM_LOG");
|
char* log_output = getenv("LIDM_LOG");
|
||||||
@@ -85,6 +87,8 @@ int main(int argc, char* argv[]) {
|
|||||||
struct Vector users = get_human_users();
|
struct Vector users = get_human_users();
|
||||||
struct Vector sessions = get_avaliable_sessions();
|
struct Vector sessions = get_avaliable_sessions();
|
||||||
|
|
||||||
|
setup_sigterm();
|
||||||
|
|
||||||
int ret = load(&users, &sessions);
|
int ret = load(&users, &sessions);
|
||||||
if (ret == 0) execl(argv[0], argv[0], NULL);
|
if (ret == 0) execl(argv[0], argv[0], NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/signal_handler.c
Normal file
26
src/signal_handler.c
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user