190 lines
7.1 KiB
Diff
190 lines
7.1 KiB
Diff
From 95210185215c933fa00be50c96505ef390df349c Mon Sep 17 00:00:00 2001
|
|
From: licunlong <licunlong1@huawei.com>
|
|
Date: Wed, 31 May 2023 10:57:10 +0800
|
|
Subject: [PATCH 2/9] refactor: rename UNitNotifyFlags to shorten code a bit
|
|
change UNIT_NOTIFY_SUCCESS to EMPTY, the original SUCCESS doesn't make sense
|
|
|
|
---
|
|
coms/mount/src/mng.rs | 2 +-
|
|
coms/service/src/mng.rs | 6 +++---
|
|
coms/socket/src/mng.rs | 2 +-
|
|
coms/target/src/mng.rs | 2 +-
|
|
core/bin/job/entry.rs | 2 +-
|
|
core/bin/job/manager.rs | 5 ++---
|
|
core/bin/unit/data/table.rs | 2 +-
|
|
core/bin/unit/entry/uentry.rs | 6 +-----
|
|
core/bin/unit/manager.rs | 1 -
|
|
core/lib/unit/state.rs | 8 ++++----
|
|
10 files changed, 15 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/coms/mount/src/mng.rs b/coms/mount/src/mng.rs
|
|
index e09d1f7..5383c4d 100644
|
|
--- a/coms/mount/src/mng.rs
|
|
+++ b/coms/mount/src/mng.rs
|
|
@@ -108,7 +108,7 @@ impl MountMng {
|
|
u.notify(
|
|
old_unit_state,
|
|
new_unit_state,
|
|
- UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE,
|
|
+ UnitNotifyFlags::RELOAD_FAILURE,
|
|
)
|
|
}
|
|
|
|
diff --git a/coms/service/src/mng.rs b/coms/service/src/mng.rs
|
|
index 0f5db5f..fa6237a 100644
|
|
--- a/coms/service/src/mng.rs
|
|
+++ b/coms/service/src/mng.rs
|
|
@@ -862,14 +862,14 @@ impl ServiceMng {
|
|
let os = service_state_to_unit_state(self.config.service_type(), original_state);
|
|
let ns = service_state_to_unit_state(self.config.service_type(), state);
|
|
if let Some(u) = self.comm.owner() {
|
|
- let mut flags = UnitNotifyFlags::UNIT_NOTIFY_SUCCESS;
|
|
+ let mut flags = UnitNotifyFlags::EMPTY;
|
|
|
|
if self.rd.will_auto_restart() {
|
|
- flags |= UnitNotifyFlags::UNIT_NOTIFY_WILL_AUTO_RESTART;
|
|
+ flags |= UnitNotifyFlags::WILL_AUTO_RESTART;
|
|
}
|
|
|
|
if self.reload_result() != ServiceResult::Success {
|
|
- flags |= UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE;
|
|
+ flags |= UnitNotifyFlags::RELOAD_FAILURE;
|
|
}
|
|
u.notify(os, ns, flags)
|
|
}
|
|
diff --git a/coms/socket/src/mng.rs b/coms/socket/src/mng.rs
|
|
index 33b9812..fe77517 100644
|
|
--- a/coms/socket/src/mng.rs
|
|
+++ b/coms/socket/src/mng.rs
|
|
@@ -650,7 +650,7 @@ impl SocketMng {
|
|
u.notify(
|
|
original_state.to_unit_active_state(),
|
|
state.to_unit_active_state(),
|
|
- UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE,
|
|
+ UnitNotifyFlags::RELOAD_FAILURE,
|
|
)
|
|
}
|
|
}
|
|
diff --git a/coms/target/src/mng.rs b/coms/target/src/mng.rs
|
|
index 039fa9e..dc52339 100644
|
|
--- a/coms/target/src/mng.rs
|
|
+++ b/coms/target/src/mng.rs
|
|
@@ -112,7 +112,7 @@ impl TargetMng {
|
|
unit.notify(
|
|
old_unit_state,
|
|
new_unit_state,
|
|
- UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE,
|
|
+ UnitNotifyFlags::RELOAD_FAILURE,
|
|
);
|
|
|
|
self.db_update();
|
|
diff --git a/core/bin/job/entry.rs b/core/bin/job/entry.rs
|
|
index 54af665..81f443a 100755
|
|
--- a/core/bin/job/entry.rs
|
|
+++ b/core/bin/job/entry.rs
|
|
@@ -621,7 +621,7 @@ fn job_process_unit_reload(
|
|
flags: UnitNotifyFlags,
|
|
) -> (Option<JobResult>, bool) {
|
|
let mut result = JobResult::Done;
|
|
- if flags.intersects(UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE) {
|
|
+ if flags.intersects(UnitNotifyFlags::RELOAD_FAILURE) {
|
|
result = JobResult::Failed;
|
|
}
|
|
match ns {
|
|
diff --git a/core/bin/job/manager.rs b/core/bin/job/manager.rs
|
|
index e8eee8b..028c4d5 100755
|
|
--- a/core/bin/job/manager.rs
|
|
+++ b/core/bin/job/manager.rs
|
|
@@ -268,7 +268,6 @@ impl Source for JobManagerData {
|
|
|
|
fn dispatch(&self, _event: &Events) -> i32 {
|
|
log::debug!("job manager data dispatch");
|
|
-
|
|
self.reli.set_last_frame1(ReliLastFrame::JobManager as u32);
|
|
self.run(None);
|
|
self.reli.clear_last_frame();
|
|
@@ -728,7 +727,7 @@ impl JobManagerData {
|
|
) {
|
|
// OnFailure=
|
|
if ns != os
|
|
- && !flags.intersects(UnitNotifyFlags::UNIT_NOTIFY_WILL_AUTO_RESTART)
|
|
+ && !flags.intersects(UnitNotifyFlags::WILL_AUTO_RESTART)
|
|
&& ns == UnitActiveState::UnitFailed
|
|
{
|
|
let job_mode = unit
|
|
@@ -746,7 +745,7 @@ impl JobManagerData {
|
|
|
|
// OnSuccess=
|
|
if ns == UnitActiveState::UnitInActive
|
|
- && !flags.intersects(UnitNotifyFlags::UNIT_NOTIFY_WILL_AUTO_RESTART)
|
|
+ && !flags.intersects(UnitNotifyFlags::WILL_AUTO_RESTART)
|
|
{
|
|
match os {
|
|
UnitActiveState::UnitFailed
|
|
diff --git a/core/bin/unit/data/table.rs b/core/bin/unit/data/table.rs
|
|
index cfacf80..480a026 100644
|
|
--- a/core/bin/unit/data/table.rs
|
|
+++ b/core/bin/unit/data/table.rs
|
|
@@ -178,7 +178,7 @@ mod tests {
|
|
let dm = DataManager::new();
|
|
let os = UnitActiveState::UnitInActive;
|
|
let ns = UnitActiveState::UnitActive;
|
|
- let flags = UnitNotifyFlags::UNIT_NOTIFY_RELOAD_FAILURE;
|
|
+ let flags = UnitNotifyFlags::RELOAD_FAILURE;
|
|
let us_sub = Rc::new(UnitStatesTest::new(ns));
|
|
|
|
let old = dm.insert_unit_state(String::from("test"), UnitState::new(os, ns, flags));
|
|
diff --git a/core/bin/unit/entry/uentry.rs b/core/bin/unit/entry/uentry.rs
|
|
index a22ad10..307240b 100644
|
|
--- a/core/bin/unit/entry/uentry.rs
|
|
+++ b/core/bin/unit/entry/uentry.rs
|
|
@@ -694,11 +694,7 @@ impl Unit {
|
|
Ok(_) => Ok(()),
|
|
Err(e) => match e {
|
|
Error::UnitActionEOpNotSupp => {
|
|
- self.notify(
|
|
- active_state,
|
|
- active_state,
|
|
- UnitNotifyFlags::UNIT_NOTIFY_SUCCESS,
|
|
- );
|
|
+ self.notify(active_state, active_state, UnitNotifyFlags::EMPTY);
|
|
Ok(())
|
|
}
|
|
_ => Err(e),
|
|
diff --git a/core/bin/unit/manager.rs b/core/bin/unit/manager.rs
|
|
index 6e83240..d5c3e10 100644
|
|
--- a/core/bin/unit/manager.rs
|
|
+++ b/core/bin/unit/manager.rs
|
|
@@ -1051,7 +1051,6 @@ impl UnitManager {
|
|
if let Err(_e) = self.jm.try_finish(&unitx, state.os, state.ns, state.flags) {
|
|
// debug
|
|
}
|
|
-
|
|
let atom = UnitRelationAtom::UnitAtomTriggeredBy;
|
|
for other in self.db.dep_gets_atom(&unitx, atom) {
|
|
other.trigger(&unitx);
|
|
diff --git a/core/lib/unit/state.rs b/core/lib/unit/state.rs
|
|
index d5e204a..1ae747b 100644
|
|
--- a/core/lib/unit/state.rs
|
|
+++ b/core/lib/unit/state.rs
|
|
@@ -102,12 +102,12 @@ impl std::fmt::Display for UnitActiveState {
|
|
bitflags! {
|
|
/// notify unit state to manager
|
|
pub struct UnitNotifyFlags: u8 {
|
|
- /// the default flags propagate to jobs, it meas nothing.
|
|
- const UNIT_NOTIFY_SUCCESS = 0;
|
|
+ /// the default flags propagate to jobs, it means nothing.
|
|
+ const EMPTY = 0;
|
|
/// notify that the unit running reload failure
|
|
- const UNIT_NOTIFY_RELOAD_FAILURE = 1 << 0;
|
|
+ const RELOAD_FAILURE = 1 << 0;
|
|
/// notify that the unit is in auto restart state
|
|
- const UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1;
|
|
+ const WILL_AUTO_RESTART = 1 << 1;
|
|
}
|
|
}
|
|
|
|
--
|
|
2.30.2
|
|
|