Skip to content

Commit b1fbab8

Browse files
Merge branch 'main' into feature/top-ni-pr
2 parents 5839069 + 77bbe0f commit b1fbab8

File tree

17 files changed

+385
-168
lines changed

17 files changed

+385
-168
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
- name: build and test all programs separately
5353
shell: bash
5454
run: |
55-
## TODO: add hugetop and skill
56-
programs="free pgrep pidof pidwait pkill pmap ps pwdx slabtop snice sysctl tload top vmstat w watch"
55+
## TODO: add hugetop
56+
programs="free pgrep pidof pidwait pkill pmap ps pwdx skill slabtop snice sysctl tload top vmstat w watch"
5757
for program in $programs; do
5858
echo "Building and testing $program"
5959
cargo test -p "uu_$program" || exit 1

Cargo.lock

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ feat_common_core = [
4040
"pmap",
4141
"ps",
4242
"pwdx",
43+
"skill",
4344
"slabtop",
4445
"snice",
4546
"sysctl",
@@ -98,6 +99,7 @@ pkill = { optional = true, version = "0.0.1", package = "uu_pkill", path = "src/
9899
pmap = { optional = true, version = "0.0.1", package = "uu_pmap", path = "src/uu/pmap" }
99100
ps = { optional = true, version = "0.0.1", package = "uu_ps", path = "src/uu/ps" }
100101
pwdx = { optional = true, version = "0.0.1", package = "uu_pwdx", path = "src/uu/pwdx" }
102+
skill = { optional = true, version = "0.0.1", package = "uu_skill", path = "src/uu/skill" }
101103
slabtop = { optional = true, version = "0.0.1", package = "uu_slabtop", path = "src/uu/slabtop" }
102104
snice = { optional = true, version = "0.0.1", package = "uu_snice", path = "src/uu/snice" }
103105
sysctl = { optional = true, version = "0.0.1", package = "uu_sysctl", path = "src/uu/sysctl" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Ongoing:
2020
* `pmap`: Displays the memory map of a process.
2121
* `ps`: Displays information about active processes.
2222
* `pwdx`: Shows the current working directory of a process.
23+
* `skill`: Sends a signal to processes based on criteria like user, terminal, etc.
2324
* `slabtop`: Displays detailed kernel slab cache information in real time.
2425
* `snice`: Changes the scheduling priority of a running process.
2526
* `sysctl`: Read or write kernel parameters at run-time.
@@ -31,7 +32,6 @@ Ongoing:
3132

3233
TODO:
3334
* `hugetop`: Report hugepage usage of processes and the system as a whole.
34-
* `skill`: Sends a signal to processes based on criteria like user, terminal, etc.
3535

3636
Elsewhere:
3737

src/uu/pkill/src/pkill.rs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55

66
// Pid utils
7-
use clap::{arg, crate_version, Command};
7+
use clap::{arg, crate_version, value_parser, Command};
88
#[cfg(unix)]
99
use nix::{
1010
sys::signal::{self, Signal},
@@ -48,19 +48,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4848
} else {
4949
let sig = (settings.signal as i32)
5050
.try_into()
51-
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
51+
.map_err(|e| Error::from_raw_os_error(e as i32))?;
5252
Some(sig)
5353
};
5454

5555
// Collect pids
5656
let pids = process_matcher::find_matching_pids(&settings)?;
5757

5858
// Send signal
59-
// TODO: Implement -q
6059
#[cfg(unix)]
61-
let echo = matches.get_flag("echo");
62-
#[cfg(unix)]
63-
kill(&pids, sig, echo);
60+
{
61+
let echo = matches.get_flag("echo");
62+
let queue = matches.get_one::<u32>("queue").cloned();
63+
64+
kill(&pids, sig, queue, echo);
65+
}
6466

6567
if matches.get_flag("count") {
6668
println!("{}", pids.len());
@@ -71,25 +73,50 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7173

7274
#[cfg(unix)]
7375
fn handle_obsolete(args: &mut [String]) {
74-
// Sanity check
75-
if args.len() > 2 {
76-
// Old signal can only be in the first argument position
77-
let slice = args[1].as_str();
78-
if let Some(signal) = slice.strip_prefix('-') {
76+
for arg in &mut args[1..] {
77+
if let Some(signal) = arg.strip_prefix('-') {
7978
// Check if it is a valid signal
8079
let opt_signal = signal_by_name_or_value(signal);
8180
if opt_signal.is_some() {
8281
// Replace with long option that clap can parse
83-
args[1] = format!("--signal={signal}");
82+
*arg = format!("--signal={signal}");
8483
}
8584
}
8685
}
8786
}
8887

88+
// Not contains in libc
89+
#[cfg(target_os = "linux")]
90+
extern "C" {
91+
fn sigqueue(
92+
pid: uucore::libc::pid_t,
93+
sig: uucore::libc::c_int,
94+
val: uucore::libc::sigval,
95+
) -> uucore::libc::c_int;
96+
}
97+
8998
#[cfg(unix)]
90-
fn kill(pids: &Vec<ProcessInformation>, sig: Option<Signal>, echo: bool) {
99+
#[allow(unused_variables)]
100+
fn kill(pids: &Vec<ProcessInformation>, sig: Option<Signal>, queue: Option<u32>, echo: bool) {
91101
for pid in pids {
92-
if let Err(e) = signal::kill(Pid::from_raw(pid.pid as i32), sig) {
102+
#[cfg(target_os = "linux")]
103+
let result = if let Some(queue) = queue {
104+
let v = unsafe {
105+
sigqueue(
106+
pid.pid as i32,
107+
sig.map_or(0, |s| s as uucore::libc::c_int),
108+
uucore::libc::sigval {
109+
sival_ptr: queue as usize as *mut uucore::libc::c_void,
110+
},
111+
)
112+
};
113+
nix::errno::Errno::result(v).map(drop)
114+
} else {
115+
signal::kill(Pid::from_raw(pid.pid as i32), sig)
116+
};
117+
#[cfg(not(target_os = "linux"))]
118+
let result = signal::kill(Pid::from_raw(pid.pid as i32), sig);
119+
if let Err(e) = result {
93120
show!(Error::from_raw_os_error(e as i32)
94121
.map_err_context(|| format!("killing pid {} failed", pid.pid)));
95122
} else if echo {
@@ -111,7 +138,8 @@ pub fn uu_app() -> Command {
111138
.args_override_self(true)
112139
.args([
113140
// arg!(-<sig> "signal to send (either number or name)"),
114-
// arg!(-q --queue <value> "integer value to be sent with the signal"),
141+
arg!(-q --queue <value> "integer value to be sent with the signal")
142+
.value_parser(value_parser!(u32)),
115143
arg!(-e --echo "display what is killed"),
116144
])
117145
.args(process_matcher::clap_args(

src/uu/pmap/src/maps_format_parser.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -378,27 +378,27 @@ mod test {
378378
limit_address_range_and_assert(&address, 0x0, low - 1, false);
379379
limit_address_range_and_assert(&address, low - 1, low - 1, false);
380380

381-
limit_address_range_and_assert(&address, 0x0, low + 0, true);
382-
limit_address_range_and_assert(&address, low - 1, low + 0, true);
383-
limit_address_range_and_assert(&address, low + 0, low + 0, true);
381+
limit_address_range_and_assert(&address, 0x0, low, true);
382+
limit_address_range_and_assert(&address, low - 1, low, true);
383+
limit_address_range_and_assert(&address, low, low, true);
384384

385385
limit_address_range_and_assert(&address, low - 1, high - 1, true);
386-
limit_address_range_and_assert(&address, low - 1, high + 0, true);
386+
limit_address_range_and_assert(&address, low - 1, high, true);
387387
limit_address_range_and_assert(&address, low - 1, high + 1, true);
388-
limit_address_range_and_assert(&address, low + 0, high - 1, true);
389-
limit_address_range_and_assert(&address, low + 0, high + 0, true);
390-
limit_address_range_and_assert(&address, low + 0, high + 1, true);
388+
limit_address_range_and_assert(&address, low, high - 1, true);
389+
limit_address_range_and_assert(&address, low, high, true);
390+
limit_address_range_and_assert(&address, low, high + 1, true);
391391
limit_address_range_and_assert(&address, low + 1, high - 1, true);
392-
limit_address_range_and_assert(&address, low + 1, high + 0, true);
392+
limit_address_range_and_assert(&address, low + 1, high, true);
393393
limit_address_range_and_assert(&address, low + 1, high + 1, true);
394394

395395
limit_address_range_and_assert(&address, high - 1, high - 1, true);
396-
limit_address_range_and_assert(&address, high - 1, high + 0, true);
396+
limit_address_range_and_assert(&address, high - 1, high, true);
397397
limit_address_range_and_assert(&address, high - 1, u64::MAX, true);
398398

399-
limit_address_range_and_assert(&address, high + 0, high + 0, false);
400-
limit_address_range_and_assert(&address, high + 0, high + 1, false);
401-
limit_address_range_and_assert(&address, high + 0, u64::MAX, false);
399+
limit_address_range_and_assert(&address, high, high, false);
400+
limit_address_range_and_assert(&address, high, high + 1, false);
401+
limit_address_range_and_assert(&address, high, u64::MAX, false);
402402
limit_address_range_and_assert(&address, 0xffffffffffff, u64::MAX, false);
403403
limit_address_range_and_assert(&address, u64::MAX, u64::MAX, false);
404404

@@ -411,24 +411,24 @@ mod test {
411411
limit_address_range_and_assert(&address, low - 1, 0x0, false);
412412
limit_address_range_and_assert(&address, low - 1, low - 1, false);
413413

414-
limit_address_range_and_assert(&address, low + 0, 0x0, false);
415-
limit_address_range_and_assert(&address, low + 0, low - 1, false);
414+
limit_address_range_and_assert(&address, low, 0x0, false);
415+
limit_address_range_and_assert(&address, low, low - 1, false);
416416

417417
limit_address_range_and_assert(&address, high - 1, low - 1, false);
418-
limit_address_range_and_assert(&address, high + 0, low - 1, false);
418+
limit_address_range_and_assert(&address, high, low - 1, false);
419419
limit_address_range_and_assert(&address, high + 1, low - 1, false);
420-
limit_address_range_and_assert(&address, high - 1, low + 0, true); // true
421-
limit_address_range_and_assert(&address, high + 0, low + 0, false);
422-
limit_address_range_and_assert(&address, high + 1, low + 0, false);
423-
limit_address_range_and_assert(&address, high - 1, low + 1, true); // true
424-
limit_address_range_and_assert(&address, high + 0, low + 1, false);
420+
limit_address_range_and_assert(&address, high - 1, low, true);
421+
limit_address_range_and_assert(&address, high, low, false);
422+
limit_address_range_and_assert(&address, high + 1, low, false);
423+
limit_address_range_and_assert(&address, high - 1, low + 1, true);
424+
limit_address_range_and_assert(&address, high, low + 1, false);
425425
limit_address_range_and_assert(&address, high + 1, low + 1, false);
426426

427-
limit_address_range_and_assert(&address, high + 0, high - 1, false);
427+
limit_address_range_and_assert(&address, high, high - 1, false);
428428
limit_address_range_and_assert(&address, u64::MAX, high - 1, false);
429429

430-
limit_address_range_and_assert(&address, high + 1, high + 0, false);
431-
limit_address_range_and_assert(&address, u64::MAX, high + 0, false);
430+
limit_address_range_and_assert(&address, high + 1, high, false);
431+
limit_address_range_and_assert(&address, u64::MAX, high, false);
432432
limit_address_range_and_assert(&address, u64::MAX, 0xffffffffffff, false);
433433
}
434434

src/uu/skill/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "uu_skill"
3+
description = "skill - (uutils) send a signal or report process status"
4+
repository = "https://github.com/uutils/procps/tree/main/src/uu/skill"
5+
authors.workspace = true
6+
categories.workspace = true
7+
edition.workspace = true
8+
homepage.workspace = true
9+
keywords.workspace = true
10+
license.workspace = true
11+
version.workspace = true
12+
13+
[dependencies]
14+
uucore = { workspace = true, features = ["signals"] }
15+
clap = { workspace = true }
16+
nix = { workspace = true }
17+
18+
uu_snice = { path = "../snice" }
19+
20+
21+
[lib]
22+
path = "src/skill.rs"
23+
24+
[[bin]]
25+
name = "skill"
26+
path = "src/main.rs"

src/uu/skill/skill.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# skill
2+
3+
```
4+
skill [signal] [options] <expression>
5+
```
6+
7+
Report processes matching an expression and send a signal to them.

src/uu/skill/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uucore::bin!(uu_skill);

0 commit comments

Comments
 (0)