Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / memory / memory_solaris.cpp
blob68ef7c5860dcd132a77e5ee6b4f0d3a9d93cd9c1
1 /*
2 * memory_solaris.cpp
4 * Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
5 */
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <kstat.h>
11 /* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
13 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
16 #endif
18 #include <sys/stat.h>
19 #include <sys/swap.h>
20 #include <vm/anon.h>
22 #define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) * (t_memsize) a)
24 void KCMMemory::fetchValues() {
26 kstat_ctl_t *kctl;
27 kstat_t *ksp;
28 kstat_named_t *kdata;
31 * get a kstat handle first and update the user's kstat chain
33 if( (kctl = kstat_open()) == NULL )
34 return;
35 while( kstat_chain_update( kctl ) != 0 )
39 * traverse the kstat chain to find the appropriate kstat
41 if( (ksp = kstat_lookup( kctl, "unix", 0, "system_pages" )) == NULL )
42 return;
44 if( kstat_read( kctl, ksp, NULL ) == -1 )
45 return;
48 * lookup the data
50 #if 0
51 kdata = (kstat_named_t *) kstat_data_lookup( ksp, "physmem" );
52 if( kdata != NULL ) {
53 memoryInfos[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
55 #endif
56 memoryInfos[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
58 kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
59 if( kdata != NULL )
60 memoryInfos[FREE_MEM] = PAGETOK(kdata->value.ui32);
61 #ifdef __GNUC__
62 #warning "FIXME: memoryInfos[CACHED_MEM]"
63 #endif
64 memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
66 kstat_close( kctl );
69 * Swap Info
72 struct anoninfo am_swap;
73 long swaptotal;
74 long swapfree;
75 long swapused;
77 swaptotal = swapused = swapfree = 0L;
80 * Retrieve overall swap information from anonymous memory structure -
81 * which is the same way "swap -s" retrieves it's statistics.
83 * swapctl(SC_LIST, void *arg) does not return what we are looking for.
86 if (swapctl(SC_AINFO, &am_swap) == -1)
87 return;
89 swaptotal = am_swap.ani_max;
90 swapused = am_swap.ani_resv;
91 swapfree = swaptotal - swapused;
93 memoryInfos[SWAP_MEM] = PAGETOK(swaptotal);
94 memoryInfos[FREESWAP_MEM] = PAGETOK(swapfree);