]> git.pld-linux.org Git - packages/monit.git/blame - monit-meminfo-vs-kcore.patch
- updated to 4.6
[packages/monit.git] / monit-meminfo-vs-kcore.patch
CommitLineData
d2873698
AM
1diff -urN monit-4.0.org/process/sysdep_LINUX.c monit-4.0/process/sysdep_LINUX.c
2--- monit-4.0.org/process/sysdep_LINUX.c 2003-09-08 19:20:44.000000000 +0200
a249c52b
AM
3+++ monit-4.0/process/sysdep_LINUX.c 2003-09-08 19:26:46.000000000 +0200
4@@ -84,24 +84,38 @@
d2873698
AM
5 * @file
6 */
7
8-#define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
a249c52b 9+#define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
d2873698
AM
10+#define FREEMEM "MemFree:"
11+#define FREESWAP "SwapFree:"
12
13 int init_process_info_sysdep(void) {
14
15- struct stat buf;
16-
17+ int memfd;
18+ char buf[1024], *ptr1, *ptr2;
19
20- /* I hope this is okay hack to get the total memsize. (-: */
21+ if ((memfd = open("/proc/meminfo", O_RDONLY)) == -1) {
22+ return FALSE;
23+ }
24
25- if ( stat("/proc/kcore", &buf) != 0 ) {
26+ /* read the file */
887147d8 27+ if (read(memfd, buf, sizeof(buf)) < 0) {
d2873698
AM
28+ close(memfd);
29+ return FALSE;
30+ }
31
32- return FALSE;
33+ close(memfd);
34+
35+ ptr1 = strstr(buf, FREEMEM);
36+ ptr2 = strstr(buf, FREESWAP);
37
38+ if (!ptr1 || !ptr2) {
39+ return FALSE;
40 }
41
42- num_cpus= sysconf(_SC_NPROCESSORS_CONF);
43+ /* we only care about integer values */
44+ mem_kbyte_max = atoi(ptr1+strlen(FREEMEM)) /* + atoi(ptr2+strlen(FREESWAP)) */ ;
45
46- mem_kbyte_max = buf.st_size>>10;
47+ num_cpus= sysconf(_SC_NPROCESSORS_CONF);
48
49 return TRUE;
50
This page took 0.145644 seconds and 4 git commands to generate.