4 D-Bus shims sustituyendo systemd: hostnamed, timedated, localed, journald

Patrón de compat-logind extendido a 4 servicios más que GNOME/KDE consultan
al boot. Cada uno: anuncia al bus interno, intenta RequestName en system bus,
degrada a idle si la policy lo bloquea, sirve método mientras esté arriba.

- compat-hostnamed: org.freedesktop.hostname1. Properties read /etc/hostname,
  /etc/os-release, /sys/class/dmi/id/* y uname(). Setters log + cache.
- compat-timedated: org.freedesktop.timedate1. Timezone via readlink
  /etc/localtime. ListTimezones desde /usr/share/zoneinfo.
- compat-localed: org.freedesktop.locale1. Lee /etc/locale.conf,
  /etc/vconsole.conf, /etc/X11/xorg.conf.d/00-keyboard.conf.
- compat-journald: stub datagram listener en /run/systemd/journal/socket
  y /dev/log. Decodifica syslog y journald native, emite tracing events.

Dev seed los incluye condicionalmente. Verificado: los 5 shims
(logind+4 nuevos) anunciados al bus interno con auth SO_PEERCRED.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sergio
2026-05-04 09:44:19 +00:00
parent f4eb7dd944
commit 6ad6d08fa8
11 changed files with 936 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "ente-localed-compat"
version = "0.0.1"
edition.workspace = true
license.workspace = true
publish.workspace = true
[[bin]]
name = "ente-localed-compat"
path = "src/main.rs"
[dependencies]
ente-card = { path = "../ente-card" }
ente-bus = { path = "../ente-bus" }
anyhow = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
zbus = { version = "4", default-features = false, features = ["tokio"] }
+188
View File
@@ -0,0 +1,188 @@
//! ente-localed-compat: shim de `org.freedesktop.locale1`.
//!
//! GNOME settings panel "Region & Language" llama aquí. Properties leen
//! /etc/locale.conf y /etc/vconsole.conf; setters log + forward.
use ente_bus::{BusClient, BusRequest, BusResponse};
use ente_card::Capability;
use std::sync::Mutex;
use tokio::signal::unix::{signal, SignalKind};
use tracing::{info, warn};
use tracing_subscriber::EnvFilter;
use zbus::{fdo, interface};
const BUS_NAME: &str = "org.freedesktop.locale1";
const OBJ_PATH: &str = "/org/freedesktop/locale1";
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
init_tracing();
info!("ente-localed-compat: arrancando");
announce_to_fractal().await;
let manager = LocaleManager::default();
let conn_result = zbus::connection::Builder::system()
.and_then(|b| b.name(BUS_NAME))
.and_then(|b| b.serve_at(OBJ_PATH, manager));
match conn_result {
Ok(builder) => match builder.build().await {
Ok(_conn) => {
info!(name = BUS_NAME, "name acquired, sirviendo");
wait_for_term().await
}
Err(e) => {
warn!(?e, "build conn falló — modo idle");
wait_for_term().await
}
},
Err(e) => {
warn!(?e, "builder D-Bus falló — modo idle");
wait_for_term().await
}
}
}
#[derive(Default)]
struct LocaleManager {
transient_locale: Mutex<Option<Vec<String>>>,
}
#[interface(name = "org.freedesktop.locale1")]
impl LocaleManager {
/// Locale actual como array de "KEY=value" (LANG=en_US.UTF-8, LC_TIME=...).
/// Default: leer /etc/locale.conf.
#[zbus(property)]
async fn locale(&self) -> Vec<String> {
if let Some(v) = self.transient_locale.lock().unwrap().clone() {
return v;
}
match std::fs::read_to_string("/etc/locale.conf") {
Ok(c) => c.lines()
.filter(|l| !l.trim().is_empty() && !l.starts_with('#'))
.map(|s| s.trim().to_string())
.collect(),
Err(_) => vec!["LANG=C.UTF-8".into()],
}
}
#[zbus(property)]
async fn x11layout(&self) -> String {
read_kv("/etc/X11/xorg.conf.d/00-keyboard.conf", "XkbLayout").unwrap_or_default()
}
#[zbus(property)]
async fn x11model(&self) -> String {
read_kv("/etc/X11/xorg.conf.d/00-keyboard.conf", "XkbModel").unwrap_or_default()
}
#[zbus(property)]
async fn x11variant(&self) -> String {
read_kv("/etc/X11/xorg.conf.d/00-keyboard.conf", "XkbVariant").unwrap_or_default()
}
#[zbus(property)]
async fn x11options(&self) -> String {
read_kv("/etc/X11/xorg.conf.d/00-keyboard.conf", "XkbOptions").unwrap_or_default()
}
#[zbus(property)]
async fn vconsole_keymap(&self) -> String {
read_vconsole("KEYMAP").unwrap_or_default()
}
#[zbus(property)]
async fn vconsole_keymap_toggle(&self) -> String {
read_vconsole("KEYMAP_TOGGLE").unwrap_or_default()
}
async fn set_locale(&self, locale: Vec<String>, _interactive: bool) -> fdo::Result<()> {
info!(?locale, "SetLocale (stub: no persistimos a /etc/locale.conf)");
*self.transient_locale.lock().unwrap() = Some(locale);
Ok(())
}
async fn set_vconsole_keymap(
&self,
keymap: String,
keymap_toggle: String,
_convert: bool,
_interactive: bool,
) -> fdo::Result<()> {
info!(%keymap, %keymap_toggle, "SetVConsoleKeymap (stub)");
Ok(())
}
async fn set_x11_keyboard(
&self,
layout: String,
model: String,
variant: String,
options: String,
_convert: bool,
_interactive: bool,
) -> fdo::Result<()> {
info!(%layout, %model, %variant, %options, "SetX11Keyboard (stub)");
Ok(())
}
}
fn read_kv(path: &str, key: &str) -> Option<String> {
let content = std::fs::read_to_string(path).ok()?;
for line in content.lines() {
let trimmed = line.trim();
if trimmed.starts_with(&format!("Option \"{key}\"")) || trimmed.starts_with(key) {
// Best-effort parse: tomar lo que está entre comillas.
if let Some(start) = trimmed.find('"') {
let rest = &trimmed[start + 1..];
if let Some(end) = rest.find('"') {
return Some(rest[..end].to_string());
}
}
}
}
None
}
fn read_vconsole(key: &str) -> Option<String> {
let content = std::fs::read_to_string("/etc/vconsole.conf").ok()?;
for line in content.lines() {
if let Some((k, v)) = line.split_once('=') {
if k.trim() == key {
return Some(v.trim().trim_matches('"').to_string());
}
}
}
None
}
async fn announce_to_fractal() {
if let Ok(mut client) = BusClient::from_env().await {
let req = BusRequest::Announce {
capabilities: vec![Capability::Endpoint {
interface: ente_card::InterfaceId([0xa2; 16]),
version: 1,
}],
};
match client.call(req).await {
Ok(BusResponse::Ok) => info!("Announce → bus interno OK"),
Ok(other) => warn!(?other, "Announce respuesta inesperada"),
Err(e) => warn!(?e, "Announce falló"),
}
}
}
async fn wait_for_term() -> anyhow::Result<()> {
let mut term = signal(SignalKind::terminate())?;
let mut int_ = signal(SignalKind::interrupt())?;
tokio::select! {
_ = term.recv() => info!("SIGTERM"),
_ = int_.recv() => info!("SIGINT"),
}
Ok(())
}
fn init_tracing() {
let filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("ente_localed_compat=info"));
tracing_subscriber::fmt().with_env_filter(filter).with_target(true).init();
}