Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Jan 13, 2020
1 parent 34817cd commit bd4f32b
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! ### status Option<name>
//! * If the param is a string show status of the unit with that name (might get the same filtering as list-units in the future).
//! * If no param is given, show status of all units
//!
//!
//! ### restart name
//! Restart unit with that name. If it was running first kill it. If it is already stopped start it.

Expand All @@ -17,7 +17,7 @@

//! ### enable name
//! Load new file with that name. Useful if you moved/copied a file in the unit-dirs and want to start it without restarting rustysd as a whole
//!
//!
//! ### shutdown
//! Shutdown rustysd by killing all services, closing all sockets and exiting
//!
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub mod notification_handler;
pub mod platform;
pub mod services;
pub mod signal_handler;
pub mod socket_activation;
pub mod sockets;
pub mod units;
pub mod socket_activation;

#[macro_use]
extern crate log;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/grnam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct GroupEntry {
pub gid: nix::unistd::Gid,
}

#[cfg(any(target_os = "linux", target_os="freebsd"))]
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
fn make_group_from_libc(groupname: &str, group: &libc::group) -> Result<GroupEntry, String> {
let gid = nix::unistd::Gid::from_raw(group.gr_gid);
let pw = if !group.gr_passwd.is_null() {
Expand Down Expand Up @@ -45,7 +45,7 @@ fn getgrnam(groupname: &str) -> Result<GroupEntry, String> {
make_group_from_libc(groupname, &res)
}

#[cfg(any(target_os = "linux", target_os="freebsd"))]
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub fn getgrnam_r(groupname: &str) -> Result<GroupEntry, String> {
let username_i8 = groupname.bytes().map(|x| x as i8).collect::<Vec<_>>();
let pointer: *const i8 = username_i8.as_ptr();
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn getgrnam_r(groupname: &str) -> Result<GroupEntry, String> {
}
}

#[cfg(not(any(target_os = "linux", target_os="freebsd")))]
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
pub fn getgrnam_r(_groupname: &str) -> Result<GroupEntry, String> {
compile_error!("getgrnam_r is not yet implemented for this platform");
}
6 changes: 3 additions & 3 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
//! We'd also need to make some more functionality optional like subprocess reaping (which only matters if we are not PID1)
//!

mod drop_privileges;
mod eventfd;
mod subreaper;
mod unix_common;
mod drop_privileges;

pub use drop_privileges::*;
pub use eventfd::*;
pub use subreaper::*;
pub use drop_privileges::*;
pub mod pwnam;
pub mod grnam;
pub mod pwnam;

#[cfg(any(
target_os = "freebsd",
Expand Down
15 changes: 9 additions & 6 deletions src/services/fork_child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,23 @@ pub fn after_fork_child(
eprintln!("[FORK_CHILD {}] error while duping fds: {}", name, e);
std::process::exit(1);
}

setup_env_vars(names, notify_socket_env_var);
let (cmd, args) = prepare_exec_args(srvc);

if nix::unistd::getuid().is_root() {
match crate::platform::drop_privileges(srvc.gid, &srvc.supp_gids, srvc.uid) {
Ok(()) => {/* Happy */},
Err(e) => {
eprintln!("[FORK_CHILD {}] could not drop privileges because: {}", name, e);
Ok(()) => { /* Happy */ }
Err(e) => {
eprintln!(
"[FORK_CHILD {}] could not drop privileges because: {}",
name, e
);
std::process::exit(1);
}
}
}

eprintln!("EXECV: {:?} {:?}", &cmd, &args);
match nix::unistd::execv(&cmd, &args) {
Ok(_) => {
Expand Down
4 changes: 3 additions & 1 deletion src/services/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl Service {
return Err(ServiceErrorReason::AlreadyHasPID(pgid));
}
if self.service_config.accept {
return Err(ServiceErrorReason::Generic("Inetd style activation is not supported".into()));
return Err(ServiceErrorReason::Generic(
"Inetd style activation is not supported".into(),
));
}
if !allow_ignore || self.socket_names.is_empty() {
trace!("Start service {}", name);
Expand Down
10 changes: 4 additions & 6 deletions src/socket_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ pub fn start_socketactivation_thread(
}

if let Some(srvc_unit_id) = srvc_unit_id {
if let Some(status) = run_info
.status_table
.read()
.unwrap()
.get(&srvc_unit_id)
if let Some(status) =
run_info.status_table.read().unwrap().get(&srvc_unit_id)
{
let srvc_status = {
let status_locked = status.lock().unwrap();
status_locked.clone()
};

if srvc_status != crate::units::UnitStatus::StartedWaitingForSocket {
if srvc_status != crate::units::UnitStatus::StartedWaitingForSocket
{
trace!(
"Ignore socket activation. Service has status: {:?}",
srvc_status
Expand Down
2 changes: 1 addition & 1 deletion src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl UnixSocketConfig {
std::fs::remove_file(&path)
.map_err(|e| format!("Error removing file {:?}: {}", path, e))?;
}

close_raw_fd(rawfd);
Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions src/units/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use super::units::*;
use crate::platform::EventFd;
use crate::services::ServiceErrorReason;
use std::sync::{Arc, Mutex};
use threadpool::ThreadPool;
use crate::services::ServiceErrorReason;

pub struct UnitOperationError {
pub reason: UnitOperationErrorReason,
Expand Down Expand Up @@ -233,7 +233,8 @@ pub fn activate_unit(
let mut status_locked = status.lock().unwrap();
*status_locked = new_status;
StartResult::Started(next_services_ids)
}).map_err(|e| {
})
.map_err(|e| {
// Update the status while we still lock the unit
let status_table_locked = run_info.status_table.read().unwrap();
let status = status_table_locked.get(&unit_locked.id).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src/units/insert_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pub fn load_new_unit(
let content = fs::read_to_string(&unit_path).map_err(|e| {
format!(
"{}",
units::ParsingError::new(units::ParsingErrorReason::from(Box::new(e)), unit_path.clone())
units::ParsingError::new(
units::ParsingErrorReason::from(Box::new(e)),
unit_path.clone()
)
)
})?;
let parsed = units::parse_file(&content)
Expand Down
1 change: 0 additions & 1 deletion src/units/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub enum LoadingError {
Dependency(DependencyError),
}


#[derive(Debug)]
pub struct DependencyError {
msg: String,
Expand Down
6 changes: 1 addition & 5 deletions src/units/unit_parsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ impl std::fmt::Display for ParsingError {
)?;
}
ParsingErrorReason::UnknownSection(name) => {
write!(
f,
"In file {:?}: Section {} is unknown",
self.path, name
)?;
write!(f, "In file {:?}: Section {} is unknown", self.path, name)?;
}
ParsingErrorReason::SectionTooOften(name) => {
write!(
Expand Down
12 changes: 6 additions & 6 deletions src/units/unit_parsing/service_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn parse_service(
if let Ok(uid) = user.parse::<u32>() {
Some(nix::unistd::Uid::from_raw(uid))
} else {
if let Ok(pwentry) =
crate::platform::pwnam::getpwnam_r(&user).map_err(|e| ParsingErrorReason::Generic(e))
if let Ok(pwentry) = crate::platform::pwnam::getpwnam_r(&user)
.map_err(|e| ParsingErrorReason::Generic(e))
{
Some(pwentry.uid)
} else {
Expand All @@ -58,8 +58,8 @@ pub fn parse_service(
if let Ok(gid) = group.parse::<u32>() {
Some(nix::unistd::Gid::from_raw(gid))
} else {
if let Ok(groupentry) =
crate::platform::grnam::getgrnam_r(&group).map_err(|e| ParsingErrorReason::Generic(e))
if let Ok(groupentry) = crate::platform::grnam::getgrnam_r(&group)
.map_err(|e| ParsingErrorReason::Generic(e))
{
Some(groupentry.gid)
} else {
Expand All @@ -79,8 +79,8 @@ pub fn parse_service(
let gid = if let Ok(gid) = group.parse::<u32>() {
nix::unistd::Gid::from_raw(gid)
} else {
if let Ok(groupentry) =
crate::platform::grnam::getgrnam_r(&group).map_err(|e| ParsingErrorReason::Generic(e))
if let Ok(groupentry) = crate::platform::grnam::getgrnam_r(&group)
.map_err(|e| ParsingErrorReason::Generic(e))
{
groupentry.gid
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/units/unit_parsing/unit_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn string_to_bool(s: &str) -> bool {
if s.len() == 0 {
return false;
}

let s_upper = &s.to_uppercase();
let c: char = s_upper.chars().nth(0).unwrap();

Expand Down

0 comments on commit bd4f32b

Please sign in to comment.