1
0
Fork 0
forked from wry/wry
wry/src/user_session.rs
Julian Orth 9812a02f87 io: use io_uring for all io
There should no longer be any

- read
- write
- connect
- sendmsg
- recvmsg
- accept

calls in the codebase. Previously we were using a mix of io_uring and
these calls which had some negative effects: Since we were using the old
system calls, we had to set the file descriptors to non-blocking. But
our io_uring code did not handle EAGAIN. This lead to programs sometimes
being killed when the wayland IO was actually blocking.

Now all file descriptors are set to blocking, but io_uring makes it
non-blocking from our perspective. The one exception are evdev files
because they are read via libinput and libinput uses the old system
calls.
2022-12-31 17:56:58 +01:00

84 lines
2.3 KiB
Rust

use {
crate::{
dbus::{DbusError, DictEntry, BUS_DEST, BUS_PATH},
state::State,
utils::errorfmt::ErrorFmt,
wire_dbus::org,
},
std::{borrow::Cow, rc::Rc},
thiserror::Error,
};
const SYSTEMD_DEST: &str = "org.freedesktop.systemd1";
const SYSTEMD_PATH: &str = "/org/freedesktop/systemd1";
#[derive(Debug, Error)]
pub enum UserSessionError {
#[error("Could not access the user session bus")]
AcquireSessionBus(#[source] DbusError),
}
pub async fn import_environment(state: &Rc<State>, key: &str, value: &str) {
if let Err(e) = import_environment_(state, key, value).await {
log::error!(
"Could not import `{}={}` into the system environment: {}",
key,
value,
ErrorFmt(e)
);
}
}
async fn import_environment_(
state: &Rc<State>,
key: &str,
value: &str,
) -> Result<(), UserSessionError> {
let session = match state.dbus.session().await {
Ok(s) => s,
Err(e) => return Err(UserSessionError::AcquireSessionBus(e)),
};
let setting = format!("{}={}", key, value);
session.call(
BUS_DEST,
BUS_PATH,
org::freedesktop::dbus::UpdateActivationEnvironment {
environment: Cow::Borrowed(&[DictEntry {
key: key.into(),
value: value.into(),
}]),
},
{
let setting = setting.clone();
move |rep| {
if let Err(e) = rep {
log::error!(
"Could not import `{}` into the dbus environment: {}",
setting,
ErrorFmt(e)
);
}
}
},
);
session.call(
SYSTEMD_DEST,
SYSTEMD_PATH,
org::freedesktop::systemd1::manager::SetEnvironment {
names: Cow::Borrowed(&[Cow::Borrowed(&setting)]),
},
{
let setting = setting.clone();
move |rep| {
if let Err(e) = rep {
log::error!(
"Could not import `{}` into the systemd environment: {}",
setting,
ErrorFmt(e)
);
}
}
},
);
Ok(())
}