vector/sources/util/
unix.rs1use std::{fs, fs::remove_file, os::unix::fs::PermissionsExt, path::Path};
2
3use crate::internal_events::UnixSocketFileDeleteError;
4
5pub const UNNAMED_SOCKET_HOST: &str = "(unnamed)";
6
7pub fn change_socket_permissions(path: &Path, perms: Option<u32>) -> crate::Result<()> {
8 if let Some(mode) = perms {
9 match fs::set_permissions(path, fs::Permissions::from_mode(mode)) {
10 Ok(_) => debug!(message = "Socket permissions updated.", permission = mode),
11 Err(e) => {
12 if let Err(error) = remove_file(path) {
13 emit!(UnixSocketFileDeleteError { path, error });
14 }
15 return Err(Box::new(e));
16 }
17 }
18 }
19 Ok(())
20}