-
Notifications
You must be signed in to change notification settings - Fork 161
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
Add rustix::process::exit
to terminate processes
#1133
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,3 +742,14 @@ pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { | |
|
||
unsafe { ret_usize(c::getgroups(len, buf.as_mut_ptr().cast()) as isize) } | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn _exit(status: i32) -> ! { | ||
unsafe { | ||
libc::_exit(status); | ||
} | ||
#[allow(unreachable_code)] | ||
{ | ||
unreachable!("_exit failed to exit the process") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can leave these four lines out. The |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -620,3 +620,14 @@ pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result<usize> { | |
)) | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn _exit(status: i32) -> ! { | ||
unsafe { | ||
syscall_noreturn!(__NR_exit_group, c_int(status)); | ||
}; | ||
#[allow(unreachable_code)] | ||
{ | ||
unreachable!("_exit failed to exit the process") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, we can leave these four lines out because the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
use crate::backend; | ||
|
||
/// `EXIT_SUCCESS` for use with [`exit`]. | ||
/// | ||
/// [`exit`]: std::process::exit | ||
/// `EXIT_SUCCESS` for use with [`exit`] or [`std::process::exit`]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is named |
||
/// | ||
/// # References | ||
/// - [POSIX] | ||
|
@@ -12,9 +10,7 @@ use crate::backend; | |
/// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html | ||
pub const EXIT_SUCCESS: i32 = backend::c::EXIT_SUCCESS; | ||
|
||
/// `EXIT_FAILURE` for use with [`exit`]. | ||
/// | ||
/// [`exit`]: std::process::exit | ||
/// `EXIT_FAILURE` for use with [`exit`] or [`std::process::exit`]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as for |
||
/// | ||
/// # References | ||
/// - [POSIX] | ||
|
@@ -34,3 +30,30 @@ pub const EXIT_FAILURE: i32 = backend::c::EXIT_FAILURE; | |
/// [`Signal::Abort`]: crate::process::Signal::Abort | ||
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))] | ||
pub const EXIT_SIGNALED_SIGABRT: i32 = backend::c::EXIT_SIGNALED_SIGABRT; | ||
|
||
/// Immediately exits the process. Exiting via this function does not unwind the | ||
/// stack and does not call any further user code. This behavior is similar to | ||
sunfishcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// the POSIX/C `_Exit` and `_exit` functions. | ||
/// | ||
/// Notably, this function does: | ||
/// - *Not* flush any buffers, such as Rust or C standard output or files. | ||
/// - *Not* call any destructors, neither in the form of stack unwinding, nor | ||
/// any global destructors. | ||
/// - *Not* call functions registered with [`atexit`] or [`at_quick_exit`] | ||
/// | ||
/// In general, most code should call [`std::process::exit`] instead, if it is | ||
/// available. | ||
/// | ||
/// # References | ||
/// - [POSIX] | ||
/// - [Linux] | ||
/// | ||
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html | ||
/// [Linux]: https://www.man7.org/linux/man-pages/man2/exit.2.html | ||
/// [`atexit`]: https://www.man7.org/linux/man-pages/man3/atexit.3.html | ||
/// [`at_quick_exit`]: https://en.cppreference.com/w/c/program/at_quick_exit | ||
#[doc(alias = "_exit")] | ||
#[inline] | ||
pub fn immediate_exit(status: i32) -> ! { | ||
backend::process::syscalls::_exit(status); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifiers with leading underscores have a special meaning in Rust, so I suggest we rename this internal function to
immediate_exit
as well.