diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index bccca4d..831248e 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -50,5 +50,8 @@ body: id: logs attributes: label: Relevant logs - description: Please copy and paste any relevant logs, error messages or any other output. This will be automatically formatted into code, so no need for backticks. Screenshots are accepted if they make life easier for you. + description: | + Please copy and paste any relevant logs, error messages or any other output. This will be automatically formatted into code, so no need for backticks. + Screenshots are accepted if they make life easier for you. + Generally, including your session log (found at /var/log/ly-session.log unless modified) is a good idea. (But make sure it's relevant!) render: shell diff --git a/res/config.ini b/res/config.ini index d7b302f..83fcc91 100644 --- a/res/config.ini +++ b/res/config.ini @@ -164,6 +164,12 @@ save = true # Service name (set to ly to use the provided pam config file) service_name = ly +# Session log file path +# This will contain stdout and stderr of X11 and Wayland sessions +# By default it's saved in the user's home directory +# Note: this file won't be used in a shell session (due to the need of stdout and stderr) +session_log = ly-session.log + # Setup command setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh diff --git a/src/auth.zig b/src/auth.zig index 255144a..29f9843 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -152,12 +152,13 @@ fn startSession( const env_list = std.mem.span(pam_env_vars.?); for (env_list) |env_var| _ = interop.stdlib.putenv(env_var); - // Execute what the user requested + // Change to the user's home directory std.posix.chdirZ(pwd.pw_dir.?) catch return error.ChangeDirectoryFailed; + // Execute what the user requested switch (current_environment.display_server) { - .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 ""), + .wayland => try executeWaylandCmd(pwd.pw_shell.?, config, current_environment.cmd), + .shell => try executeShellCmd(pwd.pw_shell.?, config), .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,21 +373,35 @@ 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, login_cmd: []const u8) !void { +fn executeShellCmd(shell: [*:0]const u8, config: Config) !void { + // We don't want to redirect stdout and stderr in a shell session + var cmd_buffer: [1024]u8 = undefined; - const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ setup_cmd, login_cmd, shell }); + const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ config.setup_cmd, config.login_cmd orelse "", 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, login_cmd: []const u8, desktop_cmd: []const u8) !void { +fn executeWaylandCmd(shell: [*:0]const u8, config: Config, desktop_cmd: []const u8) !void { + const log_file = try std.fs.cwd().createFile(config.session_log, .{ .mode = 0o666 }); + defer log_file.close(); + + try std.posix.dup2(std.posix.STDOUT_FILENO, std.posix.STDERR_FILENO); + try std.posix.dup2(log_file.handle, std.posix.STDOUT_FILENO); + var cmd_buffer: [1024]u8 = undefined; - const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ setup_cmd, login_cmd, desktop_cmd }); + const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ config.setup_cmd, config.login_cmd orelse "", desktop_cmd }); const args = [_:null]?[*:0]const u8{ shell, "-c", cmd_str }; return std.posix.execveZ(shell, &args, std.c.environ); } fn executeX11Cmd(shell: [*:0]const u8, pw_dir: [*:0]const u8, config: Config, desktop_cmd: []const u8, vt: []const u8) !void { + const log_file = try std.fs.cwd().createFile(config.session_log, .{ .mode = 0o666 }); + defer log_file.close(); + + try std.posix.dup2(std.posix.STDOUT_FILENO, std.posix.STDERR_FILENO); + try std.posix.dup2(log_file.handle, std.posix.STDOUT_FILENO); + const display_num = try getFreeDisplay(); var buf: [5]u8 = undefined; const display_name = try std.fmt.bufPrintZ(&buf, ":{d}", .{display_num}); diff --git a/src/config/Config.zig b/src/config/Config.zig index 1c4555a..f9c88db 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -43,6 +43,7 @@ restart_cmd: []const u8 = "/sbin/shutdown -r now", restart_key: []const u8 = "F2", save: bool = true, service_name: [:0]const u8 = "ly", +session_log: []const u8 = "ly-session.log", setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh", shutdown_cmd: []const u8 = "/sbin/shutdown -a now", shutdown_key: []const u8 = "F1",