Skip to content

Commit

Permalink
#557 (NetBSD): fix mem swap fun
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 8, 2016
1 parent 01564d8 commit bc6cf43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion psutil/_psutil_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ psutil_proc_memory_info(PyObject *self, PyObject *args) {
if (psutil_kinfo_proc(pid, &kp) == -1)
return NULL;


return Py_BuildValue(
"(lllll)",
#ifdef __FreeBSD__
Expand Down
12 changes: 5 additions & 7 deletions psutil/arch/bsd/netbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,24 @@ psutil_swap_mem(PyObject *self, PyObject *args) {
struct swapent *swdev;
int nswap, i;

if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0) {
warn("failed to get swap device count");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap == 0) {
// This means there's no swap partition.
return Py_BuildValue("(iiiii)", 0, 0, 0, 0, 0);
}

if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL) {
warn("failed to allocate memory for swdev structures");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
free(swdev);
warn("failed to get swap stats");
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

// Total things up
// Total things up.
swap_total = swap_free = 0;
for (i = 0; i < nswap; i++) {
if (swdev[i].se_flags & SWF_ENABLE) {
Expand Down

0 comments on commit bc6cf43

Please sign in to comment.