mirror of https://github.com/fairyglade/ly.git
fix cascade, set info_line before auth, make code clearer and a bug fix
This commit is contained in:
parent
a1caf7c0d8
commit
74f7f08801
|
@ -1,3 +1,4 @@
|
||||||
|
authenticating = authenticating...
|
||||||
capslock = capslock
|
capslock = capslock
|
||||||
err_alloc = failed memory allocation
|
err_alloc = failed memory allocation
|
||||||
err_bounds = out-of-bounds index
|
err_bounds = out-of-bounds index
|
||||||
|
|
33
src/auth.zig
33
src/auth.zig
|
@ -83,21 +83,30 @@ pub fn authenticate(config: Config, current_environment: Desktop.Environment, lo
|
||||||
std.process.exit(0);
|
std.process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry: Utmp = std.mem.zeroes(Utmp);
|
var entry = std.mem.zeroes(Utmp);
|
||||||
addUtmpEntry(&entry, pwd.pw_name, child_pid) catch {};
|
|
||||||
defer removeUtmpEntry(&entry);
|
|
||||||
|
|
||||||
// If we receive SIGTERM, forward it to child_pid
|
{
|
||||||
const act = std.posix.Sigaction{
|
// If an error occurs here, we can send SIGTERM to the session
|
||||||
.handler = .{ .handler = &sessionSignalHandler },
|
errdefer cleanup: {
|
||||||
.mask = std.posix.empty_sigset,
|
_ = std.posix.kill(child_pid, std.posix.SIG.TERM) catch break :cleanup;
|
||||||
.flags = 0,
|
_ = std.posix.waitpid(child_pid, 0);
|
||||||
};
|
}
|
||||||
try std.posix.sigaction(std.posix.SIG.TERM, &act, null);
|
|
||||||
|
|
||||||
|
// If we receive SIGTERM, forward it to child_pid
|
||||||
|
const act = std.posix.Sigaction{
|
||||||
|
.handler = .{ .handler = &sessionSignalHandler },
|
||||||
|
.mask = std.posix.empty_sigset,
|
||||||
|
.flags = 0,
|
||||||
|
};
|
||||||
|
try std.posix.sigaction(std.posix.SIG.TERM, &act, null);
|
||||||
|
|
||||||
|
try addUtmpEntry(&entry, pwd.pw_name, child_pid);
|
||||||
|
}
|
||||||
// Wait for the session to stop
|
// Wait for the session to stop
|
||||||
_ = std.posix.waitpid(child_pid, 0);
|
_ = std.posix.waitpid(child_pid, 0);
|
||||||
|
|
||||||
|
removeUtmpEntry(&entry);
|
||||||
|
|
||||||
try resetTerminal(pwd.pw_shell, config.term_reset_cmd);
|
try resetTerminal(pwd.pw_shell, config.term_reset_cmd);
|
||||||
|
|
||||||
if (shared_err.readError()) |err| return err;
|
if (shared_err.readError()) |err| return err;
|
||||||
|
@ -190,7 +199,7 @@ fn loginConv(
|
||||||
|
|
||||||
// Initialise allocated memory to 0
|
// Initialise allocated memory to 0
|
||||||
// This ensures memory can be freed by pam on success
|
// This ensures memory can be freed by pam on success
|
||||||
for (response) |*r| r.* = std.mem.zeroes(interop.pam.pam_response);
|
@memset(response, std.mem.zeroes(interop.pam.pam_response));
|
||||||
|
|
||||||
var username: ?[:0]u8 = null;
|
var username: ?[:0]u8 = null;
|
||||||
var password: ?[:0]u8 = null;
|
var password: ?[:0]u8 = null;
|
||||||
|
@ -412,7 +421,7 @@ fn addUtmpEntry(entry: *Utmp, username: [*:0]const u8, pid: c_int) !void {
|
||||||
entry.ut_pid = pid;
|
entry.ut_pid = pid;
|
||||||
|
|
||||||
var buf: [4096]u8 = undefined;
|
var buf: [4096]u8 = undefined;
|
||||||
const ttyname = try std.os.getFdPath(0, &buf);
|
const ttyname = try std.os.getFdPath(std.posix.STDIN_FILENO, &buf);
|
||||||
|
|
||||||
var ttyname_buf: [32]u8 = undefined;
|
var ttyname_buf: [32]u8 = undefined;
|
||||||
_ = try std.fmt.bufPrintZ(&ttyname_buf, "{s}", .{ttyname["/dev/".len..]});
|
_ = try std.fmt.bufPrintZ(&ttyname_buf, "{s}", .{ttyname["/dev/".len..]});
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
authenticating: []const u8 = "authenticating...",
|
||||||
capslock: []const u8 = "capslock",
|
capslock: []const u8 = "capslock",
|
||||||
err_alloc: []const u8 = "failed memory allocation",
|
err_alloc: []const u8 = "failed memory allocation",
|
||||||
err_bounds: []const u8 = "out-of-bounds index",
|
err_bounds: []const u8 = "out-of-bounds index",
|
||||||
|
|
23
src/main.zig
23
src/main.zig
|
@ -267,7 +267,7 @@ pub fn main() !void {
|
||||||
while (run) {
|
while (run) {
|
||||||
// If there's no input or there's an animation, a resolution change needs to be checked
|
// If there's no input or there's an animation, a resolution change needs to be checked
|
||||||
if (!update or config.animation != .none) {
|
if (!update or config.animation != .none) {
|
||||||
if (!update) std.time.sleep(100_000_000);
|
if (!update) std.time.sleep(std.time.ns_per_ms * 100);
|
||||||
|
|
||||||
termbox.tb_present(); // Required to update tb_width(), tb_height() and tb_cell_buffer()
|
termbox.tb_present(); // Required to update tb_width(), tb_height() and tb_cell_buffer()
|
||||||
|
|
||||||
|
@ -367,10 +367,7 @@ pub fn main() !void {
|
||||||
buffer.drawLabel(lang.login, label_x, label_y + 4);
|
buffer.drawLabel(lang.login, label_x, label_y + 4);
|
||||||
buffer.drawLabel(lang.password, label_x, label_y + 6);
|
buffer.drawLabel(lang.password, label_x, label_y + 6);
|
||||||
|
|
||||||
if (info_line.width > 0 and buffer.box_width > info_line.width) {
|
info_line.draw(buffer);
|
||||||
const x = buffer.box_x + ((buffer.box_width - info_line.width) / 2);
|
|
||||||
buffer.drawLabel(info_line.text, x, label_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.hide_key_hints) {
|
if (!config.hide_key_hints) {
|
||||||
var length: u64 = 0;
|
var length: u64 = 0;
|
||||||
|
@ -423,11 +420,11 @@ pub fn main() !void {
|
||||||
|
|
||||||
update = animate;
|
update = animate;
|
||||||
} else {
|
} else {
|
||||||
std.time.sleep(10_000_000);
|
std.time.sleep(std.time.ns_per_ms * 10);
|
||||||
update = buffer.cascade();
|
update = buffer.cascade();
|
||||||
|
|
||||||
if (!update) {
|
if (!update) {
|
||||||
std.time.sleep(7_000_000_000);
|
std.time.sleep(std.time.ns_per_s * 7);
|
||||||
auth_fails = 0;
|
auth_fails = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,6 +528,11 @@ pub fn main() !void {
|
||||||
const password_text = try allocator.dupeZ(u8, password.text.items);
|
const password_text = try allocator.dupeZ(u8, password.text.items);
|
||||||
defer allocator.free(password_text);
|
defer allocator.free(password_text);
|
||||||
|
|
||||||
|
try info_line.setText(lang.authenticating);
|
||||||
|
InfoLine.clearRendered(allocator, buffer) catch {};
|
||||||
|
info_line.draw(buffer);
|
||||||
|
_ = termbox.tb_present();
|
||||||
|
|
||||||
session_pid = try std.posix.fork();
|
session_pid = try std.posix.fork();
|
||||||
if (session_pid == 0) {
|
if (session_pid == 0) {
|
||||||
const current_environment = desktop.environments.items[desktop.current];
|
const current_environment = desktop.environments.items[desktop.current];
|
||||||
|
@ -557,14 +559,15 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
try std.posix.tcsetattr(std.posix.STDIN_FILENO, .FLUSH, tb_termios);
|
try std.posix.tcsetattr(std.posix.STDIN_FILENO, .FLUSH, tb_termios);
|
||||||
termbox.tb_clear();
|
if (auth_fails < 10) {
|
||||||
|
termbox.tb_clear();
|
||||||
|
termbox.tb_present();
|
||||||
|
}
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
|
|
||||||
var restore_cursor = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", config.term_restore_cursor_cmd }, allocator);
|
var restore_cursor = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", config.term_restore_cursor_cmd }, allocator);
|
||||||
_ = restore_cursor.spawnAndWait() catch .{};
|
_ = restore_cursor.spawnAndWait() catch .{};
|
||||||
|
|
||||||
termbox.tb_present();
|
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
if (!insert_mode) {
|
if (!insert_mode) {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
const std = @import("std");
|
||||||
const utils = @import("../utils.zig");
|
const utils = @import("../utils.zig");
|
||||||
|
const TerminalBuffer = @import("../TerminalBuffer.zig");
|
||||||
|
|
||||||
const InfoLine = @This();
|
const InfoLine = @This();
|
||||||
|
|
||||||
|
@ -9,3 +11,23 @@ pub fn setText(self: *InfoLine, text: []const u8) !void {
|
||||||
self.width = if (text.len > 0) try utils.strWidth(text) else 0;
|
self.width = if (text.len > 0) try utils.strWidth(text) else 0;
|
||||||
self.text = text;
|
self.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw(self: InfoLine, buffer: TerminalBuffer) void {
|
||||||
|
if (self.width > 0 and buffer.box_width > self.width) {
|
||||||
|
const label_y = buffer.box_y + buffer.margin_box_v;
|
||||||
|
const x = buffer.box_x + ((buffer.box_width - self.width) / 2);
|
||||||
|
|
||||||
|
buffer.drawLabel(self.text, x, label_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clearRendered(allocator: std.mem.Allocator, buffer: TerminalBuffer) !void {
|
||||||
|
// draw over the area
|
||||||
|
const y = buffer.box_y + buffer.margin_box_v;
|
||||||
|
const spaces = try allocator.alloc(u8, buffer.box_width);
|
||||||
|
defer allocator.free(spaces);
|
||||||
|
|
||||||
|
@memset(spaces, ' ');
|
||||||
|
|
||||||
|
buffer.drawLabel(spaces, buffer.box_x, y);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue