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