Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Jul 24, 2024
1 parent aeb4140 commit 60d6378
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 44 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
name = "rustysd"
version = "0.1.0"
authors = ["Moritz Borcherding <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
signal-hook = "0.3"
libc = "0.2"
nix = "0.26"
nix = { version = "0.29", features = ["user", "process", "mount", "poll", "fs", "socket", "signal"] }
log = "0.4"
fern = "0.6"
chrono = "0.4"
threadpool = "1.8"
serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
toml = "0.7"
toml = "0.8"
dbus = {version = "0.9", optional = true}
shlex = "1.1"
clap = { version = "4.1", features = ["derive"] }
shlex = "1.3"
clap = { version = "4.5", features = ["derive"] }
shmemfdrs = "0.1"
which = "4.4"
which = "6"

[features]
dbus_support = ["dbus"]
Expand Down
2 changes: 1 addition & 1 deletion src/entrypoints/exec_helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{PathBuf, Path};
use std::path::{Path, PathBuf};

use crate::units::PlatformSpecificServiceFields;

Expand Down
25 changes: 13 additions & 12 deletions src/notification_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::runtime_info::*;
use crate::services::Service;
use crate::services::StdIo;
use crate::units::*;
use std::os::fd::BorrowedFd;
use std::{collections::HashMap, os::unix::io::AsRawFd};

fn collect_from_srvc<F>(run_info: ArcMutRuntimeInfo, f: F) -> HashMap<i32, UnitId>
Expand Down Expand Up @@ -41,24 +42,24 @@ pub fn handle_all_streams(run_info: ArcMutRuntimeInfo) {

let mut fdset = nix::sys::select::FdSet::new();
for fd in fd_to_srvc_id.keys() {
fdset.insert(*fd);
fdset.insert(unsafe { BorrowedFd::borrow_raw(*fd) });
}
fdset.insert(eventfd.read_end());
fdset.insert(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) });

let result = nix::sys::select::select(None, Some(&mut fdset), None, None, None);

let run_info_locked = run_info.read().unwrap();
let unit_table = &run_info_locked.unit_table;
match result {
Ok(_) => {
if fdset.contains(eventfd.read_end()) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) }) {
trace!("Interrupted notification select because the eventfd fired");
reset_event_fd(eventfd);
trace!("Reset eventfd value");
}
let mut buf = [0u8; 512];
for (fd, id) in &fd_to_srvc_id {
if fdset.contains(*fd) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(*fd) }) {
if let Some(srvc_unit) = unit_table.get(id) {
if let Specific::Service(srvc) = &srvc_unit.specific {
let mut_state = &mut *srvc.state.write().unwrap();
Expand Down Expand Up @@ -122,24 +123,24 @@ pub fn handle_all_std_out(run_info: ArcMutRuntimeInfo) {

let mut fdset = nix::sys::select::FdSet::new();
for fd in fd_to_srvc_id.keys() {
fdset.insert(*fd);
fdset.insert(unsafe { BorrowedFd::borrow_raw(*fd) });
}
fdset.insert(eventfd.read_end());
fdset.insert(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) });

let result = nix::sys::select::select(None, Some(&mut fdset), None, None, None);

let run_info_locked = run_info.read().unwrap();
let unit_table = &run_info_locked.unit_table;
match result {
Ok(_) => {
if fdset.contains(eventfd.read_end()) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) }) {
trace!("Interrupted stdout select because the eventfd fired");
reset_event_fd(eventfd);
trace!("Reset eventfd value");
}
let mut buf = [0u8; 512];
for (fd, id) in &fd_to_srvc_id {
if fdset.contains(*fd) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(*fd) }) {
if let Some(srvc_unit) = unit_table.get(id) {
let name = srvc_unit.id.name.clone();
if let Specific::Service(srvc) = &srvc_unit.specific {
Expand Down Expand Up @@ -191,24 +192,24 @@ pub fn handle_all_std_err(run_info: ArcMutRuntimeInfo) {

let mut fdset = nix::sys::select::FdSet::new();
for fd in fd_to_srvc_id.keys() {
fdset.insert(*fd);
fdset.insert(unsafe { BorrowedFd::borrow_raw(*fd) });
}
fdset.insert(eventfd.read_end());
fdset.insert(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) });

let result = nix::sys::select::select(None, Some(&mut fdset), None, None, None);
let run_info_locked = run_info.read().unwrap();
let unit_table = &run_info_locked.unit_table;

match result {
Ok(_) => {
if fdset.contains(eventfd.read_end()) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) }) {
trace!("Interrupted stderr select because the eventfd fired");
reset_event_fd(eventfd);
trace!("Reset eventfd value");
}
let mut buf = [0u8; 512];
for (fd, id) in &fd_to_srvc_id {
if fdset.contains(*fd) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(*fd) }) {
if let Some(srvc_unit) = unit_table.get(id) {
let name = srvc_unit.id.name.clone();
if let Specific::Service(srvc) = &srvc_unit.specific {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use pipe_eventfd::*;

#[cfg(not(feature = "linux_eventfd"))]
mod pipe_eventfd {
use std::os::fd::IntoRawFd;
use std::os::unix::io::RawFd;

use log::{error, trace};
Expand All @@ -28,7 +29,7 @@ mod pipe_eventfd {

pub fn make_event_fd() -> Result<EventFd, String> {
let (r, w) = nix::unistd::pipe().map_err(|e| format!("Error creating pipe, {}", e))?;
Ok(EventFd(r, w))
Ok(EventFd(r.into_raw_fd(), w.into_raw_fd()))
}

pub fn notify_event_fd(eventfd: EventFd) {
Expand Down
8 changes: 7 additions & 1 deletion src/platform/unix_common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use nix::sys::socket::Backlog;
use std::os::fd::BorrowedFd;
use std::os::unix::io::RawFd;

pub fn make_seqpacket_socket(path: &std::path::PathBuf) -> Result<RawFd, String> {
Expand All @@ -18,7 +20,11 @@ pub fn make_seqpacket_socket(path: &std::path::PathBuf) -> Result<RawFd, String>
// then bind the socket to the path
nix::sys::socket::bind(fd, &unix_addr).unwrap();
// then make the socket an accepting one
nix::sys::socket::listen(fd, 128).unwrap();
nix::sys::socket::listen(
&unsafe { BorrowedFd::borrow_raw(fd) },
Backlog::new(128).unwrap(),
)
.unwrap();

Ok(fd)
}
3 changes: 2 additions & 1 deletion src/services/prepare_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::StdIo;
use crate::services::Service;
use crate::units::ServiceConfig;
use crate::units::StdIoOption;
use std::os::fd::IntoRawFd;
use std::os::unix::io::AsRawFd;
use std::os::unix::net::UnixDatagram;

Expand All @@ -27,7 +28,7 @@ fn open_stdio(setting: &Option<StdIoOption>) -> Result<StdIo, String> {
}
None => {
let (r, w) = nix::unistd::pipe().unwrap();
Ok(super::StdIo::Piped(r, w))
Ok(super::StdIo::Piped(r.into_raw_fd(), w.into_raw_fd()))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/service_exit_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn service_exit_handler(
name
);
loop {
let res = crate::units::deactivate_unit_recursive(&srvc_id, run_info.clone());
let res = crate::units::deactivate_unit_recursive(&srvc_id, run_info);
let retry = if let Err(e) = &res {
if let UnitOperationErrorReason::DependencyError(_) = e.reason {
// Only retry if this is the case. This only occurs if, while the units are being deactivated,
Expand Down
24 changes: 12 additions & 12 deletions src/services/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl Service {
&run_info.config.notification_sockets_dir,
)
.map_err(|e| ServiceErrorReason::PreparingFailed(e))?;
self.run_prestart(conf, id.clone(), name, run_info.clone())
self.run_prestart(conf, id.clone(), name, run_info)
.map_err(|prestart_err| {
match self.run_poststop(conf, id.clone(), name, run_info.clone()) {
match self.run_poststop(conf, id.clone(), name, run_info) {
Ok(_) => ServiceErrorReason::PrestartFailed(prestart_err),
Err(poststop_err) => ServiceErrorReason::PrestartAndPoststopFailed(
prestart_err,
Expand All @@ -203,7 +203,7 @@ impl Service {
&run_info.config.self_path,
self,
conf,
name.clone(),
name,
&*run_info.fd_store.read().unwrap(),
)
.map_err(|e| ServiceErrorReason::StartFailed(e))?;
Expand All @@ -213,16 +213,16 @@ impl Service {
}

super::fork_parent::wait_for_service(self, conf, name, run_info).map_err(
|start_err| match self.run_poststop(conf, id.clone(), name, run_info.clone()) {
|start_err| match self.run_poststop(conf, id.clone(), name, run_info) {
Ok(_) => ServiceErrorReason::StartFailed(start_err),
Err(poststop_err) => {
ServiceErrorReason::StartAndPoststopFailed(start_err, poststop_err)
}
},
)?;
self.run_poststart(conf, id.clone(), name, run_info.clone())
self.run_poststart(conf, id.clone(), name, run_info)
.map_err(|poststart_err| {
match self.run_poststop(conf, id.clone(), name, run_info.clone()) {
match self.run_poststop(conf, id.clone(), name, run_info) {
Ok(_) => ServiceErrorReason::PrestartFailed(poststart_err),
Err(poststop_err) => ServiceErrorReason::PoststartAndPoststopFailed(
poststart_err,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Service {
name: &str,
run_info: &RuntimeInfo,
) -> Result<(), RunCmdError> {
self.run_stop_cmd(conf, id, name, run_info.clone())
self.run_stop_cmd(conf, id, name, run_info)
}
pub fn kill(
&mut self,
Expand Down Expand Up @@ -469,7 +469,7 @@ impl Service {
run_info: &RuntimeInfo,
) -> Result<(), RunCmdError> {
for cmd in cmds {
self.run_cmd(cmd, id.clone(), name, timeout, run_info.clone())?;
self.run_cmd(cmd, id.clone(), name, timeout, run_info)?;
}
Ok(())
}
Expand All @@ -486,7 +486,7 @@ impl Service {
}
let timeout = self.get_stop_timeout(conf);
let cmds = conf.stop.clone();
self.run_all_cmds(&cmds, id, name, timeout, run_info.clone())
self.run_all_cmds(&cmds, id, name, timeout, run_info)
}
fn run_prestart(
&mut self,
Expand All @@ -500,7 +500,7 @@ impl Service {
}
let timeout = self.get_start_timeout(conf);
let cmds = conf.startpre.clone();
self.run_all_cmds(&cmds, id, name, timeout, run_info.clone())
self.run_all_cmds(&cmds, id, name, timeout, run_info)
}
fn run_poststart(
&mut self,
Expand All @@ -514,7 +514,7 @@ impl Service {
}
let timeout = self.get_start_timeout(conf);
let cmds = conf.startpost.clone();
self.run_all_cmds(&cmds, id, name, timeout, run_info.clone())
self.run_all_cmds(&cmds, id, name, timeout, run_info)
}
fn run_poststop(
&mut self,
Expand All @@ -526,7 +526,7 @@ impl Service {
trace!("Run poststop for {}", name);
let timeout = self.get_stop_timeout(conf);
let cmds = conf.stoppost.clone();
let res = self.run_all_cmds(&cmds, id, name, timeout, run_info.clone());
let res = self.run_all_cmds(&cmds, id, name, timeout, run_info);

if conf.srcv_type != ServiceType::OneShot {
// already happened when the oneshot process exited in the exit handler
Expand Down
6 changes: 5 additions & 1 deletion src/services/start_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ fn start_service_with_filedescriptors(
let name_arg = std::ffi::CString::new("exec_helper").unwrap();
let self_args = [name_arg.as_ptr(), std::ptr::null()];

trace!("Start main executable for service: {name}: {:?} {:?}", exec_helper_conf.cmd, exec_helper_conf.args);
trace!(
"Start main executable for service: {name}: {:?} {:?}",
exec_helper_conf.cmd,
exec_helper_conf.args
);
match unsafe { nix::unistd::fork() } {
Ok(nix::unistd::ForkResult::Parent { child, .. }) => {
// make sure the file exists until after we fork before closing it
Expand Down
10 changes: 6 additions & 4 deletions src/socket_activation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Wait for sockets to activate their respective services

use log::error;
use log::trace;
use std::os::fd::BorrowedFd;

use crate::runtime_info::*;
use crate::units::*;
Expand Down Expand Up @@ -106,11 +108,11 @@ pub fn wait_for_socket(run_info: ArcMutRuntimeInfo) -> Result<Vec<UnitId>, Strin
if let Specific::Socket(specific) = &unit.specific {
let mut_state = &*specific.state.read().unwrap();
if !mut_state.sock.activated {
fdset.insert(*fd);
fdset.insert(unsafe { BorrowedFd::borrow_raw(*fd) });
}
}
}
fdset.insert(eventfd.read_end());
fdset.insert(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) });
}
(fdset, fd_to_sock_id)
};
Expand All @@ -119,13 +121,13 @@ pub fn wait_for_socket(run_info: ArcMutRuntimeInfo) -> Result<Vec<UnitId>, Strin
match result {
Ok(_) => {
let mut activated_ids = Vec::new();
if fdset.contains(eventfd.read_end()) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(eventfd.read_end()) }) {
trace!("Interrupted socketactivation select because the eventfd fired");
crate::platform::reset_event_fd(eventfd);
trace!("Reset eventfd value");
} else {
for (fd, id) in &fd_to_sock_id {
if fdset.contains(*fd) {
if fdset.contains(unsafe { BorrowedFd::borrow_raw(*fd) }) {
activated_ids.push(id.clone());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/units/unitset_manipulation/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn activate_unit(

let next_services_ids = unit.common.dependencies.before.clone();

unit.activate(run_info.clone(), source)
unit.activate(run_info, source)
.map(|_| StartResult::Started(next_services_ids))
}

Expand Down
6 changes: 3 additions & 3 deletions src/units/unitset_manipulation/deactivate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn deactivate_unit_recursive(

deactivate_units_recursive(&unit.common.dependencies.required_by, run_info)?;

deactivate_unit(id_to_kill, run_info.clone())
deactivate_unit(id_to_kill, run_info)
}

pub fn deactivate_unit(
Expand All @@ -45,7 +45,7 @@ pub fn deactivate_unit(
});
}
};
unit.deactivate(run_info.clone())?;
unit.deactivate(run_info)?;

Ok(())
}
Expand All @@ -65,7 +65,7 @@ pub fn deactivate_units(
run_info: &RuntimeInfo,
) -> Result<(), UnitOperationError> {
for id in ids_to_kill {
deactivate_unit(id, run_info.clone())?;
deactivate_unit(id, run_info)?;
}
Ok(())
}
Expand Down

0 comments on commit 60d6378

Please sign in to comment.