Skip to content

Commit

Permalink
fix: correct arg type of prctl::set_timerslack (#2505)
Browse files Browse the repository at this point in the history
* fix: correct arg type of prctl::set_timerslack

* test: update test
  • Loading branch information
SteveLauC authored Sep 15, 2024
1 parent 7d75bbc commit 9b69cff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/2505.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `ns` argument of `sys::prctl::set_timerslack()` should be of type `c_ulong`
2 changes: 1 addition & 1 deletion src/sys/prctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn get_name() -> Result<CString> {

/// Sets the timer slack value for the calling thread. Timer slack is used by the kernel to group
/// timer expirations and make them the supplied amount of nanoseconds late.
pub fn set_timerslack(ns: u64) -> Result<()> {
pub fn set_timerslack(ns: c_ulong) -> Result<()> {
let res = unsafe { libc::prctl(libc::PR_SET_TIMERSLACK, ns, 0, 0, 0) };

Errno::result(res).map(drop)
Expand Down
8 changes: 4 additions & 4 deletions test/sys/test_prctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ mod test_prctl {
#[cfg_attr(qemu, ignore)]
#[test]
fn test_get_set_timerslack() {
let original = prctl::get_timerslack().unwrap();
let original = prctl::get_timerslack().unwrap() as libc::c_ulong;

let slack = 60_000;
prctl::set_timerslack(slack).unwrap();
let res = prctl::get_timerslack().unwrap();
assert_eq!(slack, res as u64);
let res = prctl::get_timerslack().unwrap() as libc::c_ulong;
assert_eq!(slack, res);

prctl::set_timerslack(original as u64).unwrap();
prctl::set_timerslack(original).unwrap();
}

#[test]
Expand Down

0 comments on commit 9b69cff

Please sign in to comment.