diff --git a/res/config.ini b/res/config.ini index a83ee41..951b003 100644 --- a/res/config.ini +++ b/res/config.ini @@ -1,11 +1,11 @@ # The active animation -# none -> Nothing (default) +# none -> Nothing # doom -> PSX DOOM fire # matrix -> CMatrix animation = none # Stop the animation after some time -# 0 -> Run forever (default) +# 0 -> Run forever # 1..2e12 -> Stop the animation after this many seconds animation_timeout_sec = 0 @@ -112,6 +112,18 @@ lang = en # Load the saved desktop and username load = true +# Command executed when logging in +# If null, no command will be executed +# Important: the code itself must end with `exec "$@"` in order to launch the session! +# You can also set environment variables in there, they'll persist until logout +login_cmd = null + +# Command executed when logging out +# If null, no command will be executed +# Important: the session will already be terminated when this command is executed, so +# no need to add `exec "$@"` at the end +logout_cmd = null + # Main box horizontal margin margin_box_h = 2 diff --git a/src/auth.zig b/src/auth.zig index 281777d..255144a 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -156,8 +156,8 @@ fn startSession( std.posix.chdirZ(pwd.pw_dir.?) catch return error.ChangeDirectoryFailed; switch (current_environment.display_server) { - .wayland => try executeWaylandCmd(pwd.pw_shell.?, config.setup_cmd, current_environment.cmd), - .shell => try executeShellCmd(pwd.pw_shell.?, config.setup_cmd), + .wayland => try executeWaylandCmd(pwd.pw_shell.?, config.setup_cmd, config.login_cmd orelse "", current_environment.cmd), + .shell => try executeShellCmd(pwd.pw_shell.?, config.setup_cmd, config.login_cmd orelse ""), .xinitrc, .x11 => if (build_options.enable_x11_support) { var vt_buf: [5]u8 = undefined; const vt = try std.fmt.bufPrint(&vt_buf, "vt{d}", .{config.tty}); @@ -372,16 +372,16 @@ fn xauth(display_name: [:0]u8, shell: [*:0]const u8, pw_dir: [*:0]const u8, xaut if (status.status != 0) return error.XauthFailed; } -fn executeShellCmd(shell: [*:0]const u8, setup_cmd: []const u8) !void { +fn executeShellCmd(shell: [*:0]const u8, setup_cmd: []const u8, login_cmd: []const u8) !void { var cmd_buffer: [1024]u8 = undefined; - const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ setup_cmd, shell }); + const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ setup_cmd, login_cmd, shell }); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; return std.posix.execveZ(shell, &args, std.c.environ); } -fn executeWaylandCmd(shell: [*:0]const u8, setup_cmd: []const u8, desktop_cmd: []const u8) !void { +fn executeWaylandCmd(shell: [*:0]const u8, setup_cmd: []const u8, login_cmd: []const u8, desktop_cmd: []const u8) !void { var cmd_buffer: [1024]u8 = undefined; - const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ setup_cmd, desktop_cmd }); + const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ setup_cmd, login_cmd, desktop_cmd }); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; return std.posix.execveZ(shell, &args, std.c.environ); } @@ -418,7 +418,7 @@ fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, config: Config, de xorg_pid = try std.posix.fork(); if (xorg_pid == 0) { var cmd_buffer: [1024]u8 = undefined; - const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s}", .{ config.setup_cmd, desktop_cmd }) catch std.process.exit(1); + const cmd_str = std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ config.setup_cmd, config.login_cmd orelse "", desktop_cmd }) catch std.process.exit(1); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; std.posix.execveZ(shell, &args, std.c.environ) catch {}; std.process.exit(1); diff --git a/src/config/Config.zig b/src/config/Config.zig index f77ea00..89a56cd 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -32,6 +32,8 @@ initial_info_text: ?[]const u8 = null, input_len: u8 = 34, lang: []const u8 = "en", load: bool = true, +login_cmd: ?[]const u8 = null, +logout_cmd: ?[]const u8 = null, margin_box_h: u8 = 2, margin_box_v: u8 = 1, min_refresh_delta: u16 = 5, diff --git a/src/main.zig b/src/main.zig index 0089ec8..039c184 100644 --- a/src/main.zig +++ b/src/main.zig @@ -698,6 +698,11 @@ pub fn main() !void { try info_line.addMessage(getAuthErrorMsg(err, lang), config.error_bg, config.error_fg); if (config.clear_password or err != error.PamAuthError) password.clear(); } else { + if (config.logout_cmd) |logout_cmd| { + var logout_process = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", logout_cmd }, allocator); + _ = logout_process.spawnAndWait() catch .{}; + } + password.clear(); try info_line.addMessage(lang.logout, config.bg, config.fg); }