⎇ d3649bfd1a80153652c2a028315369bb4b184024
crates/core/ente-soma/src/lib.rs
History
Who touched what
raw
1//! `ente-soma` — wrapper histórico sobre [`ente_incarnate`].
2//!
3//! La rutina de namespacing fue extraída a `ente-incarnate` para que
4//! shipote, exploradores y cualquier supervisor no-PID-1 puedan reusarla.
5//! Este crate sobrevive como compat para `ente-zero` y otros que importan
6//! `ente_soma::{set_bus_sock, incarnate}`.
7//!
8//! Semántica preservada:
9//! - `BUS_SOCK_PATH` global vía `OnceLock` (init lo setea una vez).
10//! - `NOTIFY_SOCKET=/run/systemd/notify` se inyecta automáticamente.
11//! - `strict_caps = false` (errores no-fatales se loguean, encarnación sigue).
12
13use ente_card::EntityCard;
14use ente_incarnate::{Incarnator, IncarnatorConfig};
15use nix::unistd::Pid;
16use std::path::PathBuf;
17use std::sync::OnceLock;
18use tracing::warn;
19
20static INCARNATOR: OnceLock<Incarnator> = OnceLock::new();
21
22/// Establece el path del socket del bus interno. Se llama una sola vez al
23/// arrancar PID 1 (después de que el listener bind exitoso). Cada hijo
24/// encarnado recibirá este path en `ENTE_BUS_SOCK`.
25pub fn set_bus_sock(path: String) {
26 let cfg = IncarnatorConfig {
27 bus_sock: Some(PathBuf::from(path)),
28 notify_socket: Some(PathBuf::from("/run/systemd/notify")),
29 extra_env: Vec::new(),
30 strict_caps: false,
31 };
32 let _ = INCARNATOR.set(Incarnator::new(cfg));
33}
34
35/// Encarna un EntityCard. Si `set_bus_sock` no fue invocado todavía,
36/// usa un Incarnator default (sin bus, sin notify).
37pub fn incarnate(card: &EntityCard) -> anyhow::Result<Pid> {
38 let inc = INCARNATOR.get_or_init(|| Incarnator::new(IncarnatorConfig::default()));
39 let out = inc.incarnate(card)?;
40 for d in &out.degradations {
41 warn!(?d, ?out.pid, "incarnation degradation");
42 }
43 Ok(out.pid)
44}