Skip to content

Commit

Permalink
Chmod the socket correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Aug 14, 2019
1 parent 16ea85c commit 52d9e03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -4,4 +4,4 @@ edition = "2018"
name = "process-manager"
version = "0.1.0"
[dependencies]
regex = "*"
regex = "1"
12 changes: 11 additions & 1 deletion src/main.rs
Expand Up @@ -2,7 +2,8 @@ extern crate regex;

use regex::Regex;
use std::fs;
use std::io::Read;
use std::io::prelude::*;
use std::os::unix::fs::PermissionsExt;
use std::os::unix::net::UnixListener;
use std::os::unix::prelude::*;
use std::process::{Child, Command};
Expand Down Expand Up @@ -55,12 +56,21 @@ impl Subprocess {
std::path::Path::new(&format!("{}/{}", &self.dir, file)).to_owned()
}

fn chmod(&self, file: &str) -> Result<(), std::io::Error> {
let path = self.get_file_path(file);
let mut perms = fs::metadata(&path)?.permissions();
perms.set_mode(0o775);
fs::set_permissions(&path, perms)?;
Ok(())
}

fn start(&mut self) -> Result<(), std::io::Error> {
fs::remove_file(self.get_file_path("application/sock")).unwrap_or_default();
if let Some(process) = &mut self.process {
process.kill()?;
}
self.process = Some(self.make_process()?);
self.chmod("application/sock")?;
Ok(())
}
}
Expand Down

0 comments on commit 52d9e03

Please sign in to comment.