/home/fernape/Projects/lkmonitor/src/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.

Defines

#define TAM   10
#define TAM   10
#define BASE   2
#define STR_DEFAULT   _("No info.")

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)
int get_cmd_ver_info (struct cmd_ver *cmdversion)
int get_loadavg_info (struct cmd_ver *cmdversion)
int get_channels_info (struct channels_info *channels)
int get_net_info (struct net_dev_info *netinfo, const int index)
int get_fs_info (struct fs_info *fsinfo)
int get_mod_info (struct modules_info *modinfo)


Define Documentation

#define BASE   2

Referenced by get_net_info().

#define STR_DEFAULT   _("No info.")

Referenced by get_fs_info().

#define TAM   10

#define TAM   10

Referenced by find_data_for(), get_acpi_info(), and get_battery_info().


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 285 of file lininfo.c.

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

Referenced by update_misc().

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

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(), TAM, and battery_info::type.

Referenced by main().

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

int get_channels_info ( struct channels_info channels  ) 

Get communication channels information

Parameters:
channels channels_info structure pointer
Returns:
0 on success, -1 on error

Definition at line 412 of file lininfo.c.

References channels_info::dma, DMA_FILE, channels_info::iomem, IOMEM_FILE, channels_info::ioports, and IOPORTS_FILE.

Referenced by update_channels().

00413 {
00414         g_assert(channels!=NULL);
00415 
00416         gchar *contents;
00417         char *unk_string=_("Not available");
00418         int ret_val=-1;
00419 
00420         if(g_file_get_contents(IOMEM_FILE,&contents,NULL,NULL)==FALSE){
00421                 g_free(contents);
00422                 channels->iomem=g_string_new(unk_string);
00423                 ret_val=-1;
00424         }else{
00425                 channels->iomem=g_string_new(contents);
00426                 g_free(contents);
00427         }
00428 
00429 
00430         if(g_file_get_contents(IOPORTS_FILE,&contents,NULL,NULL)==FALSE){
00431                 g_free(contents);
00432                 channels->ioports=g_string_new(unk_string);
00433                 ret_val=-1;
00434         }else{
00435                 channels->ioports=g_string_new(contents);
00436                 g_free(contents);
00437         }
00438 
00439         if(g_file_get_contents(DMA_FILE,&contents,NULL,NULL)==FALSE){
00440                 g_free(contents);
00441                 channels->dma=g_string_new(unk_string);
00442                 ret_val=-1;
00443         }else{
00444                 channels->dma=g_string_new(contents);
00445                 g_free(contents);
00446         }
00447 
00448         return(ret_val);
00449 }

int get_cmd_ver_info ( struct cmd_ver cmdversion  ) 

Get cmdline version kernel information

Parameters:
cmdversion pointer to cmd_ver to store the data
Returns:
0 on success, 1 on error

Definition at line 352 of file lininfo.c.

References cmd_ver::cmd, CMD_FILE, cmdversion, VER_FILE, and cmd_ver::version.

Referenced by update_cmd_ver().

00353 {
00354         gchar *contents;
00355         gchar *unk_string=_("Unknown");
00356         int ret_val=0;
00357 
00358         if(g_file_get_contents(CMD_FILE,&contents,NULL,NULL)==FALSE){
00359                 g_free(contents);
00360                 cmdversion->cmd=g_string_new(unk_string);
00361                 ret_val=-1;
00362         }
00363         else{
00364                 cmdversion->cmd=g_string_new(contents);
00365                 g_free(contents);        
00366         }
00367 
00368         if(g_file_get_contents(VER_FILE,&contents,NULL,NULL)==FALSE){
00369                 g_free(contents);
00370                 cmdversion->version=g_string_new(unk_string);
00371                 ret_val=-11;
00372         }
00373         else{
00374                 cmdversion->version=g_string_new(contents);
00375                 g_free(contents);        
00376         }
00377 
00378 
00379 
00380         return(ret_val);
00381 }

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 135 of file lininfo.c.

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

Referenced by update_devs().

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

int get_fs_info ( struct fs_info fsinfo  ) 

Get information about filesystems

Parameters:
fsinfo fs_info structure pointer
Returns:
0

Definition at line 513 of file lininfo.c.

References fs_info::devs, FS_FILE, fsinfo, fs_info::nodevs, and STR_DEFAULT.

Referenced by update_fs_info().

00514 {
00515         g_assert(fsinfo!=NULL);
00516 
00517         #define STR_DEFAULT _("No info.")
00518         gchar *contents,*p;
00519         char second[20];
00520         char first[20];
00521         char line[80];
00522 
00523 
00524         if(g_file_get_contents(FS_FILE,&contents,NULL,NULL)==FALSE){
00525                 /* Clean up and exit */
00526                 g_warning("No filesystems file");
00527                 g_free(contents);
00528                 fsinfo->devs=g_string_new(STR_DEFAULT);
00529                 fsinfo->nodevs=g_string_new(STR_DEFAULT);
00530                 return -1;
00531         }
00532 
00533         /* Create GString instances */
00534         fsinfo->devs=g_string_new("");
00535         fsinfo->nodevs=g_string_new("");
00536 
00537         p=contents;
00538         /* Pseudo and normal in separate lists */
00539         while(sscanf(p,"%[^\n]",line)!=EOF){
00540                 sscanf(line,"%s %s",first,second);
00541                 if(line[0]!='n'){
00542                         fsinfo->devs=g_string_append(fsinfo->devs,first);
00543                         fsinfo->devs=g_string_append(fsinfo->devs,"\n");
00544                 }else{
00545                         fsinfo->nodevs=g_string_append(fsinfo->nodevs,second);
00546                         fsinfo->nodevs=g_string_append(fsinfo->nodevs,"\n");
00547                 }
00548 
00549 
00550                 p=strchr(p,'\n') +1; 
00551         }
00552 
00553         g_free(contents);
00554 
00555         return 0;
00556 }

int get_loadavg_info ( struct cmd_ver cmdversion  ) 

Get load average information

Parameters:
cmdversion pointer to cmd_ver to store the data
Returns:
0 on success, 1 on error

Definition at line 387 of file lininfo.c.

References cmdversion, LOAD_FILE, and cmd_ver::loadavg.

Referenced by update_process().

00388 {
00389         g_assert(cmdversion!=NULL);
00390 
00391         char *unk_string=_("Unknown");
00392         gchar *contents;
00393         int ret_val=0;
00394 
00395         if(g_file_get_contents(LOAD_FILE,&contents,NULL,NULL)==FALSE){
00396                 g_free(contents);
00397                 cmdversion->loadavg=g_string_new(unk_string);
00398                 ret_val=-1;
00399         }else{
00400                 cmdversion->loadavg=g_string_new(contents);
00401                 g_free(contents);
00402         }
00403 
00404         return(ret_val);
00405 }

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 99 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().

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

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_mod_info ( struct modules_info modinfo  ) 

Get information about modules

Parameters:
modinfo modules_info structure pointer
Returns:
0 on success, -1 otherwise

Definition at line 563 of file lininfo.c.

References modules_info::contents, MOD_FILE, and modinfo.

Referenced by update_modules_info().

00564 {
00565         g_assert(modinfo!=NULL);
00566 
00567         gchar *contents,*p,*p2;
00568         gsize length;
00569         int i;
00570         char *states[]={"Live", "Loading", "Unloading"};
00571         char name[20];
00572         char size[10];
00573         char refcount[5];
00574         char status[10];
00575         char address[20];
00576 
00577 
00578         if((g_file_get_contents(MOD_FILE,&contents,&length,NULL))==FALSE){
00579                 g_warning("No modules information file!");
00580                 g_free(contents);
00581                 return -1;
00582         }
00583 
00584 
00585         /* In case we have the buffer filled... */
00586         modinfo->contents=g_string_new("");
00587 
00588         p=contents;
00589 
00590         /* Traverse and process the buffer */
00591         while(p-contents!=length){
00592                 sscanf(p,"%s %s %s",name,size,refcount);
00593                 /* Try to find the status */
00594                 for(i=0;i<3;i++){
00595                         if((p2=strstr(p,states[i]))!=NULL){
00596                                 /* We found the state */
00597                                 sscanf(p2,"%s %s",status,address);
00598                                 break;
00599                         }
00600                 }
00601                 if(p2!=NULL){
00602                         modinfo->contents=g_string_append(modinfo->contents,name);
00603                         modinfo->contents=g_string_append(modinfo->contents," ");
00604                         modinfo->contents=g_string_append(modinfo->contents, size);
00605                         modinfo->contents=g_string_append(modinfo->contents, " ");
00606                         modinfo->contents=g_string_append(modinfo->contents, refcount);
00607                         modinfo->contents=g_string_append(modinfo->contents," ");
00608                         modinfo->contents=g_string_append(modinfo->contents,status);
00609                         modinfo->contents=g_string_append(modinfo->contents," ");
00610                         modinfo->contents=g_string_append(modinfo->contents, address);
00611                         modinfo->contents=g_string_append(modinfo->contents,"\n");
00612                 }
00613 
00614                 /* Let's point to the next line */
00615                 p=strchr(p2,'\n')+1;
00616         }
00617 
00618         /* Cleaning up and going back to system */
00619 
00620         g_free(contents);  
00621 
00622         return 0;
00623 
00624 }

int get_net_info ( struct net_dev_info netinfo,
const int  index 
)

Get information about a network interface

Parameters:
netinfo net_dev_info structure pointer
index device index.
Returns:
0 on success, -1 on error

Definition at line 457 of file lininfo.c.

References BASE, net_dev_info::bytes, net_dev_info::compressed, net_dev_info::drop, net_dev_info::errs, net_dev_info::fifo, NET_DEVS, netinfo, net_dev_info::packets, net_dev_info::r_frame, net_dev_info::r_multicast, skip_lines(), net_dev_info::t_carrier, and net_dev_info::t_colls.

Referenced by update_net_info().

00458 {
00459         g_assert(netinfo!=NULL && index >=0);
00460 
00461         gchar *contents;
00462         char *p;
00463         char name[10];
00464         #define BASE 2  /* Base for skip's jump */
00465 
00466         if(g_file_get_contents(NET_DEVS,&contents,NULL,NULL)==FALSE){
00467                 g_free(contents);
00468                 return -1;
00469         }
00470 
00471         /* File exists */
00472         p=skip_lines((char *)contents,BASE+index);
00473         
00474         /* 
00475         *       Change the ':' by a " " (white space) 
00476         *       This is to make easier the sscanf pattern
00477         *       
00478         */
00479 
00480         {
00481                 char *p2=NULL;
00482                 if((p2=strchr(p,':'))!=NULL)
00483                         *p2=' ';
00484                 
00485         }
00486 
00487         /* Now we are ready to read */
00488         sscanf(p,"%s %llu %lu %d %d %d %d %d %d %llu %lu %d %d %d %d %d %d",
00489                         name,
00490                         &netinfo->bytes[0],&netinfo->packets[0],&netinfo->errs[0],
00491                         &netinfo->drop[0],&netinfo->fifo[0],&netinfo->r_frame,
00492                         &netinfo->compressed[0],&netinfo->r_multicast,
00493                         &netinfo->bytes[1],&netinfo->packets[1],&netinfo->errs[1],
00494                         &netinfo->drop[1],&netinfo->fifo[1],&netinfo->t_colls,
00495                         &netinfo->t_carrier,&netinfo->compressed[1]);
00496 
00497         /* Remove the ':' character */
00498         if((p=strchr(name,':'))!=NULL)
00499                 *p='\0';
00500 
00501         /* Clean up */
00502         g_free(contents);
00503         
00504         return 0;
00505 }

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 163 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().

00164 {
00165         gchar *unk_string=_("Unknown");
00166         gchar *contents;
00167         int ret = 0;
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                 ret = -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                 ret = -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(ret);
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 Tue Apr 1 22:52:55 2008 for lkmonitor by  doxygen 1.5.1