lininfo.c File Reference

#include <gnome.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <stdlib.h>
#include <glib.h>
#include "lininfo.h"
#include "others.h"

Go to the source code of this file.

Functions

int get_cpu_info (struct cpu_info *cpu)
int get_mhz_info (char *mhz)
 End get_cpu_info.
int get_mem_info (struct mem_info *mem)
int get_devs_info (struct dev_info *devs)
 End get_mem_info.
int get_settings_info (struct settings_info *settings)
int get_stats_info (struct stats_info *stats)
int get_battery_info (struct battery_info *battery, const char *file)
int get_acpi_info (struct acpi_info *acpi)


Function Documentation

int get_acpi_info ( struct acpi_info acpi  ) 

Collects ACPI information (Battery state and system temperature).

Parameters:
acpi Structure to fill with collected information
Returns:
0 if success, -1 otherwise

Definition at line 283 of file lininfo.c.

References acpi, BATT_STATE, BATT_STATE1, acpi_info::battery, parse_batt(), battery_info::rem, acpi_info::temp, acpi_info::temp_critical, TEMP_TRIP, and TEMPERATURE.

Referenced by update_misc().

00284 {
00285         gchar *contents;
00286         int ret=0;
00287         gchar *unk_string=_("Unknown");
00288         gchar data[10];
00289         
00290         //Read the current battery status.
00291         if(g_file_get_contents(BATT_STATE,&contents,NULL,NULL)==FALSE){
00292                 acpi->battery.rem=g_string_new(unk_string);
00293                 g_free(contents);
00294                 g_warning("Failed to read %s file\n",BATT_STATE);
00295                 
00296                 /* Try with BAT1 subdirectory */
00297                 if(g_file_get_contents(BATT_STATE1,&contents,NULL,NULL)==FALSE){
00298                         acpi->battery.rem=g_string_new(unk_string);
00299                         g_warning("Failed to read %s file\n",BATT_STATE1);
00300                         g_free(contents);
00301                         ret=-1;
00302                 }else{  
00303                         strcpy(data,parse_batt("remaining capacity",contents));
00304                         g_free(contents);
00305                         acpi->battery.rem=g_string_new(data);
00306                 }
00307                 
00308                 //ret=-1;
00309         }else{  
00310                 strcpy(data,parse_batt("remaining capacity",contents));
00311                 g_free(contents);
00312                 acpi->battery.rem=g_string_new(data);
00313         }
00314         
00315         //Read the current temperature.
00316         if(g_file_get_contents(TEMPERATURE,&contents,NULL,NULL)==FALSE){
00317                 acpi->temp=g_string_new(unk_string);
00318                 g_warning("Failed to read %s file\n",TEMPERATURE);
00319                 g_free(contents);
00320                 ret=-1;
00321         }else{  
00322                 //parse_batt also works for this file.
00323                 strcpy(data,parse_batt("temperature",contents));
00324                 g_free(contents);
00325                 acpi->temp=g_string_new(data);
00326         }
00327         
00328         
00329                 //Read the current temperature.
00330         if(g_file_get_contents(TEMP_TRIP,&contents,NULL,NULL)==FALSE){
00331                 acpi->temp_critical=g_string_new(unk_string);
00332                 g_free(contents);
00333                 g_warning("Failed to read %s file\n",TEMP_TRIP);
00334                 ret=-1;
00335         }else{  
00336                 //parse_batt also works for this file.
00337                 strcpy(data,parse_batt("critical",contents));
00338                 g_free(contents);
00339                 acpi->temp_critical=g_string_new(data);
00340         }
00341         
00342         //g_free(contents);
00343         
00344         return(ret);
00345 }

int get_battery_info ( struct battery_info battery,
const char *  file 
)

Collects battery information.

Parameters:
battery Structure to fill with collected information
file File to read data
Returns:
0 if success, -1 otherwise

Definition at line 245 of file lininfo.c.

References battery_info::cap, battery_info::cap_low, battery_info::cap_warning, battery_info::last_cap, parse_batt(), and battery_info::type.

Referenced by main().

00246 {
00247         gchar *contents;
00248         gchar *unk_string=_("Unknown");
00249         int ret=0;
00250         gchar data[10];
00251         
00252         if(g_file_get_contents(file,&contents,NULL,NULL)==FALSE){
00253                 battery->cap=g_string_new(unk_string);
00254                 battery->last_cap=g_string_new(unk_string);
00255                 battery->type=g_string_new(unk_string);
00256                 battery->cap_warning=g_string_new(unk_string);
00257                 battery->cap_low=g_string_new(unk_string);
00258                 
00259                 g_free(contents);
00260                 g_warning("Failed to read %s file\n",file);
00261                 ret=-1;
00262         }else{  
00263                 strcpy(data,parse_batt("design capacity",contents));
00264                 battery->cap=g_string_new(data);
00265                 strcpy(data,parse_batt("last full capacity",contents));
00266                 battery->last_cap=g_string_new(data);
00267                 strcpy(data,parse_batt("design capacity warning",contents));
00268                 battery->cap_warning=g_string_new(data);
00269                 strcpy(data,parse_batt("design capacity low",contents));
00270                 battery->cap_low=g_string_new(data);
00271                 strcpy(data,parse_batt("battery type",contents));
00272                 battery->type=g_string_new(data);
00273         }
00274         
00275         g_free(contents);
00276         return ret;
00277 }

int get_cpu_info ( struct cpu_info cpu  ) 

Collects cpu information.

Parameters:
cpu Structure to fill with collected information
Returns:
0 if success

Definition at line 43 of file lininfo.c.

References cpu_info::bogomips, cpu_info::cache, cpu, cpu_info::cpu_family, CPU_FILE, cpu_info::cpuid_level, find_data_for(), cpu_info::flags, cpu_info::fpu, cpu_info::fpu_exception, cpu_info::Mhz, cpu_info::model, cpu_info::model_name, cpu_info::processor, cpu_info::stepping, cpu_info::vendor_id, and cpu_info::wp.

Referenced by update_cpu().

00044 {
00045   gchar* contents;
00046   char* str;
00047   
00048   if(g_file_get_contents(CPU_FILE,&contents,NULL,NULL)==FALSE)
00049           //Error accesing file. Stop program 
00050         g_error("Can't read %s file",CPU_FILE);
00051   
00052   str=contents;
00053   find_data_for("processor : %[^\n]",cpu->processor,str);
00054   find_data_for("vendor_id : %[^\n]",cpu->vendor_id,str);
00055   find_data_for("cpu family : %[^\n]",cpu->cpu_family,str);
00056   find_data_for("model : %[^\n]",cpu->model,str);
00057   find_data_for("model name : %[^\n]",cpu->model_name,str)      ;
00058   find_data_for("stepping : %[^\n]",cpu->stepping,str);
00059   find_data_for("cpu MHz : %[^\n]",cpu->Mhz,str);
00060   find_data_for("cache size : %[^\n]",cpu->cache,str);
00061   find_data_for("fpu : %[^\n]",cpu->fpu,str);
00062   find_data_for("fpu_exception : %[^\n]",cpu->fpu_exception,str);
00063   find_data_for("cpuid level : %[^\n]",cpu->cpuid_level,str);
00064   find_data_for("wp : %[^\n]",cpu->wp,str);
00065   find_data_for("flags : %[^\n]",cpu->flags,str);
00066   find_data_for("bogomips : %[^\n]",cpu->bogomips,str);
00067         
00068   g_free(contents);
00069 
00070   return (0);
00071 }                               

int get_devs_info ( struct dev_info devs  ) 

End get_mem_info.

Collects devices information.

Parameters:
devs Structure to fill with collected information
Returns:
0 if success, -1 otherwise

Definition at line 136 of file lininfo.c.

References dev_info::blocks, dev_info::characters, DEV_FILE, devs, and skip_lines().

Referenced by update_devs().

00137 {
00138   gchar *contents;
00139   gsize tam;
00140   char *p;
00141 
00142    if(g_file_get_contents(DEV_FILE,&contents,&tam,NULL)==FALSE){
00143             //Can't read file. Stop program
00144                 g_error("Can't read %s file",DEV_FILE);
00145             return -1;
00146    }
00147         
00148     p=strstr(contents,"Block devices:");
00149     *p='\0';
00150     p=skip_lines(p,1);
00151     devs->blocks=g_string_new((gchar*) p);
00152     p=skip_lines(contents,1);
00153     devs->characters=g_string_new(p);
00154    
00155     g_free(contents);
00156    
00157     return(0);
00158 }

int get_mem_info ( struct mem_info mem  ) 

Collects memory information.

Parameters:
mem Structure to fill with collected information
Returns:
0 if success

Definition at line 100 of file lininfo.c.

References mem_info::active, mem_info::buffers, mem_info::cached, mem_info::dirty, find_data_for(), mem_info::free, mem_info::high_free, mem_info::high_total, mem_info::hugepages_free, mem_info::hugepages_size, mem_info::hugepages_total, mem_info::inactive, mem_info::low_free, mem_info::low_total, mem, MEM_FILE, mem_info::swap_cached, mem_info::swap_free, mem_info::swap_total, and mem_info::total.

Referenced by update_mem().

00101 {
00102         gchar* contents;
00103         
00104         if(g_file_get_contents(MEM_FILE,&contents,NULL,NULL)==FALSE)
00105                 //Can't read file. Stop program
00106                 g_error("Can't read %s file",MEM_FILE);
00107 
00108   find_data_for ("MemTotal: %[^\n]",mem->total, contents);
00109   find_data_for ("MemFree: %[^\n]",mem->free, contents);
00110   find_data_for ("Buffers: %[^\n]",mem->buffers, contents);
00111   find_data_for ("Cached: %[^\n]",mem->cached, contents);
00112   find_data_for ("SwapCached: %[^\n]",mem->swap_cached, contents);
00113   find_data_for ("Active: %[^\n]",mem->active, contents);
00114   find_data_for ("Inactive: %[^\n]",mem->inactive,contents);
00115   find_data_for ("Dirty: %[^\n]",mem->dirty, contents);
00116   find_data_for ("HighTotal: %[^\n]",mem->high_total, contents);
00117   find_data_for ("HighFree: %[^\n]",mem->high_free, contents);
00118   find_data_for ("LowTotal: %[^\n]",mem->low_total, contents);
00119   find_data_for ("LowFree: %[^\n]",mem->low_free, contents);
00120   find_data_for ("SwapTotal: %[^\n]",mem->swap_total, contents);
00121   find_data_for ("SwapFree: %[^\n]",mem->swap_free, contents);
00122   find_data_for ("HugePages_Total: %[^\n]",mem->hugepages_total, contents);
00123   find_data_for ("HugePages_Free: %[^\n]",mem->hugepages_free, contents);
00124   find_data_for ("Hugepagesize: %[^\n]",mem->hugepages_size, contents);
00125 
00126   g_free(contents);
00127   
00128   return (0);
00129 }                               

int get_mhz_info ( char *  mhz  ) 

End get_cpu_info.

Updates CPU processor frequency.

Parameters:
mhz string to put the updated data
Returns:
0 if success

Definition at line 77 of file lininfo.c.

References CPU_FILE, and find_data_for().

Referenced by update_cpu_mhz().

00078 {
00079         gchar *contents;
00080         
00081         if(g_file_get_contents(CPU_FILE,&contents,NULL,NULL)==FALSE){
00082           //Error accesing file. Stop program 
00083                 g_error("Can't read %s file",CPU_FILE);
00084                 return -1;
00085         }
00086         
00087         find_data_for("cpu MHz : %[^\n]",mhz,contents);
00088         
00089         g_free(contents);
00090         
00091         return(0);
00092 }

int get_settings_info ( struct settings_info settings  ) 

Collects settings information.

Parameters:
settings Structure to fill with collected information
Returns:
0 if success, -1 otherwise

Definition at line 164 of file lininfo.c.

References settings_info::domain, DOMAIN_NAME, settings_info::fdasig, settings_info::fdfreed, settings_info::fdmax, FILES, settings_info::host, HOST_NAME, settings_info::inasig, settings_info::inmax, INODES, settings_info::max_opcall, settings_info::max_seminset, settings_info::max_semsets, settings_info::max_semsys, P_MAX_M, P_MAX_Q, P_MAX_S, settings_info::page_max, PAGE_MAX, settings_info::posix_mpq, settings_info::posix_mq, settings_info::posix_ms, read_values_from_file(), settings_info::seg_max, SEG_MAX, settings_info::seg_size, SEG_SIZE, SEM, settings, settings_info::threads, and THREADS_MAX.

Referenced by update_settings().

00165 {
00166         gchar *unk_string=_("Unknown");
00167         gchar *contents;
00168         
00169         if(g_file_get_contents(HOST_NAME,&contents,NULL,NULL)==FALSE){
00170                 g_warning("Failed to read %s file\n",HOST_NAME);
00171                 settings->host=g_string_new(unk_string);
00172                 g_free(contents);
00173                 return (-1);
00174         }else{
00175                 settings->host=g_string_new(contents);
00176                 g_free(contents);
00177         }
00178         
00179         if(g_file_get_contents(DOMAIN_NAME,&contents,NULL,NULL)==FALSE){
00180                 settings->domain=g_string_new(unk_string);
00181                 g_warning("Failed to read %s file\n",DOMAIN_NAME);
00182                 g_free(contents);
00183                 return (-1);
00184         }else{
00185                 settings->domain=g_string_new(contents);
00186                 g_free(contents);               
00187         }
00188         /* We need to read the current values for the settings */
00189         
00190         read_values_from_file(3,FILES,&settings->fdasig,&settings->fdfreed,\
00191         &settings->fdmax);
00192         read_values_from_file(1,THREADS_MAX,&settings->threads);
00193         read_values_from_file(1,P_MAX_Q,&settings->posix_mq);
00194         read_values_from_file(1,P_MAX_M,&settings->posix_mpq);
00195         read_values_from_file(1,P_MAX_S,&settings->posix_ms);
00196         read_values_from_file(2,INODES,&settings->inmax,&settings->inasig);
00197         read_values_from_file(1,PAGE_MAX,&settings->page_max);
00198         read_values_from_file(1,SEG_MAX,&settings->seg_max);
00199         read_values_from_file(1,SEG_SIZE,&settings->seg_size);
00200         read_values_from_file(4,SEM,&settings->max_seminset, &settings->max_semsys,\
00201                                                         &settings->max_opcall, &settings->max_semsets);
00202         
00203         //g_free(contents);
00204         
00205         return(0);
00206 }

int get_stats_info ( struct stats_info stats  ) 

Collects status information. Times for the cpu usage.

Parameters:
stats Structure to fill with collected information
Returns:
0 if success, -1 otherwise

Definition at line 212 of file lininfo.c.

References stats_info::cpu, stats_info::cpu0, stats_info::cpu1, stats_info::ctxt, find_data_for(), stats, and STATS_FILE.

Referenced by update_misc().

00213 {
00214         gchar *contents;
00215         gchar str[50];
00216         
00217         if(g_file_get_contents(STATS_FILE,&contents,NULL,NULL)==FALSE){
00218                 //Can't read file.
00219                 g_warning("Failed to read %s file",STATS_FILE);
00220                 g_free(contents);
00221                 stats->cpu=g_string_new("Unknown");
00222                 return -1;
00223         }else{
00224                 find_data_for ("cpu %[^\n]",str, contents);
00225                 stats->cpu=g_string_new(str);
00226                 find_data_for ("cpu0 %[^\n]",str, contents);
00227                 stats->cpu0=g_string_new(str);
00228                 find_data_for ("cpu1 %[^\n]",str, contents);
00229                 stats->cpu1=g_string_new(str);
00230                 find_data_for ("ctxt %[^\n]",str, contents);
00231                 stats->ctxt=g_string_new(str);
00232         }
00233         
00234         g_free(contents);
00235 
00236         return (0);
00237 }


Generated on Sat Dec 2 11:27:53 2006 for lkmonitor by  doxygen 1.5.1