diff options
author | Explorer09 <explorer09@gmail.com> | 2023-08-03 09:28:47 +0800 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2023-08-30 17:00:36 +0200 |
commit | 4c08171ebd4395e358ec630306c1268473078046 (patch) | |
tree | 28891a8df1bd788649da519ee8b29f1d42fee736 /dragonflybsd | |
parent | e783cf9f45425c59ef920a3bb6aff53c5e6ddc0f (diff) |
BSD platforms: Reject negative and zero KERN_FSCALE factors
The "fscale" value, retrieved by sysctl() in BSD platforms, is used for
computing CPU percentages of the processes. To prevent a division by
zero, we should reject a zero "fscale" value. (A negative "fscale"
value will not make sense either.)
For DragonFlyBSD and FreeBSD, this would fall back to the hard-coded
default scale.
For NetBSD and OpenBSD, there is no hard-coded default value, so the
zero or negative "fscale" is now a fatal error.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'dragonflybsd')
-rw-r--r-- | dragonflybsd/DragonFlyBSDMachine.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/dragonflybsd/DragonFlyBSDMachine.c b/dragonflybsd/DragonFlyBSDMachine.c index e1da417b..04962d7c 100644 --- a/dragonflybsd/DragonFlyBSDMachine.c +++ b/dragonflybsd/DragonFlyBSDMachine.c @@ -105,7 +105,7 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) { } len = sizeof(this->kernelFScale); - if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1) { + if (sysctlbyname("kern.fscale", &this->kernelFScale, &len, NULL, 0) == -1 || this->kernelFScale <= 0) { //sane default for kernel provided CPU percentage scaling, at least on x86 machines, in case this sysctl call failed this->kernelFScale = 2048; } |