exit cleanly on INT/TERM

This commit is contained in:
Devin J. Pohly 2021-05-26 23:30:49 -05:00
parent 823cefd292
commit bd2f7fbb40

11
dwl.c
View File

@ -259,6 +259,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time); double sx, double sy, uint32_t time);
static void printstatus(void); static void printstatus(void);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void quitsignal(int signo);
static void render(struct wlr_surface *surface, int sx, int sy, void *data); static void render(struct wlr_surface *surface, int sx, int sy, void *data);
static void renderclients(Monitor *m, struct timespec *now); static void renderclients(Monitor *m, struct timespec *now);
static void renderlayer(struct wl_list *layer_surfaces, struct timespec *now); static void renderlayer(struct wl_list *layer_surfaces, struct timespec *now);
@ -1578,6 +1579,12 @@ quit(const Arg *arg)
wl_display_terminate(dpy); wl_display_terminate(dpy);
} }
void
quitsignal(int signo)
{
quit(NULL);
}
void void
render(struct wlr_surface *surface, int sx, int sy, void *data) render(struct wlr_surface *surface, int sx, int sy, void *data)
{ {
@ -1965,8 +1972,10 @@ setup(void)
* clients from the Unix socket, manging Wayland globals, and so on. */ * clients from the Unix socket, manging Wayland globals, and so on. */
dpy = wl_display_create(); dpy = wl_display_create();
/* clean up child processes immediately */ /* Set up signal handlers */
sigchld(0); sigchld(0);
signal(SIGINT, quitsignal);
signal(SIGTERM, quitsignal);
/* The backend is a wlroots feature which abstracts the underlying input and /* The backend is a wlroots feature which abstracts the underlying input and
* output hardware. The autocreate option will choose the most suitable * output hardware. The autocreate option will choose the most suitable