Skip to main content

seat/
seat.rs

1// SPDX-FileCopyrightText: (c) 2026 Joel Winarske
2// SPDX-License-Identifier: MIT
3
4//! Report whether this process can hold a seat, and what it can open on it.
5//!
6//! ```text
7//! cargo run -p drmkit-session --example seat -- /dev/dri/card0
8//! ```
9//!
10//! Expect it to say there is no seat unless it is run from a login session on
11//! the machine's own console. Over SSH logind reports the session busy, seatd
12//! is not running, and libseat's builtin backend wants root and a TTY.
13//! `LIBSEAT_BACKEND` forces one.
14
15use drmkit_session::{Session, SessionError};
16
17fn main() {
18    let paths: Vec<String> = std::env::args().skip(1).collect();
19
20    let mut backend = match drmkit_session::LibseatBackend::open() {
21        Ok(backend) => backend,
22        Err(SessionError::NoBackend) => {
23            println!("no seat here: not a login session, no seatd, no root TTY");
24            return;
25        }
26        Err(error) => {
27            eprintln!("seat: {error}");
28            std::process::exit(1);
29        }
30    };
31
32    println!("seat: {}", backend.name());
33    let mut session = Session::new(backend);
34
35    for path in &paths {
36        match session.take_device(path) {
37            Ok(device) => println!("  {path}: fd {}", device.fd),
38            Err(error) => println!("  {path}: {error}"),
39        }
40    }
41
42    if paths.is_empty() {
43        println!("pass device paths to open some");
44    }
45}