From b71789912dc55375cc43c9738492f6e6c7f5328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas?= Date: Mon, 4 Aug 2025 00:00:18 +0200 Subject: [PATCH] Add enable_session_log option to control session logging (#809) (fixes #808) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/809 Reviewed-by: AnErrupTion Co-authored-by: João Lucas Co-committed-by: João Lucas --- res/config.ini | 3 ++- src/auth.zig | 13 +++++++++---- src/config/Config.zig | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/res/config.ini b/res/config.ini index b987e94..15844e5 100644 --- a/res/config.ini +++ b/res/config.ini @@ -253,7 +253,8 @@ service_name = ly # This will contain stdout and stderr of Wayland sessions # By default it's saved in the user's home directory # Important: due to technical limitations, X11 and shell sessions aren't supported, which -# means you won't get any logs from those sessions +# means you won't get any logs from those sessions. +# If null, no session log will be created session_log = ly-session.log # Setup command diff --git a/src/auth.zig b/src/auth.zig index d1e3a0a..e57e237 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -15,7 +15,7 @@ pub const AuthOptions = struct { tty: u8, service_name: [:0]const u8, path: ?[:0]const u8, - session_log: []const u8, + session_log: ?[]const u8, xauth_cmd: []const u8, setup_cmd: []const u8, login_cmd: ?[]const u8, @@ -399,8 +399,11 @@ fn executeShellCmd(shell: [*:0]const u8, options: AuthOptions) !void { } fn executeWaylandCmd(shell: [*:0]const u8, options: AuthOptions, desktop_cmd: []const u8) !void { - const log_file = try redirectStandardStreams(options.session_log, true); - defer log_file.close(); + var maybe_log_file: ?std.fs.File = null; + if (options.session_log) |log_path| { + maybe_log_file = try redirectStandardStreams(log_path, true); + } + defer if (maybe_log_file) |log_file| log_file.close(); var cmd_buffer: [1024]u8 = undefined; const cmd_str = try std.fmt.bufPrintZ(&cmd_buffer, "{s} {s} {s}", .{ options.setup_cmd, options.login_cmd orelse "", desktop_cmd }); @@ -470,7 +473,9 @@ fn executeCustomCmd(shell: [*:0]const u8, options: AuthOptions, is_terminal: boo // For custom desktop entries, the "Terminal" value here determines if // we redirect standard output & error or not. That is, we redirect only // if it's equal to false (so if it's not running in a TTY). - maybe_log_file = try redirectStandardStreams(options.session_log, true); + if (options.session_log) |log_path| { + maybe_log_file = try redirectStandardStreams(log_path, true); + } } defer if (maybe_log_file) |log_file| log_file.close(); diff --git a/src/config/Config.zig b/src/config/Config.zig index 4fc0af7..ef91cb1 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -66,7 +66,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", +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",