aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_loadavg.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-03-11 06:39:59 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-03-11 06:39:59 +0000
commit7d5c275cb8df79637212dc89ab980dabfc39a6df (patch)
treee3f51842280e06133de00726fa987765d4464f10 /plugin_loadavg.c
parenta3501369a917c15bdba91811a32c271bbc5dc5b0 (diff)
downloadlcd4linux-7d5c275cb8df79637212dc89ab980dabfc39a6df.tar.gz
[lcd4linux @ 2004-03-11 06:39:58 by reinelt]
big patch from Martin: - reuse filehandles - memory leaks fixed - earlier busy-flag checking with HD44780 - reuse memory for strings in RESULT and hash - netdev_fast to wavid time-consuming regex git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@393 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_loadavg.c')
-rw-r--r--plugin_loadavg.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/plugin_loadavg.c b/plugin_loadavg.c
index 2c63310..4c868b0 100644
--- a/plugin_loadavg.c
+++ b/plugin_loadavg.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_loadavg.c,v 1.5 2004/03/08 18:46:21 hejl Exp $
+/* $Id: plugin_loadavg.c,v 1.6 2004/03/11 06:39:59 reinelt Exp $
*
* plugin for load average
*
@@ -23,6 +23,14 @@
*
*
* $Log: plugin_loadavg.c,v $
+ * Revision 1.6 2004/03/11 06:39:59 reinelt
+ * big patch from Martin:
+ * - reuse filehandles
+ * - memory leaks fixed
+ * - earlier busy-flag checking with HD44780
+ * - reuse memory for strings in RESULT and hash
+ * - netdev_fast to wavid time-consuming regex
+ *
* Revision 1.5 2004/03/08 18:46:21 hejl
* Fixed bug introduced with "caching" the loadavg values
*
@@ -76,20 +84,19 @@
#include "plugin.h"
#ifndef HAVE_GETLOADAVG
+static int fd = -2;
int getloadavg (double loadavg[], int nelem)
{
- static int fd=-2;
char buf[65], *p;
ssize_t nread;
int i;
- if (fd==-2) fd = open ("/proc/loadavg", O_RDONLY);
+ 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);
- //close (fd);
if (nread < 0) return -1;
buf[nread - 1] = '\0';
@@ -149,7 +156,6 @@ static void my_loadavg (RESULT *result, RESULT *arg1)
}
-
int plugin_init_loadavg (void)
{
AddFunction ("loadavg", 1, my_loadavg);
@@ -158,4 +164,8 @@ int plugin_init_loadavg (void)
void plugin_exit_loadavg(void)
{
+#ifndef HAVE_GETLOADAVG
+ if (fd>0) close(fd);
+ fd=-2;
+#endif
}