Skip to content

Commit c1a3f6f

Browse files
oech3sylvestre
authored andcommitted
nproc: Reject quota with some schedulers
1 parent 76c63ee commit c1a3f6f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/uu/nproc/src/nproc.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr sysconf
6+
// spell-checker:ignore (ToDO) NPROCESSORS SCHED getscheduler nprocs numstr sched sysconf
77

88
use clap::{Arg, ArgAction, Command};
99
use std::io::{Write, stdout};
@@ -67,7 +67,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6767
}
6868
// the variable 'OMP_NUM_THREADS' doesn't exist
6969
// fallback to the regular CPU detection
70-
Err(_) => available_parallelism(),
70+
Err(_) => {
71+
// ignore quota under some schedulers
72+
#[cfg(any(target_os = "linux", target_os = "android"))]
73+
match unsafe { libc::sched_getscheduler(0) } {
74+
libc::SCHED_FIFO | libc::SCHED_RR | libc::SCHED_DEADLINE => num_cpus_all(),
75+
_ => available_parallelism(), // include fallback for error
76+
}
77+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
78+
available_parallelism()
79+
}
7180
}
7281
};
7382

0 commit comments

Comments
 (0)