~kennylevinsen/greetd-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Use a sysfs fallback if XDG_VTNR is undefined

Details
Message ID
<20240307120436.29075-2-hugo@whynothugo.nl>
DKIM signature
pass
Download raw message
Patch: +15 -5
---
 agreety/src/main.rs | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 67a87bf..1721c49 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -32,18 +32,28 @@ fn get_distro_name() -> Result<String, Box<dyn std::error::Error>> {
    maybe_unquote(general.get("PRETTY_NAME").ok_or("no pretty name")?)
}

/// Returns the current VT. May contain trailing whitespace.
fn get_vt() -> String {
    if let Ok(vtnr) = env::var("XDG_VTNR") {
        format!("tty{vtnr}")
    } else {
        if let Ok(tty) = std::fs::read_to_string("/sys/class/tty/tty0/active") {
            tty
        } else {
            String::from("tty0")
        }
    }
}

fn get_issue() -> Result<String, Box<dyn std::error::Error>> {
    let vtnr: usize = env::var("XDG_VTNR")
        .unwrap_or_else(|_| "0".to_string())
        .parse()
        .expect("unable to parse VTNR");
    let vt = get_vt();
    let uts = uname()?;
    Ok(fs::read_to_string("/etc/issue")?
        .replace(
            "\\S",
            &get_distro_name().unwrap_or_else(|_| "Linux".to_string()),
        )
        .replace("\\l", &format!("tty{vtnr}"))
        .replace("\\l", vt.trim())
        .replace("\\s", uts.sysname().to_str().unwrap())
        .replace("\\r", uts.release().to_str().unwrap())
        .replace("\\v", uts.version().to_str().unwrap())
-- 
2.44.0
Details
Message ID
<vqtoyr5arahtexdj7e4orpg6hxlx6pyprzkleded43yttsvvqg@25jsdi6tuhdg>
In-Reply-To
<20240307120436.29075-2-hugo@whynothugo.nl> (view parent)
DKIM signature
pass
Download raw message
On 2024-03-07 13:04, Hugo Osvaldo Barrera wrote:
> ---
>  agreety/src/main.rs | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
Please disregard this patch. The sysfs path used here provides the ACTIVE vt,
so will yield wrong results for agreety instances running in a background vt.

-- 
Hugo
Reply to thread Export thread (mbox)