mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 06:27:39 +00:00
agent: enhance get handled signal
For runC, send the signal to the init process directly. For kata, we try to send `SIGKILL` instead of `SIGTERM` when the process has not installed the handler for `SIGTERM`. The `is_signal_handled` function determine which signal the container process has been handled. But currently `is_signal_handled` is only catching (SigCgt). While the container process is ignoring (SigIgn) or blocking (SigBlk) also should not be converted from the `SIGTERM` to `SIGKILL`. For example, when using terminationGracePeriodSeconds the k8s will send SIGTERM first and then send `SIGKILL`, in this case, the container ignores the `SIGTERM`, so we should send the `SIGTERM` not the `SIGKILL` to the container. Fixes: #4478 Signed-off-by: quanweiZhou <quanweiZhou@linux.alibaba.com>
This commit is contained in:
parent
6fd40085ef
commit
2a4fbd6d8c
@ -1793,34 +1793,25 @@ fn is_signal_handled(proc_status_file: &str, signum: u32) -> bool {
|
|||||||
let sig_mask: u64 = 1 << shift_count;
|
let sig_mask: u64 = 1 << shift_count;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
// Read the file line by line using the lines() iterator from std::io::BufRead.
|
// read lines start with SigBlk/SigIgn/SigCgt and check any match the signal mask
|
||||||
for (_index, line) in reader.lines().enumerate() {
|
reader
|
||||||
let line = match line {
|
.lines()
|
||||||
Ok(l) => l,
|
.flatten()
|
||||||
Err(_) => {
|
.filter(|line| {
|
||||||
warn!(sl!(), "failed to read file {}", proc_status_file);
|
line.starts_with("SigBlk:")
|
||||||
return false;
|
|| line.starts_with("SigIgn:")
|
||||||
}
|
|| line.starts_with("SigCgt:")
|
||||||
};
|
})
|
||||||
if line.starts_with("SigCgt:") {
|
.any(|line| {
|
||||||
let mask_vec: Vec<&str> = line.split(':').collect();
|
let mask_vec: Vec<&str> = line.split(':').collect();
|
||||||
if mask_vec.len() != 2 {
|
if mask_vec.len() == 2 {
|
||||||
warn!(sl!(), "parse the SigCgt field failed");
|
let sig_str = mask_vec[1].trim();
|
||||||
return false;
|
if let Ok(sig) = u64::from_str_radix(sig_str, 16) {
|
||||||
}
|
return sig & sig_mask == sig_mask;
|
||||||
let sig_cgt_str = mask_vec[1].trim();
|
|
||||||
let sig_cgt_mask = match u64::from_str_radix(sig_cgt_str, 16) {
|
|
||||||
Ok(h) => h,
|
|
||||||
Err(_) => {
|
|
||||||
warn!(sl!(), "failed to parse the str {} to hex", sig_cgt_str);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
false
|
||||||
return (sig_cgt_mask & sig_mask) == sig_mask;
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_mem_hotplug_by_probe(addrs: &[u64]) -> Result<()> {
|
fn do_mem_hotplug_by_probe(addrs: &[u64]) -> Result<()> {
|
||||||
@ -2642,7 +2633,12 @@ OtherField:other
|
|||||||
TestData {
|
TestData {
|
||||||
status_file_data: Some("SigBlk:0000000000000001"),
|
status_file_data: Some("SigBlk:0000000000000001"),
|
||||||
signum: 1,
|
signum: 1,
|
||||||
result: false,
|
result: true,
|
||||||
|
},
|
||||||
|
TestData {
|
||||||
|
status_file_data: Some("SigIgn:0000000000000001"),
|
||||||
|
signum: 1,
|
||||||
|
result: true,
|
||||||
},
|
},
|
||||||
TestData {
|
TestData {
|
||||||
status_file_data: None,
|
status_file_data: None,
|
||||||
|
Loading…
Reference in New Issue
Block a user