From 52d9e03eeb132179da473b51c0767c09f251a50e Mon Sep 17 00:00:00 2001 From: chee Date: Wed, 14 Aug 2019 02:57:57 +0100 Subject: [PATCH] Chmod the socket correctly --- Cargo.toml | 2 +- src/main.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c027360..5efde78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ edition = "2018" name = "process-manager" version = "0.1.0" [dependencies] -regex = "*" +regex = "1" diff --git a/src/main.rs b/src/main.rs index bb19989..635ab3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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}; @@ -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(()) } }