X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcontextswitch.c;h=c207318f9d62425fbfb18e7e86727bce62b65bcb;hb=ab3724ba43c8d86d5c0bc3c777ff0f5aab44dc33;hp=56d8bf09ee490f79bf148eaff6d67947ad98d1f2;hpb=1538fa84b575c8cc8fc19345c7bc597a2069f19d;p=collectd.git diff --git a/src/contextswitch.c b/src/contextswitch.c index 56d8bf09..c207318f 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -1,6 +1,7 @@ /** * collectd - src/contextswitch.c * Copyright (C) 2009 Patrik Weiskircher + * Copyright (C) 2010 Kimo Rosenbaum * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,6 +18,7 @@ * * Authors: * Patrik Weiskircher + * Kimo Rosenbaum **/ #include "collectd.h" @@ -57,29 +59,31 @@ static void cs_submit (derive_t context_switches) static int cs_read (void) { - int status = -2; #if HAVE_SYSCTLBYNAME - int value; + int value = 0; size_t value_len = sizeof (value); + int status; - if (sysctlbyname ("vm.stats.sys.v_swtch", (void *) &value, &value_len, - NULL, 0) == 0) - { - cs_submit(value); - status = 0; - } - else + status = sysctlbyname ("vm.stats.sys.v_swtch", + &value, &value_len, + /* new pointer = */ NULL, /* new length = */ 0); + if (status != 0) { - ERROR("contextswitch plugin: sysctlbyname failed"); + ERROR("contextswitch plugin: sysctlbyname " + "(vm.stats.sys.v_swtch) failed"); + return (-1); } + cs_submit (value); /* #endif HAVE_SYSCTLBYNAME */ + #elif KERNEL_LINUX FILE *fh; char buffer[64]; int numfields; char *fields[3]; derive_t result = 0; + int status = -2; fh = fopen ("/proc/stat", "r"); if (fh == NULL) {