Add enable_session_log option to control session logging (#809) (fixes #808)

Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/809
Reviewed-by: AnErrupTion <anerruption@disroot.org>
Co-authored-by: João Lucas <jlucaso@hotmail.com>
Co-committed-by: João Lucas <jlucaso@hotmail.com>
This commit is contained in:
João Lucas 2025-08-04 00:00:18 +02:00 committed by AnErrupTion
parent 5bacc8870b
commit b71789912d
3 changed files with 12 additions and 6 deletions

View File

@ -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

View File

@ -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();

View File

@ -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",