Don't shutdown termbox2 if authentication fails

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion 2025-03-06 15:29:56 +01:00
parent 6cb102257c
commit 9168266cca
No known key found for this signature in database
2 changed files with 20 additions and 2 deletions

View File

@ -20,6 +20,7 @@ pub const AuthOptions = struct {
setup_cmd: []const u8,
login_cmd: ?[]const u8,
x_cmd: []const u8,
session_pid: std.posix.pid_t,
};
var xorg_pid: std.posix.pid_t = 0;
@ -164,6 +165,9 @@ fn startSession(
// Change to the user's home directory
std.posix.chdirZ(pwd.pw_dir.?) catch return error.ChangeDirectoryFailed;
// Signal to the session process to give up control on the TTY
_ = std.posix.kill(options.session_pid, std.posix.SIG.CHLD) catch return error.TtyControlTransferFailed;
// Execute what the user requested
switch (current_environment.display_server) {
.wayland => try executeWaylandCmd(pwd.pw_shell.?, options, current_environment.cmd),

View File

@ -26,7 +26,7 @@ const unistd = interop.unistd;
const temporary_allocator = std.heap.page_allocator;
var session_pid: std.posix.pid_t = -1;
pub fn signalHandler(i: c_int) callconv(.C) void {
fn signalHandler(i: c_int) callconv(.C) void {
if (session_pid == 0) return;
// Forward signal to session to clean up
@ -40,6 +40,10 @@ pub fn signalHandler(i: c_int) callconv(.C) void {
std.c.exit(i);
}
fn ttyControlTransferSignalHandler(_: c_int) callconv(.C) void {
_ = termbox.tb_shutdown();
}
pub fn main() !void {
var shutdown = false;
var restart = false;
@ -718,7 +722,7 @@ pub fn main() !void {
defer allocator.free(password_text);
// Give up control on the TTY
_ = termbox.tb_shutdown();
// _ = termbox.tb_shutdown();
session_pid = try std.posix.fork();
if (session_pid == 0) {
@ -732,8 +736,17 @@ pub fn main() !void {
.setup_cmd = config.setup_cmd,
.login_cmd = config.login_cmd,
.x_cmd = config.x_cmd,
.session_pid = session_pid,
};
// Signal action to give up control on the TTY
const tty_control_transfer_act = std.posix.Sigaction{
.handler = .{ .handler = &ttyControlTransferSignalHandler },
.mask = std.posix.empty_sigset,
.flags = 0,
};
std.posix.sigaction(std.posix.SIG.CHLD, &tty_control_transfer_act, null);
auth.authenticate(auth_options, current_environment, login_text, password_text) catch |err| {
shared_err.writeError(err);
std.process.exit(1);
@ -830,6 +843,7 @@ fn getAuthErrorMsg(err: anyerror, lang: Lang) []const u8 {
error.SetUserGidFailed => lang.err_user_gid,
error.SetUserUidFailed => lang.err_user_uid,
error.ChangeDirectoryFailed => lang.err_perm_dir,
error.TtyControlTransferFailed => "tty control transfer failed",
error.SetPathFailed => lang.err_path,
error.PamAccountExpired => lang.err_pam_acct_expired,
error.PamAuthError => lang.err_pam_auth,