diff --git a/backport-fix-Fixed-parsing-single-quotes-error.patch b/backport-fix-Fixed-parsing-single-quotes-error.patch new file mode 100644 index 0000000..6381003 --- /dev/null +++ b/backport-fix-Fixed-parsing-single-quotes-error.patch @@ -0,0 +1,78 @@ +From e052fac4f325236f88ef225ed3c3cc96a02fbfa8 Mon Sep 17 00:00:00 2001 +From: zhangyao2022 +Date: Mon, 14 Aug 2023 18:33:47 +0800 +Subject: [PATCH] fix: Fixed parsing single quotes error + +--- + core/libcore/src/exec/cmd.rs | 40 ++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +diff --git a/core/libcore/src/exec/cmd.rs b/core/libcore/src/exec/cmd.rs +index 8f9c62f9..60427397 100755 +--- a/core/libcore/src/exec/cmd.rs ++++ b/core/libcore/src/exec/cmd.rs +@@ -173,8 +173,24 @@ fn parse_exec(s: &str) -> Result> { + let mut argv: Vec = Vec::new(); + let mut cur = String::new(); + let mut found_semicolon_wait_space = false; ++ let mut found_single_quote = false; + for c in content.chars() { + argv_start += 1; ++ ++ if found_single_quote && c != '\'' { ++ cur += &c.to_string(); ++ continue; ++ } ++ if c == '\'' { ++ if found_single_quote { ++ argv.push(cur); ++ cur = "".to_string(); ++ found_single_quote = false; ++ continue; ++ } ++ found_single_quote = true; ++ continue; ++ } + if c == ' ' { + /* now we find " ; ", break the loop */ + if found_semicolon_wait_space { +@@ -205,6 +221,12 @@ fn parse_exec(s: &str) -> Result> { + found_semicolon_wait_space = false; + cur += &c.to_string(); + } ++ ++ if found_single_quote { ++ return Err(Error::Invalid { ++ what: "no valid exec command, wrong single quote".to_string(), ++ }); ++ } + /* No more characters after " ;", drop current argv */ + if found_semicolon_wait_space { + cur = String::new(); +@@ -395,5 +417,23 @@ mod tests { + assert!(parse_exec(&path).is_err()); + + assert!(parse_exec("/bin/echo good ; ; ; ;").is_err()); ++ assert!(parse_exec("/bin/echo 'good1 good2").is_err()); ++ assert!(parse_exec("/bin/echo 'good good1' 'good2").is_err()); ++ assert_eq!( ++ parse_exec("/bin/echo 'good good1' good2").unwrap(), ++ VecDeque::from([ExecCommand { ++ path: "/bin/echo".to_string(), ++ argv: vec!["good good1".to_string(), "good2".to_string()], ++ flags: ExecFlag::EXEC_COMMAND_EMPTY ++ }]) ++ ); ++ assert_eq!( ++ parse_exec("/bin/echo 'good good1' 'good2'").unwrap(), ++ VecDeque::from([ExecCommand { ++ path: "/bin/echo".to_string(), ++ argv: vec!["good good1".to_string(), "good2".to_string()], ++ flags: ExecFlag::EXEC_COMMAND_EMPTY ++ }]) ++ ); + } + } +-- +2.30.2 + diff --git a/backport-fix-make-control-command-accept.patch b/backport-fix-make-control-command-accept.patch new file mode 100644 index 0000000..53c953e --- /dev/null +++ b/backport-fix-make-control-command-accept.patch @@ -0,0 +1,104 @@ +From 948493051d5ebe07267973ab863ebfd8d9f7c94c Mon Sep 17 00:00:00 2001 +From: licunlong +Date: Tue, 22 Aug 2023 11:51:00 +0800 +Subject: [PATCH] fix: make control command accept - + +--- + core/coms/service/src/mng.rs | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) + +diff --git a/core/coms/service/src/mng.rs b/core/coms/service/src/mng.rs +index f9051f6..b91806d 100755 +--- a/core/coms/service/src/mng.rs ++++ b/core/coms/service/src/mng.rs +@@ -64,6 +64,7 @@ pub(super) struct ServiceMng { + rd: Rc, + monitor: RefCell, + current_main_command: RefCell, ++ current_control_command: RefCell, + } + + impl ReStation for ServiceMng { +@@ -164,6 +165,7 @@ impl ServiceMng { + rd: rd.clone(), + monitor: RefCell::new(ServiceMonitor::new()), + current_main_command: RefCell::new(ExecCommand::empty()), ++ current_control_command: RefCell::new(ExecCommand::empty()), + } + } + +@@ -291,6 +293,7 @@ impl ServiceMng { + self.control_command_fill(ServiceCommand::Condition); + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service( + &cmd, + self.config.config_data().borrow().Service.TimeoutStartSec, +@@ -316,6 +319,7 @@ impl ServiceMng { + self.control_command_fill(ServiceCommand::StartPre); + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service( + &cmd, + self.config.config_data().borrow().Service.TimeoutStartSec, +@@ -423,6 +427,7 @@ impl ServiceMng { + self.control_command_fill(ServiceCommand::StartPost); + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service( + &cmd, + self.config.config_data().borrow().Service.TimeoutStartSec, +@@ -484,6 +489,7 @@ impl ServiceMng { + self.control_command_fill(ServiceCommand::Stop); + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service(&cmd, 0, ExecFlags::CONTROL) { + Ok(pid) => self.pid.set_control(pid), + Err(_e) => { +@@ -532,6 +538,7 @@ impl ServiceMng { + self.control_command_fill(ServiceCommand::StopPost); + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service(&cmd, 0, ExecFlags::CONTROL) { + Ok(pid) => self.pid.set_control(pid), + Err(_e) => { +@@ -636,6 +643,7 @@ impl ServiceMng { + + match self.control_command_pop() { + Some(cmd) => { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service( + &cmd, + self.config.config_data().borrow().Service.TimeoutStartSec, +@@ -895,6 +903,7 @@ impl ServiceMng { + }; + + if let Some(cmd) = self.control_command_pop() { ++ *self.current_control_command.borrow_mut() = cmd.clone(); + match self.spawn.start_service(&cmd, time_out, ExecFlags::CONTROL) { + Ok(pid) => self.pid.set_control(pid), + Err(_e) => { +@@ -1490,6 +1499,15 @@ impl ServiceMng { + } else if self.pid.control() == Some(pid) { + self.pid.reset_control(); + ++ if self ++ .current_control_command ++ .borrow() ++ .get_exec_flag() ++ .contains(ExecFlag::EXEC_COMMAND_IGNORE_FAILURE) ++ { ++ res = ServiceResult::Success; ++ } ++ + if !self.control_command.borrow().is_empty() && res == ServiceResult::Success { + self.run_next_control(); + return; +-- +2.33.0 + diff --git a/backport-fix-return-the-correct-error-when-condition-assert-f.patch b/backport-fix-return-the-correct-error-when-condition-assert-f.patch new file mode 100644 index 0000000..c06fe8d --- /dev/null +++ b/backport-fix-return-the-correct-error-when-condition-assert-f.patch @@ -0,0 +1,33 @@ +From 17ba56f34249a0256009b139ad45c4259e95bae0 Mon Sep 17 00:00:00 2001 +From: licunlong +Date: Fri, 1 Sep 2023 14:54:42 +0800 +Subject: [PATCH] fix: return the correct error when condition/assert failed + +--- + core/sysmaster/src/unit/entry/uentry.rs | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/core/sysmaster/src/unit/entry/uentry.rs b/core/sysmaster/src/unit/entry/uentry.rs +index f44979ec..5f9938e2 100755 +--- a/core/sysmaster/src/unit/entry/uentry.rs ++++ b/core/sysmaster/src/unit/entry/uentry.rs +@@ -659,12 +659,12 @@ impl Unit { + return Err(Error::UnitActionEInval); + } + if active_state != UnitActiveState::UnitActivating && !self.conditions().conditions_test() { +- log::error!("Starting failed the unit condition test failed"); +- return Err(Error::UnitActionEInval); ++ log::info!("The condition check failed, not starting {}.", self.id()); ++ return Err(Error::UnitActionEComm); + } + if active_state != UnitActiveState::UnitActivating && !self.conditions().asserts_test() { +- log::error!("Starting failed the unit assert test failed"); +- return Err(Error::UnitActionEInval); ++ log::info!("The assert check failed, not starting {}.", self.id()); ++ return Err(Error::UnitActionEProto); + } + + self.sub.start() +-- +2.30.2 + diff --git a/backport-typo-optimizing-print-statements.patch b/backport-typo-optimizing-print-statements.patch new file mode 100644 index 0000000..af9ac1e --- /dev/null +++ b/backport-typo-optimizing-print-statements.patch @@ -0,0 +1,144 @@ +From 23e254fb250b7a6e5f777ae10ce6cd50f9fb1e35 Mon Sep 17 00:00:00 2001 +From: overweight +Date: Tue, 22 Aug 2023 09:48:05 +0800 +Subject: [PATCH] typo: optimizing print statements + +--- + init/src/main.rs | 43 +++++++++++++++++++++++++++---------------- + 1 file changed, 27 insertions(+), 16 deletions(-) + +diff --git a/init/src/main.rs b/init/src/main.rs +index f94b8dad..98290085 100644 +--- a/init/src/main.rs ++++ b/init/src/main.rs +@@ -11,6 +11,8 @@ + // See the Mulan PSL v2 for more details. + + //! The init daemon ++use core::panic; ++use kernlog::KernelLog; + use mio::unix::SourceFd; + use mio::Events; + use mio::Interest; +@@ -86,15 +88,21 @@ impl InitConfig { + + pub fn load(path: Option) -> std::io::Result { + let mut config = Self::default(); +- let default_config_file = INIT_CONFIG.to_string(); +- let path = path.unwrap_or(default_config_file); ++ let path = path.unwrap_or_else(|| INIT_CONFIG.to_string()); + let file = Path::new(&path); + if file.exists() { + let mut content = String::new(); + let file = File::open(file); + match file.map(|mut f| f.read_to_string(&mut content)) { + Ok(_) => (), +- Err(_) => return Ok(config), ++ Err(e) => { ++ log::info!( ++ "failed to read config file {}: {}, use default value", ++ path, ++ e ++ ); ++ return Ok(config); ++ } + }; + + for (_, line) in content.lines().enumerate() { +@@ -138,7 +146,7 @@ impl InitConfig { + } + } + } +- log::debug!("{:?}", config); ++ log::debug!("loaded configuration: {:?}", config); + } + + Ok(config) +@@ -196,7 +204,7 @@ impl Runtime { + Err(e) => panic!("Invalid value: {:?}", e), + }; + } else { +- panic!("Missing value for option --deserialize."); ++ panic!("Missing value for option --pid."); + } + } + _ => { +@@ -361,7 +369,6 @@ impl Runtime { + let (pid, _, _) = match si { + Some((pid, code, sig)) => (pid, code, sig), + None => { +- log::debug!("ignored child signal: {:?}!", wait_status); + return; + } + }; +@@ -374,8 +381,6 @@ impl Runtime { + // pop: recycle the zombie + if let Err(e) = waitid(Id::Pid(pid), WaitPidFlag::WEXITED) { + log::error!("error when reap the zombie({:?}), ignored: {:?}!", pid, e); +- } else { +- log::debug!("reap the zombie: {:?}.", pid); + } + } + } +@@ -456,7 +461,6 @@ impl Runtime { + // do not refresh the status. + self.online = true; + self.pid = pid; +- log::debug!("keepalive: receive a heartbeat from pid({})!", pid); + } + Ok(()) + } +@@ -623,13 +627,14 @@ impl Drop for Runtime { + fn prepare_init() { + // version + let version = env!("CARGO_PKG_VERSION"); +- log::info!("sysMaster init version: {}", version); + let args: Vec = std::env::args().collect(); + if args.contains(&String::from("--version")) || args.contains(&String::from("-V")) { +- println!("sysMaster init version: {}!", version); ++ println!("sysMaster-init version: {}!", version); + std::process::exit(0); + } + ++ log::info!("sysMaster-init version: {}", version); ++ + // common umask + let mode = Mode::from_bits_truncate(0o77); + umask(umask(mode) | Mode::from_bits_truncate(0o22)); +@@ -668,7 +673,7 @@ fn reset_all_signal_handlers() { + } + + extern "C" fn crash_handler(_signal: i32) { +- log::error!("crash_handler"); ++ panic!("crash_handler"); + } + + fn install_crash_handler() { +@@ -694,14 +699,20 @@ fn install_crash_handler() { + + fn shutdown_init() { + nix::unistd::sync(); +- log::info!("shutdowning init"); ++ log::info!("shutdowning..."); + } + +-fn main() -> std::io::Result<()> { +- match kernlog::init() { +- Ok(_) => (), ++fn set_logger(loglevel: log::LevelFilter) { ++ let klog = match KernelLog::with_level(loglevel) { ++ Ok(v) => v, + Err(e) => panic!("Unsupported when cannot log into /dev/kmsg : {:?}!", e), + }; ++ log::set_boxed_logger(Box::new(klog)).expect("Failed to set logger!"); ++ log::set_max_level(loglevel); ++} ++ ++fn main() -> std::io::Result<()> { ++ set_logger(log::LevelFilter::Info); + + prepare_init(); + +-- +2.30.2 + diff --git a/sysmaster.spec b/sysmaster.spec index 61bd648..53ee584 100644 --- a/sysmaster.spec +++ b/sysmaster.spec @@ -11,7 +11,7 @@ Name: sysmaster Version: 0.2.5 -Release: 3 +Release: 4 Summary: redesign and reimplement process1. License: Mulan PSL v2 @@ -20,6 +20,10 @@ Source0: %{name}-%{version}.tar.gz Patch6001: backport-fix-delete-and-re-add-the-restart-timer-to-make-time.patch Patch6002: backport-fix-log-the-status-message-to-stdout.patch +Patch6003: backport-fix-Fixed-parsing-single-quotes-error.patch +Patch6004: backport-typo-optimizing-print-statements.patch +Patch6005: backport-fix-make-control-command-accept.patch +Patch6006: backport-fix-return-the-correct-error-when-condition-assert-f.patch ExclusiveArch: x86_64 aarch64 @@ -72,6 +76,9 @@ install -Dm0640 -t %{buildroot}/etc/sysmaster %{conf_install_source}/system.conf /etc/sysmaster/system.conf %changelog +* Fri Sep 01 2023 licunlong - 0.2.5-4 +- sync patchs from upstream + * Thu Aug 31 2023 licunlong - 0.2.5-3 - log the status message to stdout