From f19b0b0a7e6903ee99110fa7cd217522374d2e5c Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 20 Mar 2004 16:09:35 +0000 Subject: [PATCH] Added experiment for disk tests --- ChangeLog | 5 +- mbmon/mbmon.c | 131 +++++++++++++++------------- mbtask/mbtask.c | 5 +- mbtask/taskdisk.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 292 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 817549ee..215f483b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,8 +11,8 @@ v0.51.2 06-Mar-2004 Start mbsetup, this can take a while on a system with lots of files, during startup the files database will be converted. After the menu appears, enter global setup, exit and save. - Open the system again. - If you want you may restart mbtask. + Now stop and restart mbtask. + Open the system with mbstat open. general: Updated to a new files database structure that allows for @@ -95,6 +95,7 @@ v0.51.2 06-Mar-2004 mbmon: Switched to use new filesystems command. + On screen 2 added disk status. mbtask: Added communication commands for disk watch thread. diff --git a/mbmon/mbmon.c b/mbmon/mbmon.c index a5d7fbb6..d4d18d19 100644 --- a/mbmon/mbmon.c +++ b/mbmon/mbmon.c @@ -247,70 +247,81 @@ void system_moni(void) void system_stat(void) { - int ch; - char buf[256]; - char *cnt; - time_t now; + int ch; + char buf[256], *cnt; + time_t now; - clr_index(); - set_color(WHITE, BLACK); - mvprintw( 5, 6, "2. SERVER STATISTICS"); - set_color(CYAN, BLACK); - mvprintw( 7, 6, "First date started"); - mvprintw( 7,62, "BBS Open"); - mvprintw( 8, 6, "Last date started"); - mvprintw( 8,62, "ZMH"); - mvprintw( 9, 6, "Total server starts"); - mvprintw( 9,62, "Internet"); - mvprintw(10, 6, "Connected clients"); - mvprintw(10,62, "Need inet"); - mvprintw(11,62, "Running"); - mvprintw(12,30, "Total Today"); - mvprintw(12,62, "Load avg"); - hor_lin(13,30,8); - hor_lin(13,45,8); - mvprintw(14, 6, "Client connects"); - mvprintw(15, 6, "Peak connections"); - mvprintw(16, 6, "Protocol syntax errors"); - mvprintw(17, 6, "Communication errors"); - mvprintw(19, 6, "Next sequence number"); - mvprintw(19,62, "Press any key"); - IsDoing("System Statistics"); + clr_index(); + set_color(WHITE, BLACK); + mvprintw( 5, 6, "2. SERVER STATISTICS"); + set_color(CYAN, BLACK); + mvprintw( 7, 6, "First date started"); + mvprintw( 7,62, "BBS Open"); + mvprintw( 8, 6, "Last date started"); + mvprintw( 8,62, "ZMH"); + mvprintw( 9, 6, "Total server starts"); + mvprintw( 9,62, "Internet"); + mvprintw(10, 6, "Connected clients"); + mvprintw(10,62, "Need inet"); + mvprintw(11,62, "Running"); + mvprintw(12,30, "Total Today"); + mvprintw(12,62, "Load avg"); + hor_lin(13,30,8); + hor_lin(13,45,8); + mvprintw(13,62, "Disk stat"); + mvprintw(14, 6, "Client connects"); + mvprintw(15, 6, "Peak connections"); + mvprintw(16, 6, "Protocol syntax errors"); + mvprintw(17, 6, "Communication errors"); + mvprintw(19, 6, "Next sequence number"); + mvprintw(19,62, "Press any key"); + IsDoing("System Statistics"); - do { - show_date(LIGHTGRAY, BLACK, 0, 0); + do { + show_date(LIGHTGRAY, BLACK, 0, 0); - sprintf(buf, "GSTA:1,%d;", getpid()); - if (socket_send(buf) == 0) { - strcpy(buf, socket_receive()); - set_color(LIGHTGRAY, BLACK); - cnt = strtok(buf, ","); - now = atoi(strtok(NULL, ",")); - mvprintw(7, 30, "%s", ctime(&now)); - now = atoi(strtok(NULL, ",")); - mvprintw(8, 30, "%s", ctime(&now)); - cnt = strtok(NULL, ","); - mvprintw(9, 30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(10,30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(14,30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(15,30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(16,30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(17,30, (char *)"%s ", strtok(NULL, ",")); - mvprintw(14,45, (char *)"%s ", strtok(NULL, ",")); - mvprintw(15,45, (char *)"%s ", strtok(NULL, ",")); - mvprintw(16,45, (char *)"%s ", strtok(NULL, ",")); - mvprintw(17,45, (char *)"%s ", strtok(NULL, ",")); - mvprintw(7,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); - mvprintw(8,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); - mvprintw(9,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); - mvprintw(10,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); - mvprintw(11,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); - mvprintw(12,72, "%s ", strtok(NULL, ",")); - mvprintw(19,30, (char *)"%s", strtok(NULL, ";")); - } + sprintf(buf, "GSTA:1,%d;", getpid()); + if (socket_send(buf) == 0) { + strcpy(buf, socket_receive()); + set_color(LIGHTGRAY, BLACK); + cnt = strtok(buf, ","); + now = atoi(strtok(NULL, ",")); + mvprintw(7, 30, "%s", ctime(&now)); + now = atoi(strtok(NULL, ",")); + mvprintw(8, 30, "%s", ctime(&now)); + cnt = strtok(NULL, ","); + mvprintw(9, 30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(10,30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(14,30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(15,30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(16,30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(17,30, (char *)"%s ", strtok(NULL, ",")); + mvprintw(14,45, (char *)"%s ", strtok(NULL, ",")); + mvprintw(15,45, (char *)"%s ", strtok(NULL, ",")); + mvprintw(16,45, (char *)"%s ", strtok(NULL, ",")); + mvprintw(17,45, (char *)"%s ", strtok(NULL, ",")); + mvprintw(7,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); + mvprintw(8,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); + mvprintw(9,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); + mvprintw(10,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); + mvprintw(11,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No "); + mvprintw(12,72, "%s ", strtok(NULL, ",")); + mvprintw(19,30, (char *)"%s", strtok(NULL, ";")); + } - ch = testkey(19,76); - } while (ch == '\0'); + switch (enoughspace()) { + case 0: mvprintw(13, 72, "Full "); + break; + case 1: mvprintw(13, 72, "Ok "); + break; + case 2: mvprintw(13, 72, "N/A "); + break; + case 3: mvprintw(13, 72, "Error"); + break; + } + + ch = testkey(19,76); + } while (ch == '\0'); } diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index c59b64f7..e7f08b20 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -712,7 +712,10 @@ void die(int onsig) while ((cmd_run || ping_run || sched_run || disk_run) && (time(NULL) < now)) { sleep(1); } - Syslog('+', "All threads stopped"); + if (cmd_run || ping_run || sched_run || disk_run) + Syslog('+', "Not all threads stopped! Forced shutdown"); + else + Syslog('+', "All threads stopped"); /* * Free memory diff --git a/mbtask/taskdisk.c b/mbtask/taskdisk.c index 505aef93..eb081bf2 100644 --- a/mbtask/taskdisk.c +++ b/mbtask/taskdisk.c @@ -175,9 +175,86 @@ char *disk_getfs() +/* + * Add path to table. + * Find out if the parameter is a path or a file on a path. + */ void add_path(char *path) { + struct stat sb; + char *p, *fsname; +#if defined(__linux__) + char *mtab, *fs; + FILE *fp; +#elif defined(__FreeBSD__) || defined(__NetBSD__) + struct statfs *mntbuf; + int i; +#endif + + if (strlen(path) == 0) { + Syslog('d', "add_path() empty pathname"); + return; + } + Syslog('d', "add_path(%s)", path); + if (lstat(path, &sb) == 0) { + 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)); + fsname[0] = '\0'; + + while (fgets(mtab, PATH_MAX -1, fp)) { + fs = strtok(mtab, " \t"); + fs = strtok(NULL, " \t"); + /* + * Overwrite fsname each time a match is found, the last + * 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); + } + } + fclose(fp); + free(mtab); + Syslog('d', "Should be on \"%s\"", fsname); + free(fsname); + } + +#elif defined(__FreeBSD__) || defined(__NetBSD__) + + if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT))) { + fsname = 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", fs); + sprintf(fsname, "%s", fs); + } + } + Syslog('d', "Should be on \"%s\"", fsname); + free(fsname); + } + +#endif + + } else { + Syslog('d', "**** Is not a dir"); + } + } else { + /* + * Possible cause, we were given a filename that + * may not be present because this is a temporary file. + * Strip the last part of the name and try again. + */ + if ((p = strrchr(path, '/'))) + *p = '\0'; + Syslog('d', "Recursive add name %s", path); + add_path(path); + } } @@ -187,6 +264,9 @@ void add_path(char *path) */ void *disk_thread(void) { + FILE *fp; + char *temp; + Syslog('+', "Start disk thread"); disk_run = TRUE; disk_reread = TRUE; @@ -196,7 +276,141 @@ void *disk_thread(void) if (disk_reread) { disk_reread = FALSE; Syslog('+', "Reread disk filesystems"); + add_path(getenv("MBSE_ROOT")); add_path(CFG.bbs_menus); + add_path(CFG.bbs_txtfiles); + add_path(CFG.alists_path); + add_path(CFG.req_magic); + add_path(CFG.bbs_usersdir); + add_path(CFG.nodelists); + add_path(CFG.inbound); + add_path(CFG.pinbound); + add_path(CFG.outbound); + add_path(CFG.ftp_base); + add_path(CFG.bbs_macros); + add_path(CFG.out_queue); + add_path(CFG.rulesdir); + add_path(CFG.tmailshort); + add_path(CFG.tmaillong); + + temp = calloc(PATH_MAX, sizeof(char )); + sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&areahdr, sizeof(areahdr), 1, fp); + fseek(fp, areahdr.hdrsize, SEEK_SET); + + while (fread(&area, areahdr.recsize, 1, fp)) { + if (area.Available) { + if (area.CDrom) + add_path(area.FilesBbs); + else + add_path(area.Path); + } + } + fclose(fp); + } + + sprintf(temp, "%s/etc/mareas.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&msgshdr, sizeof(msgshdr), 1, fp); + fseek(fp, msgshdr.hdrsize, SEEK_SET); + + while (fread(&msgs, msgshdr.recsize, 1, fp)) { + if (msgs.Active) + add_path(msgs.Base); + fseek(fp, msgshdr.syssize, SEEK_CUR); + } + fclose(fp); + } + + sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&langhdr, sizeof(langhdr), 1, fp); + fseek(fp, langhdr.hdrsize, SEEK_SET); + + while (fread(&lang, langhdr.recsize, 1, fp)) { + if (lang.Available) { + add_path(lang.MenuPath); + add_path(lang.TextPath); + add_path(lang.MacroPath); + } + } + fclose(fp); + } + + sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&nodeshdr, sizeof(nodeshdr), 1, fp); + fseek(fp, nodeshdr.hdrsize, SEEK_SET); + + while (fread(&nodes, nodeshdr.recsize, 1, fp)) { + if (nodes.Session_in == S_DIR) + add_path(nodes.Dir_in_path); + if (nodes.Session_out == S_DIR) + add_path(nodes.Dir_out_path); + add_path(nodes.OutBox); + fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); + } + fclose(fp); + } + + sprintf(temp, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&fgrouphdr, sizeof(fgrouphdr), 1, fp); + fseek(fp, fgrouphdr.hdrsize, SEEK_SET); + + while (fread(&fgroup, fgrouphdr.recsize, 1, fp)) { + if (fgroup.Active) + add_path(fgroup.BasePath); + } + fclose(fp); + } + + sprintf(temp, "%s/etc/mgroups.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&mgrouphdr, sizeof(mgrouphdr), 1, fp); + fseek(fp, mgrouphdr.hdrsize, SEEK_SET); + + while (fread(&mgroup, mgrouphdr.recsize, 1, fp)) { + if (mgroup.Active) + add_path(mgroup.BasePath); + } + fclose(fp); + } + + sprintf(temp, "%s/etc/hatch.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&hatchhdr, sizeof(hatchhdr), 1, fp); + fseek(fp, hatchhdr.hdrsize, SEEK_SET); + + while (fread(&hatch, hatchhdr.recsize, 1, fp)) { + if (hatch.Active) + add_path(hatch.Spec); + } + fclose(fp); + } + + sprintf(temp, "%s/etc/magic.data", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + Syslog('d', "+ %s", temp); + fread(&magichdr, sizeof(magichdr), 1, fp); + fseek(fp, magichdr.hdrsize, SEEK_SET); + + while (fread(&magic, magichdr.recsize, 1, fp)) { + if (magic.Active && ((magic.Attrib == MG_COPY) || (magic.Attrib == MG_UNPACK))) + add_path(magic.Path); + } + fclose(fp); + } + free(temp); + Syslog('d', "All directories added"); } sleep(1);