/* $Id$ * $URL$ * * plugin for load average * * Copyright (C) 2003 Michael Reinelt * Copyright (C) 2004 The LCD4Linux Team * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * exported functions: * * int plugin_init_loadavg (void) * adds functions for load average * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include "debug.h" #include "plugin.h" #ifndef HAVE_GETLOADAVG static int fd = -2; 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; } #endif 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; } last_value = now; } 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; } int plugin_init_loadavg(void) { AddFunction("loadavg", 1, my_loadavg); return 0; } void plugin_exit_loadavg(void) { #ifndef HAVE_GETLOADAVG if (fd > 0) close(fd); fd = -2; #endif } configure?id=8c2ea5ba9705f6a0e43ea73609b131a442e3ee09&follow=1'>update to automake 1.11.2michael3-44/+78 2012-01-08DPF driver by Stefan Kuhne 8note that you need libdpf)michael9-4/+337 2012-01-08[PATCH 2/2] gcc warnings by Jonathan McCrohanmichael1-1/+1 2012-01-08ATCH 1/2] gcc warnings by Jonathan McCrohanmichael1-2/+2 2011-12-26old ancient legacy port access disabled by defaultmichael6-162/+491 2011-12-22All compilation related issues in the headers have been fixed. Now each heade...mjona10-0/+11 2011-12-09Replaced parameter NoPowerCycle with PowerCyclesonic741-5/+5 2011-12-09Blit speedup, switch PICASO back to 9600 baud when exitingsonic741-47/+46 2011-12-08Removed compiler warningsonic741-1/+1 2011-12-08SGC supportsonic741-111/+254 2011-08-31Fix spelling errors. Flagged by Debian lintian checkjmccrohan4-4/+4 2011-07-28driver for Futaba MDM166A Graphic(96x16) vf-displays by Andreas Bracholdmichael9-2/+684 2011-07-27driver for Newhaven's NHD‐0420D3Z‐FL‐GBW. 4x20 LCD by Rusty Clarksonmichael9-4/+573 2011-07-27indentation :-(michael1-3/+3 2011-07-27magic bold escape char by Andrew Thompsonmichael1-1/+9 2011-07-27picoLCDGraphics needs keypad linkedmichael2-0/+2 2011-07-27various compiler warnings fixedmichael13-60/+39 2011-07-27Autoconf 2.68michael3-1455/+2751 2011-07-27run smoketest on all of my 8 coresmichael1-2/+2 2011-07-27indentationmichael4-330/+320 2011-07-27patch to replace outdate library libmpd with recent library libmpdclient from...michael2-240/+427 2011-07-27lcd4linux-wireless.patch from Hans de Goedemichael1-1/+1 2011-07-27st2205-width-height-swap.patch from Hans de Goedemichael1-2/+2 2011-07-27hwmon patch from Hans de Goedemichael1-0/+14 2011-07-27patch to support SureElectronicsDE-LD023 from Matt Joicemichael1-3/+16 2011-05-06Fixed keypad widget in GLCD2USBharbaum1-0/+7 2011-02-12timer.c: fixed detection of positive clock skew (and some typos)mzuther4-10/+10 2011-01-23timer.c: fixed clock skew detectionmzuther1-26/+46 2011-01-23timer.c: skip intermediate timer intervalsmzuther2-16/+46 2011-01-05fix for a bug introduced in the DE-LD021 drivermichael1-3/+3 2011-01-04indentationmichael2-3/+3 2011-01-04support for Sure Electronics DE-LD021 by Natanael Olaizmichael1-10/+8 2011-01-02driver for EFN LED modules by Tilman Glötznermichael9-21/+469 2010-11-28commented, corrected and beautified both timer and timer group codemzuther11-197/+511 2010-11-27finished commenting the timer codemzuther2-46/+138 2010-11-20started commenting the timer codemzuther5-52/+170 2010-11-19Added brightness support for GLCD2USBharbaum5-28/+8014