X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fswap.c;h=8d8f7525d1d3ced55c6ff1b8539043ab29223f72;hb=c0f5748983a962f7be82bf49ac6c28a59d4658ff;hp=46d3534fcae818cd6fc286cd448d824ad22ccad8;hpb=3faf514fd9b869cadda0f895e14e5036313c7781;p=collectd.git diff --git a/src/swap.c b/src/swap.c index 46d3534f..8d8f7525 100644 --- a/src/swap.c +++ b/src/swap.c @@ -160,6 +160,8 @@ static int swap_init (void) /* {{{ */ /* #endif defined(VM_SWAPUSAGE) */ #elif HAVE_LIBKVM_GETSWAPINFO + char errbuf[_POSIX2_LINE_MAX]; + if (kvm_obj != NULL) { kvm_close (kvm_obj); @@ -168,14 +170,11 @@ static int swap_init (void) /* {{{ */ kvm_pagesize = getpagesize (); - if ((kvm_obj = kvm_open (NULL, /* execfile */ - NULL, /* corefile */ - NULL, /* swapfile */ - O_RDONLY, /* flags */ - NULL)) /* errstr */ - == NULL) + kvm_obj = kvm_openfiles (NULL, "/dev/null", NULL, O_RDONLY, errbuf); + + if (kvm_obj == NULL) { - ERROR ("swap plugin: kvm_open failed."); + ERROR ("swap plugin: kvm_openfiles failed, %s", errbuf); return (-1); } /* #endif HAVE_LIBKVM_GETSWAPINFO */ @@ -339,7 +338,7 @@ static int swap_read_combined (void) /* {{{ */ fclose (fh); - if (have_data != 0x07) + if ((have_data & 0x03) != 0x03) return (ENOENT); if (isnan (swap_total) @@ -351,7 +350,8 @@ static int swap_read_combined (void) /* {{{ */ swap_submit_gauge (NULL, "used", 1024.0 * swap_used); swap_submit_gauge (NULL, "free", 1024.0 * swap_free); - swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached); + if (have_data & 0x04) + swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached); return (0); } /* }}} int swap_read_combined */ @@ -534,10 +534,10 @@ static int swap_read (void) /* {{{ */ return (0); /* Allocate and initialize the swaptbl_t structure */ - s = (swaptbl_t *) smalloc (swap_num * sizeof (swapent_t) + sizeof (struct swaptable)); + s = malloc (swap_num * sizeof (swapent_t) + sizeof (struct swaptable)); if (s == NULL) { - ERROR ("swap plugin: smalloc failed."); + ERROR ("swap plugin: malloc failed."); return (-1); } @@ -547,7 +547,7 @@ static int swap_read (void) /* {{{ */ s_paths = calloc (swap_num, PATH_MAX); if (s_paths == NULL) { - ERROR ("swap plugin: malloc failed."); + ERROR ("swap plugin: calloc failed."); sfree (s); return (-1); }