Small fixes, code cleanup
This commit is contained in:
parent
dd62eda1b4
commit
54df4da730
@ -1169,7 +1169,7 @@ void scheduler(void)
|
|||||||
static char doing[32], buf[2048];
|
static char doing[32], buf[2048];
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm *tm, *utm;
|
struct tm *tm, *utm;
|
||||||
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
|
#if defined(__linux__)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
#endif
|
#endif
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
@ -1277,16 +1277,17 @@ void scheduler(void)
|
|||||||
/*
|
/*
|
||||||
* Check the systems load average. FIXME: doesn't work in FreeBSD !!!
|
* Check the systems load average. FIXME: doesn't work in FreeBSD !!!
|
||||||
*/
|
*/
|
||||||
Load = 0.0;
|
Load = loadavg[0] = loadavg[1] = loadavg[2] = 0.0;
|
||||||
loadavg[0] = loadavg[1] = loadavg[2] = 0.0;
|
|
||||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||||
if (getloadavg(loadavg, 3) == 3) {
|
if (getloadavg(loadavg, 3) == 3) {
|
||||||
Load = loadavg[0];
|
Load = loadavg[0];
|
||||||
}
|
}
|
||||||
#else
|
#elif defined(__linux__)
|
||||||
if ((fp = fopen((char *)"/proc/loadavg", "r"))) {
|
if ((fp = fopen((char *)"/proc/loadavg", "r"))) {
|
||||||
if (fscanf(fp, "%f %f %f", &loadavg[0], &loadavg[1], &loadavg[2]) == 3) {
|
if (fscanf(fp, "%lf %lf %lf", &loadavg[0], &loadavg[1], &loadavg[2]) == 3) {
|
||||||
Load = loadavg[0];
|
Load = loadavg[0];
|
||||||
|
} else {
|
||||||
|
tasklog('-', "error");
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,13 @@ char *get_diskstat()
|
|||||||
|
|
||||||
#if defined (__linux__)
|
#if defined (__linux__)
|
||||||
|
|
||||||
mtab = calloc(PATH_MAX, sizeof(char));
|
if ((fp = fopen((char *)"/etc/mtab", "r")) == NULL) {
|
||||||
if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) {
|
|
||||||
sprintf(buf, "100:0;");
|
sprintf(buf, "100:0;");
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(mtab, 255, fp)) {
|
mtab = calloc(PATH_MAX, sizeof(char));
|
||||||
|
while (fgets(mtab, PATH_MAX - 1, fp)) {
|
||||||
dev = strtok(mtab, " \t");
|
dev = strtok(mtab, " \t");
|
||||||
fs = strtok(NULL, " \t");
|
fs = strtok(NULL, " \t");
|
||||||
type = strtok(NULL, " \t");
|
type = strtok(NULL, " \t");
|
||||||
@ -90,6 +90,7 @@ char *get_diskstat()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
free(mtab);
|
||||||
|
|
||||||
if (strlen(tmp) > (SS_BUFSIZE - 8))
|
if (strlen(tmp) > (SS_BUFSIZE - 8))
|
||||||
sprintf(buf, "100:0;");
|
sprintf(buf, "100:0;");
|
||||||
@ -98,7 +99,10 @@ char *get_diskstat()
|
|||||||
|
|
||||||
#elif defined(__FreeBSD__) || (__NetBSD__)
|
#elif defined(__FreeBSD__) || (__NetBSD__)
|
||||||
|
|
||||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
|
||||||
|
sprintf(buf, "100:0;");
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < mntsize; i++) {
|
for (i = 0; i < mntsize; i++) {
|
||||||
if ((strncmp(mntbuf[i].f_fstypename, (char *)"kernfs", 6)) &&
|
if ((strncmp(mntbuf[i].f_fstypename, (char *)"kernfs", 6)) &&
|
||||||
@ -116,7 +120,7 @@ char *get_diskstat()
|
|||||||
mntbuf[i].f_mntonname, mntbuf[i].f_fstypename);
|
mntbuf[i].f_mntonname, mntbuf[i].f_fstypename);
|
||||||
tmp = xstrcat(tmp, tt);
|
tmp = xstrcat(tmp, tt);
|
||||||
j++;
|
j++;
|
||||||
if (j == 10)
|
if (j == 10) /* No more then 10 filesystems */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,6 +135,9 @@ char *get_diskstat()
|
|||||||
sprintf(buf, "100:0;");
|
sprintf(buf, "100:0;");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (tmp != NULL)
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user