aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_loadavg.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2005-05-08 04:32:45 +0000
commitdbf5d92605a9db10e3e3cb154d03a515c5d5c5af (patch)
tree501d5dda3ce90fe924b893e487d9ef9f0683382b /plugin_loadavg.c
parenta1c471e9fb7cadb68bb182ab2e9715a0aa092386 (diff)
downloadlcd4linux-dbf5d92605a9db10e3e3cb154d03a515c5d5c5af.tar.gz
[lcd4linux @ 2005-05-08 04:32:43 by reinelt]
CodingStyle added and applied git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@547 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_loadavg.c')
-rw-r--r--plugin_loadavg.c138
1 files changed, 73 insertions, 65 deletions
diff --git a/plugin_loadavg.c b/plugin_loadavg.c
index e599c68..bdb3091 100644
--- a/plugin_loadavg.c
+++ b/plugin_loadavg.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_loadavg.c,v 1.9 2005/01/18 06:30:23 reinelt Exp $
+/* $Id: plugin_loadavg.c,v 1.10 2005/05/08 04:32:44 reinelt Exp $
*
* plugin for load average
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_loadavg.c,v $
+ * Revision 1.10 2005/05/08 04:32:44 reinelt
+ * CodingStyle added and applied
+ *
* Revision 1.9 2005/01/18 06:30:23 reinelt
* added (C) to all copyright statements
*
@@ -99,86 +102,91 @@
#ifndef HAVE_GETLOADAVG
static int fd = -2;
-int getloadavg (double loadavg[], int nelem)
+int getloadavg(double loadavg[], int nelem)
{
- char buf[65], *p;
- ssize_t nread;
- int i;
-
- if (fd == -2) fd = open ("/proc/loadavg", O_RDONLY);
- if (fd < 0) return -1;
-
- lseek(fd,0,SEEK_SET);
- nread = read (fd, buf, sizeof buf - 1);
-
- if (nread < 0) return -1;
- buf[nread - 1] = '\0';
-
- if (nelem > 3) nelem = 3;
- p = buf;
- for (i = 0; i < nelem; ++i) {
- char *endp;
- loadavg[i] = strtod (p, &endp);
- if (endp == NULL || endp == p)
- /* This should not happen. The format of /proc/loadavg
- must have changed. Don't return with what we have,
- signal an error. */
- return -1;
- p = endp;
- }
-
- return i;
+ char buf[65], *p;
+ ssize_t nread;
+ int i;
+
+ if (fd == -2)
+ fd = open("/proc/loadavg", O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ lseek(fd, 0, SEEK_SET);
+ nread = read(fd, buf, sizeof buf - 1);
+
+ if (nread < 0)
+ return -1;
+ buf[nread - 1] = '\0';
+
+ if (nelem > 3)
+ nelem = 3;
+ p = buf;
+ for (i = 0; i < nelem; ++i) {
+ char *endp;
+ loadavg[i] = strtod(p, &endp);
+ if (endp == NULL || endp == p)
+ /* This should not happen. The format of /proc/loadavg
+ must have changed. Don't return with what we have,
+ signal an error. */
+ return -1;
+ p = endp;
+ }
+
+ return i;
}
#endif
-static void my_loadavg (RESULT *result, RESULT *arg1)
+static void my_loadavg(RESULT * result, RESULT * arg1)
{
- static int nelem=-1;
- int index,age;
- static double loadavg[3];
- static struct timeval last_value;
- struct timeval now;
-
- gettimeofday(&now,NULL);
-
- age = (now.tv_sec - last_value.tv_sec)*1000 + (now.tv_usec - last_value.tv_usec)/1000;
- /* reread every 10 msec only */
- if (nelem==-1 || age==0 || age>10) {
-
- nelem=getloadavg(loadavg, 3);
- if (nelem<0) {
- error ("getloadavg() failed!");
- SetResult(&result, R_STRING, "");
- return;
+ static int nelem = -1;
+ int index, age;
+ static double loadavg[3];
+ static struct timeval last_value;
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+
+ age = (now.tv_sec - last_value.tv_sec) * 1000 + (now.tv_usec - last_value.tv_usec) / 1000;
+ /* reread every 10 msec only */
+ if (nelem == -1 || age == 0 || age > 10) {
+
+ nelem = getloadavg(loadavg, 3);
+ if (nelem < 0) {
+ error("getloadavg() failed!");
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+ last_value = now;
}
- last_value=now;
- }
- index=R2N(arg1);
- if (index<1 || index>nelem) {
- error ("loadavg(%d): index out of range!", index);
- SetResult(&result, R_STRING, "");
+ index = R2N(arg1);
+ if (index < 1 || index > nelem) {
+ error("loadavg(%d): index out of range!", index);
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+
+
+ SetResult(&result, R_NUMBER, &(loadavg[index - 1]));
return;
- }
-
- SetResult(&result, R_NUMBER, &(loadavg[index-1]));
- return;
-
}
-int plugin_init_loadavg (void)
+int plugin_init_loadavg(void)
{
- AddFunction ("loadavg", 1, my_loadavg);
- return 0;
+ AddFunction("loadavg", 1, my_loadavg);
+ return 0;
}
-void plugin_exit_loadavg(void)
+void plugin_exit_loadavg(void)
{
-#ifndef HAVE_GETLOADAVG
- if (fd>0) close(fd);
- fd=-2;
+#ifndef HAVE_GETLOADAVG
+ if (fd > 0)
+ close(fd);
+ fd = -2;
#endif
}