146 lines
4.6 KiB
Diff
146 lines
4.6 KiB
Diff
From c38d3c9dd677b28cbdd638b853475f74c42936bf Mon Sep 17 00:00:00 2001
|
|
From: licunlong <licunlong1@huawei.com>
|
|
Date: Mon, 22 May 2023 11:56:18 +0800
|
|
Subject: [PATCH] fix: unwatch all pids when the service enters dead
|
|
|
|
---
|
|
coms/service/src/mng.rs | 10 ++++++++++
|
|
coms/service/src/pid.rs | 6 ++++++
|
|
core/bin/unit/datastore/child.rs | 18 ++++++++++++------
|
|
core/bin/unit/datastore/mod.rs | 4 ++++
|
|
core/bin/unit/manager.rs | 9 +++++++++
|
|
core/lib/unit/umif.rs | 3 +++
|
|
6 files changed, 44 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/coms/service/src/mng.rs b/coms/service/src/mng.rs
|
|
index dff610e..d73fa34 100644
|
|
--- a/coms/service/src/mng.rs
|
|
+++ b/coms/service/src/mng.rs
|
|
@@ -845,6 +845,16 @@ impl ServiceMng {
|
|
self.set_cmd_type(None);
|
|
}
|
|
|
|
+ if vec![
|
|
+ ServiceState::Dead,
|
|
+ ServiceState::Failed,
|
|
+ ServiceState::AutoRestart,
|
|
+ ]
|
|
+ .contains(&state)
|
|
+ {
|
|
+ self.pid.child_unwatch_all_pids();
|
|
+ }
|
|
+
|
|
// todo!()
|
|
// trigger the unit the dependency trigger_by
|
|
|
|
diff --git a/coms/service/src/pid.rs b/coms/service/src/pid.rs
|
|
index deba828..a25de50 100644
|
|
--- a/coms/service/src/pid.rs
|
|
+++ b/coms/service/src/pid.rs
|
|
@@ -94,6 +94,12 @@ impl ServicePid {
|
|
}
|
|
}
|
|
|
|
+ pub(super) fn child_unwatch_all_pids(&self) {
|
|
+ if let Some(u) = self.comm.owner() {
|
|
+ self.comm.um().child_unwatch_all_pids(u.id());
|
|
+ }
|
|
+ }
|
|
+
|
|
pub(super) fn main(&self) -> Option<Pid> {
|
|
self.data.borrow().main()
|
|
}
|
|
diff --git a/core/bin/unit/datastore/child.rs b/core/bin/unit/datastore/child.rs
|
|
index fd8fffa..af63792 100644
|
|
--- a/core/bin/unit/datastore/child.rs
|
|
+++ b/core/bin/unit/datastore/child.rs
|
|
@@ -57,17 +57,23 @@ impl UnitChild {
|
|
pub(super) fn add_watch_pid(&self, id: &str, pid: Pid) {
|
|
log::debug!("borrow add watch_pids for pid:{}, id:{}", pid, id);
|
|
let unit = self.units.get(id).unwrap();
|
|
- let u = Rc::clone(&unit);
|
|
- self.data.add_watch_pid(unit, pid);
|
|
- u.child_add_pids(pid);
|
|
+ self.data.add_watch_pid(unit.clone(), pid);
|
|
+ unit.child_add_pids(pid);
|
|
}
|
|
|
|
pub(super) fn unwatch_pid(&self, id: &str, pid: Pid) {
|
|
let unit = self.units.get(id).unwrap();
|
|
- let u = Rc::clone(&unit);
|
|
log::debug!("borrow remove watch_pids for {}", pid);
|
|
- self.data.unwatch_pid(unit, pid);
|
|
- u.child_remove_pids(pid);
|
|
+ self.data.unwatch_pid(unit.clone(), pid);
|
|
+ unit.child_remove_pids(pid);
|
|
+ }
|
|
+
|
|
+ pub(super) fn unwatch_all_pids(&self, id: &str) {
|
|
+ let unit = self.units.get(id).unwrap();
|
|
+ for i in self.data.watch_pids.borrow().keys() {
|
|
+ unit.child_remove_pids(*i);
|
|
+ }
|
|
+ self.data.watch_pids.borrow_mut().clear();
|
|
}
|
|
|
|
pub(super) fn get_unit_by_pid(&self, pid: Pid) -> Option<Rc<UnitX>> {
|
|
diff --git a/core/bin/unit/datastore/mod.rs b/core/bin/unit/datastore/mod.rs
|
|
index d3f8839..1dc09d7 100644
|
|
--- a/core/bin/unit/datastore/mod.rs
|
|
+++ b/core/bin/unit/datastore/mod.rs
|
|
@@ -160,6 +160,10 @@ impl UnitDb {
|
|
}
|
|
}
|
|
|
|
+ pub fn child_unwatch_all_pids(&self, id: &str) {
|
|
+ self.child.unwatch_all_pids(id);
|
|
+ }
|
|
+
|
|
pub fn get_unit_by_pid(&self, pid: Pid) -> Option<Rc<UnitX>> {
|
|
self.child.get_unit_by_pid(pid)
|
|
}
|
|
diff --git a/core/bin/unit/manager.rs b/core/bin/unit/manager.rs
|
|
index 0677c1b..bee3093 100644
|
|
--- a/core/bin/unit/manager.rs
|
|
+++ b/core/bin/unit/manager.rs
|
|
@@ -392,6 +392,10 @@ impl UmIf for UnitManager {
|
|
self.child_watch_all_pids(id)
|
|
}
|
|
|
|
+ fn child_unwatch_all_pids(&self, id: &str) {
|
|
+ self.child_unwatch_all_pids(id)
|
|
+ }
|
|
+
|
|
fn notify_socket(&self) -> Option<PathBuf> {
|
|
self.notify_socket()
|
|
}
|
|
@@ -480,6 +484,11 @@ impl UnitManager {
|
|
self.db.child_watch_all_pids(id)
|
|
}
|
|
|
|
+ /// remove all pids
|
|
+ fn child_unwatch_all_pids(&self, id: &str) {
|
|
+ self.db.child_unwatch_all_pids(id)
|
|
+ }
|
|
+
|
|
/// delete the pid from the db
|
|
fn child_unwatch_pid(&self, id: &str, pid: Pid) {
|
|
self.db.child_unwatch_pid(id, pid)
|
|
diff --git a/core/lib/unit/umif.rs b/core/lib/unit/umif.rs
|
|
index 027c59f..4821ff9 100644
|
|
--- a/core/lib/unit/umif.rs
|
|
+++ b/core/lib/unit/umif.rs
|
|
@@ -134,6 +134,9 @@ pub trait UmIf {
|
|
/// add all the pid of unit id, read pids from cgroup path.
|
|
fn child_watch_all_pids(&self, _id: &str) {}
|
|
|
|
+ /// remove all the pid of unit id
|
|
+ fn child_unwatch_all_pids(&self, _id: &str) {}
|
|
+
|
|
///rentry_trigger_merge
|
|
fn rentry_trigger_merge(&self, _unit_id: &str, _force: bool) {}
|
|
|
|
--
|
|
2.30.2
|
|
|