/* $Id: system.c,v 1.30 2003/10/05 17:58:50 reinelt Exp $ * * system status retreivement * * Copyright 1999, 2000 Michael Reinelt * * 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. * * * $Log: system.c,v $ * Revision 1.30 2003/10/05 17:58:50 reinelt * libtool junk; copyright messages cleaned up * * Revision 1.29 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * * Revision 1.28 2003/06/26 05:31:16 reinelt * bug in /proc/net/dev parsing fixed * * Revision 1.27 2003/06/13 05:11:10 reinelt * error message cosmetics * * Revision 1.26 2003/02/22 07:53:10 reinelt * cfg_get(key,defval) * * Revision 1.25 2002/12/05 19:12:47 reinelt * sensors factor and offset patch from Petri Damsten * * Revision 1.24 2001/08/05 17:13:29 reinelt * * cleaned up inlude of sys/time.h and time.h * * Revision 1.23 2001/03/13 08:34:15 reinelt * * corrected a off-by-one bug with sensors * * Revision 1.22 2001/03/12 12:39:36 reinelt * * reworked autoconf a lot: drivers may be excluded, #define's went to config.h * * Revision 1.21 2001/03/09 12:14:24 reinelt * * minor cleanups * * Revision 1.20 2001/03/02 20:18:12 reinelt * * allow compile on systems without net/if_ppp.h * * Revision 1.19 2001/02/16 08:23:09 reinelt * * new token 'ic' (ISDN connected) by Carsten Nau * * Revision 1.18 2000/11/17 10:36:23 reinelt * * fixed parsing of /proc/net/dev for 2.0 kernels * * Revision 1.17 2000/10/08 09:16:40 reinelt * * * Linux-2.4.0-test9 changed the layout of /proc/stat (especially the disk_io line) * rearranged parsing of some /proc files and (hopefully) made it more robust in concerns of format changes * * Revision 1.16 2000/08/10 09:44:09 reinelt * * new debugging scheme: error(), info(), debug() * uses syslog if in daemon mode * * Revision 1.15 2000/08/09 11:03:07 reinelt * * fixed a bug in system.c where the format of /proc/net/dev was not correctly * detected and parsed with different kernels * * Revision 1.14 2000/08/09 09:50:29 reinelt * * opened 0.98 development * removed driver-specific signal-handlers * added 'quit'-function to driver structure * added global signal-handler * * Revision 1.13 2000/07/31 10:43:44 reinelt * * some changes to support kernel-2.4 (different layout of various files in /proc) * * Revision 1.12 2000/05/21 06:20:35 reinelt * * added ppp throughput * token is '%t[iomt]' at the moment, but this will change in the near future * * Revision 1.11 2000/04/15 11:56:35 reinelt * * more debug messages * * Revision 1.10 2000/04/13 06:09:52 reinelt * * added BogoMips() to system.c (not used by now, maybe sometimes we can * calibrate our delay loop with this value) * * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully * no compiler will optimize away the delay loop! * * Revision 1.9 2000/
# Poitiers - France (DVB-T transmitter of Poitiers ( Agglomération ) )
# Poitiers - France (signal DVB-T transmis depuis l'émetteur de Agglomération )
#
# ATTENTION ! Ce fichier a ete construit automatiquement a partir
# des frequences obtenues sur : http://www.tvnt.net/multiplex_frequences.htm
# en Avril 2006. Si vous constatez des problemes et voulez apporter des
# modifications au fichier, envoyez le fichier modifie a
# l'adresse linux-dvb@linuxtv.org (depot des fichiers d'init dvb)
# ou a l'auteur du fichier :
# Nicolas Estre <n_estre@yahoo.fr>
#
# T freq bw fec_hi fec_lo mod transmission-mode guard-interval hierarchy
#### Poitiers - Agglomération ####
#R1
T 706000000 8MHz AUTO NONE QAM64 8k AUTO NONE
#R2
T 778000000 8MHz AUTO NONE QAM64 8k AUTO NONE
#R3
T 802000000 8MHz AUTO NONE QAM64 8k AUTO NONE
#R4
T 730000000 8MHz AUTO NONE QAM64 8k AUTO NONE
#R5
T 754000000 8MHz AUTO NONE QAM64 8k AUTO NONE
#R6
T 794000000 8MHz AUTO NONE QAM64 8k AUTO NONE
", buffer))<0) { fd=-1; return -1; } if ((v3=parse_meminfo ("MemShared:", buffer))<0) { fd=-1; return -1; } if ((v4=parse_meminfo ("Buffers:", buffer))<0) { fd=-1; return -1; } if ((v5=parse_meminfo ("Cached:", buffer))<0) { fd=-1; return -1; } *total=v1; *free=v2; *shared=v3; *buffered=v4; *cached=v5; return 0; } int Load (double *load1, double *load2, double *load3) { static int fd=-2; char buffer[16]; static double val1=0; static double val2=0; static double val3=0; static time_t now=0; *load1=val1; *load2=val2; *load3=val3; if (fd==-1) return -1; if (time(NULL)==now) return 0; time(&now); if (fd==-2) { fd=open("/proc/loadavg", O_RDONLY); if (fd==-1) { error ("open(/proc/loadavg) failed: %s", strerror(errno)); return -1; } debug ("open(/proc/loadavg)=%d", fd); } if (lseek(fd, 0L, SEEK_SET)!=0) { error("lseek(/proc/loadavg) failed: %s", strerror(errno)); fd=-1; return -1; } if (read (fd, &buffer, sizeof(buffer)-1)==-1) { error("read(/proc/loadavg) failed: %s", strerror(errno)); fd=-1; return -1; } if (sscanf(buffer, "%lf %lf %lf", &val1, &val2, &val3)!=3) { error ("parse(/proc/loadavg) failed: unknown format"); fd=-1; return -1; } *load1=val1; *load2=val2; *load3=val3; return 0; } int Busy (double *user, double *nice, double *system, double *idle) { static int fd=-2; char buffer[64], *p; unsigned long v1, v2, v3, v4; double d1, d2, d3, d4, d5; *user=0.0; *nice=0.0; *system=0.0; *idle=0.0; if (fd==-1) return -1; if (fd==-2) { fd=open("/proc/stat", O_RDONLY); if (fd==-1) { error ("open(proc/stat) failed: %s", strerror(errno)); return -1; } debug ("open (/proc/stat)=%d", fd); } if (lseek(fd, 0L, SEEK_SET)!=0) { error ("lseek(/proc/stat) failed: %s", strerror(errno)); fd=-1; return -1; } if (read (fd, &buffer, sizeof(buffer)-1)==-1) { error ("read(/proc/stat) failed: %s", strerror(errno)); fd=-1; return -1; } p=strstr(buffer, "cpu "); if (p==NULL) { error ("parse(/proc/stat) failed: no 'cpu' line"); fd=-1; return -1; } if (sscanf(p+4, " %lu %lu %lu %lu", &v1, &v2, &v3, &v4)!=4) { error ("parse(/proc/stat) failed: unknown 'cpu' format"); fd=-1; return -1; } d1=smooth("cpu_user", 500, v1); d2=smooth("cpu_nice", 500, v2); d3=smooth("cpu_sys", 500, v3); d4=smooth("cpu_idle", 500, v4); d5=d1+d2+d3+d4; if (d5!=0.0) { *user=(d1+d2)/d5; *nice=d2/d5; *system=d3/d5; *idle=d4/d5; } return 0; } int Disk (int *r, int *w) { char buffer[4096], *p; static int fd=-2; *r=0; *w=0; if (fd==-1) return -1; if (fd==-2) { fd = open("/proc/stat", O_RDONLY | O_NDELAY); if (fd==-1) { error ("open(/proc/stat) failed: %s", strerror(errno)); return -1; } debug ("open (/proc/stat)=%d", fd); } if (lseek(fd, 0L, SEEK_SET)!=0) { error ("lseek(/proc/stat) failed: %s", strerror(errno)); fd=-1; return -1; } if (read (fd, &buffer, sizeof(buffer)-1)==-1) { error ("read(/proc/stat) failed: %s", strerror(errno)); fd=-1; return -1; } p=strstr(buffer, "disk_io:"); if (p!=NULL) { unsigned long rsum=0, wsum=0; p+=8; while (*p==' ') p++; while (*p && *p!='\n') { int i, n; unsigned long dummy; unsigned long rblk, wblk; i=sscanf(p, "(%lu,%lu):(%lu,%lu,%lu,%lu,%lu)%n", &dummy, &dummy, &dummy, &dummy, &rblk, &dummy, &wblk, &n); if (n==0 || i!= 7) { i=sscanf(p, "(%lu,%lu):(%lu,%lu,%lu,%lu)%n", &dummy, &dummy, &dummy, &rblk, &dummy, &wblk, &n)+1; } if (n>0 && i==7) { rsum+=rblk; wsum+=wblk; p+=n; while (*p==' ') p++; } else { error ("parse(/proc/stat) failed: unknown 'disk_io' format"); fd=-1; return -1; } } // assume that we got the number of sectors, and a sector size of 512 bytes. // to get te number in kilobytes/sec, we calculate as follows: // kb=blocks*512/1024, which is blocks/2 *r=smooth ("disk_r", 500, rsum/2); *w=smooth ("disk_w", 500, wsum/2); } else { unsigned long r1, r2, r3, r4; unsigned long w1, w2, w3, w4; p=strstr(buffer, "disk_rblk"); if (p==NULL) { error ("parse(/proc/stat) failed: neither 'disk_io' nor 'disk_rblk' found"); fd=-1; return -1; } if (sscanf(p+9, "%lu %lu %lu %lu", &r1, &r2, &r3, &r4)!=4) { error ("parse(/proc/stat) failed: unknown 'disk_rblk' format"); fd=-1; return -1; } p=strstr(buffer, "disk_wblk"); if (p==NULL) { error ("parse(/proc/stat) failed: no 'disk_wblk' line"); fd=-1; return -1; } if (sscanf(p+9, "%lu %lu %lu %lu", &w1, &w2, &w3, &w4)!=4) { error ("parse(/proc/stat) failed: unknown 'disk_wblk' format"); fd=-1; return -1; } *r=smooth ("disk_r", 500, r1+r2+r3+r4); *w=smooth ("disk_w", 500, w1+w2+w3+w4); } return 0; } int Net (int *rx, int *tx, int *bytes) { char buffer[4096], *p, *s; static int fd=-2; unsigned long pkg_rx, pkg_tx; *rx=0; *tx=0; *bytes=0; if (fd==-1) return -1; if (fd==-2) { fd = open("/proc/net/dev", O_RDONLY | O_NDELAY); if (fd==-1) { error ("open(/proc/net/dev) failed: %s", strerror(errno)); return -1; } debug ("open (/proc/net/dev)=%d", fd); } if (lseek(fd, 0L, SEEK_SET)!=0) { error ("lseek(/proc/net/dev) failed: %s", strerror(errno)); fd=-1; return -1; } if (read (fd, &buffer, sizeof(buffer)-1)==-1) { error ("read(/proc/net/dev) failed: %s", strerror(errno)); fd=-1; return -1; } pkg_rx=0; pkg_tx=0; p=buffer; while ((s=strsep(&p, "\n"))) { int n, u; unsigned long v[16]={0}; n=sscanf (s, " eth%d:%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu", &u, &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9], &v[10], &v[11], &v[12], &v[13], &v[14], &v[15]); if (n==17) { pkg_rx+=v[0]; pkg_tx+=v[8]; *bytes=1; } else if (n==12) { pkg_rx+=v[0]; pkg_tx+=v[5]; *bytes=0; } else if (n>0) { error ("parse(/proc/net/dev) failed: unknown format"); fd=-1; return -1; } } *rx=smooth("net_rx", 500, pkg_rx); *tx=smooth("net_tx", 500, pkg_tx); return 0; } int PPP (int unit, int *rx, int *tx) { static int fd=-2; char buffer[16]; #ifdef HAVE_NET_IF_PPP_H struct ifpppstatsreq req; #endif *rx=0; *tx=0; #ifdef HAVE_NET_IF_PPP_H if (fd==-1) return -1; if (fd==-2) { fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd==-1) { error ("socket() failed: %s", strerror(errno)); return -1; } debug ("socket()=%d", fd); } memset (&req, 0, sizeof (req)); req.stats_ptr = (caddr_t) &req.stats; snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit); if (ioctl(fd, SIOCGPPPSTATS, &req) < 0) return 0; snprintf (buffer, sizeof(buffer), "ppp%d_rx", unit); *rx=smooth(buffer, 500, req.stats.p.ppp_ibytes); snprintf (buffer, sizeof(buffer), "ppp%d_tx", unit); *tx=smooth(buffer, 500, req.stats.p.ppp_obytes); #endif return 0; } int Sensor (int index, double *val, double *min, double *max) { char buffer[32]; double dummy, value; static int fd[SENSORS+1]={[0 ... SENSORS]=-2,}; static char *sensor[SENSORS+1]={NULL,}; static double val_buf[SENSORS+1]={0.0,}; static double min_buf[SENSORS+1]={0.0,}; static double max_buf[SENSORS+1]={0.0,}; static double factor_buf[SENSORS+1]={0.0,}; static double offset_buf[SENSORS+1]={0.0,}; static time_t now[SENSORS+1]={0,}; if (index<0 || index>SENSORS) return -1; *val=val_buf[index]; *min=min_buf[index]; *max=max_buf[index]; if (fd[index]==-1) return -1; if (time(NULL)==now[index]) return 0; time(&now[index]); if (fd[index]==-2) { snprintf(buffer, 32, "Sensor%d", index); sensor[index]=cfg_get(buffer, NULL); if (sensor[index]==NULL || *sensor[index]=='\0') { error ("no entry for '%s' in %s", buffer, cfg_source()); fd[index]=-1; return -1; } snprintf(buffer, 32, "Sensor%d_min", index); min_buf[index]=atof(cfg_get(buffer,"0")); *min=min_buf[index]; snprintf(buffer, 32, "Sensor%d_max", index); max_buf[index]=atof(cfg_get(buffer,"100")); *max=max_buf[index]; snprintf(buffer, 32, "Sensor%d_factor", index); factor_buf[index]=atof(cfg_get(buffer,"1")); snprintf(buffer, 32, "Sensor%d_offset", index); offset_buf[index]=atof(cfg_get(buffer,"0")); fd[index]=open(sensor[index], O_RDONLY); if (fd[index]==-1) { error ("open(%s) failed: %s", sensor[index], strerror(errno)); return -1; } debug ("open (%s)=%d", sensor[index], fd[index]); } if (lseek(fd[index], 0L, SEEK_SET)!=0) { error ("lseek(%s) failed: %s", sensor[index], strerror(errno)); fd[index]=-1; return -1; } if (read (fd[index], &buffer, sizeof(buffer)-1)==-1) { error ("read(%s) failed: %s", sensor[index], strerror(errno)); fd[index]=-1; return -1; } if (sscanf(buffer, "%lf %lf %lf", &dummy, &dummy, &value)!=3) { error ("parse(%s) failed: unknown format", sensor[index]); fd[index]=-1; return -1; } value *= factor_buf[index]; value += offset_buf[index]; val_buf[index]=value; *val=value; return 0; }