Skip to content

Commit

Permalink
Add support in uucore for illumos and solaris (#5489)
Browse files Browse the repository at this point in the history
* uucore support for illumos and solaris

* use macro to consolidate illumos and solaris signals

* fixing some CI issues

* replaced macro with better cfg usage
  • Loading branch information
bbarker authored Nov 4, 2023
1 parent 347bded commit 44d105d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ impl FileInformation {
not(target_os = "android"),
not(target_os = "freebsd"),
not(target_os = "netbsd"),
not(target_os = "illumos"),
not(target_os = "solaris"),
not(target_arch = "aarch64"),
not(target_arch = "riscv64"),
target_pointer_width = "64"
Expand All @@ -127,6 +129,8 @@ impl FileInformation {
target_os = "android",
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_arch = "aarch64",
target_arch = "riscv64",
not(target_pointer_width = "64")
Expand Down
13 changes: 11 additions & 2 deletions src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ use std::convert::{AsRef, From};
target_os = "openbsd",
target_os = "linux",
target_os = "android",
target_os = "illumos",
target_os = "solaris",
))]
use std::ffi::CStr;
#[cfg(not(windows))]
Expand Down Expand Up @@ -309,7 +311,7 @@ impl MountInfo {
target_os = "freebsd",
target_vendor = "apple",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
impl From<StatFs> for MountInfo {
fn from(statfs: StatFs) -> Self {
Expand Down Expand Up @@ -615,6 +617,8 @@ impl FsMeta for StatFs {
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
not(target_os = "illumos"),
not(target_os = "solaris"),
not(target_arch = "s390x"),
target_pointer_width = "64"
))]
Expand All @@ -630,7 +634,12 @@ impl FsMeta for StatFs {
)
))]
return self.f_bsize.into();
#[cfg(any(target_env = "musl", target_os = "freebsd"))]
#[cfg(any(
target_env = "musl",
target_os = "freebsd",
target_os = "illumos",
target_os = "solaris"
))]
return self.f_bsize.try_into().unwrap();
}
fn total_blocks(&self) -> u64 {
Expand Down
116 changes: 114 additions & 2 deletions src/uucore/src/lib/features/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (vars/api) fcntl setrlimit setitimer
// spell-checker:ignore (vars/signals) ABRT ALRM CHLD SEGV SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGEMT SIGFPE SIGHUP SIGILL SIGINFO SIGINT SIGIO SIGIOT SIGKILL SIGPIPE SIGPROF SIGPWR SIGQUIT SIGSEGV SIGSTOP SIGSYS SIGTERM SIGTRAP SIGTSTP SIGTHR SIGTTIN SIGTTOU SIGURG SIGUSR SIGVTALRM SIGWINCH SIGXCPU SIGXFSZ STKFLT PWR THR TSTP TTIN TTOU VTALRM XCPU XFSZ
// spell-checker:ignore (vars/api) fcntl setrlimit setitimer rubout pollable occured sysconf
// spell-checker:ignore (vars/signals) ABRT ALRM CHLD SEGV SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGEMT SIGFPE SIGHUP SIGILL SIGINFO SIGINT SIGIO SIGIOT SIGKILL SIGPIPE SIGPROF SIGPWR SIGQUIT SIGSEGV SIGSTOP SIGSYS SIGTERM SIGTRAP SIGTSTP SIGTHR SIGTTIN SIGTTOU SIGURG SIGUSR SIGVTALRM SIGWINCH SIGXCPU SIGXFSZ STKFLT PWR THR TSTP TTIN TTOU VTALRM XCPU XFSZ SIGCLD SIGPOLL SIGWAITING SIGAIOCANCEL SIGLWP SIGFREEZE SIGTHAW SIGCANCEL SIGLOST SIGXRES SIGJVM SIGRTMIN SIGRT SIGRTMAX AIOCANCEL XRES RTMIN RTMAX
#[cfg(unix)]
use nix::errno::Errno;
#[cfg(unix)]
use nix::sys::signal::{
signal, SigHandler::SigDfl, SigHandler::SigIgn, Signal::SIGINT, Signal::SIGPIPE,
};

pub static DEFAULT_SIGNAL: usize = 15;

/*
Expand Down Expand Up @@ -178,6 +179,117 @@ pub static ALL_SIGNALS: [&str; 33] = [
"XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "INFO", "USR1", "USR2", "THR",
];

/*
The following signals are defined in Solaris and illumos;
(the signals for illumos are the same as Solaris, but illumos still has SIGLWP
as well as the alias for SIGLWP (SIGAIOCANCEL)):
SIGHUP 1 hangup
SIGINT 2 interrupt (rubout)
SIGQUIT 3 quit (ASCII FS)
SIGILL 4 illegal instruction (not reset when caught)
SIGTRAP 5 trace trap (not reset when caught)
SIGIOT 6 IOT instruction
SIGABRT 6 used by abort, replace SIGIOT in the future
SIGEMT 7 EMT instruction
SIGFPE 8 floating point exception
SIGKILL 9 kill (cannot be caught or ignored)
SIGBUS 10 bus error
SIGSEGV 11 segmentation violation
SIGSYS 12 bad argument to system call
SIGPIPE 13 write on a pipe with no one to read it
SIGALRM 14 alarm clock
SIGTERM 15 software termination signal from kill
SIGUSR1 16 user defined signal 1
SIGUSR2 17 user defined signal 2
SIGCLD 18 child status change
SIGCHLD 18 child status change alias (POSIX)
SIGPWR 19 power-fail restart
SIGWINCH 20 window size change
SIGURG 21 urgent socket condition
SIGPOLL 22 pollable event occured
SIGIO SIGPOLL socket I/O possible (SIGPOLL alias)
SIGSTOP 23 stop (cannot be caught or ignored)
SIGTSTP 24 user stop requested from tty
SIGCONT 25 stopped process has been continued
SIGTTIN 26 background tty read attempted
SIGTTOU 27 background tty write attempted
SIGVTALRM 28 virtual timer expired
SIGPROF 29 profiling timer expired
SIGXCPU 30 exceeded cpu limit
SIGXFSZ 31 exceeded file size limit
SIGWAITING 32 reserved signal no longer used by threading code
SIGAIOCANCEL 33 reserved signal no longer used by threading code (formerly SIGLWP)
SIGFREEZE 34 special signal used by CPR
SIGTHAW 35 special signal used by CPR
SIGCANCEL 36 reserved signal for thread cancellation
SIGLOST 37 resource lost (eg, record-lock lost)
SIGXRES 38 resource control exceeded
SIGJVM1 39 reserved signal for Java Virtual Machine
SIGJVM2 40 reserved signal for Java Virtual Machine
SIGINFO 41 information request
SIGRTMIN ((int)_sysconf(_SC_SIGRT_MIN)) first realtime signal
SIGRTMAX ((int)_sysconf(_SC_SIGRT_MAX)) last realtime signal
*/

#[cfg(target_os = "solaris")]
const SIGNALS_SIZE: usize = 46;

#[cfg(target_os = "illumos")]
const SIGNALS_SIZE: usize = 47;

#[cfg(any(target_os = "solaris", target_os = "illumos"))]
static ALL_SIGNALS: [&str; SIGNALS_SIZE] = [
"HUP",
"INT",
"QUIT",
"ILL",
"TRAP",
"IOT",
"ABRT",
"EMT",
"FPE",
"KILL",
"BUS",
"SEGV",
"SYS",
"PIPE",
"ALRM",
"TERM",
"USR1",
"USR2",
"CLD",
"CHLD",
"PWR",
"WINCH",
"URG",
"POLL",
"IO",
"STOP",
"TSTP",
"CONT",
"TTIN",
"TTOU",
"VTALRM",
"PROF",
"XCPU",
"XFSZ",
"WAITING",
"AIOCANCEL",
#[cfg(target_os = "illumos")]
"LWP",
"FREEZE",
"THAW",
"CANCEL",
"LOST",
"XRES",
"JVM1",
"JVM2",
"INFO",
"RTMIN",
"RTMAX",
];

pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<usize> {
if let Ok(value) = signal_name_or_value.parse() {
if is_signal(value) {
Expand Down

0 comments on commit 44d105d

Please sign in to comment.