mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
agent: fix OCI hook handling
We should call write_sync with proper arguments. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
03a4d107ba
commit
095ebb8ca3
@ -1515,12 +1515,16 @@ fn execute_hook(logger: &Logger, h: &Hook, st: &OCIState) -> Result<()> {
|
||||
});
|
||||
|
||||
match unistd::fork()? {
|
||||
ForkResult::Parent { child: _ch } => {
|
||||
ForkResult::Parent { child } => {
|
||||
let buf = read_sync(rfd)?;
|
||||
let status = if buf.len() == 4 {
|
||||
let buf_array: [u8; 4] = [buf[0], buf[1], buf[2], buf[3]];
|
||||
let status: i32 = i32::from_be_bytes(buf_array);
|
||||
i32::from_be_bytes(buf_array)
|
||||
} else {
|
||||
-libc::EPIPE
|
||||
};
|
||||
|
||||
info!(logger, "hook child: {}", _ch);
|
||||
info!(logger, "hook child: {} status: {}", child, status);
|
||||
|
||||
// let _ = wait::waitpid(_ch,
|
||||
// Some(WaitPidFlag::WEXITED | WaitPidFlag::__WALL));
|
||||
@ -1649,7 +1653,11 @@ fn execute_hook(logger: &Logger, h: &Hook, st: &OCIState) -> Result<()> {
|
||||
};
|
||||
|
||||
handle.join().unwrap();
|
||||
let _ = write_sync(wfd, status, "");
|
||||
let _ = write_sync(
|
||||
wfd,
|
||||
SYNC_DATA,
|
||||
std::str::from_utf8(&status.to_be_bytes()).unwrap_or_default(),
|
||||
);
|
||||
// let _ = wait::waitpid(Pid::from_raw(pid),
|
||||
// Some(WaitPidFlag::WEXITED | WaitPidFlag::__WALL));
|
||||
std::process::exit(0);
|
||||
|
Loading…
Reference in New Issue
Block a user