the log wrapper in C/C++ accepts formats

This commit is contained in:
2026-03-17 13:22:44 +11:00
parent 2b3fe0630f
commit bdbd94eda2
9 changed files with 259 additions and 7 deletions

View File

@@ -7,6 +7,7 @@
use std::ffi::CStr;
use std::os::raw::c_char;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::env;
mod auth;
mod logging;
@@ -15,14 +16,19 @@ mod error;
#[no_mangle]
pub extern "C" fn rust_init_logging(log_path: *const c_char) {
let _ = catch_unwind(AssertUnwindSafe(|| {
let path = unsafe {
if log_path.is_null() {
"/var/log/pam_rust_backend.log"
} else {
CStr::from_ptr(log_path).to_str().unwrap_or("/var/log/pam_rust_backend.log")
let env_path = env::var("PAM_RUST_LOG_PATH").ok().and_then(|s| if s.is_empty() { None } else { Some(s) });
let path = if let Some(p) = env_path {
p
} else {
unsafe {
if log_path.is_null() {
"/var/log/pam_rust_backend.log".to_string()
} else {
CStr::from_ptr(log_path).to_str().unwrap_or("/var/log/pam_rust_backend.log").to_string()
}
}
};
logging::init_logger(path);
logging::init_logger(&path);
}));
}