gardesk/garlock / 4ccc7e8

Browse files

add diagnostic file logging to /tmp/garlock.log

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
4ccc7e82bae3a97af1dfc7030350392c92841a77
Parents
360253a
Tree
25f380c

4 changed files

StatusFile+-
M Cargo.lock 1 1
M garlock/src/auth.rs 6 1
M garlock/src/main.rs 50 12
M garlock/src/x11/window.rs 4 3
Cargo.lockmodified
@@ -523,7 +523,7 @@ dependencies = [
523523
 
524524
 [[package]]
525525
 name = "garlock"
526
-version = "0.3.0"
526
+version = "0.3.2"
527527
 dependencies = [
528528
  "anyhow",
529529
  "cairo-rs",
garlock/src/auth.rsmodified
@@ -67,7 +67,12 @@ pub fn authenticate_async(username: String, password: String) -> PendingAuth {
6767
 ///
6868
 /// This should be called from a background thread to avoid blocking the UI.
6969
 fn authenticate_blocking(username: &str, password: &str) -> AuthResult {
70
-    tracing::debug!(%username, "Starting PAM authentication");
70
+    tracing::info!(
71
+        %username,
72
+        pw_bytes = password.len(),
73
+        pw_chars = password.chars().count(),
74
+        "Starting PAM authentication"
75
+    );
7176
 
7277
     match pam_authenticate(username, password) {
7378
         Ok(()) => {
garlock/src/main.rsmodified
@@ -68,15 +68,29 @@ enum Commands {
6868
 fn main() -> Result<()> {
6969
     let args = Args::parse();
7070
 
71
-    // Initialize logging
71
+    // Initialize logging (stderr + file at /tmp/garlock.log)
7272
     let log_level = if args.debug { "debug" } else { "info" };
73
-    tracing_subscriber::registry()
74
-        .with(
75
-            EnvFilter::try_from_default_env()
76
-                .unwrap_or_else(|_| EnvFilter::new(log_level)),
77
-        )
78
-        .with(tracing_subscriber::fmt::layer())
79
-        .init();
73
+    let filter = EnvFilter::try_from_default_env()
74
+        .unwrap_or_else(|_| EnvFilter::new(log_level));
75
+    let registry = tracing_subscriber::registry().with(filter);
76
+
77
+    if let Ok(log_file) = std::fs::OpenOptions::new()
78
+        .create(true)
79
+        .append(true)
80
+        .open("/tmp/garlock.log")
81
+    {
82
+        let file_layer = tracing_subscriber::fmt::layer()
83
+            .with_writer(std::sync::Mutex::new(log_file))
84
+            .with_ansi(false);
85
+        registry
86
+            .with(tracing_subscriber::fmt::layer())
87
+            .with(file_layer)
88
+            .init();
89
+    } else {
90
+        registry
91
+            .with(tracing_subscriber::fmt::layer())
92
+            .init();
93
+    }
8094
 
8195
     tracing::info!("garlock {} starting", env!("CARGO_PKG_VERSION"));
8296
     tracing::debug!(?args, "Command line arguments");
@@ -498,10 +512,11 @@ fn run_lock(config: Config) -> Result<()> {
498512
                 match event {
499513
                     x11rb::protocol::Event::KeyPress(key_event) => {
500514
                         let keycode = key_event.detail;
501
-                        tracing::debug!(keycode, "Key press");
515
+                        tracing::info!(keycode, event_window = key_event.event, "Key press");
502516
 
503517
                         // Process key through XKB
504518
                         let key_result = keyboard.process_key(keycode, true);
519
+                        tracing::info!(?key_result, "XKB key result");
505520
 
506521
                         match key_result {
507522
                             #[cfg(feature = "dev")]
@@ -552,6 +567,14 @@ fn run_lock(config: Config) -> Result<()> {
552567
                             }
553568
 
554569
                             KeyResult::Enter => {
570
+                                tracing::info!(
571
+                                    pw_empty = password.is_empty(),
572
+                                    pw_chars = password.char_count(),
573
+                                    pw_bytes = password.len(),
574
+                                    auth_pending = pending_auth.is_some(),
575
+                                    in_cooldown = locker_state.is_in_cooldown(),
576
+                                    "Enter pressed"
577
+                                );
555578
                                 // Block attempts during cooldown
556579
                                 if locker_state.is_in_cooldown() {
557580
                                     let remaining = locker_state.cooldown_remaining();
@@ -568,6 +591,7 @@ fn run_lock(config: Config) -> Result<()> {
568591
                                     needs_redraw = true;
569592
                                     tracing::info!(
570593
                                         chars = password.char_count(),
594
+                                        bytes = password.len(),
571595
                                         "Starting PAM authentication"
572596
                                     );
573597
 
@@ -578,6 +602,12 @@ fn run_lock(config: Config) -> Result<()> {
578602
                                     ));
579603
                                     password.clear();
580604
                                     ring.clear_highlight();
605
+                                } else {
606
+                                    tracing::warn!(
607
+                                        "Enter ignored: pw_empty={} auth_pending={}",
608
+                                        password.is_empty(),
609
+                                        pending_auth.is_some()
610
+                                    );
581611
                                 }
582612
                             }
583613
 
@@ -600,13 +630,21 @@ fn run_lock(config: Config) -> Result<()> {
600630
                         keyboard.process_key(key_event.detail, false);
601631
                     }
602632
 
603
-                    x11rb::protocol::Event::Expose(_) => {
604
-                        tracing::trace!("Expose event");
633
+                    x11rb::protocol::Event::Expose(e) => {
634
+                        tracing::info!(x = e.x, y = e.y, w = e.width, h = e.height, "Expose event");
605635
                         needs_redraw = true;
606636
                     }
607637
 
638
+                    x11rb::protocol::Event::FocusIn(e) => {
639
+                        tracing::info!(?e.mode, ?e.detail, "FocusIn");
640
+                    }
641
+
642
+                    x11rb::protocol::Event::FocusOut(e) => {
643
+                        tracing::warn!(?e.mode, ?e.detail, "FocusOut - may lose keyboard!");
644
+                    }
645
+
608646
                     _ => {
609
-                        tracing::trace!(?event, "Unhandled event");
647
+                        tracing::debug!(?event, "Unhandled event");
610648
                     }
611649
                 }
612650
             }
garlock/src/x11/window.rsmodified
@@ -85,7 +85,8 @@ impl LockerWindow {
8585
                         | EventMask::BUTTON_PRESS
8686
                         | EventMask::BUTTON_RELEASE
8787
                         | EventMask::POINTER_MOTION
88
-                        | EventMask::STRUCTURE_NOTIFY,
88
+                        | EventMask::STRUCTURE_NOTIFY
89
+                        | EventMask::FOCUS_CHANGE,
8990
                 ),
9091
         )
9192
         .context("Failed to create window")?;
@@ -251,11 +252,11 @@ impl LockerWindow {
251252
 
252253
             match reply.status {
253254
                 GrabStatus::SUCCESS => {
254
-                    tracing::debug!(attempt, "Keyboard grab successful");
255
+                    tracing::info!(attempt, "Keyboard grab successful");
255256
                     return Ok(());
256257
                 }
257258
                 status => {
258
-                    tracing::trace!(?status, attempt, "Keyboard grab failed, retrying");
259
+                    tracing::warn!(?status, attempt, "Keyboard grab failed, retrying");
259260
                     std::thread::sleep(RETRY_DELAY);
260261
                 }
261262
             }