• Home
  • Raw
  • Download

Lines Matching +full:use +full:- +full:libc

2 // See https://www.rust-lang.org/policies/licenses.
6 use crate::errno::Errno;
7 use crate::{Error, Result};
8 use cfg_if::cfg_if;
9 use std::fmt;
10 use std::mem;
12 use std::os::unix::io::RawFd;
13 use std::ptr;
14 use std::str::FromStr;
18 pub use self::sigevent::*;
23 // Currently there is only one definition of c_int in libc, as well as only one
25 // We would prefer to use the libc::c_int alias in the repr attribute. Unfortunately
77 /// Like TTIN if (tp->t_local&LTOSTOP)
121 fn from_str(s: &str) -> Result<Signal> { in from_str()
204 pub const fn as_str(self) -> &'static str { in as_str()
281 fn as_ref(&self) -> &str { in as_ref()
288 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { in fmt()
294 pub use self::Signal::*;
376 fn next(&mut self) -> Option<Signal> {
389 pub const fn iterator() -> SignalIterator {
404 type SaFlags_t = libc::c_ulong;
406 type SaFlags_t = libc::c_ulong;
408 type SaFlags_t = libc::c_int;
462 use crate::unistd::Pid;
463 use std::iter::Extend;
464 use std::iter::FromIterator;
465 use std::iter::IntoIterator;
473 sigset: libc::sigset_t
479 pub fn all() -> SigSet {
481 let _ = unsafe { libc::sigfillset(sigset.as_mut_ptr()) };
488 pub fn empty() -> SigSet {
490 let _ = unsafe { libc::sigemptyset(sigset.as_mut_ptr()) };
498 unsafe { libc::sigaddset(&mut self.sigset as *mut libc::sigset_t, signal as libc::c_int) };
504 unsafe { libc::sigemptyset(&mut self.sigset as *mut libc::sigset_t) };
510 unsafe { libc::sigdelset(&mut self.sigset as *mut libc::sigset_t, signal as libc::c_int) };
515 pub fn contains(&self, signal: Signal) -> bool {
516 …let res = unsafe { libc::sigismember(&self.sigset as *const libc::sigset_t, signal as libc::c_int)…
526 pub fn iter(&self) -> SigSetIter<'_> {
531 pub fn thread_get_mask() -> Result<SigSet> {
538 pub fn thread_set_mask(&self) -> Result<()> {
543 pub fn thread_block(&self) -> Result<()> {
548 pub fn thread_unblock(&self) -> Result<()> {
553 pub fn thread_swap_mask(&self, how: SigmaskHow) -> Result<SigSet> {
563 pub fn wait(&self) -> Result<Signal> {
564 use std::convert::TryFrom;
567 … let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, signum.as_mut_ptr()) };
574 /// Converts a `libc::sigset_t` object to a [`SigSet`] without checking whether the
575 /// `libc::sigset_t` is already initialized.
579 /// The `sigset` passed in must be a valid an initialized `libc::sigset_t` by calling either
580 /// [`sigemptyset(3)`](https://man7.org/linux/man-pages/man3/sigemptyset.3p.html) or
581 /// [`sigfillset(3)`](https://man7.org/linux/man-pages/man3/sigfillset.3p.html).
583 pub unsafe fn from_sigset_t_unchecked(sigset: libc::sigset_t) -> SigSet {
588 impl AsRef<libc::sigset_t> for SigSet {
589 fn as_ref(&self) -> &libc::sigset_t {
594 // TODO: Consider specialization for the case where T is &SigSet and libc::sigorset is available.
605 fn from_iter<T>(iter: T) -> Self
624 fn next(&mut self) -> Option<Signal> {
638 fn into_iter(self) -> Self::IntoIter {
651 /// Use the given signal-catching function, which takes in the signal.
652 Handler(extern fn(libc::c_int)),
653 /// Use the given signal-catching function, which takes in the signal, information about how
657 SigAction(extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void))
663 sigaction: libc::sigaction
671 /// the signal-catching function.
672 pub fn new(handler: SigHandler, flags: SaFlags, mask: SigSet) -> SigAction {
673 unsafe fn install_sig(p: *mut libc::sigaction, handler: SigHandler) {
675 SigHandler::SigDfl => libc::SIG_DFL,
676 SigHandler::SigIgn => libc::SIG_IGN,
677 SigHandler::Handler(f) => f as *const extern fn(libc::c_int) as usize,
679 …SigHandler::SigAction(f) => f as *const extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_…
683 let mut s = mem::MaybeUninit::<libc::sigaction>::uninit();
690 _ => (flags - SaFlags::SA_SIGINFO).bits(),
699 pub fn flags(&self) -> SaFlags {
704 /// signal-catching function.
705 pub fn mask(&self) -> SigSet {
710 pub fn handler(&self) -> SigHandler {
712 libc::SIG_DFL => SigHandler::SigDfl,
713 libc::SIG_IGN => SigHandler::SigIgn,
737 as *const extern fn(libc::c_int))
739 as extern fn(libc::c_int)),
752 /// what is safe to do in the body of the signal-catching function. Be certain
761 pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result<SigAction> {
762 let mut oldact = mem::MaybeUninit::<libc::sigaction>::uninit();
764 let res = libc::sigaction(signal as libc::c_int,
765 &sigaction.sigaction as *const libc::sigaction,
788 /// # use nix::sys::signal::{self, Signal, SigHandler};
792 /// Use a signal handler to set a flag variable:
796 /// # use std::convert::TryFrom;
797 /// # use std::sync::atomic::{AtomicBool, Ordering};
798 /// # use nix::sys::signal::{self, Signal, SigHandler};
803 /// extern fn handle_sigint(signal: libc::c_int) {
817 /// [`SigAction`][SigActionStruct]. Use [`sigaction`][SigActionFn] instead.
819 /// `signal` also returns any error from `libc::signal`, such as when an attempt
826 pub unsafe fn signal(signal: Signal, handler: SigHandler) -> Result<SigHandler> {
827 let signal = signal as libc::c_int;
829 SigHandler::SigDfl => libc::signal(signal, libc::SIG_DFL),
830 SigHandler::SigIgn => libc::signal(signal, libc::SIG_IGN),
831 SigHandler::Handler(handler) => libc::signal(signal, handler as libc::sighandler_t),
837 libc::SIG_DFL => SigHandler::SigDfl,
838 libc::SIG_IGN => SigHandler::SigIgn,
841 as *const extern fn(libc::c_int))
842 as extern fn(libc::c_int)),
849 oldset: Option<*mut libc::sigset_t>) -> Result<()> {
856 libc::pthread_sigmask(how as libc::c_int,
857 set.map_or_else(ptr::null::<libc::sigset_t>,
858 |s| &s.sigset as *const libc::sigset_t),
877 /// If both `set` and `oldset` is None, this function is a no-op.
883 oldset: Option<&mut SigSet>) -> Result<()>
892 pub fn sigprocmask(how: SigmaskHow, set: Option<&SigSet>, oldset: Option<&mut SigSet>) -> Result<()…
899 libc::sigprocmask(how as libc::c_int,
900 set.map_or_else(ptr::null::<libc::sigset_t>,
901 |s| &s.sigset as *const libc::sigset_t),
902 oldset.map_or_else(ptr::null_mut::<libc::sigset_t>,
903 |os| &mut os.sigset as *mut libc::sigset_t))
913 /// * `pid` - Specifies which processes should receive the signal.
914 /// - If positive, specifies an individual process.
915 /// - If zero, the signal will be sent to all processes whose group
919 /// - If `-1` and the process has super-user privileges, the signal
921 /// - If less than `-1`, the signal is sent to all processes whose
923 /// * `signal` - Signal to send. If `None`, error checking is performed
928 pub fn kill<T: Into<Option<Signal>>>(pid: Pid, signal: T) -> Result<()> {
929 let res = unsafe { libc::kill(pid.into(),
931 Some(s) => s as libc::c_int,
942 /// * `pgrp` - Process group to signal. If less then or equal 1, the behavior
943 /// is platform-specific.
944 /// * `signal` - Signal to send. If `None`, `killpg` will only preform error
949 pub fn killpg<T: Into<Option<Signal>>>(pgrp: Pid, signal: T) -> Result<()> {
950 let res = unsafe { libc::killpg(pgrp.into(),
952 Some(s) => s as libc::c_int,
962 pub fn raise(signal: Signal) -> Result<()> {
963 let res = unsafe { libc::raise(signal as libc::c_int) };
974 pub type type_of_thread_id = libc::lwpid_t;
977 pub type type_of_thread_id = libc::pid_t;
981 // as a pointer, because neither libc nor the kernel ever dereference it. nix
992 /// Will be present in the `si_value` field of the [`libc::siginfo_t`]
994 si_value: libc::intptr_t
996 // Note: SIGEV_THREAD is not implemented because libc::sigevent does not
1005 udata: libc::intptr_t
1015 /// Will be present in the `si_value` field of the [`libc::siginfo_t`]
1017 si_value: libc::intptr_t
1028 use std::mem;
1029 use std::ptr;
1030 use super::SigevNotify;
1032 use super::type_of_thread_id;
1039 sigevent: libc::sigevent
1057 // See https://github.com/nix-rust/nix/issues/1441
1059 pub fn new(sigev_notify: SigevNotify) -> SigEvent {
1060 let mut sev = unsafe { mem::MaybeUninit::<libc::sigevent>::zeroed().assume_init() };
1062 SigevNotify::SigevNone => libc::SIGEV_NONE,
1063 SigevNotify::SigevSignal{..} => libc::SIGEV_SIGNAL,
1065 SigevNotify::SigevKevent{..} => libc::SIGEV_KEVENT,
1067 SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
1069 SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
1071 SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
1076 SigevNotify::SigevSignal{ signal, .. } => signal as libc::c_int,
1080 SigevNotify::SigevThreadId{ signal, .. } => signal as libc::c_int,
1084 SigevNotify::SigevNone => ptr::null_mut::<libc::c_void>(),
1085 SigevNotify::SigevSignal{ si_value, .. } => si_value as *mut libc::c_void,
1087 SigevNotify::SigevKevent{ udata, .. } => udata as *mut libc::c_void,
1089 SigevNotify::SigevThreadId{ si_value, .. } => si_value as *mut libc::c_void,
1096 fn set_tid(sev: &mut libc::sigevent, sigev_notify: &SigevNotify) {
1104 fn set_tid(_sev: &mut libc::sigevent, _sigev_notify: &SigevNotify) {
1108 pub fn sigevent(&self) -> libc::sigevent {
1113 pub fn as_mut_ptr(&mut self) -> *mut libc::sigevent {
1118 impl<'a> From<&'a libc::sigevent> for SigEvent {
1119 fn from(sigevent: &libc::sigevent) -> Self {
1128 use super::*;
1130 use std::thread;
1274 extern "C" fn test_sigaction_handler(_: libc::c_int) {} in test_sigaction()
1276 _: libc::c_int, in test_sigaction()
1277 _: *mut libc::siginfo_t, in test_sigaction()
1278 _: *mut libc::c_void, in test_sigaction()