diff --git a/implementations/main.cpp b/implementations/main.cpp index 0ee566c..8e4f6bb 100644 --- a/implementations/main.cpp +++ b/implementations/main.cpp @@ -41,7 +41,7 @@ import Imsd; namespace { // ---- static config (env-overridable, same knobs as imsd.py) --------------- -constexpr const char* Version = "0.3.3"; +constexpr const char* Version = "0.3.2"; constexpr const char* BusName = "net.catcrafts.IMS1"; constexpr const char* ObjPath = "/net/catcrafts/IMS1"; constexpr const char* Iface = "net.catcrafts.IMS1"; diff --git a/implementations/media.cpp b/implementations/media.cpp index b7d5964..1dffd0a 100644 --- a/implementations/media.cpp +++ b/implementations/media.cpp @@ -410,28 +410,6 @@ std::size_t RtpPayloadOffset(std::span pkt) { return off; } -// The desktop user's uid, resolved ONCE and thread-safely. getpwnam() hands -// out one static buffer, and the mic and playout threads spawn their pw -// helpers at the same instant — the race sent both into /run/user/0, where -// no PipeWire session lives, and a call was answered into static (dev phone, -// 2026-09-08 20:01: tx_mic=0 rx_played=0 qdrop=883). Logged per call so a -// journal shows which session the helpers were aimed at. -uid_t AudioUid() { - static std::once_flag once; - static uid_t uid = 0; - std::call_once(once, [] { - std::string user = EnvOr("AUDIO_USER", "user"); - passwd pw{}; - passwd* res = nullptr; - char buf[4096]; - if (getpwnam_r(user.c_str(), &pw, buf, sizeof buf, &res) == 0 && res) uid = res->pw_uid; - else - std::println(std::cerr, "imsd-media: AUDIO_USER '{}' not found; no PipeWire session for uid 0", user); - std::println(std::cerr, "imsd-media: audio session: {} -> /run/user/{}", user, uid); - }); - return uid; -} - // Spawn pw-record/pw-play in the desktop user's PipeWire session (sudo -u // when run as root). AUDIO_USER names the session owner; the default "user" // is postmarketOS's standard account. `toChild` true = we write the child's @@ -443,8 +421,10 @@ Child SpawnPw(bool play, bool toChild, int rate) { std::vector argv; if (geteuid() == 0) { std::string user = EnvOr("AUDIO_USER", "user"); + uid_t uid = 0; + if (passwd* pw = getpwnam(user.c_str())) uid = pw->pw_uid; argv = {"sudo", "-u", user, "env", - std::format("XDG_RUNTIME_DIR=/run/user/{}", AudioUid())}; + std::format("XDG_RUNTIME_DIR=/run/user/{}", uid)}; } const char* tool = play ? "pw-play" : "pw-record"; const char* lat = play ? "40ms" : "20ms";