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-timedated-compat"
version = "0.0.1"
edition.workspace = true
license.workspace = true
publish.workspace = true
[[bin]]
name = "ente-timedated-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"] }
+168
View File
@@ -0,0 +1,168 @@
//! ente-timedated-compat: shim de `org.freedesktop.timedate1`.
//!
//! GNOME settings panel "Date & Time" llama aquí. Properties read-only se
//! mapean a syscalls/lecturas del sistema; setters log + forward.
use ente_bus::{BusClient, BusRequest, BusResponse};
use ente_card::Capability;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::signal::unix::{signal, SignalKind};
use tracing::{info, warn};
use tracing_subscriber::EnvFilter;
use zbus::{fdo, interface};
const BUS_NAME: &str = "org.freedesktop.timedate1";
const OBJ_PATH: &str = "/org/freedesktop/timedate1";
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
init_tracing();
info!("ente-timedated-compat: arrancando");
announce_to_fractal().await;
let manager = TimedateManager::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 TimedateManager;
#[interface(name = "org.freedesktop.timedate1")]
impl TimedateManager {
// ----- Properties -----
/// Timezone configurada. Por defecto leemos el target de /etc/localtime
/// (un symlink a /usr/share/zoneinfo/<TZ>).
#[zbus(property)]
async fn timezone(&self) -> String {
std::fs::read_link("/etc/localtime")
.ok()
.and_then(|p| {
let s = p.to_string_lossy().into_owned();
s.strip_prefix("/usr/share/zoneinfo/").map(String::from)
.or_else(|| s.split("/zoneinfo/").nth(1).map(String::from))
})
.unwrap_or_else(|| "UTC".into())
}
/// True si el RTC del hardware está en local time. Convención moderna
/// es UTC (false). Reportamos false como default.
#[zbus(property)]
async fn local_rtc(&self) -> bool { false }
/// Si NTP es soportado. Reportamos true (asumimos systemd-timesyncd
/// o chrony están disponibles en el host).
#[zbus(property)]
async fn can_ntp(&self) -> bool { true }
/// Si NTP está activo. Sin daemon real bajo nuestro control no podemos
/// consultarlo con precisión — false como default seguro.
#[zbus(property)]
async fn ntp(&self) -> bool { false }
#[zbus(property)]
async fn ntpsynchronized(&self) -> bool { false }
/// Timestamp actual en microsegundos desde epoch.
#[zbus(property)]
async fn time_usec(&self) -> u64 {
SystemTime::now().duration_since(UNIX_EPOCH)
.map(|d| d.as_micros() as u64)
.unwrap_or(0)
}
#[zbus(property)]
async fn rtctime_usec(&self) -> u64 {
// El RTC real requiere ioctl a /dev/rtc — usamos system clock como aprox.
SystemTime::now().duration_since(UNIX_EPOCH)
.map(|d| d.as_micros() as u64)
.unwrap_or(0)
}
// ----- Setters -----
async fn set_time(&self, usec_utc: i64, _relative: bool, _interactive: bool) -> fdo::Result<()> {
info!(usec_utc, "SetTime (stub: requiere CAP_SYS_TIME para aplicar)");
Ok(())
}
async fn set_timezone(&self, timezone: String, _interactive: bool) -> fdo::Result<()> {
info!(%timezone, "SetTimezone (stub: no actualizamos /etc/localtime)");
Ok(())
}
async fn set_local_rtc(&self, local_rtc: bool, _fix_system: bool, _interactive: bool) -> fdo::Result<()> {
info!(local_rtc, "SetLocalRTC (stub)");
Ok(())
}
async fn set_ntp(&self, ntp: bool, _interactive: bool) -> fdo::Result<()> {
info!(ntp, "SetNTP (stub: no controlamos timesyncd)");
Ok(())
}
async fn list_timezones(&self) -> fdo::Result<Vec<String>> {
// Listar /usr/share/zoneinfo recursivamente. Hacemos un best-effort.
let mut out = Vec::new();
if let Ok(rd) = std::fs::read_dir("/usr/share/zoneinfo") {
for entry in rd.flatten() {
if let Ok(name) = entry.file_name().into_string() {
if !name.starts_with(|c: char| c.is_lowercase()) && name != "posix" && name != "right" {
out.push(name);
}
}
}
}
Ok(out)
}
}
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([0xa1; 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_timedated_compat=info"));
tracing_subscriber::fmt().with_env_filter(filter).with_target(true).init();
}