From: Florian Forster Date: Mon, 16 Feb 2009 12:34:44 +0000 (+0100) Subject: swap plugin: Be more sensitive about integer sizes in the *BSD code. X-Git-Tag: collectd-4.6.0~15 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=2244db315b2e13c47a4e4406f607a66e80dea450 swap plugin: Be more sensitive about integer sizes in the *BSD code. --- diff --git a/src/swap.c b/src/swap.c index bcfe4a22..ca3b5efa 100644 --- a/src/swap.c +++ b/src/swap.c @@ -298,9 +298,9 @@ static int swap_read (void) } #if defined(DEV_BSIZE) && (DEV_BSIZE > 0) -# define C_SWAP_BLOCK_SIZE DEV_BSIZE +# define C_SWAP_BLOCK_SIZE ((uint64_t) DEV_BSIZE) #else -# define C_SWAP_BLOCK_SIZE 512 +# define C_SWAP_BLOCK_SIZE ((uint64_t) 512) #endif for (i = 0; i < swap_num; i++) @@ -308,8 +308,18 @@ static int swap_read (void) if ((swap_entries[i].se_flags & SWF_ENABLE) == 0) continue; - used += swap_entries[i].se_inuse * C_SWAP_BLOCK_SIZE; - total += swap_entries[i].se_nblks * C_SWAP_BLOCK_SIZE; + used += ((uint64_t) swap_entries[i].se_inuse) + * C_SWAP_BLOCK_SIZE; + total += ((uint64_t) swap_entries[i].se_nblks) + * C_SWAP_BLOCK_SIZE; + } + + if (total < used) + { + ERROR ("swap plugin: Total swap space (%"PRIu64") " + "is less than used swap space (%"PRIu64").", + total, used); + return (-1); } swap_submit ("used", (gauge_t) used);