Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / memory / memory_sgi.cpp
blobcacd0253e2f5504e5bd8aa40e6af5b2b96681e71
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/sysmp.h>
5 #include <sys/ipc.h>
7 // The following define is needed for SGI IRIX 6.2
8 #define _KMEMUSER
9 #include <sys/shm.h>
11 #include <sys/param.h>
12 #include <sys/swap.h>
14 #ifndef UBSIZE
15 #define UBSIZE 512
16 #endif
19 void KCMMemory::fetchValues()
21 int pagesize = getpagesize();
23 struct rminfo rmi;
24 if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
25 return;
26 memoryInfos[TOTAL_MEM] = MEMORY(rmi.physmem) * pagesize; // total physical memory (without swaps)
27 memoryInfos[FREE_MEM] = MEMORY(rmi.freemem) * pagesize; // total free physical memory (without swaps)
28 memoryInfos[BUFFER_MEM] = MEMORY(rmi.bufmem) * pagesize;
31 //FIXME: memoryInfos[CACHED_MEM]"
32 memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
34 long val;
35 swapctl(SC_GETSWAPTOT, &val);
36 memoryInfos[SWAP_MEM] = MEMORY(val) * UBSIZE; // total size of all swap-partitions
38 swapctl(SC_GETFREESWAP, &val);
39 memoryInfos[FREESWAP_MEM] = MEMORY(val) * UBSIZE; // free memory in swap-partitions
41 #ifndef MPKA_SHMINFO
42 /* Irix 6.5 (also 6.4?) */
43 memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
44 #else
45 FILE *kmem = fopen("/dev/kmem", "r");
46 if( kmem == 0 ) {
47 memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
48 return;
51 long shmip = sysmp(MP_KERNADDR, MPKA_SHMINFO);
52 fseek( kmem, shmip, 0 );
53 struct shminfo shmi;
54 fread( &shmi, sizeof(shmi), 1, kmem );
56 long shmem = sysmp(MP_KERNADDR, MPKA_SHM);
58 val = 0;
59 long pos;
60 struct shmid_ds shmid;
61 for( int i=0 ; i<shmi.shmmni ; i++ ) {
62 fseek( kmem, shmem, 0 );
63 shmem += sizeof(shmem);
64 fread( &pos, sizeof(shmem), 1, kmem );
65 if(pos != 0) {
66 fseek( kmem, pos, 0 );
67 fread( &shmid, sizeof(shmid), 1, kmem );
68 val += shmid.shm_segsz;
71 memoryInfos[SHARED_MEM] = MEMORY(val);
73 fclose(kmem);
74 #endif