Skip to content

Rollup of 7 pull requests #142558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1e10dfc
Add all rustc_std_internal_symbol to symbols.o
bjorn3 May 8, 2025
2d2d70f
Remove dependency injection for the panic runtime
bjorn3 May 8, 2025
3a7ae67
Stop handling explicit dependencies on the panic runtime
bjorn3 May 8, 2025
f8d1bfa
Avoid exporting panic_unwind as stdlib cargo feature
bjorn3 May 8, 2025
6df5456
Make comment on activate_injected_dep a doc comment
bjorn3 May 9, 2025
269ee72
add ChildExt(::send_signal)
Qelxiros Jun 12, 2025
96fd9fc
use `if let` guards where possible
fee1-dead Jun 15, 2025
1ac89f1
Refactor `rustc_attr_data_structures` documentation
xizheyin Jun 5, 2025
a0db28f
clarify `rustc_do_not_const_check` comment
fee1-dead Jun 15, 2025
3871203
Stabilize "file_lock" feature
cberner May 29, 2025
ce457e1
Get rid of `EscapeDebugInner`.
reitermarkus Mar 8, 2025
487a265
Rollup merge of #138237 - reitermarkus:remove-escape-debug-inner, r=t…
tgross35 Jun 16, 2025
79c6454
Rollup merge of #140809 - bjorn3:panic_runtime_cleanup, r=wesleywiser…
tgross35 Jun 16, 2025
3b939b7
Rollup merge of #141990 - Qelxiros:141975-unix_send_signal, r=ChrisDe…
tgross35 Jun 16, 2025
ff6f7ed
Rollup merge of #142082 - xizheyin:rustc_attr_data_structures, r=jdon…
tgross35 Jun 16, 2025
867f71b
Rollup merge of #142125 - cberner:file_lock_stable, r=ChrisDenton
tgross35 Jun 16, 2025
969298b
Rollup merge of #142528 - fee1-dead-contrib:push-rlxklunqkwmv, r=Ralf…
tgross35 Jun 16, 2025
f145a46
Rollup merge of #142530 - fee1-dead-contrib:push-klusvwusyqvq, r=comp…
tgross35 Jun 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub mod prelude {
#[stable(feature = "rust1", since = "1.0.0")]
pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
#[doc(no_inline)]
#[unstable(feature = "unix_send_signal", issue = "141975")]
pub use super::process::ChildExt;
#[doc(no_inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use super::process::{CommandExt, ExitStatusExt};
#[doc(no_inline)]
Expand Down
35 changes: 35 additions & 0 deletions library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,41 @@ impl ExitStatusExt for process::ExitStatusError {
}
}

#[unstable(feature = "unix_send_signal", issue = "141975")]
pub trait ChildExt: Sealed {
/// Sends a signal to a child process.
///
/// # Errors
///
/// This function will return an error if the signal is invalid. The integer values associated
/// with signals are implemenation-specific, so it's encouraged to use a crate that provides
/// posix bindings.
///
/// # Examples
///
/// ```rust
/// #![feature(unix_send_signal)]
///
/// use std::{io, os::unix::process::ChildExt, process::{Command, Stdio}};
///
/// use libc::SIGTERM;
///
/// fn main() -> io::Result<()> {
/// let child = Command::new("cat").stdin(Stdio::piped()).spawn()?;
/// child.send_signal(SIGTERM)?;
/// Ok(())
/// }
/// ```
fn send_signal(&self, signal: i32) -> io::Result<()>;
}

#[unstable(feature = "unix_send_signal", issue = "141975")]
impl ChildExt for process::Child {
fn send_signal(&self, signal: i32) -> io::Result<()> {
self.handle.send_signal(signal)
}
}

#[stable(feature = "process_extensions", since = "1.2.0")]
impl FromRawFd for process::Stdio {
#[inline]
Expand Down
6 changes: 5 additions & 1 deletion library/std/src/sys/pal/unix/linux/pidfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ pub(crate) struct PidFd(FileDesc);

impl PidFd {
pub fn kill(&self) -> io::Result<()> {
self.send_signal(libc::SIGKILL)
}

pub(crate) fn send_signal(&self, signal: i32) -> io::Result<()> {
cvt(unsafe {
libc::syscall(
libc::SYS_pidfd_send_signal,
self.0.as_raw_fd(),
libc::SIGKILL,
signal,
crate::ptr::null::<()>(),
0,
)
Expand Down
10 changes: 7 additions & 3 deletions library/std/src/sys/process/unix/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,18 +964,22 @@ impl Process {
}

pub fn kill(&mut self) -> io::Result<()> {
self.send_signal(libc::SIGKILL)
}

pub(crate) fn send_signal(&self, signal: i32) -> io::Result<()> {
// If we've already waited on this process then the pid can be recycled
// and used for another process, and we probably shouldn't be killing
// and used for another process, and we probably shouldn't be signaling
// random processes, so return Ok because the process has exited already.
if self.status.is_some() {
return Ok(());
}
#[cfg(target_os = "linux")]
if let Some(pid_fd) = self.pidfd.as_ref() {
// pidfd_send_signal predates pidfd_open. so if we were able to get an fd then sending signals will work too
return pid_fd.kill();
return pid_fd.send_signal(signal);
}
cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop)
cvt(unsafe { libc::kill(self.pid, signal) }).map(drop)
}

pub fn wait(&mut self) -> io::Result<ExitStatus> {
Expand Down