Updates for diskwatcher
This commit is contained in:
parent
f55ff6280f
commit
f10a39a9e7
22
lib/clcomm.c
22
lib/clcomm.c
@ -472,19 +472,29 @@ unsigned long sequencer()
|
||||
int enoughspace(unsigned long needed)
|
||||
{
|
||||
char *buf, *res;
|
||||
int rc = 3;
|
||||
int rc = 3, cnt;
|
||||
unsigned long avail = 0L;
|
||||
|
||||
buf = calloc(SS_BUFSIZE, sizeof(char));
|
||||
sprintf(buf, "DSPC:1,%ld;", needed);
|
||||
|
||||
if (socket_send(buf) == 0) {
|
||||
free(buf);
|
||||
buf = socket_receive();
|
||||
res = strtok(buf, ",");
|
||||
res = strtok(NULL, ";");
|
||||
rc = atoi(res);
|
||||
sprintf(buf, "%s", socket_receive());
|
||||
res = strtok(buf, ":");
|
||||
cnt = atoi(strtok(NULL, ","));
|
||||
if (cnt == 1) {
|
||||
rc = atoi(strtok(NULL, ";"));
|
||||
} else if (cnt == 2) {
|
||||
rc = atoi(strtok(NULL, ","));
|
||||
avail = atol(strtok(NULL, ";"));
|
||||
if (rc == 0)
|
||||
Syslog('+', "Only %ld MBytes diskspace, need %ld MBytes", avail, needed);
|
||||
} else {
|
||||
Syslog('-', "Error in enoughspace()");
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -346,10 +346,8 @@ int main(int argc, char *argv[])
|
||||
/*
|
||||
* Don't do outbound calls if low diskspace
|
||||
*/
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
WriteError("Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (addr == NULL) {
|
||||
WriteError("Calling mbcico without node address not supported anymore");
|
||||
|
@ -143,10 +143,8 @@ int main(int argc, char **argv)
|
||||
if (!do_quiet)
|
||||
printf("\n");
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (lockprogram((char *)"mbaff")) {
|
||||
if (!do_quiet)
|
||||
|
@ -167,10 +167,8 @@ int main(int argc, char **argv)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract work directory from the first commandline parameter
|
||||
|
@ -424,10 +424,8 @@ int main(int argc, char **argv)
|
||||
/*
|
||||
* Not yet locked, if anything goes wrong, exit with die(MBERR_NO_PROGLOCK)
|
||||
*/
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (do_mail) {
|
||||
/*
|
||||
|
@ -234,10 +234,8 @@ int main(int argc, char **argv)
|
||||
if (!do_quiet)
|
||||
printf("\n");
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (lockprogram((char *)"mbfile")) {
|
||||
if (!do_quiet)
|
||||
|
@ -173,10 +173,8 @@ void ImportFiles(int Area)
|
||||
/*
|
||||
* Check diskspace
|
||||
*/
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
Files++;
|
||||
memset(&f_db, 0, sizeof(f_db));
|
||||
|
@ -358,10 +358,8 @@ void ReqIndex(void)
|
||||
|
||||
if (area.Available) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("\r%4ld => %-44s \b\b\b\b", i, area.Name);
|
||||
@ -599,10 +597,8 @@ void HtmlIndex(char *Lang)
|
||||
|
||||
if (area.Available) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("\r%4ld => %-44s \b\b\b\b", i, area.Name);
|
||||
|
@ -86,10 +86,8 @@ void Kill(void)
|
||||
|
||||
if ((area.Available) && (area.DLdays || area.FDdays) && (!area.CDrom)) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("\r%4d => %-44s \b\b\b\b", i, area.Name);
|
||||
|
@ -79,10 +79,8 @@ void PackFileBase(void)
|
||||
|
||||
if (area.Available && !area.CDrom) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("\r%4d => %-44s", i, area.Name);
|
||||
|
@ -158,10 +158,8 @@ void SortFileBase(int Area)
|
||||
|
||||
if (area.Available) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
printf("Sorting area %d: %-44s", Area, area.Name);
|
||||
|
@ -177,10 +177,8 @@ int main(int argc,char *argv[])
|
||||
Syslog(' ', cmd);
|
||||
free(cmd);
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (lockprogram((char *)"mbindex")) {
|
||||
if (!do_quiet)
|
||||
|
@ -277,10 +277,8 @@ void DoMsgBase()
|
||||
fread(&msgs, msgshdr.recsize, 1, pAreas);
|
||||
if (msgs.Active) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (!do_quiet) {
|
||||
colour(3, 0);
|
||||
@ -308,10 +306,8 @@ void DoMsgBase()
|
||||
arearec++;
|
||||
if (msgs.Active) {
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
die(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
Nopper();
|
||||
if (!do_quiet) {
|
||||
|
@ -268,7 +268,7 @@ void system_stat(void)
|
||||
mvprintw(12,62, "Load avg");
|
||||
hor_lin(13,30,8);
|
||||
hor_lin(13,45,8);
|
||||
mvprintw(13,62, "Disk stat");
|
||||
mvprintw(13,62, "Diskspace");
|
||||
mvprintw(14, 6, "Client connects");
|
||||
mvprintw(15, 6, "Peak connections");
|
||||
mvprintw(16, 6, "Protocol syntax errors");
|
||||
|
@ -100,10 +100,8 @@ int main(int argc, char **argv)
|
||||
Syslog(' ', cmd);
|
||||
free(cmd);
|
||||
|
||||
if (enoughspace(CFG.freespace) == 0) {
|
||||
Syslog('+', "Low diskspace, abort");
|
||||
if (enoughspace(CFG.freespace) == 0)
|
||||
ExitClient(MBERR_DISK_FULL);
|
||||
}
|
||||
|
||||
if (lockprogram((char *)"mbuser")) {
|
||||
if (!do_quiet)
|
||||
|
@ -378,8 +378,8 @@ char *exe_cmd(char *in)
|
||||
|
||||
/*
|
||||
* DSPC:1,n; Check free space in MBytes
|
||||
* 100:1,0; No
|
||||
* 100:1,1; Yes
|
||||
* 100:2,0,n; No, n = lowest size in MBytes
|
||||
* 100:2,1,n; Yes, n = lowest size in MBytes
|
||||
* 100:1,2; Unknown
|
||||
* 100:1,3; Error
|
||||
*/
|
||||
|
@ -40,6 +40,7 @@ typedef struct _mfs_list {
|
||||
char *fstype; /* FS type */
|
||||
unsigned long size; /* Size in MB */
|
||||
unsigned long avail; /* Available in MB */
|
||||
unsigned ro : 1; /* Read-Only fs. */
|
||||
} mfs_list;
|
||||
|
||||
mfs_list *mfs = NULL; /* List of filesystems */
|
||||
@ -72,6 +73,7 @@ void tidy_mfslist(mfs_list **fap)
|
||||
for (tmp = *fap; tmp; tmp = old) {
|
||||
old = tmp->next;
|
||||
free(tmp->mountpoint);
|
||||
free(tmp->fstype);
|
||||
free(tmp);
|
||||
}
|
||||
*fap = NULL;
|
||||
@ -105,6 +107,7 @@ void fill_mfslist(mfs_list **fap, char *mountpoint, char *fstype)
|
||||
tmp->fstype = xstrcpy(fstype);
|
||||
tmp->size = 0L;
|
||||
tmp->avail = 0L;
|
||||
tmp->ro = TRUE; // Read-only, statfs will set real value.
|
||||
*fap = tmp;
|
||||
}
|
||||
|
||||
@ -132,20 +135,12 @@ char *disk_check(char *token)
|
||||
{
|
||||
static char buf[SS_BUFSIZE];
|
||||
mfs_list *tmp;
|
||||
unsigned long needed;
|
||||
unsigned long needed, lowest = 0xffffffff;
|
||||
int rc;
|
||||
|
||||
strtok(token, ",");
|
||||
needed = atol(strtok(NULL, ";"));
|
||||
|
||||
if (! needed) {
|
||||
/*
|
||||
* Answer enough space
|
||||
*/
|
||||
sprintf(buf, "100:1,1");
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (mfs == NULL) {
|
||||
/*
|
||||
* Answer Error
|
||||
@ -158,24 +153,18 @@ char *disk_check(char *token)
|
||||
Syslog('!', "disk_check() mutex_lock failed rc=%d", rc);
|
||||
|
||||
for (tmp = mfs; tmp; tmp = tmp->next) {
|
||||
if (tmp->avail < needed) {
|
||||
/*
|
||||
* Answer Not enough space
|
||||
*/
|
||||
if ((rc = pthread_mutex_unlock(&a_mutex)))
|
||||
Syslog('!', "disk_check() mutex_unlock failed rc=%d", rc);
|
||||
sprintf(buf, "100:1,0");
|
||||
return buf;
|
||||
}
|
||||
if (!tmp->ro && (tmp->avail < lowest))
|
||||
lowest = tmp->avail;
|
||||
}
|
||||
|
||||
if ((rc = pthread_mutex_unlock(&a_mutex)))
|
||||
Syslog('!', "disk_check() mutex_unlock failed rc=%d", rc);
|
||||
|
||||
/*
|
||||
* Enough space
|
||||
*/
|
||||
sprintf(buf, "100:1,1");
|
||||
if (lowest < needed) {
|
||||
sprintf(buf, "100:2,0,%ld;", lowest);
|
||||
} else {
|
||||
sprintf(buf, "100:2,1,%ld;", lowest);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
@ -247,6 +236,16 @@ void update_diskstat(void)
|
||||
temp = (unsigned long)(sfs.f_bsize / 512L);
|
||||
tmp->size = (unsigned long)(sfs.f_blocks * temp) / 2048L;
|
||||
tmp->avail = (unsigned long)(sfs.f_bavail * temp) / 2048L;
|
||||
#if defined(__linux__)
|
||||
/*
|
||||
* The struct statfs (or statvfs) seems to have no information
|
||||
* about read-only filesystems, so we guess it based on fstype.
|
||||
* See man 2 statvfs about what approximately is defined.
|
||||
*/
|
||||
tmp->ro = (strstr(tmp->fstype, "iso") != NULL);
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
Syslog('-', "%s %d", tmp->mountpoint, sfs.f_flags);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,6 +282,7 @@ void add_path(char *path)
|
||||
if (S_ISDIR(sb.st_mode)) {
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
if ((fp = fopen((char *)"/etc/mtab", "r"))) {
|
||||
mtab = calloc(PATH_MAX, sizeof(char));
|
||||
fsname = calloc(PATH_MAX, sizeof(char));
|
||||
@ -297,7 +297,6 @@ void add_path(char *path)
|
||||
* mounted filesystem that matches must be the one we seek.
|
||||
*/
|
||||
if (strncmp(fs, path, strlen(fs)) == 0) {
|
||||
Syslog('d', "Found fs %s", fs);
|
||||
sprintf(fsname, "%s", fs);
|
||||
fs = strtok(NULL, " \t");
|
||||
sprintf(fstype, "%s", fs);
|
||||
@ -318,9 +317,7 @@ void add_path(char *path)
|
||||
fstype = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
for (i = 0; i < mntsize; i++) {
|
||||
Syslog('d', "Check fs %s", mntbuf[i].f_mntonname);
|
||||
if (strncmp(mntbuf[i].f_mntonname, path, strlen(mntbuf[i].f_mntonname)) == 0) {
|
||||
Syslog('d', "Found fs %s", mntbuf[i].f_mntonname);
|
||||
sprintf(fsname, "%s", mntbuf[i].f_mntonname);
|
||||
sprintf(fstype, "%s", mntbuf[i].f_fstypename);
|
||||
}
|
||||
@ -331,10 +328,18 @@ void add_path(char *path)
|
||||
free(fstype);
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Unknow OS - don't know what to do"
|
||||
#endif
|
||||
|
||||
} else {
|
||||
Syslog('d', "**** Is not a dir");
|
||||
/*
|
||||
* Not a directory, maybe a file.
|
||||
*/
|
||||
if ((p = strrchr(path, '/')))
|
||||
*p = '\0';
|
||||
Syslog('d', "Recursive add name %s", path);
|
||||
add_path(path);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
@ -513,7 +518,7 @@ void *disk_thread(void)
|
||||
Syslog('d', "All directories added");
|
||||
|
||||
for (tmp = mfs; tmp; tmp = tmp->next) {
|
||||
Syslog('+', "%s %s %ld %ld", tmp->mountpoint, tmp->fstype, tmp->size, tmp->avail);
|
||||
Syslog('+', "Found filesystem: %s type: %s", tmp->mountpoint, tmp->fstype);
|
||||
}
|
||||
|
||||
if ((rc = pthread_mutex_unlock(&a_mutex)))
|
||||
|
Reference in New Issue
Block a user