server: handle SIGINT/SIGTERM with wl_event_loop

This is cleaner than having a separate signal handler and should be more
consistent/reliable.
This commit is contained in:
Isaac Freund
2020-08-01 17:27:49 +02:00
parent 54b09c4ae9
commit 56df9176b3
3 changed files with 22 additions and 21 deletions

View File

@ -32,8 +32,6 @@ const usage: []const u8 =
\\
;
var server: Server = undefined;
pub fn main() anyerror!void {
var startup_command: ?[*:0]const u8 = null;
{
@ -71,15 +69,7 @@ pub fn main() anyerror!void {
log.info(.server, "initializing", .{});
// Setup a handler for SIGINT and SIGTERM so we can clean up properly
var act = std.os.Sigaction{
.sigaction = handleSignal,
.mask = std.os.empty_sigset,
.flags = 0,
};
std.os.sigaction(std.os.SIGINT, &act, null);
std.os.sigaction(std.os.SIGTERM, &act, null);
var server: Server = undefined;
try server.init();
defer server.deinit();
@ -109,10 +99,3 @@ fn printErrorExit(comptime format: []const u8, args: var) noreturn {
stderr.print(format ++ "\n", args) catch std.os.exit(1);
std.os.exit(1);
}
fn handleSignal(sig: i32, info: *const std.os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {
switch (sig) {
std.os.SIGINT, std.os.SIGTERM => c.wl_display_terminate(server.wl_display),
else => unreachable,
}
}