key.c: fix zombie terminal processes

This commit is contained in:
Iris Lightshard 2022-01-18 16:29:16 -07:00
parent 4d0f0f62da
commit d1a8d31b45
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

35
key.c
View file

@ -6,6 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xos.h> #include <X11/Xos.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -782,22 +783,28 @@ void keypress(XKeyEvent* e) {
else if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) { else if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) {
kbLaunch = 1; kbLaunch = 1;
if (fork() == 0) { if (fork() == 0) {
close(ConnectionNumber(dpy)); if (fork() == 0) {
if (dpy != '\0') // this code doesn't seem necessary
putenv(dpy); // close(ConnectionNumber(dpy));
signal(SIGINT, SIG_DFL); // if (dpy != '\0')
signal(SIGTERM, SIG_DFL); // putenv(dpy);
signal(SIGHUP, SIG_DFL); signal(SIGINT, SIG_DFL);
if (termprog != NULL) { signal(SIGTERM, SIG_DFL);
execl(shell, shell, "-c", termprog, (char*)0); signal(SIGHUP, SIG_DFL);
fprintf(stderr, "ryudo: exec %s", shell); if (termprog != NULL) {
perror(" failed"); execl(shell, shell, "-c", termprog, (char*)0);
fprintf(stderr, "ryudo: exec %s", shell);
perror(" failed");
}
execlp("urxvt", "urxvt", (char*)0);
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("ryudo: exec urxvt/9term/xterm failed");
exit(1);
} }
execlp("urxvt", "urxvt", (char*)0); exit(0);
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("ryudo: exec urxvt/9term/xterm failed");
} }
wait((int*)0);
} }
#endif #endif