From a310466e68c35b0937adc201a0c7a77f7bab8b2a Mon Sep 17 00:00:00 2001 From: Gijs Burghoorn Date: Thu, 30 Mar 2023 22:01:52 +0200 Subject: [PATCH] Impr: Properly integrate no-log with xorg/client log --- extra/config.toml | 3 +++ src/config.rs | 2 ++ src/main.rs | 2 ++ src/post_login/mod.rs | 17 +++++++++++------ src/post_login/x.rs | 18 ++++++++++++------ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/extra/config.toml b/extra/config.toml index 8f693ff..4c0b07a 100644 --- a/extra/config.toml +++ b/extra/config.toml @@ -55,6 +55,9 @@ client_log_path = "/var/log/lemurs.client.log" # Where to log to for the XServer. xserver_log_path = "/var/log/lemurs.xorg.log" +# Disable all logging. This is overwritten by the `--no-log` flag. +no_log = false + # The PAM service that should be used to login pam_service = "lemurs" diff --git a/src/config.rs b/src/config.rs index cad0d92..16c4d5b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -159,6 +159,8 @@ toml_config_struct! { Config, PartialConfig, client_log_path => String, xserver_log_path => String, + no_log => bool, + pam_service => String, shell_login_flag => ShellLoginFlag, diff --git a/src/main.rs b/src/main.rs index e088238..b4823d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,6 +141,8 @@ fn main() -> Result<(), Box> { if !cli.no_log { setup_logger(cli.preview); info!("Lemurs logger is running"); + } else { + config.no_log = true; } if !cli.preview { diff --git a/src/post_login/mod.rs b/src/post_login/mod.rs index d606e43..da81d11 100644 --- a/src/post_login/mod.rs +++ b/src/post_login/mod.rs @@ -172,13 +172,18 @@ impl PostLoginEnvironment { ShellLoginFlag::Long => Some("--login"), }; - let client = lower_command_permissions_to_user(Command::new(SYSTEM_SHELL), user_info); + let mut client = lower_command_permissions_to_user(Command::new(SYSTEM_SHELL), user_info); - info!( - "Setup client to log `stdout` and `stderr` to '{log_path}'", - log_path = config.client_log_path - ); - let mut client = output_command_to_log(client, Path::new(&config.client_log_path)); + let mut client = if config.no_log { + client.stdout(Stdio::null()).stderr(Stdio::null()); + client + } else { + info!( + "Setup client to log `stdout` and `stderr` to '{log_path}'", + log_path = config.client_log_path + ); + output_command_to_log(client, Path::new(&config.client_log_path)) + }; if let Some(shell_login_flag) = shell_login_flag { client.arg(shell_login_flag); diff --git a/src/post_login/x.rs b/src/post_login/x.rs index 1ccc2b2..dd93369 100644 --- a/src/post_login/x.rs +++ b/src/post_login/x.rs @@ -135,12 +135,18 @@ pub fn setup_x( libc::signal(SIGUSR1, SIG_IGN); } - let child = Command::new(super::SYSTEM_SHELL); - info!( - "Setup XServer to log `stdout` and `stderr` to '{log_path}'", - log_path = config.xserver_log_path - ); - let mut child = output_command_to_log(child, Path::new(&config.xserver_log_path)); + let mut child = Command::new(super::SYSTEM_SHELL); + + let mut child = if config.no_log { + child.stdout(Stdio::null()).stderr(Stdio::null()); + child + } else { + info!( + "Setup XServer to log `stdout` and `stderr` to '{log_path}'", + log_path = config.xserver_log_path + ); + output_command_to_log(child, Path::new(&config.xserver_log_path)) + }; let mut child = child .arg("-c") .arg(format!("/usr/bin/X {display_value} vt{doubledigit_vtnr}"))