Misc 4 #66

Merged
oysteikt merged 7 commits from misc into main 2024-08-19 00:18:45 +02:00
2 changed files with 6 additions and 2 deletions
Showing only changes of commit cd0b2c3e6d - Show all commits

View File

@ -50,10 +50,12 @@ async fn socket_activate(config: ServerConfig) -> anyhow::Result<()> {
// TODO: allow getting socket path from other socket activation sources // TODO: allow getting socket path from other socket activation sources
let conn = get_socket_from_systemd().await?; let conn = get_socket_from_systemd().await?;
let uid = conn.peer_cred()?.uid(); let uid = conn.peer_cred()?.uid();
let unix_user = UnixUser::from_uid(uid.into())?; let unix_user = UnixUser::from_uid(uid)?;
log::info!("Accepted connection from {}", unix_user.username); log::info!("Accepted connection from {}", unix_user.username);
sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).ok();
handle_requests_for_single_session(conn, &unix_user, &config).await?; handle_requests_for_single_session(conn, &unix_user, &config).await?;
Ok(()) Ok(())

View File

@ -57,11 +57,13 @@ pub async fn listen_for_incoming_connections(
let listener = UnixListener::bind(socket_path)?; let listener = UnixListener::bind(socket_path)?;
sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).ok();
while let Ok((mut conn, _addr)) = listener.accept().await { while let Ok((mut conn, _addr)) = listener.accept().await {
let uid = conn.peer_cred()?.uid(); let uid = conn.peer_cred()?.uid();
log::trace!("Accepted connection from uid {}", uid); log::trace!("Accepted connection from uid {}", uid);
let unix_user = match UnixUser::from_uid(uid.into()) { let unix_user = match UnixUser::from_uid(uid) {
Ok(user) => user, Ok(user) => user,
Err(e) => { Err(e) => {
eprintln!("Failed to get UnixUser from uid: {}", e); eprintln!("Failed to get UnixUser from uid: {}", e);