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);
|
||||||
}
|
}
|
||||||
|
@ -41,97 +41,104 @@
|
|||||||
*/
|
*/
|
||||||
char *get_diskstat()
|
char *get_diskstat()
|
||||||
{
|
{
|
||||||
static char buf[SS_BUFSIZE];
|
static char buf[SS_BUFSIZE];
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
char tt[80];
|
char tt[80];
|
||||||
struct statfs sfs;
|
struct statfs sfs;
|
||||||
unsigned long temp;
|
unsigned long temp;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
char *mtab, *dev, *fs, *type;
|
char *mtab, *dev, *fs, *type;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
#elif defined(__FreeBSD__) || (__NetBSD__)
|
#elif defined(__FreeBSD__) || (__NetBSD__)
|
||||||
struct statfs *mntbuf;
|
struct statfs *mntbuf;
|
||||||
long mntsize;
|
long mntsize;
|
||||||
int i, j = 0;
|
int i, j = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
#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));
|
||||||
dev = strtok(mtab, " \t");
|
while (fgets(mtab, PATH_MAX - 1, fp)) {
|
||||||
fs = strtok(NULL, " \t");
|
dev = strtok(mtab, " \t");
|
||||||
type = strtok(NULL, " \t");
|
fs = strtok(NULL, " \t");
|
||||||
if (strncmp((char *)"/dev/", dev, 5) == 0) {
|
type = strtok(NULL, " \t");
|
||||||
if (statfs(fs, &sfs) == 0) {
|
if (strncmp((char *)"/dev/", dev, 5) == 0) {
|
||||||
i++;
|
if (statfs(fs, &sfs) == 0) {
|
||||||
if (tmp == NULL)
|
i++;
|
||||||
tmp = xstrcpy((char *)",");
|
if (tmp == NULL)
|
||||||
else
|
tmp = xstrcpy((char *)",");
|
||||||
tmp = xstrcat(tmp, (char *)",");
|
else
|
||||||
tt[0] = '\0';
|
tmp = xstrcat(tmp, (char *)",");
|
||||||
temp = (unsigned long)(sfs.f_bsize / 512L);
|
tt[0] = '\0';
|
||||||
sprintf(tt, "%lu %lu %s %s",
|
temp = (unsigned long)(sfs.f_bsize / 512L);
|
||||||
(unsigned long)(sfs.f_blocks * temp) / 2048L,
|
sprintf(tt, "%lu %lu %s %s",
|
||||||
(unsigned long)(sfs.f_bavail * temp) / 2048L,
|
(unsigned long)(sfs.f_blocks * temp) / 2048L,
|
||||||
fs, type);
|
(unsigned long)(sfs.f_bavail * temp) / 2048L,
|
||||||
tmp = xstrcat(tmp, tt);
|
fs, type);
|
||||||
}
|
tmp = xstrcat(tmp, tt);
|
||||||
if (i == 10) /* No more then 10 filesystems */
|
}
|
||||||
break;
|
if (i == 10) /* No more then 10 filesystems */
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
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;");
|
||||||
else
|
else
|
||||||
sprintf(buf, "100:%d%s;", i, tmp);
|
sprintf(buf, "100:%d%s;", i, tmp);
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) || (__NetBSD__)
|
#elif defined(__FreeBSD__) || (__NetBSD__)
|
||||||
|
|
||||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
|
||||||
|
|
||||||
for (i = 0; i < mntsize; i++) {
|
|
||||||
if ((strncmp(mntbuf[i].f_fstypename, (char *)"kernfs", 6)) &&
|
|
||||||
(strncmp(mntbuf[i].f_fstypename, (char *)"procfs", 6)) &&
|
|
||||||
(statfs(mntbuf[i].f_mntonname, &sfs) == 0)) {
|
|
||||||
if (tmp == NULL)
|
|
||||||
tmp = xstrcpy((char *)",");
|
|
||||||
else
|
|
||||||
tmp = xstrcat(tmp, (char *)",");
|
|
||||||
tt[0] = '\0';
|
|
||||||
temp = (unsigned long)(sfs.f_bsize / 512L);
|
|
||||||
sprintf(tt, "%lu %lu %s %s",
|
|
||||||
(unsigned long)(sfs.f_blocks * temp) / 2048L,
|
|
||||||
(unsigned long)(sfs.f_bavail * temp) / 2048L,
|
|
||||||
mntbuf[i].f_mntonname, mntbuf[i].f_fstypename);
|
|
||||||
tmp = xstrcat(tmp, tt);
|
|
||||||
j++;
|
|
||||||
if (j == 10)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (strlen(tmp) > (SS_BUFSIZE - 8))
|
|
||||||
sprintf(buf, "100:0;");
|
|
||||||
else
|
|
||||||
sprintf(buf, "100:%d%s;", j, tmp);
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* Not supported, so return nothing usefull.
|
|
||||||
*/
|
|
||||||
sprintf(buf, "100:0;");
|
sprintf(buf, "100:0;");
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < mntsize; i++) {
|
||||||
|
if ((strncmp(mntbuf[i].f_fstypename, (char *)"kernfs", 6)) &&
|
||||||
|
(strncmp(mntbuf[i].f_fstypename, (char *)"procfs", 6)) &&
|
||||||
|
(statfs(mntbuf[i].f_mntonname, &sfs) == 0)) {
|
||||||
|
if (tmp == NULL)
|
||||||
|
tmp = xstrcpy((char *)",");
|
||||||
|
else
|
||||||
|
tmp = xstrcat(tmp, (char *)",");
|
||||||
|
tt[0] = '\0';
|
||||||
|
temp = (unsigned long)(sfs.f_bsize / 512L);
|
||||||
|
sprintf(tt, "%lu %lu %s %s",
|
||||||
|
(unsigned long)(sfs.f_blocks * temp) / 2048L,
|
||||||
|
(unsigned long)(sfs.f_bavail * temp) / 2048L,
|
||||||
|
mntbuf[i].f_mntonname, mntbuf[i].f_fstypename);
|
||||||
|
tmp = xstrcat(tmp, tt);
|
||||||
|
j++;
|
||||||
|
if (j == 10) /* No more then 10 filesystems */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strlen(tmp) > (SS_BUFSIZE - 8))
|
||||||
|
sprintf(buf, "100:0;");
|
||||||
|
else
|
||||||
|
sprintf(buf, "100:%d%s;", j, tmp);
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Not supported, so return nothing usefull.
|
||||||
|
*/
|
||||||
|
sprintf(buf, "100:0;");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return buf;
|
if (tmp != NULL)
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user