Skip to content

Commit

Permalink
add pid to delete response
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzzzzzzy9 committed Aug 1, 2024
1 parent 765111e commit d8bc165
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/runc-shim/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ use containerd_shim::{
monitor::{Subject, Topic},
protos::{events::task::TaskExit, protobuf::MessageDyn},
util::{
convert_to_timestamp, read_options, read_runtime, read_spec, timestamp, write_str_to_file,
convert_to_timestamp, read_options, read_pid_from_file, read_runtime, read_spec, timestamp,
write_str_to_file,
},
Config, Context, DeleteResponse, Error, Flags, StartOpts,
};
use log::{debug, error, warn};
use tokio::sync::mpsc::{channel, Receiver, Sender};

use crate::{
common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS},
common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS, INIT_PID_FILE},
container::Container,
processes::Process,
runc::{RuncContainer, RuncFactory},
Expand Down Expand Up @@ -116,6 +117,7 @@ impl Shim for Service {
&opts,
Some(Arc::new(ShimExecutor::default())),
)?;
let pid = read_pid_from_file(&bundle.join(INIT_PID_FILE)).await?;

runc.delete(&self.id, Some(&DeleteOpts { force: true }))
.await
Expand All @@ -124,6 +126,7 @@ impl Shim for Service {
// sigkill
resp.set_exit_status(137);
resp.set_exited_at(timestamp()?);
resp.set_pid(pid as u32);
Ok(resp)
}

Expand Down
6 changes: 6 additions & 0 deletions crates/shim/src/asynchronous/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ pub async fn write_str_to_file(filename: impl AsRef<Path>, s: impl AsRef<str>) -
Ok(())
}

pub async fn read_pid_from_file(pid_path: &Path) -> Result<i32> {
let pid_str = read_file_to_str(pid_path).await?;
let pid = pid_str.parse::<i32>()?;
Ok(pid)
}

pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> {
let path = bundle.as_ref().join(CONFIG_FILE_NAME);
let content = read_file_to_str(&path).await?;
Expand Down

0 comments on commit d8bc165

Please sign in to comment.