[packages] monit: update to 5.2.4
[openwrt/svn-archive/archive.git] / admin / monit / patches / 002-uclibc_loadavg.patch
1 --- a/process/sysdep_LINUX.c
2 +++ b/process/sysdep_LINUX.c
3 @@ -144,6 +144,45 @@ static time_t get_starttime() {
4
5 return time(NULL) - (time_t)up;
6 }
7 +
8 +
9 +/* uclibc and dietlibc do not have this junk -ReneR */
10 +#if defined (__UCLIBC__) || defined (__dietlibc__)
11 +static int getloadavg (double loadavg[], int nelem)
12 +{
13 + int fd;
14 +
15 + fd = open ("/proc/loadavg", O_RDONLY);
16 + if (fd < 0)
17 + return -1;
18 + else
19 + {
20 + char buf[65], *p;
21 + ssize_t nread;
22 + int i;
23 +
24 + nread = read (fd, buf, sizeof buf - 1);
25 + close (fd);
26 + if (nread <= 0)
27 + return -1;
28 + buf[nread - 1] = '\0';
29 +
30 + if (nelem > 3)
31 + nelem = 3;
32 + p = buf;
33 + for (i = 0; i < nelem; ++i)
34 + {
35 + char *endp;
36 + loadavg[i] = strtod (p, &endp);
37 + if (endp == p)
38 + return -1;
39 + p = endp;
40 + }
41 +
42 + return i;
43 + }
44 +}
45 +#endif
46
47
48 /* ------------------------------------------------------------------ Public */