diff options
author | Robert Rothenberg <rrwo@cpan.org> | 2020-03-25 08:46:15 +0000 |
---|---|---|
committer | Robert Rothenberg <rrwo@cpan.org> | 2020-03-25 08:46:15 +0000 |
commit | 5760e153862336ceedcf1631ef9027c050996786 (patch) | |
tree | 0f07953cf80013013dcc47deba58fad4f0199c3d | |
parent | 0ec74226825cfcb40ee601e0ee8832d4fbe299c8 (diff) |
Check return value of getloadavg, fixes #4
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | CpuLoad.xs | 18 |
2 files changed, 16 insertions, 5 deletions
@@ -1,6 +1,9 @@ Revision history for Perl extension {{$dist->name}}: {{$NEXT}} + [Bug Fixes] + - The return value of getloadavg is now checked, #4. + [Documentation] - Update POD about changes in version 0.12. @@ -17,11 +17,19 @@ void _getbsdload() PREINIT: double loadavg[3]; + int nelem; PPCODE: #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__linux__) - getloadavg(loadavg, 3); + nelem = getloadavg(loadavg, 3); +#else + nelem = -1; #endif - EXTEND(SP, 3); - PUSHs(sv_2mortal(newSVnv(loadavg[0]))); - PUSHs(sv_2mortal(newSVnv(loadavg[1]))); - PUSHs(sv_2mortal(newSVnv(loadavg[2]))); + if (nelem != -1) { + EXTEND(SP, 3); + PUSHs(sv_2mortal(newSVnv(loadavg[0]))); + PUSHs(sv_2mortal(newSVnv(loadavg[1]))); + PUSHs(sv_2mortal(newSVnv(loadavg[2]))); + } + else { + XSRETURN_UNDEF; + } |