From bd4f32b0ca97c1738b3d98010dafcdf79cf74571 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Mon, 13 Jan 2020 10:45:09 +0100 Subject: [PATCH] cargo fmt --- src/control/mod.rs | 4 ++-- src/lib.rs | 2 +- src/platform/grnam.rs | 6 +++--- src/platform/mod.rs | 6 +++--- src/services/fork_child.rs | 15 +++++++++------ src/services/services.rs | 4 +++- src/socket_activation.rs | 10 ++++------ src/sockets.rs | 2 +- src/units/activate.rs | 5 +++-- src/units/insert_new.rs | 5 ++++- src/units/loading.rs | 1 - src/units/unit_parsing/mod.rs | 6 +----- src/units/unit_parsing/service_unit.rs | 12 ++++++------ src/units/unit_parsing/unit_parser.rs | 2 +- 14 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/control/mod.rs b/src/control/mod.rs index b998ce9..4298fde 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -8,7 +8,7 @@ //! ### status Option //! * 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. @@ -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 //! diff --git a/src/lib.rs b/src/lib.rs index 6605a68..7ce932d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/platform/grnam.rs b/src/platform/grnam.rs index ac72282..c98de95 100644 --- a/src/platform/grnam.rs +++ b/src/platform/grnam.rs @@ -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 { let gid = nix::unistd::Gid::from_raw(group.gr_gid); let pw = if !group.gr_passwd.is_null() { @@ -45,7 +45,7 @@ fn getgrnam(groupname: &str) -> Result { 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 { let username_i8 = groupname.bytes().map(|x| x as i8).collect::>(); let pointer: *const i8 = username_i8.as_ptr(); @@ -92,7 +92,7 @@ pub fn getgrnam_r(groupname: &str) -> Result { } } -#[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 { compile_error!("getgrnam_r is not yet implemented for this platform"); } diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 6315860..446800e 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -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", diff --git a/src/services/fork_child.rs b/src/services/fork_child.rs index 80b15b3..121c3c9 100644 --- a/src/services/fork_child.rs +++ b/src/services/fork_child.rs @@ -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(_) => { diff --git a/src/services/services.rs b/src/services/services.rs index 3de0d47..cada561 100644 --- a/src/services/services.rs +++ b/src/services/services.rs @@ -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); diff --git a/src/socket_activation.rs b/src/socket_activation.rs index 10daca0..23ce381 100644 --- a/src/socket_activation.rs +++ b/src/socket_activation.rs @@ -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 diff --git a/src/sockets.rs b/src/sockets.rs index aac01c4..c9a9650 100644 --- a/src/sockets.rs +++ b/src/sockets.rs @@ -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(()) } diff --git a/src/units/activate.rs b/src/units/activate.rs index 719aa66..067255c 100644 --- a/src/units/activate.rs +++ b/src/units/activate.rs @@ -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, @@ -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(); diff --git a/src/units/insert_new.rs b/src/units/insert_new.rs index bd01014..5db4077 100644 --- a/src/units/insert_new.rs +++ b/src/units/insert_new.rs @@ -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) diff --git a/src/units/loading.rs b/src/units/loading.rs index e295da3..d9c0be2 100644 --- a/src/units/loading.rs +++ b/src/units/loading.rs @@ -8,7 +8,6 @@ pub enum LoadingError { Dependency(DependencyError), } - #[derive(Debug)] pub struct DependencyError { msg: String, diff --git a/src/units/unit_parsing/mod.rs b/src/units/unit_parsing/mod.rs index 0820034..4ed3bf2 100644 --- a/src/units/unit_parsing/mod.rs +++ b/src/units/unit_parsing/mod.rs @@ -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!( diff --git a/src/units/unit_parsing/service_unit.rs b/src/units/unit_parsing/service_unit.rs index 1dfad4c..421d71a 100644 --- a/src/units/unit_parsing/service_unit.rs +++ b/src/units/unit_parsing/service_unit.rs @@ -37,8 +37,8 @@ pub fn parse_service( if let Ok(uid) = user.parse::() { 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 { @@ -58,8 +58,8 @@ pub fn parse_service( if let Ok(gid) = group.parse::() { 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 { @@ -79,8 +79,8 @@ pub fn parse_service( let gid = if let Ok(gid) = group.parse::() { 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 { diff --git a/src/units/unit_parsing/unit_parser.rs b/src/units/unit_parsing/unit_parser.rs index aaa359e..f592909 100644 --- a/src/units/unit_parsing/unit_parser.rs +++ b/src/units/unit_parsing/unit_parser.rs @@ -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();