Spaces:
Sleeping
Sleeping
更新 main.rs
Browse files- src/main.rs +15 -8
src/main.rs
CHANGED
|
@@ -6,8 +6,6 @@ use std::time::Duration;
|
|
| 6 |
|
| 7 |
use anyhow::{anyhow, Context, Result};
|
| 8 |
use base64::Engine;
|
| 9 |
-
use nix::sys::signal::{self, Signal};
|
| 10 |
-
use nix::unistd::Pid;
|
| 11 |
use reqwest::header::{AUTHORIZATION, CONTENT_TYPE};
|
| 12 |
use reqwest::StatusCode;
|
| 13 |
use serde::{Deserialize, Serialize};
|
|
@@ -465,11 +463,16 @@ fn spawn_child_from_args() -> Result<Child> {
|
|
| 465 |
command.spawn().context("failed to spawn child process")
|
| 466 |
}
|
| 467 |
|
|
|
|
| 468 |
fn forward_sigterm(child: &mut Child) {
|
| 469 |
if let Some(id) = child.id() {
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
}
|
| 474 |
}
|
| 475 |
}
|
|
@@ -488,9 +491,13 @@ async fn wait_for_child_shutdown(child: &mut Child) {
|
|
| 488 |
FINAL_WAIT_TIMEOUT
|
| 489 |
);
|
| 490 |
if let Some(id) = child.id() {
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
}
|
| 495 |
}
|
| 496 |
}
|
|
|
|
| 6 |
|
| 7 |
use anyhow::{anyhow, Context, Result};
|
| 8 |
use base64::Engine;
|
|
|
|
|
|
|
| 9 |
use reqwest::header::{AUTHORIZATION, CONTENT_TYPE};
|
| 10 |
use reqwest::StatusCode;
|
| 11 |
use serde::{Deserialize, Serialize};
|
|
|
|
| 463 |
command.spawn().context("failed to spawn child process")
|
| 464 |
}
|
| 465 |
|
| 466 |
+
/// Forward SIGTERM to the child process using libc::kill.
|
| 467 |
fn forward_sigterm(child: &mut Child) {
|
| 468 |
if let Some(id) = child.id() {
|
| 469 |
+
// SAFETY: id is a valid pid obtained from a live child process.
|
| 470 |
+
let ret = unsafe { libc::kill(id as libc::pid_t, libc::SIGTERM) };
|
| 471 |
+
if ret != 0 {
|
| 472 |
+
eprintln!(
|
| 473 |
+
"failed to forward SIGTERM: errno={}",
|
| 474 |
+
std::io::Error::last_os_error()
|
| 475 |
+
);
|
| 476 |
}
|
| 477 |
}
|
| 478 |
}
|
|
|
|
| 491 |
FINAL_WAIT_TIMEOUT
|
| 492 |
);
|
| 493 |
if let Some(id) = child.id() {
|
| 494 |
+
// SAFETY: id is a valid pid obtained from a live child process.
|
| 495 |
+
let ret = unsafe { libc::kill(id as libc::pid_t, libc::SIGKILL) };
|
| 496 |
+
if ret != 0 {
|
| 497 |
+
eprintln!(
|
| 498 |
+
"failed to SIGKILL child: errno={}",
|
| 499 |
+
std::io::Error::last_os_error()
|
| 500 |
+
);
|
| 501 |
}
|
| 502 |
}
|
| 503 |
}
|