Set socket permissions to 777 (ChatGPT Code xd)
Some checks failed
Build using Cargo / build (push) Has been cancelled
Some checks failed
Build using Cargo / build (push) Has been cancelled
This commit is contained in:
parent
be3183a62e
commit
a4047bee63
1 changed files with 61 additions and 48 deletions
15
src/main.rs
15
src/main.rs
|
@ -13,6 +13,8 @@ use std::io::ErrorKind;
|
|||
use std::net::TcpListener;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::{env, io};
|
||||
use std::fs;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
#[cfg(not(any(feature = "reqwest-native-tls", feature = "reqwest-rustls")))]
|
||||
compile_error!("feature \"reqwest-native-tls\" or \"reqwest-rustls\" must be set for proxy to have TLS support");
|
||||
|
@ -80,7 +82,18 @@ async fn main() -> std::io::Result<()> {
|
|||
server = if utils::get_env_bool("UDS") {
|
||||
let socket_path =
|
||||
env::var("BIND_UNIX").unwrap_or_else(|_| "./socket/actix.sock".to_string());
|
||||
server.bind_uds(socket_path)?
|
||||
// Create the socket directory if it doesn't exist
|
||||
if let Some(pos) = socket_path.rfind('/') {
|
||||
let dir = &socket_path[..pos];
|
||||
fs::create_dir_all(dir).expect("Failed to create socket directory");
|
||||
}
|
||||
let listener = server.bind_uds(socket_path.clone())?;
|
||||
// Set permissions to 777
|
||||
let permissions = fs::metadata(&socket_path)?.permissions();
|
||||
let mut mode = permissions.mode();
|
||||
mode |= 0o777; // Set to 777
|
||||
fs::set_permissions(&socket_path, fs::Permissions::from_mode(mode))?;
|
||||
listener
|
||||
} else {
|
||||
let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string());
|
||||
server.bind(bind)?
|
||||
|
|
Loading…
Reference in a new issue