diff --git a/backport-fix-dropin-get-real-file-name.patch b/backport-fix-dropin-get-real-file-name.patch new file mode 100644 index 0000000..8d37595 --- /dev/null +++ b/backport-fix-dropin-get-real-file-name.patch @@ -0,0 +1,29 @@ +From 4683b40fd9a8ed9ae747b7b7add1de963cc80c4e Mon Sep 17 00:00:00 2001 +From: zhangyao +Date: Tue, 6 Sep 2022 09:21:15 +0800 +Subject: [PATCH 2/4] fix dropin: get real file name + +--- + process1/src/manager/unit/uload_util/unit_file.rs | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/process1/src/manager/unit/uload_util/unit_file.rs b/process1/src/manager/unit/uload_util/unit_file.rs +index 9fae099..928ff20 100755 +--- a/process1/src/manager/unit/uload_util/unit_file.rs ++++ b/process1/src/manager/unit/uload_util/unit_file.rs +@@ -139,7 +139,11 @@ impl UnitFileData { + for entry in dir.read_dir().unwrap() { + let dropin = entry.unwrap().path(); + if dropin.is_symlink() { +- pathbuf_dropin.push(dropin); ++ if let Ok(abs_path) = dropin.canonicalize() { ++ let mut file_name = PathBuf::new(); ++ file_name.push(abs_path.file_name().unwrap()); ++ pathbuf_dropin.push(file_name); ++ } + } + } + } +-- +2.30.2 + diff --git a/backport-fix-start-and-stop-repeatly-if-the-unit-is-already-i.patch b/backport-fix-start-and-stop-repeatly-if-the-unit-is-already-i.patch new file mode 100644 index 0000000..0a740cf --- /dev/null +++ b/backport-fix-start-and-stop-repeatly-if-the-unit-is-already-i.patch @@ -0,0 +1,276 @@ +From 8974d82867d2ebc5fef178514eae7422b8a5fa47 Mon Sep 17 00:00:00 2001 +From: l00346806 +Date: Thu, 8 Sep 2022 22:07:27 +0800 +Subject: [PATCH 4/4] fix start and stop repeatly, if the unit is already in + process, just return before do action. + +Signed-off-by: Xiaoguang Li +--- + components/service/src/service_mng.rs | 40 ++++++++++++++----- + components/service/src/service_pid.rs | 14 +++++++ + components/service/src/service_unit.rs | 6 ++- + components/socket/src/socket_mng.rs | 12 +++--- + components/socket/src/socket_unit.rs | 15 ++++++- + .../src/manager/unit/unit_entry/u_entry.rs | 10 +++++ + 6 files changed, 77 insertions(+), 20 deletions(-) + +diff --git a/components/service/src/service_mng.rs b/components/service/src/service_mng.rs +index b8ac9f2..f11c23c 100755 +--- a/components/service/src/service_mng.rs ++++ b/components/service/src/service_mng.rs +@@ -115,7 +115,7 @@ impl ServiceMng { + } + } + +- pub(super) fn start_check(&self) -> Result<(), UnitActionError> { ++ pub(super) fn start_check(&self) -> Result { + if IN_SET!( + self.state(), + ServiceState::Stop, +@@ -131,7 +131,18 @@ impl ServiceMng { + return Err(UnitActionError::UnitActionEAgain); + } + +- Ok(()) ++ // service is in starting ++ if IN_SET!( ++ self.state(), ++ ServiceState::Condition, ++ ServiceState::StartPre, ++ ServiceState::Start, ++ ServiceState::StartPost ++ ) { ++ return Ok(true); ++ } ++ ++ Ok(false) + } + + pub(super) fn start_action(&self) { +@@ -140,15 +151,16 @@ impl ServiceMng { + } + + pub(super) fn stop_check(&self) -> Result<(), UnitActionError> { +- let stop_state = vec![ ++ if IN_SET!( ++ self.state(), + ServiceState::Stop, + ServiceState::StopSigterm, + ServiceState::StopSigkill, + ServiceState::StopPost, +- ]; +- +- if stop_state.contains(&self.state()) { +- return Err(UnitActionError::UnitActionEAlready); ++ ServiceState::FinalSigterm, ++ ServiceState::FinalSigkill ++ ) { ++ return Ok(()); + } + + Ok(()) +@@ -306,7 +318,11 @@ impl ServiceMng { + if self.result() != ServiceResult::Success { + self.enter_signal(ServiceState::StopSigterm, sr); + } else if self.service_alive() { +- self.set_state(ServiceState::Runing); ++ if self.rd.notify_state() == NotifyState::Stoping { ++ self.enter_stop_by_notify(); ++ } else { ++ self.set_state(ServiceState::Runing); ++ } + } else if let Some(remain_after_exit) = + self.config.config_data().borrow().Service.RemainAfterExit + { +@@ -514,8 +530,11 @@ impl ServiceMng { + } + + fn service_alive(&self) -> bool { +- // todo!() +- true ++ if let Ok(v) = self.pid.main_alive() { ++ return v; ++ } ++ ++ self.cgroup_good() + } + + fn run_next_control(&self) { +@@ -660,7 +679,6 @@ impl ServiceMng { + msg: "main pid is not alive", + }); + } +- + if self + .comm + .um() +diff --git a/components/service/src/service_pid.rs b/components/service/src/service_pid.rs +index b976c5e..b2841ef 100755 +--- a/components/service/src/service_pid.rs ++++ b/components/service/src/service_pid.rs +@@ -1,7 +1,9 @@ + use super::service_comm::ServiceComm; + use nix::unistd::Pid; ++use process1::manager::UnitActionError; + use std::cell::RefCell; + use std::rc::Rc; ++use utils::process_util; + + pub(super) struct ServicePid { + comm: Rc, +@@ -59,6 +61,10 @@ impl ServicePid { + pub(super) fn control(&self) -> Option { + self.data.borrow().control() + } ++ ++ pub(super) fn main_alive(&self) -> Result { ++ self.data.borrow().main_alive() ++ } + } + + struct ServicePidData { +@@ -98,4 +104,12 @@ impl ServicePidData { + pub(self) fn control(&self) -> Option { + self.control.as_ref().cloned() + } ++ ++ pub(self) fn main_alive(&self) -> Result { ++ if self.main.is_none() { ++ return Err(UnitActionError::UnitActionEAgain); ++ } ++ ++ Ok(process_util::alive(self.main.unwrap())) ++ } + } +diff --git a/components/service/src/service_unit.rs b/components/service/src/service_unit.rs +index d9826f8..9ab1679 100755 +--- a/components/service/src/service_unit.rs ++++ b/components/service/src/service_unit.rs +@@ -55,7 +55,11 @@ impl UnitObj for ServiceUnit { + + fn start(&self) -> Result<(), UnitActionError> { + log::debug!("begin to start the service unit"); +- self.mng.start_check()?; ++ let started = self.mng.start_check()?; ++ if started { ++ log::debug!("service already in starting, just return immediately"); ++ return Ok(()); ++ } + + self.monitor.start_action(); + self.mng.start_action(); +diff --git a/components/socket/src/socket_mng.rs b/components/socket/src/socket_mng.rs +index 9cca6f3..596fc12 100644 +--- a/components/socket/src/socket_mng.rs ++++ b/components/socket/src/socket_mng.rs +@@ -150,7 +150,7 @@ impl SocketMng { + .map_or(None, |v| Some(v.to_string())) + } + +- pub(super) fn start_check(&self) -> Result<(), UnitActionError> { ++ pub(super) fn start_check(&self) -> Result { + if IN_SET!( + self.state(), + SocketState::StopPre, +@@ -170,7 +170,7 @@ impl SocketMng { + SocketState::StartChown, + SocketState::StartPost + ) { +- return Ok(()); ++ return Ok(true); + } + + self.unit_ref_target() +@@ -179,7 +179,7 @@ impl SocketMng { + Err(e) => Err(e), + })?; + +- Ok(()) ++ Ok(false) + } + + pub(super) fn start_action(&self) { +@@ -190,7 +190,7 @@ impl SocketMng { + self.enter_stop_pre(SocketResult::Success) + } + +- pub(super) fn stop_check(&self) -> Result<(), UnitActionError> { ++ pub(super) fn stop_check(&self) -> Result { + if IN_SET!( + self.state(), + SocketState::StopPre, +@@ -200,7 +200,7 @@ impl SocketMng { + SocketState::FinalSigterm, + SocketState::FinalSigkill + ) { +- return Ok(()); ++ return Ok(true); + } + + if IN_SET!( +@@ -213,7 +213,7 @@ impl SocketMng { + return Err(UnitActionError::UnitActionEAgain); + } + +- Ok(()) ++ Ok(false) + } + + pub(super) fn current_active_state(&self) -> UnitActiveState { +diff --git a/components/socket/src/socket_unit.rs b/components/socket/src/socket_unit.rs +index 0e25ed0..2db7154 100644 +--- a/components/socket/src/socket_unit.rs ++++ b/components/socket/src/socket_unit.rs +@@ -53,7 +53,13 @@ impl UnitObj for SocketUnit { + // the function entrance to start the unit + fn start(&self) -> Result<(), UnitActionError> { + self.ports.attach(self.mng.clone()); +- self.mng.start_check()?; ++ ++ let starting = self.mng.start_check()?; ++ if starting { ++ log::debug!("socket already in start"); ++ return Ok(()); ++ } ++ + self.mng.start_action(); + + Ok(()) +@@ -64,7 +70,12 @@ impl UnitObj for SocketUnit { + } + + fn stop(&self) -> Result<(), UnitActionError> { +- self.mng.stop_check()?; ++ let stoping = self.mng.stop_check()?; ++ if stoping { ++ log::debug!("socket already in stop, return immediretly"); ++ return Ok(()); ++ } ++ + self.mng.stop_action(); + + Ok(()) +diff --git a/process1/src/manager/unit/unit_entry/u_entry.rs b/process1/src/manager/unit/unit_entry/u_entry.rs +index 904ade1..9653dd8 100644 +--- a/process1/src/manager/unit/unit_entry/u_entry.rs ++++ b/process1/src/manager/unit/unit_entry/u_entry.rs +@@ -458,6 +458,16 @@ impl Unit { + } + + pub(super) fn stop(&self) -> Result<(), UnitActionError> { ++ let active_state = self.current_active_state(); ++ let inactive_or_failed = match active_state { ++ UnitActiveState::UnitInActive | UnitActiveState::UnitFailed => true, ++ _ => false, ++ }; ++ ++ if inactive_or_failed { ++ return Err(UnitActionError::UnitActionEAlready); ++ } ++ + self.sub.stop() + } + +-- +2.30.2 + diff --git a/backport-if-Type-item-is-not-configured-set-it-to-default-Sim.patch b/backport-if-Type-item-is-not-configured-set-it-to-default-Sim.patch new file mode 100644 index 0000000..f019b02 --- /dev/null +++ b/backport-if-Type-item-is-not-configured-set-it-to-default-Sim.patch @@ -0,0 +1,95 @@ +From c696bc4257355f2e06275900fd1e1c6d4756f9ca Mon Sep 17 00:00:00 2001 +From: Xiaoguang Li +Date: Thu, 25 Aug 2022 20:45:55 +0800 +Subject: [PATCH 3/4] if Type item is not configured, set it to default Simple + +Signed-off-by: Xiaoguang Li +--- + components/service/src/service_base.rs | 20 +++++++++++++++++++- + components/service/src/service_config.rs | 10 ++++------ + components/service/src/service_mng.rs | 6 +----- + 3 files changed, 24 insertions(+), 12 deletions(-) + +diff --git a/components/service/src/service_base.rs b/components/service/src/service_base.rs +index 529334c..8f79ca6 100755 +--- a/components/service/src/service_base.rs ++++ b/components/service/src/service_base.rs +@@ -1,4 +1,5 @@ +-use serde::{Deserialize, Serialize}; ++use process1::manager::DeserializeWith; ++use serde::{Deserialize, Deserializer, Serialize}; + + #[derive(PartialEq, EnumString, Display, Debug)] + pub(super) enum ServiceTimeoutFailureMode { +@@ -73,6 +74,23 @@ impl Default for ServiceType { + } + } + ++impl DeserializeWith for ServiceType { ++ fn deserialize_with<'de, D>(de: D) -> Result ++ where ++ D: Deserializer<'de>, ++ { ++ let s = String::deserialize(de)?; ++ ++ match s.as_ref() { ++ "simple" => Ok(ServiceType::Simple), ++ "forking" => Ok(ServiceType::Forking), ++ "oneshot" => Ok(ServiceType::Oneshot), ++ "notify" => Ok(ServiceType::Notify), ++ &_ => Ok(ServiceType::Simple), ++ } ++ } ++} ++ + #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy, Clone)] + pub(super) enum ServiceCommand { + Condition, +diff --git a/components/service/src/service_config.rs b/components/service/src/service_config.rs +index 9932fe8..0c740e6 100755 +--- a/components/service/src/service_config.rs ++++ b/components/service/src/service_config.rs +@@ -44,11 +44,7 @@ impl ServiceConfig { + } + + pub(super) fn service_type(&self) -> ServiceType { +- self.data +- .borrow() +- .Service +- .Type +- .map_or(ServiceType::Simple, |e| e) ++ self.data.borrow().Service.Type + } + + pub(super) fn set_notify_access(&self, v: NotifyAccess) { +@@ -84,7 +80,9 @@ impl ServiceConfigData { + + #[derive(Config, Default, Debug)] + pub(super) struct SectionService { +- pub Type: Option, ++ #[config(deserialize_with = ServiceType::deserialize_with)] ++ #[config(default = "simple")] ++ pub Type: ServiceType, + #[config(deserialize_with = Vec::::deserialize_with)] + pub ExecStart: Option>, + #[config(deserialize_with = Vec::::deserialize_with)] +diff --git a/components/service/src/service_mng.rs b/components/service/src/service_mng.rs +index 0a42cfa..b8ac9f2 100755 +--- a/components/service/src/service_mng.rs ++++ b/components/service/src/service_mng.rs +@@ -176,11 +176,7 @@ impl ServiceMng { + } + + pub(super) fn current_active_state(&self) -> UnitActiveState { +- if let Some(service_type) = self.config.config_data().borrow().Service.Type { +- service_state_to_unit_state(service_type, self.state()) +- } else { +- UnitActiveState::UnitFailed +- } ++ service_state_to_unit_state(self.config.service_type(), self.state()) + } + + fn enter_contion(&self) { +-- +2.30.2 + diff --git a/backport-replaced-argv0-with-the-absolute-path.patch b/backport-replaced-argv0-with-the-absolute-path.patch new file mode 100644 index 0000000..4a4be44 --- /dev/null +++ b/backport-replaced-argv0-with-the-absolute-path.patch @@ -0,0 +1,30 @@ +From cbe3cc5daf87c605548d46800fd6c719d8582f95 Mon Sep 17 00:00:00 2001 +From: Xiaoguang Li +Date: Mon, 5 Sep 2022 23:54:03 +0800 +Subject: [PATCH 1/4] replaced argv0 with the absolute path + +--- + process1/src/manager/unit/execute/exec_spawn.rs | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/process1/src/manager/unit/execute/exec_spawn.rs b/process1/src/manager/unit/execute/exec_spawn.rs +index 303e363..d41af93 100755 +--- a/process1/src/manager/unit/execute/exec_spawn.rs ++++ b/process1/src/manager/unit/execute/exec_spawn.rs +@@ -111,12 +111,8 @@ fn build_run_args( + cmdline: &ExecCommand, + env: &ExecParameters, + ) -> (std::ffi::CString, Vec) { +- // let command = cmdline.borrow(); + let cmd = std::ffi::CString::new(cmdline.path().clone()).unwrap(); +- +- let exec_name = std::path::PathBuf::from(cmdline.path()); +- let exec_name = exec_name.file_name().unwrap().to_str().unwrap(); +- let exec_name = std::ffi::CString::new::>(exec_name.bytes().collect()).unwrap(); ++ let exec_name = std::ffi::CString::new(cmdline.path().clone()).unwrap(); + + let mut args = Vec::new(); + args.push(exec_name); +-- +2.30.2 + diff --git a/process1.spec b/process1.spec index 874b552..354ed8f 100644 --- a/process1.spec +++ b/process1.spec @@ -9,13 +9,17 @@ Name: process1 Version: 0.2.1 -Release: 2 +Release: 1 Summary: redesign and reimplement process1. License: Mulan PSL v2 URL: https://gitee.com/openeuler/process1 Source0: %{name}-%{version}.tar.gz +Patch0001: backport-replaced-argv0-with-the-absolute-path.patch +Patch0002: backport-fix-dropin-get-real-file-name.patch +Patch0003: backport-if-Type-item-is-not-configured-set-it-to-default-Sim.patch +Patch0004: backport-fix-start-and-stop-repeatly-if-the-unit-is-already-i.patch ExclusiveArch: x86_64 aarch64 @@ -69,6 +73,9 @@ install -Dm0644 -t %{process1_install_target}/plugin config/plugin.conf %changelog +* Tue Sep 13 2022 licunlong - 0.2.1-1 +- sync patches from upstream + * Mon Aug 22 2022 He Xiaowen - 0.2.0-2 - strip the libraries