diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index 68b6bd7b..0fe5d091 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -1169,7 +1169,7 @@ void scheduler(void) static char doing[32], buf[2048]; time_t now; struct tm *tm, *utm; -#if !defined(__FreeBSD__) && !defined(__NetBSD__) +#if defined(__linux__) FILE *fp; #endif struct pollfd pfd; @@ -1277,16 +1277,17 @@ void scheduler(void) /* * Check the systems load average. FIXME: doesn't work in FreeBSD !!! */ - Load = 0.0; - loadavg[0] = loadavg[1] = loadavg[2] = 0.0; + Load = loadavg[0] = loadavg[1] = loadavg[2] = 0.0; #if defined(__FreeBSD__) || defined(__NetBSD__) if (getloadavg(loadavg, 3) == 3) { Load = loadavg[0]; } -#else +#elif defined(__linux__) 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]; + } else { + tasklog('-', "error"); } fclose(fp); } diff --git a/mbtask/taskdisk.c b/mbtask/taskdisk.c index 17cf0a2f..644640a4 100644 --- a/mbtask/taskdisk.c +++ b/mbtask/taskdisk.c @@ -41,97 +41,104 @@ */ char *get_diskstat() { - static char buf[SS_BUFSIZE]; - char *tmp = NULL; - char tt[80]; - struct statfs sfs; - unsigned long temp; + static char buf[SS_BUFSIZE]; + char *tmp = NULL; + char tt[80]; + struct statfs sfs; + unsigned long temp; #if defined(__linux__) - char *mtab, *dev, *fs, *type; - FILE *fp; - int i = 0; + char *mtab, *dev, *fs, *type; + FILE *fp; + int i = 0; #elif defined(__FreeBSD__) || (__NetBSD__) - struct statfs *mntbuf; - long mntsize; - int i, j = 0; + struct statfs *mntbuf; + long mntsize; + int i, j = 0; #endif - buf[0] = '\0'; + buf[0] = '\0'; #if defined (__linux__) - mtab = calloc(PATH_MAX, sizeof(char)); - if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) { - sprintf(buf, "100:0;"); - return buf; - } + if ((fp = fopen((char *)"/etc/mtab", "r")) == NULL) { + sprintf(buf, "100:0;"); + return buf; + } - while (fgets(mtab, 255, fp)) { - dev = strtok(mtab, " \t"); - fs = strtok(NULL, " \t"); - type = strtok(NULL, " \t"); - if (strncmp((char *)"/dev/", dev, 5) == 0) { - if (statfs(fs, &sfs) == 0) { - i++; - 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, - fs, type); - tmp = xstrcat(tmp, tt); - } - if (i == 10) /* No more then 10 filesystems */ - break; - } + mtab = calloc(PATH_MAX, sizeof(char)); + while (fgets(mtab, PATH_MAX - 1, fp)) { + dev = strtok(mtab, " \t"); + fs = strtok(NULL, " \t"); + type = strtok(NULL, " \t"); + if (strncmp((char *)"/dev/", dev, 5) == 0) { + if (statfs(fs, &sfs) == 0) { + i++; + 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, + fs, type); + tmp = xstrcat(tmp, tt); + } + if (i == 10) /* No more then 10 filesystems */ + break; } - fclose(fp); + } + fclose(fp); + free(mtab); - if (strlen(tmp) > (SS_BUFSIZE - 8)) - sprintf(buf, "100:0;"); - else - sprintf(buf, "100:%d%s;", i, tmp); + if (strlen(tmp) > (SS_BUFSIZE - 8)) + sprintf(buf, "100:0;"); + else + sprintf(buf, "100:%d%s;", i, tmp); #elif defined(__FreeBSD__) || (__NetBSD__) - mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); - - 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. - */ + if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 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 - return buf; + if (tmp != NULL) + free(tmp); + + return buf; }