Skip to content

Commit b308d13

Browse files
zzzzzzzzzy9mxpv
authored andcommitted
add pid to delete response
1 parent 765111e commit b308d13

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

crates/runc-shim/src/service.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ use containerd_shim::{
2929
monitor::{Subject, Topic},
3030
protos::{events::task::TaskExit, protobuf::MessageDyn},
3131
util::{
32-
convert_to_timestamp, read_options, read_runtime, read_spec, timestamp, write_str_to_file,
32+
convert_to_timestamp, read_options, read_pid_from_file, read_runtime, read_spec, timestamp,
33+
write_str_to_file,
3334
},
3435
Config, Context, DeleteResponse, Error, Flags, StartOpts,
3536
};
3637
use log::{debug, error, warn};
3738
use tokio::sync::mpsc::{channel, Receiver, Sender};
3839

3940
use crate::{
40-
common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS},
41+
common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS, INIT_PID_FILE},
4142
container::Container,
4243
processes::Process,
4344
runc::{RuncContainer, RuncFactory},
@@ -116,6 +117,7 @@ impl Shim for Service {
116117
&opts,
117118
Some(Arc::new(ShimExecutor::default())),
118119
)?;
120+
let pid = read_pid_from_file(&bundle.join(INIT_PID_FILE)).await?;
119121

120122
runc.delete(&self.id, Some(&DeleteOpts { force: true }))
121123
.await
@@ -124,6 +126,7 @@ impl Shim for Service {
124126
// sigkill
125127
resp.set_exit_status(137);
126128
resp.set_exited_at(timestamp()?);
129+
resp.set_pid(pid as u32);
127130
Ok(resp)
128131
}
129132

crates/shim/src/asynchronous/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ pub async fn write_str_to_file(filename: impl AsRef<Path>, s: impl AsRef<str>) -
8787
Ok(())
8888
}
8989

90+
pub async fn read_pid_from_file(pid_path: &Path) -> Result<i32> {
91+
let pid_str = read_file_to_str(pid_path).await?;
92+
let pid = pid_str.parse::<i32>()?;
93+
Ok(pid)
94+
}
95+
9096
pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> {
9197
let path = bundle.as_ref().join(CONFIG_FILE_NAME);
9298
let content = read_file_to_str(&path).await?;

0 commit comments

Comments
 (0)