Created attachment 166300 [details] Patch for the atrun source The atrun utility needs the number of CPUs for calculating the load limit. If the average load is lower than that limit the next pending batch job is started. The number of CPUs is retrieved with an call to 'sysctlbyname'. This subroutine writes the number (which is an integer) to the "ncpu" variable. The variable ist defined as size_t, which is an unsigned integer but is never initalized. So the result of this operation is undefined. The value of ncpu after calling sysctlbyname: current version: 34359738369 patched version: 1
Created attachment 166306 [details] Fix ncpu type I believe that you found the issue, but your fix is not right. E.g., the problem of invalid ncpu value would be still present on the big-endian LP64 machines. The fix is to use int type, consistent with the type expected by the hw.ncpu MIB.
A commit references this bug: Author: ngie Date: Sat Jan 30 17:54:18 UTC 2016 New revision: 295079 URL: https://svnweb.freebsd.org/changeset/base/295079 Log: Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on 64-bit architectures where sizeof(int) != sizeof(size_t). MFC after: 1 week PR: 206758 Reported by: Christoph Sch?nweiler <public2016@hauptsignal.at> Submitted by: kib Sponsored by: EMC / Isilon Storage Division Changes: head/libexec/atrun/atrun.c
Thank you for the submission/patch. I proved that it was doing the wrong thing by adding a printf(3) after the sysctlbyname call on my amd64 VM.
Any update with this patch on MFC to 10-STABLE?
A commit references this bug: Author: ngie Date: Sat Mar 12 19:09:52 UTC 2016 New revision: 296756 URL: https://svnweb.freebsd.org/changeset/base/296756 Log: MFC r295079: Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on 64-bit architectures where sizeof(int) != sizeof(size_t). PR: 206758 Changes: _U stable/10/ stable/10/libexec/atrun/atrun.c
A commit references this bug: Author: ngie Date: Sat Mar 12 19:11:45 UTC 2016 New revision: 296757 URL: https://svnweb.freebsd.org/changeset/base/296757 Log: MFstable/10 r296756: MFC r295079: Fix the type for hw.ncpu, so sysctlbyname doesn't consistently fail on 64-bit architectures where sizeof(int) != sizeof(size_t). PR: 206758 Changes: _U stable/9/ _U stable/9/libexec/atrun/ stable/9/libexec/atrun/atrun.c
(In reply to op from comment #4) I just MFCed it to stable/10.