From: Pavel Rochnyack Date: Sat, 27 Oct 2018 07:57:11 +0000 (+0700) Subject: swap plugin: Drop support for Linux 2.4. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c6b9bda2432a1f46712b8b64aa2b5e45a4d9f8b5;p=collectd.git swap plugin: Drop support for Linux 2.4. Related: #2955 --- diff --git a/src/swap.c b/src/swap.c index db0b987c..929df6db 100644 --- a/src/swap.c +++ b/src/swap.c @@ -332,52 +332,31 @@ static int swap_read_combined(void) /* {{{ */ static int swap_read_io(void) /* {{{ */ { - FILE *fh; char buffer[1024]; - bool old_kernel = false; - uint8_t have_data = 0; derive_t swap_in = 0; derive_t swap_out = 0; - fh = fopen("/proc/vmstat", "r"); + FILE *fh = fopen("/proc/vmstat", "r"); if (fh == NULL) { - /* /proc/vmstat does not exist in kernels <2.6 */ - fh = fopen("/proc/stat", "r"); - if (fh == NULL) { - WARNING("swap: fopen: %s", STRERRNO); - return -1; - } else - old_kernel = true; + WARNING("swap: fopen(/proc/vmstat): %s", STRERRNO); + return -1; } while (fgets(buffer, sizeof(buffer), fh) != NULL) { char *fields[8]; - int numfields; + int numfields = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields)); - numfields = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields)); + if (numfields != 2) + continue; - if (!old_kernel) { - if (numfields != 2) - continue; - - if (strcasecmp("pswpin", fields[0]) == 0) { - strtoderive(fields[1], &swap_in); - have_data |= 0x01; - } else if (strcasecmp("pswpout", fields[0]) == 0) { - strtoderive(fields[1], &swap_out); - have_data |= 0x02; - } - } else /* if (old_kernel) */ - { - if (numfields != 3) - continue; - - if (strcasecmp("page", fields[0]) == 0) { - strtoderive(fields[1], &swap_in); - strtoderive(fields[2], &swap_out); - } + if (strcasecmp("pswpin", fields[0]) == 0) { + strtoderive(fields[1], &swap_in); + have_data |= 0x01; + } else if (strcasecmp("pswpout", fields[0]) == 0) { + strtoderive(fields[1], &swap_out); + have_data |= 0x02; } } /* while (fgets) */