Skip to content

Commit

Permalink
fix: socket file permission is not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 16, 2024
1 parent 7116fc3 commit 7c4ecfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nyanpasu_ipc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ pub async fn create_server(placeholder: &str, app: Router) -> Result<()> {

let listener = options.create_tokio()?;
// change the socket group
tracing::debug!("changing socket group...");
tracing::debug!("changing socket group and permissions...");
crate::utils::os::change_socket_group(placeholder)?;
crate::utils::os::change_socket_mode(placeholder)?;

tracing::debug!("mounting service...");
let mut make_service = app.route("/ws", get(ws::ws_handler)).into_make_service();
// See https://github.com/tokio-rs/axum/blob/main/examples/serve-with-hyper/src/main.rs for
Expand Down
22 changes: 22 additions & 0 deletions nyanpasu_ipc/src/utils/os.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_variables)]
use std::io::Result;

pub const NYANPASU_USER_GROUP: &str = "nyanpasu";
Expand All @@ -22,3 +23,24 @@ pub(crate) fn change_socket_group(placeholder: &str) -> Result<()> {
}
Ok(())
}

pub(crate) fn change_socket_mode(placeholder: &str) -> Result<()> {
#[cfg(not(windows))]
{
use std::{
io::{Error as IoError, ErrorKind},
process::Command,
};
let output = Command::new("chmod")
.arg("664")
.arg(format!("/var/run/{placeholder}.sock"))
.output()?;
if !output.status.success() {
return Err(IoError::new(
ErrorKind::Other,
"failed to change socket mode",
));
}
}
Ok(())
}

0 comments on commit 7c4ecfd

Please sign in to comment.