mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
Remove config.console_dev option + handle ioctl errors
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -28,7 +28,6 @@ cmatrix_max_codepoint: u16 = 0x7B,
|
||||
colormix_col1: u32 = 0x00FF0000,
|
||||
colormix_col2: u32 = 0x000000FF,
|
||||
colormix_col3: u32 = 0x20000000,
|
||||
console_dev: []const u8 = "/dev/console",
|
||||
default_input: Input = .login,
|
||||
doom_top_color: u32 = 0x00FF0000,
|
||||
doom_middle_color: u32 = 0x00FFFF00,
|
||||
|
||||
@@ -18,6 +18,7 @@ err_domain: []const u8 = "invalid domain",
|
||||
err_empty_password: []const u8 = "empty password not allowed",
|
||||
err_envlist: []const u8 = "failed to get envlist",
|
||||
err_hostname: []const u8 = "failed to get hostname",
|
||||
err_lock_state: []const u8 = "failed to get lock state",
|
||||
err_mlock: []const u8 = "failed to lock password memory",
|
||||
err_null: []const u8 = "null pointer",
|
||||
err_numlock: []const u8 = "failed to set numlock",
|
||||
@@ -43,6 +44,7 @@ err_perm_group: []const u8 = "failed to downgrade group permissions",
|
||||
err_perm_user: []const u8 = "failed to downgrade user permissions",
|
||||
err_pwnam: []const u8 = "failed to get user info",
|
||||
err_sleep: []const u8 = "failed to execute sleep command",
|
||||
err_switch_tty: []const u8 = "failed to switch tty",
|
||||
err_tty_ctrl: []const u8 = "tty control transfer failed",
|
||||
err_user_gid: []const u8 = "failed to set user GID",
|
||||
err_user_init: []const u8 = "failed to initialize user",
|
||||
|
||||
@@ -36,7 +36,7 @@ pub const stdlib = @cImport({
|
||||
pub const pwd = @cImport({
|
||||
@cInclude("pwd.h");
|
||||
// We include a FreeBSD-specific header here since login_cap.h references
|
||||
// the passwd struct directly, so we can't import it separately'
|
||||
// the passwd struct directly, so we can't import it separately
|
||||
if (builtin.os.tag == .freebsd) @cInclude("login_cap.h");
|
||||
});
|
||||
|
||||
@@ -75,23 +75,21 @@ pub fn timeAsString(buf: [:0]u8, format: [:0]const u8) ![]u8 {
|
||||
return buf[0..len];
|
||||
}
|
||||
|
||||
pub fn switchTty(console_dev: []const u8, tty: u8) !void {
|
||||
const fd = try std.posix.open(console_dev, .{ .ACCMODE = .WRONLY }, 0);
|
||||
defer std.posix.close(fd);
|
||||
pub fn switchTty(tty: u8) !void {
|
||||
var status = std.c.ioctl(std.c.STDIN_FILENO, vt.VT_ACTIVATE, tty);
|
||||
if (status != 0) return error.FailedToActivateTty;
|
||||
|
||||
_ = std.c.ioctl(fd, vt.VT_ACTIVATE, tty);
|
||||
_ = std.c.ioctl(fd, vt.VT_WAITACTIVE, tty);
|
||||
status = std.c.ioctl(std.c.STDIN_FILENO, vt.VT_WAITACTIVE, tty);
|
||||
if (status != 0) return error.FailedToWaitForActiveTty;
|
||||
}
|
||||
|
||||
pub fn getLockState(console_dev: []const u8) !struct {
|
||||
pub fn getLockState() !struct {
|
||||
numlock: bool,
|
||||
capslock: bool,
|
||||
} {
|
||||
const fd = try std.posix.open(console_dev, .{ .ACCMODE = .RDONLY }, 0);
|
||||
defer std.posix.close(fd);
|
||||
|
||||
var led: LedState = undefined;
|
||||
_ = std.c.ioctl(fd, get_led_state, &led);
|
||||
const status = std.c.ioctl(std.c.STDIN_FILENO, get_led_state, &led);
|
||||
if (status != 0) return error.FailedToGetLockState;
|
||||
|
||||
return .{
|
||||
.numlock = (led & numlock_led) != 0,
|
||||
@@ -101,11 +99,12 @@ pub fn getLockState(console_dev: []const u8) !struct {
|
||||
|
||||
pub fn setNumlock(val: bool) !void {
|
||||
var led: LedState = undefined;
|
||||
_ = std.c.ioctl(0, get_led_state, &led);
|
||||
var status = std.c.ioctl(std.c.STDIN_FILENO, get_led_state, &led);
|
||||
if (status != 0) return error.FailedToGetNumlock;
|
||||
|
||||
const numlock = (led & numlock_led) != 0;
|
||||
if (numlock != val) {
|
||||
const status = std.c.ioctl(std.posix.STDIN_FILENO, set_led_state, led ^ numlock_led);
|
||||
status = std.c.ioctl(std.posix.STDIN_FILENO, set_led_state, led ^ numlock_led);
|
||||
if (status != 0) return error.FailedToSetNumlock;
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.zig
14
src/main.zig
@@ -389,12 +389,10 @@ pub fn main() !void {
|
||||
var update = true;
|
||||
var resolution_changed = false;
|
||||
var auth_fails: u64 = 0;
|
||||
var can_access_console_dev = true;
|
||||
|
||||
// Switch to selected TTY if possible
|
||||
interop.switchTty(config.console_dev, config.tty) catch {
|
||||
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
||||
can_access_console_dev = false;
|
||||
// Switch to selected TTY
|
||||
interop.switchTty(config.tty) catch {
|
||||
try info_line.addMessage(lang.err_switch_tty, config.error_bg, config.error_fg);
|
||||
};
|
||||
|
||||
while (run) {
|
||||
@@ -546,9 +544,9 @@ pub fn main() !void {
|
||||
buffer.drawLabel(label_txt, buffer.box_x, buffer.box_y + buffer.box_height);
|
||||
}
|
||||
|
||||
if (can_access_console_dev) draw_lock_state: {
|
||||
const lock_state = interop.getLockState(config.console_dev) catch {
|
||||
try info_line.addMessage(lang.err_console_dev, config.error_bg, config.error_fg);
|
||||
draw_lock_state: {
|
||||
const lock_state = interop.getLockState() catch {
|
||||
try info_line.addMessage(lang.err_lock_state, config.error_bg, config.error_fg);
|
||||
break :draw_lock_state;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user