diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/Linux/Makefile.am kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/Makefile.am --- kdebase-3.5.0/ksysguard/ksysguardd/Linux/Makefile.am 2005-09-10 10:26:15.000000000 +0200 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/Makefile.am 2006-01-22 18:14:21.000000000 +0100 @@ -11,4 +11,4 @@ noinst_LIBRARIES = libksysguardd.a libksysguardd_a_SOURCES = ProcessList.c Memory.c stat.c netdev.c apm.c acpi.c \ - loadavg.c cpuinfo.c lmsensors.c netstat.c diskstat.c logfile.c i8k.c + loadavg.c cpuinfo.c lmsensors.c netstat.c diskstat.c logfile.c i8k.c script.c diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/Linux/Makefile.in kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/Makefile.in --- kdebase-3.5.0/ksysguard/ksysguardd/Linux/Makefile.in 2005-11-26 08:08:40.000000000 +0100 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/Makefile.in 2006-01-22 18:26:42.000000000 +0100 @@ -56,15 +56,15 @@ stat.$(OBJEXT) netdev.$(OBJEXT) apm.$(OBJEXT) acpi.$(OBJEXT) \ loadavg.$(OBJEXT) cpuinfo.$(OBJEXT) lmsensors.$(OBJEXT) \ netstat.$(OBJEXT) diskstat.$(OBJEXT) logfile.$(OBJEXT) \ - i8k.$(OBJEXT) + i8k.$(OBJEXT) script.$(OBJEXT) #>- libksysguardd_a_OBJECTS = $(am_libksysguardd_a_OBJECTS) #>+ 8 -libksysguardd_a_final_OBJECTS = ProcessList.o Memory.o stat.o netdev.o apm.o acpi.o loadavg.o cpuinfo.o lmsensors.o netstat.o diskstat.o logfile.o i8k.o +libksysguardd_a_final_OBJECTS = ProcessList.o Memory.o stat.o netdev.o apm.o acpi.o loadavg.o cpuinfo.o lmsensors.o netstat.o diskstat.o logfile.o i8k.o script.o libksysguardd_a_nofinal_OBJECTS = ProcessList.$(OBJEXT) Memory.$(OBJEXT) \ stat.$(OBJEXT) netdev.$(OBJEXT) apm.$(OBJEXT) acpi.$(OBJEXT) \ loadavg.$(OBJEXT) cpuinfo.$(OBJEXT) lmsensors.$(OBJEXT) \ netstat.$(OBJEXT) diskstat.$(OBJEXT) logfile.$(OBJEXT) \ - i8k.$(OBJEXT) + i8k.$(OBJEXT) script.${OBJEXT} @KDE_USE_FINAL_FALSE@libksysguardd_a_OBJECTS = $(libksysguardd_a_nofinal_OBJECTS) @KDE_USE_FINAL_TRUE@libksysguardd_a_OBJECTS = $(libksysguardd_a_final_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) @@ -575,7 +575,7 @@ INCLUDES = -I$(srcdir)/../../CContLib -I$(srcdir)/.. $(KSGRD_SUPPORTS) $(all_includes) noinst_LIBRARIES = libksysguardd.a libksysguardd_a_SOURCES = ProcessList.c Memory.c stat.c netdev.c apm.c acpi.c \ - loadavg.c cpuinfo.c lmsensors.c netstat.c diskstat.c logfile.c i8k.c + loadavg.c cpuinfo.c lmsensors.c netstat.c diskstat.c logfile.c i8k.c script.c #>- all: all-am #>+ 1 @@ -642,6 +642,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Memory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ProcessList.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acpi.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apm.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpuinfo.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskstat.Po@am__quote@ @@ -860,7 +861,7 @@ .NOEXPORT: #>+ 2 -KDE_DIST=cpuinfo.h diskstat.h Makefile.in apm.h loadavg.h netstat.h ProcessList.h i8k.h Memory.h lmsensors.h stat.h netdev.h logfile.h acpi.h Makefile.am +KDE_DIST=cpuinfo.h diskstat.h Makefile.in apm.h loadavg.h netstat.h ProcessList.h i8k.h Memory.h lmsensors.h stat.h netdev.h logfile.h acpi.h script.h Makefile.am #>+ 2 docs-am: diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/Linux/script.c kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/script.c --- kdebase-3.5.0/ksysguard/ksysguardd/Linux/script.c 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/script.c 2006-01-24 16:43:03.000000000 +0100 @@ -0,0 +1,390 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2005 Corentin Chary + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Command.h" +#include "ksysguardd.h" + +#include "script.h" + + +#define LOCALSCRIPTPATH "/.kde/share/apps/ksysguard/scripts" +#define GLOBALSCRIPTPATH "/usr/share/apps/ksysguard/scripts" + +#define SCRIPTMAXLINE 1024 + +#define SCRIPTMONITORSBUF 16 +#define SCRIPTPATHBUF 4 + +static struct script * ScriptPath; +static int ScriptPathNum = 0; + +static struct scriptMonitor * ScriptMonitors; +static int ScriptMonitorsNum = 0; + +void initScript(struct SensorModul *sm) +{ + DIR *d; + struct dirent *de; + struct stat infos; + struct passwd *pwp; + char *dir; + char *filename=NULL; + + ScriptPath = malloc(sizeof(struct script)*SCRIPTPATHBUF); + ScriptMonitors = malloc(sizeof(struct scriptMonitor)*SCRIPTMONITORSBUF); + ScriptPathNum = 0; + + if ((d = opendir(GLOBALSCRIPTPATH)) == NULL) { + ScriptPathNum = -1; + } else { + while ((de = readdir(d))) + if ((strcmp(de->d_name, ".") != 0) + && (strcmp(de->d_name, "..") != 0)) { +/* printf("%s\n", de->d_name);*/ + + filename = malloc(strlen(GLOBALSCRIPTPATH) + strlen(de->d_name) + 2); + sprintf(filename,"%s/%s",GLOBALSCRIPTPATH,de->d_name); + if(!stat(filename, &infos)) { + if((infos.st_mode&S_IXGRP) && createScriptMonitors(filename, de->d_name, sm)) { + ScriptPath[ScriptPathNum].path = strdup(filename); + ScriptPath[ScriptPathNum].m_time = infos.st_mtime; + ScriptPathNum++; + if((ScriptPathNum%SCRIPTPATHBUF) == 0) { + ScriptPath = realloc(ScriptPath,sizeof(struct script)*(ScriptPathNum+SCRIPTPATHBUF)); + } + } + } + free(filename); + } + } + + /* get user home dir */ + if ( (pwp = getpwuid(getuid()))){ + dir = malloc(strlen(pwp->pw_dir) + strlen(LOCALSCRIPTPATH) + 1); + sprintf(dir, "%s%s", pwp->pw_dir,LOCALSCRIPTPATH); + if ((d = opendir(dir)) != NULL) { + while ((de = readdir(d))) + if ((strcmp(de->d_name, ".") != 0) + && (strcmp(de->d_name, "..") != 0)) { +/* printf("%s\n", de->d_name);*/ + + filename = malloc(strlen(dir) + strlen(de->d_name) + 2); + sprintf(filename,"%s/%s",dir,de->d_name); + if(!stat(filename, &infos)) { + if((infos.st_mode&S_IXGRP) && createScriptMonitors(filename, de->d_name, sm)) { + ScriptPath[ScriptPathNum].path = strdup(filename); + ScriptPath[ScriptPathNum].m_time = infos.st_mtime; + ScriptPathNum++; + if((ScriptPathNum%SCRIPTPATHBUF) == 0) { + ScriptPath = realloc(ScriptPath,sizeof(struct script)*(ScriptPathNum+SCRIPTPATHBUF)); + } + } + } + free(filename); + } + } + free(dir); + + } + + if(ScriptPathNum == 0) { + ScriptPathNum = -1; + } + +} + +void exitScript(void) +{ + int i; + + for(i = 0; i < ScriptPathNum; ++i) { + free(ScriptPath[i].path); + } + free(ScriptPath); + + for(i = 0; i < ScriptMonitorsNum; ++i) { + free(ScriptMonitors[i].name); + free(ScriptMonitors[i].kname); + free(ScriptMonitors[i].type); + free(ScriptMonitors[i].unit); + } + free(ScriptMonitors); +} + +int updateScript(void) +{ + struct stat infos; + char *filename; + int i; + FILE *stream; + char line[SCRIPTMAXLINE+1]; + char *name = NULL; + char *type = NULL; + char *unit = NULL; + double output = 0, min =0, max = 0; + struct scriptMonitor *mon; + uid_t uid = getuid(); + + for(i = 0; i < ScriptPathNum; i++) { + filename = ScriptPath[i].path; + if(!stat(filename, &infos)) { + if(((infos.st_uid == uid && infos.st_mode&S_IXUSR) || infos.st_mode&S_IXGRP ) + && infos.st_mtime == ScriptPath[i].m_time) { + if ((stream = popen(filename, "r")) != NULL) { + mon = getMonPtr(getScriptId(filename), -1); + while(fgets(line, SCRIPTMAXLINE, stream)) { +/* printf("test1\n");*/ + if(!parseScriptLine(line, &name, &type, &output, &unit, &min, &max)) { +/* printf("Name: %s \t Type: %s \t Valeur: %lf\n",name,type,output);*/ + + +/* printf("Capteur %s %d %d ok !\n",kname,strlen(kname), strlen("scripts/") + strlen(file) + strlen("/") + strlen(tmp) + sizeof(int) + \ + 1); +*/ +/* MAJ § */ + mon->output = output; + free(name); + free(type); + free(unit); + mon++; + } + } + pclose(stream); + } + } + } + + } + + + return 0; +} + +int createScriptMonitors(const char *filename,const char *file, struct SensorModul *sm) +{ + FILE *stream; + char line[SCRIPTMAXLINE+1]; + char *kname = NULL; + char *name = NULL; + char *tmp = NULL; + char *type = NULL; + char *unit = NULL; + double output = 0, min =0, max = 0; + int i = 0; + + if ((stream = popen(filename, "r")) == NULL) { + return -1; + } + + while(fgets(line, SCRIPTMAXLINE, stream)) { +/* printf("test1\n");*/ + if(!parseScriptLine(line, &name, &type, &output, &unit, &min, &max)) { +/* printf("Name: %s \t Type: %s \t Valeur: %lf\n",name,type,output);*/ + + tmp = strdup(name); + cleanScriptName(tmp); + + kname = malloc((strlen("scripts/") + strlen(file) + 3 + strlen(tmp) + sizeof(int) + 1)); + sprintf(kname, "scripts/%s:%d/%s:%d", file, ScriptPathNum, tmp,i); + + free(tmp); + +/* printf("Capteur %s %d %d ok !\n",kname,strlen(kname), strlen("scripts/") + strlen(file) + strlen("/") + strlen(tmp) + sizeof(int) + 1); + */ + registerMonitor(kname, type, printScript, printScriptInfo, sm); + + ScriptMonitors[ScriptMonitorsNum].sid = ScriptPathNum; + ScriptMonitors[ScriptMonitorsNum].mid = i; + ScriptMonitors[ScriptMonitorsNum].name = strdup(name); + ScriptMonitors[ScriptMonitorsNum].type = strdup(type); + ScriptMonitors[ScriptMonitorsNum].kname = strdup(kname); + ScriptMonitors[ScriptMonitorsNum].unit = strdup(unit); + ScriptMonitors[ScriptMonitorsNum].output = output; + ScriptMonitors[ScriptMonitorsNum].max = max; + ScriptMonitors[ScriptMonitorsNum].min = min; + + free(name); + free(type); + free(kname); + free(unit); + unit =type = name = kname = NULL; + + ScriptMonitorsNum++; + + if((ScriptMonitorsNum%SCRIPTMONITORSBUF) == 0) { + ScriptMonitors = realloc(ScriptMonitors,sizeof(struct scriptMonitor)*(ScriptMonitorsNum+SCRIPTMONITORSBUF)); + } + i++; + } + } + + + + pclose(stream); + return i; +} + +int parseScriptLine(char *line, char **name, char **type, double *output, char ** unit, double *min, double *max) { + char *reste=NULL,*ptr,*tmp; + + line[strlen(line)-1] = '\0'; /* Stupid \n */ +/*printf(">> Sortie: %s\n",line);*/ + if((ptr = strchr(line,'\t')) != NULL) { + ptr++; + *name = strdup(line); + (*name)[ptr-line-1] = '\0'; + reste = strdup(ptr); + + if((ptr = strchr(reste,'\t')) != NULL) { + ptr++; + *type = reste; + (*type)[ptr-reste-1] = '\0'; + reste = strdup(ptr); + + if((!strcmp(*type,"integer") || !strcmp(*type,"float")) && sscanf(reste,"%lf",output)){ + tmp = reste; + if((ptr = strchr(reste,'\t')) != NULL) { + ptr++; + tmp = reste; + reste=strdup(ptr); + if((ptr = strchr(reste,'\t')) != NULL) { + *unit = reste; + (*unit)[ptr-reste-1] = '\0'; + reste = ptr; + sscanf(reste,"%lf\t%lf\n",min,max); + return 0; + } else if(reste[0]) { + *unit = reste; + return 0; + } + free(reste); + } + + free(tmp); + *unit = malloc(1); + *unit[0] = '\0'; + return 0; + } + } + } + + free(reste); + return -1; +} + +void printScript(const char *cmd) +{ + int sid,mid; + char *ptr; + struct scriptMonitor *mon; + + ptr = strchr(cmd, ':'); + ptr++; + sscanf(ptr,"%d",&sid); + + ptr = strrchr(cmd, ':'); + ptr++; + sscanf(ptr,"%d",&mid); + + mon = getMonPtr(sid,mid); + + if(!strcmp(mon->type,"integer")) { + printf("%d\n",(int) mon->output); + } else { + printf("%lf\n",mon->output); + } +} + + +void printScriptInfo(const char *cmd) +{ + int sid,mid; + char *ptr; + struct scriptMonitor *mon; + + + + ptr = strchr(cmd, ':'); + ptr++; + sscanf(ptr,"%d",&sid); + + ptr = strrchr(cmd, ':'); + ptr++; + sscanf(ptr,"%d",&mid); + + mon = getMonPtr(sid,mid); + + if(!strcmp(mon->type,"integer")) { + printf("%s\t%d\t%s\t%d\t%d\n",mon->name,(int) mon->output, mon->unit, (int) mon->min, (int) mon->max); + } else { + printf("%s\t%lf\t%s\t%lf\t%lf\n",mon->name,mon->output, mon->unit, mon->min, mon->max); + } +} + +int getScriptId(char * filename) { + int i; + + for(i = 0; i < ScriptPathNum; ++i) { + if(!strcmp(filename,ScriptPath[i].path)) { + return i; + } + } + return -1; +} + + +struct scriptMonitor * getMonPtr(int sid, int mid) { + int i; + + if(mid >= 0) { + for(i = mid; i < ScriptMonitorsNum; ++i) { + if(ScriptMonitors[i].sid == sid && ScriptMonitors[i].mid == mid) { + return &ScriptMonitors[i]; + } + } + } else { + for(i = 0; i < ScriptMonitorsNum; ++i) { + if(ScriptMonitors[i].sid == sid) { + return &ScriptMonitors[i]; + } + } + } + + return NULL; +} + +void cleanScriptName(char *kname) { + for(; *kname; ++kname) { + if(!isalnum(kname[0]) && !isupper(kname[0])) { + kname[0] = '_'; + } + } +} diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/Linux/script.h kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/script.h --- kdebase-3.5.0/ksysguard/ksysguardd/Linux/script.h 1970-01-01 01:00:00.000000000 +0100 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/Linux/script.h 2006-01-24 15:22:56.000000000 +0100 @@ -0,0 +1,58 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2005 Corentin Chary + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef KSG_SCRIPT_H +#define KSG_SCRIPT_H + + +struct script { + char * path; + time_t m_time; +}; + +struct scriptMonitor { + int sid; + int mid; + char * name; + char * kname; + char * type; + char * unit; + double output; + double min; + double max; +}; + + +void initScript(struct SensorModul *sm); +void exitScript(void); + +int updateScript(void); + +int createScriptMonitors(const char * filename, const char *file, struct SensorModul *sm); +int parseScriptLine(char *line, char **name, char **type, double *output, char ** unit, double *min, double *max); + +void printScript(const char *cmd); +void printScriptInfo(const char *cmd); + +struct scriptMonitor * getMonPtr(int sid, int mid); +int getScriptId(char * filename); + +void cleanScriptName(char *name); + +#endif diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/conf.c kdebase-3.5.0-new/ksysguard/ksysguardd/conf.c --- kdebase-3.5.0/ksysguard/ksysguardd/conf.c 2005-10-10 17:04:32.000000000 +0200 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/conf.c 2006-01-22 18:31:03.000000000 +0100 @@ -79,6 +79,7 @@ push_ctnr( SensorList, strdup( "DiskStat" ) ); push_ctnr( SensorList, strdup( "LogFile" ) ); push_ctnr( SensorList, strdup( "DellLaptop" ) ); + push_ctnr( SensorList, strdup( "Script" ) ); return; } diff -U 3 -H -d -r -N -- kdebase-3.5.0/ksysguard/ksysguardd/modules.h kdebase-3.5.0-new/ksysguard/ksysguardd/modules.h --- kdebase-3.5.0/ksysguard/ksysguardd/modules.h 2005-10-10 17:04:32.000000000 +0200 +++ kdebase-3.5.0-new/ksysguard/ksysguardd/modules.h 2006-01-23 21:46:29.000000000 +0100 @@ -39,6 +39,7 @@ #include "netdev.h" #include "netstat.h" #include "stat.h" +#include "script.c" #endif /* OSTYPE_Linux */ #ifdef OSTYPE_FreeBSD @@ -104,6 +105,7 @@ { "DiskStat", initDiskStat, exitDiskStat, updateDiskStat, checkDiskStat, 0, NULLTIME }, { "LogFile", initLogFile, exitLogFile, NULLIVFUNC, NULLVVFUNC, 0, NULLTIME }, { "DellLaptop", initI8k, exitI8k, updateI8k, NULLVVFUNC, 0, NULLTIME }, + { "Script", initScript, exitScript, updateScript, NULLVVFUNC, 0, NULLTIME }, #endif /* OSTYPE_Linux */ #ifdef OSTYPE_FreeBSD