118 lines
4.4 KiB
Diff
118 lines
4.4 KiB
Diff
From aedd0986761b7310321c31496917e93ae47a0d4b Mon Sep 17 00:00:00 2001
|
|
From: huyubiao <h13958451065@163.com>
|
|
Date: Wed, 31 May 2023 01:15:09 +0800
|
|
Subject: [PATCH] fix: recycle the zombie of sysmaster
|
|
|
|
---
|
|
exts/init/src/runtime/mod.rs | 18 ++++++------------
|
|
exts/init/src/runtime/signals.rs | 10 ++--------
|
|
exts/sctl/src/main.rs | 2 +-
|
|
3 files changed, 9 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/exts/init/src/runtime/mod.rs b/exts/init/src/runtime/mod.rs
|
|
index 11c7a8d..e37ff01 100644
|
|
--- a/exts/init/src/runtime/mod.rs
|
|
+++ b/exts/init/src/runtime/mod.rs
|
|
@@ -18,7 +18,6 @@ mod timer;
|
|
|
|
use comm::{Comm, CommType};
|
|
use epoll::Epoll;
|
|
-use libc::signalfd_siginfo;
|
|
use nix::errno::Errno;
|
|
use nix::libc;
|
|
use nix::sys::epoll::EpollEvent;
|
|
@@ -190,7 +189,7 @@ impl RunTime {
|
|
if let Some(siginfo) = self.signals.read(event)? {
|
|
let signo = siginfo.ssi_signo as i32;
|
|
match signo {
|
|
- _x if self.signals.is_zombie(signo) => self.do_recycle(siginfo),
|
|
+ _x if self.signals.is_zombie(signo) => self.do_recycle(),
|
|
_x if self.signals.is_restart(signo) => self.do_reexec(),
|
|
_x if self.signals.is_unrecover(signo) => self.change_to_unrecover(),
|
|
_ => {}
|
|
@@ -203,7 +202,7 @@ impl RunTime {
|
|
if let Some(siginfo) = self.signals.read(event)? {
|
|
let signo = siginfo.ssi_signo as i32;
|
|
match signo {
|
|
- _x if self.signals.is_zombie(signo) => self.do_recycle(siginfo),
|
|
+ _x if self.signals.is_zombie(signo) => self.do_recycle(),
|
|
_x if self.signals.is_restart(signo) => self.do_reexec(),
|
|
_x if self.signals.is_switch_root(signo) => self.send_switch_root_signal(),
|
|
_ => {}
|
|
@@ -217,10 +216,9 @@ impl RunTime {
|
|
let signo = siginfo.ssi_signo as i32;
|
|
match signo {
|
|
_x if self.signals.is_zombie(signo) => {
|
|
+ self.signals.recycle_zombie();
|
|
if self.is_sysmaster(siginfo.ssi_pid as i32) && self.switching {
|
|
self.reexec_self()
|
|
- } else {
|
|
- self.signals.recycle_zombie(Pid::from_raw(0))
|
|
}
|
|
}
|
|
_x if self.signals.is_restart(signo) => self.do_recreate(),
|
|
@@ -233,8 +231,7 @@ impl RunTime {
|
|
fn change_to_unrecover(&mut self) {
|
|
println!("change run state to unrecover");
|
|
self.state = InitState::Unrecover;
|
|
- // Attempt to recycle the zombie sysmaster.
|
|
- self.signals.recycle_zombie(Pid::from_raw(0));
|
|
+ self.signals.recycle_zombie();
|
|
}
|
|
|
|
fn do_reexec(&mut self) {
|
|
@@ -250,11 +247,8 @@ impl RunTime {
|
|
}
|
|
}
|
|
|
|
- fn do_recycle(&mut self, siginfo: signalfd_siginfo) {
|
|
- let pid = siginfo.ssi_pid as i32;
|
|
- if !self.is_sysmaster(pid) {
|
|
- self.signals.recycle_zombie(Pid::from_raw(pid));
|
|
- }
|
|
+ fn do_recycle(&mut self) {
|
|
+ self.signals.recycle_zombie();
|
|
}
|
|
|
|
fn create_sysmaster(&mut self) -> Result<(), Errno> {
|
|
diff --git a/exts/init/src/runtime/signals.rs b/exts/init/src/runtime/signals.rs
|
|
index a30c7c2..eee088c 100644
|
|
--- a/exts/init/src/runtime/signals.rs
|
|
+++ b/exts/init/src/runtime/signals.rs
|
|
@@ -148,17 +148,11 @@ impl Signals {
|
|
}
|
|
}
|
|
|
|
- pub fn recycle_zombie(&mut self, dest_pid: unistd::Pid) {
|
|
+ pub fn recycle_zombie(&mut self) {
|
|
// peek signal
|
|
let flags = WaitPidFlag::WEXITED | WaitPidFlag::WNOHANG | WaitPidFlag::WNOWAIT;
|
|
loop {
|
|
- // get wait information
|
|
- let mut id_flag = Id::All;
|
|
- if dest_pid.as_raw() > 0 {
|
|
- id_flag = Id::Pid(dest_pid);
|
|
- }
|
|
-
|
|
- let wait_status = match wait::waitid(id_flag, flags) {
|
|
+ let wait_status = match wait::waitid(Id::All, flags) {
|
|
Ok(status) => status,
|
|
Err(_) => return,
|
|
};
|
|
diff --git a/exts/sctl/src/main.rs b/exts/sctl/src/main.rs
|
|
index f799629..ef360c7 100644
|
|
--- a/exts/sctl/src/main.rs
|
|
+++ b/exts/sctl/src/main.rs
|
|
@@ -203,7 +203,7 @@ fn main() {
|
|
let stream = match TcpStream::connect(&addrs[..]) {
|
|
Err(e) => {
|
|
eprintln!("Failed to connect to sysmaster: {}", e);
|
|
- exit(e.raw_os_error().unwrap() as i32);
|
|
+ exit(e.raw_os_error().unwrap());
|
|
}
|
|
Ok(v) => v,
|
|
};
|
|
--
|
|
2.33.0
|
|
|