Signal scanout after nodes edit

This commit is contained in:
Michiel Broek 2002-07-13 15:10:00 +00:00
parent e9562655ae
commit 55ed2dd121
2 changed files with 257 additions and 238 deletions

View File

@ -37,6 +37,7 @@ v0.35.03 06-Jul-2002
mbsetup: mbsetup:
Enabled setting of nodelist override settings in menu 7.x.3 Enabled setting of nodelist override settings in menu 7.x.3
After nodes setup edit the semafore scanout is set.
script: script:
The bbsdoor.sh and rundoor.sh scripts are now only installed The bbsdoor.sh and rundoor.sh scripts are now only installed

View File

@ -58,34 +58,34 @@ int NodeUpdated = 0;
int CountNoderec(void); int CountNoderec(void);
int CountNoderec(void) int CountNoderec(void)
{ {
FILE *fil; FILE *fil;
char ffile[PATH_MAX]; char ffile[PATH_MAX];
int count; int count;
sprintf(ffile, "%s/etc/nodes.data", getenv("MBSE_ROOT")); sprintf(ffile, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "r")) == NULL) { if ((fil = fopen(ffile, "r")) == NULL) {
if ((fil = fopen(ffile, "a+")) != NULL) { if ((fil = fopen(ffile, "a+")) != NULL) {
Syslog('+', "Created new %s", ffile); Syslog('+', "Created new %s", ffile);
nodeshdr.hdrsize = sizeof(nodeshdr); nodeshdr.hdrsize = sizeof(nodeshdr);
nodeshdr.recsize = sizeof(nodes); nodeshdr.recsize = sizeof(nodes);
nodeshdr.filegrp = CFG.tic_groups * 13; nodeshdr.filegrp = CFG.tic_groups * 13;
nodeshdr.mailgrp = CFG.toss_groups * 13; nodeshdr.mailgrp = CFG.toss_groups * 13;
fwrite(&nodeshdr, sizeof(nodeshdr), 1, fil); fwrite(&nodeshdr, sizeof(nodeshdr), 1, fil);
fclose(fil); fclose(fil);
chmod(ffile, 0640); chmod(ffile, 0640);
return 0; return 0;
} else } else
return -1; return -1;
} }
fread(&nodeshdr, sizeof(nodeshdr), 1, fil); fread(&nodeshdr, sizeof(nodeshdr), 1, fil);
fseek(fil, 0, SEEK_SET); fseek(fil, 0, SEEK_SET);
fread(&nodeshdr, nodeshdr.hdrsize, 1, fil); fread(&nodeshdr, nodeshdr.hdrsize, 1, fil);
fseek(fil, 0, SEEK_END); fseek(fil, 0, SEEK_END);
count = (ftell(fil) - nodeshdr.hdrsize) / (nodeshdr.recsize + nodeshdr.filegrp + nodeshdr.mailgrp); count = (ftell(fil) - nodeshdr.hdrsize) / (nodeshdr.recsize + nodeshdr.filegrp + nodeshdr.mailgrp);
fclose(fil); fclose(fil);
return count; return count;
} }
@ -97,167 +97,176 @@ int CountNoderec(void)
*/ */
int OpenNoderec(void) int OpenNoderec(void)
{ {
FILE *fin, *fout; FILE *fin, *fout;
char fnin[PATH_MAX], fnout[PATH_MAX]; char *fnin, *fnout, group[13];
char group[13]; int i, old_fgroups, old_mgroups;
long oldsize; long oldsize, oldfilegrp, oldmailgrp;
int i, old_fgroups, old_mgroups;
long oldfilegrp, oldmailgrp;
sprintf(fnin, "%s/etc/nodes.data", getenv("MBSE_ROOT")); fnin = calloc(PATH_MAX, sizeof(char));
sprintf(fnout, "%s/etc/nodes.temp", getenv("MBSE_ROOT")); fnout = calloc(PATH_MAX, sizeof(char));
if ((fin = fopen(fnin, "r")) != NULL) { sprintf(fnin, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fout = fopen(fnout, "w")) != NULL) { sprintf(fnout, "%s/etc/nodes.temp", getenv("MBSE_ROOT"));
NodeUpdated = 0;
fread(&nodeshdr, sizeof(nodeshdr), 1, fin);
fseek(fin, 0, SEEK_SET);
fread(&nodeshdr, nodeshdr.hdrsize, 1, fin);
if (nodeshdr.hdrsize != sizeof(nodeshdr)) {
nodeshdr.hdrsize = sizeof(nodeshdr);
nodeshdr.lastupd = time(NULL);
NodeUpdated = 1;
}
/* if ((fin = fopen(fnin, "r")) != NULL) {
* In case we are automatic upgrading the data format if ((fout = fopen(fnout, "w")) != NULL) {
* we save the old format. If it is changed, the NodeUpdated = 0;
* database must always be updated. fread(&nodeshdr, sizeof(nodeshdr), 1, fin);
*/ fseek(fin, 0, SEEK_SET);
oldsize = nodeshdr.recsize; fread(&nodeshdr, nodeshdr.hdrsize, 1, fin);
oldfilegrp = nodeshdr.filegrp; if (nodeshdr.hdrsize != sizeof(nodeshdr)) {
oldmailgrp = nodeshdr.mailgrp; nodeshdr.hdrsize = sizeof(nodeshdr);
old_fgroups = oldfilegrp / 13; nodeshdr.lastupd = time(NULL);
old_mgroups = oldmailgrp / 13; NodeUpdated = 1;
if ((oldsize != sizeof(nodes) || }
(CFG.tic_groups != old_fgroups) ||
(CFG.toss_groups != old_mgroups))) {
NodeUpdated = 1;
if (oldsize != sizeof(nodes))
Syslog('+', "Upgraded %s, format changed", fnin);
else if (CFG.tic_groups != old_fgroups)
Syslog('+', "Upgraded %s, nr of tic groups is now %d", fnin, CFG.tic_groups);
else if (CFG.toss_groups != old_mgroups)
Syslog('+', "Upgraded %s, nr of mail groups is now %d", fnin, CFG.toss_groups);
}
nodeshdr.hdrsize = sizeof(nodeshdr);
nodeshdr.recsize = sizeof(nodes);
nodeshdr.filegrp = CFG.tic_groups * 13;
nodeshdr.mailgrp = CFG.toss_groups * 13;
fwrite(&nodeshdr, sizeof(nodeshdr), 1, fout);
/* /*
* The datarecord is filled with zero's before each * In case we are automatic upgrading the data format
* read, so if the format changed, the new fields * we save the old format. If it is changed, the
* will be empty. * database must always be updated.
*/ */
memset(&nodes, 0, sizeof(nodes)); oldsize = nodeshdr.recsize;
while (fread(&nodes, oldsize, 1, fin) == 1) { oldfilegrp = nodeshdr.filegrp;
if (oldsize != sizeof(nodes)) { oldmailgrp = nodeshdr.mailgrp;
strcpy(nodes.Spasswd, nodes.Epasswd); old_fgroups = oldfilegrp / 13;
} old_mgroups = oldmailgrp / 13;
fwrite(&nodes, sizeof(nodes), 1, fout); if ((oldsize != sizeof(nodes) || (CFG.tic_groups != old_fgroups) || (CFG.toss_groups != old_mgroups))) {
memset(&nodes, 0, sizeof(nodes)); NodeUpdated = 1;
if (oldsize != sizeof(nodes))
Syslog('+', "Upgraded %s, format changed", fnin);
else if (CFG.tic_groups != old_fgroups)
Syslog('+', "Upgraded %s, nr of tic groups is now %d", fnin, CFG.tic_groups);
else if (CFG.toss_groups != old_mgroups)
Syslog('+', "Upgraded %s, nr of mail groups is now %d", fnin, CFG.toss_groups);
}
nodeshdr.hdrsize = sizeof(nodeshdr);
nodeshdr.recsize = sizeof(nodes);
nodeshdr.filegrp = CFG.tic_groups * 13;
nodeshdr.mailgrp = CFG.toss_groups * 13;
fwrite(&nodeshdr, sizeof(nodeshdr), 1, fout);
/* /*
* Copy the existing file groups * The datarecord is filled with zero's before each read,
*/ * so if the format changed, the new fields will be empty.
for (i = 1; i <= old_fgroups; i++) { */
fread(&group, 13, 1, fin); memset(&nodes, 0, sizeof(nodes));
if (i <= CFG.tic_groups) while (fread(&nodes, oldsize, 1, fin) == 1) {
fwrite(&group, 13, 1, fout); if (oldsize != sizeof(nodes)) {
} strcpy(nodes.Spasswd, nodes.Epasswd);
if (old_fgroups < CFG.tic_groups) { }
/* fwrite(&nodes, sizeof(nodes), 1, fout);
* The size increased, fill with memset(&nodes, 0, sizeof(nodes));
* blank records
*/
memset(&group, 0, 13);
for (i = (old_fgroups + 1); i <= CFG.tic_groups; i++)
fwrite(&group, 13, 1, fout);
}
/*
* Copy the existing mail groups
*/
for (i = 1; i <= old_mgroups; i++) {
fread(&group, 13, 1, fin);
if (i <= CFG.toss_groups)
fwrite(&group, 13, 1, fout);
}
if (old_mgroups < CFG.toss_groups) {
memset(&group, 0, 13);
for (i = (old_mgroups + 1); i <= CFG.toss_groups; i++)
fwrite(&group, 13, 1, fout);
}
}
fclose(fin); /*
fclose(fout); * Copy the existing file groups
return 0; */
} else for (i = 1; i <= old_fgroups; i++) {
return -1; fread(&group, 13, 1, fin);
} if (i <= CFG.tic_groups)
return -1; fwrite(&group, 13, 1, fout);
}
if (old_fgroups < CFG.tic_groups) {
/*
* The size increased, fill with blank records
*/
memset(&group, 0, 13);
for (i = (old_fgroups + 1); i <= CFG.tic_groups; i++)
fwrite(&group, 13, 1, fout);
}
/*
* Copy the existing mail groups
*/
for (i = 1; i <= old_mgroups; i++) {
fread(&group, 13, 1, fin);
if (i <= CFG.toss_groups)
fwrite(&group, 13, 1, fout);
}
if (old_mgroups < CFG.toss_groups) {
memset(&group, 0, 13);
for (i = (old_mgroups + 1); i <= CFG.toss_groups; i++)
fwrite(&group, 13, 1, fout);
}
}
fclose(fin);
fclose(fout);
free(fnin);
free(fnout);
return 0;
} else
return -1;
}
free(fnin);
free(fnout);
return -1;
} }
void CloseNoderec(int Force) void CloseNoderec(int Force)
{ {
char fin[PATH_MAX], fout[PATH_MAX]; char *fin, *fout, group[13];
FILE *fi, *fo; FILE *fi, *fo;
int i; int i;
char group[13]; st_list *nod = NULL, *tmp;
st_list *nod = NULL, *tmp; unsigned long crc1, crc2;
unsigned long crc1, crc2;
sprintf(fin, "%s/etc/nodes.data", getenv("MBSE_ROOT")); fin = calloc(PATH_MAX, sizeof(char));
sprintf(fout,"%s/etc/nodes.temp", getenv("MBSE_ROOT")); fout = calloc(PATH_MAX, sizeof(char));
sprintf(fin, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
sprintf(fout,"%s/etc/nodes.temp", getenv("MBSE_ROOT"));
if (NodeUpdated == 1) { if (NodeUpdated == 1) {
if (Force || (yes_no((char *)"Nodes database is changed, save changes") == 1)) { if (Force || (yes_no((char *)"Nodes database is changed, save changes") == 1)) {
working(1, 0, 0); working(1, 0, 0);
fi = fopen(fout, "r"); fi = fopen(fout, "r");
fo = fopen(fin, "w"); fo = fopen(fin, "w");
fread(&nodeshdr, nodeshdr.hdrsize, 1, fi); fread(&nodeshdr, nodeshdr.hdrsize, 1, fi);
fwrite(&nodeshdr, nodeshdr.hdrsize, 1, fo); fwrite(&nodeshdr, nodeshdr.hdrsize, 1, fo);
while (fread(&nodes, nodeshdr.recsize, 1, fi) == 1) { while (fread(&nodes, nodeshdr.recsize, 1, fi) == 1) {
if (!nodes.Deleted) if (!nodes.Deleted)
fill_stlist(&nod, nodes.Sysop, ftell(fi) - nodeshdr.recsize); fill_stlist(&nod, nodes.Sysop, ftell(fi) - nodeshdr.recsize);
fseek(fi, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); fseek(fi, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
} }
sort_stlist(&nod); sort_stlist(&nod);
crc1 = crc2 = 0xffffffff; crc1 = crc2 = 0xffffffff;
for (tmp = nod; tmp; tmp = tmp->next) { for (tmp = nod; tmp; tmp = tmp->next) {
fseek(fi, tmp->pos, SEEK_SET); fseek(fi, tmp->pos, SEEK_SET);
fread(&nodes, nodeshdr.recsize, 1, fi); fread(&nodes, nodeshdr.recsize, 1, fi);
crc2 = upd_crc32((char *)&nodes, crc2, 100); crc2 = upd_crc32((char *)&nodes, crc2, 100);
if (crc2 == crc1) if (crc2 == crc1)
WriteError("Removing double noderecord %s %s", nodes.Sysop, aka2str(nodes.Aka[0])); WriteError("Removing double noderecord %s %s", nodes.Sysop, aka2str(nodes.Aka[0]));
else { else {
fwrite(&nodes, nodeshdr.recsize, 1, fo); fwrite(&nodes, nodeshdr.recsize, 1, fo);
for (i = 0; i < ((nodeshdr.filegrp + nodeshdr.mailgrp) / sizeof(group)); i++) { for (i = 0; i < ((nodeshdr.filegrp + nodeshdr.mailgrp) / sizeof(group)); i++) {
fread(&group, sizeof(group), 1, fi); fread(&group, sizeof(group), 1, fi);
fwrite(&group, sizeof(group), 1, fo); fwrite(&group, sizeof(group), 1, fo);
} }
}
crc1 = crc2;
crc2 = 0xffffffff;
}
tidy_stlist(&nod);
fclose(fi);
fclose(fo);
unlink(fout);
chmod(fin, 0640);
Syslog('+', "Updated \"nodes.data\"");
return;
} }
crc1 = crc2;
crc2 = 0xffffffff;
}
tidy_stlist(&nod);
fclose(fi);
fclose(fo);
unlink(fout);
chmod(fin, 0640);
free(fin);
free(fout);
Syslog('+', "Updated \"nodes.data\"");
CreateSema((char *)"scanout");
return;
} }
chmod(fin, 0640); }
working(1, 0, 0);
unlink(fout); chmod(fin, 0640);
working(1, 0, 0);
free(fin);
free(fout);
unlink(fout);
} }
@ -265,78 +274,86 @@ void CloseNoderec(int Force)
int AppendNoderec(void); int AppendNoderec(void);
int AppendNoderec(void) int AppendNoderec(void)
{ {
FILE *fil; FILE *fil;
char ffile[PATH_MAX]; char *ffile, group[13];
char group[13]; int i;
int i;
sprintf(ffile, "%s/etc/nodes.temp", getenv("MBSE_ROOT")); ffile = calloc(PATH_MAX, sizeof(char));
if ((fil = fopen(ffile, "a")) != NULL) { sprintf(ffile, "%s/etc/nodes.temp", getenv("MBSE_ROOT"));
memset(&nodes, 0, sizeof(nodes));
/* if ((fil = fopen(ffile, "a")) != NULL) {
* Fill in the defaults memset(&nodes, 0, sizeof(nodes));
*/ /*
nodes.Tic = TRUE; * Fill in the defaults
nodes.Notify = FALSE; */
nodes.AdvTic = FALSE; nodes.Tic = TRUE;
nodes.Hold = TRUE; nodes.Notify = FALSE;
nodes.ARCmailCompat = TRUE; nodes.AdvTic = FALSE;
nodes.ARCmailAlpha = TRUE; nodes.Hold = TRUE;
nodes.StartDate = time(NULL); nodes.ARCmailCompat = TRUE;
fwrite(&nodes, sizeof(nodes), 1, fil); nodes.ARCmailAlpha = TRUE;
memset(&group, 0, 13); nodes.StartDate = time(NULL);
for (i = 1; i <= CFG.tic_groups; i++) fwrite(&nodes, sizeof(nodes), 1, fil);
fwrite(&group, 13, 1, fil); memset(&group, 0, 13);
for (i = 1; i <= CFG.toss_groups; i++) for (i = 1; i <= CFG.tic_groups; i++)
fwrite(&group, 13, 1, fil); fwrite(&group, 13, 1, fil);
fclose(fil); for (i = 1; i <= CFG.toss_groups; i++)
NodeUpdated = 1; fwrite(&group, 13, 1, fil);
return 0; fclose(fil);
} else NodeUpdated = 1;
return -1; free(ffile);
return 0;
}
free(ffile);
return -1;
} }
int GroupInNode(char *Group, int Mail) int GroupInNode(char *Group, int Mail)
{ {
char temp[PATH_MAX], group[13]; char *temp, group[13];
FILE *no; FILE *no;
int i, groups, RetVal = 0; int i, groups, RetVal = 0;
sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT")); temp = calloc(PATH_MAX, sizeof(char));
if ((no = fopen(temp, "r")) == NULL) sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
return 0; if ((no = fopen(temp, "r")) == NULL) {
free(temp);
return 0;
}
free(temp);
fread(&nodeshdr, sizeof(nodeshdr), 1, no); fread(&nodeshdr, sizeof(nodeshdr), 1, no);
fseek(no, 0, SEEK_SET); fseek(no, 0, SEEK_SET);
fread(&nodeshdr, nodeshdr.hdrsize, 1, no); fread(&nodeshdr, nodeshdr.hdrsize, 1, no);
while ((fread(&nodes, nodeshdr.recsize, 1, no)) == 1) { while ((fread(&nodes, nodeshdr.recsize, 1, no)) == 1) {
groups = nodeshdr.filegrp / sizeof(group); groups = nodeshdr.filegrp / sizeof(group);
for (i = 0; i < groups; i++) { for (i = 0; i < groups; i++) {
fread(&group, sizeof(group), 1, no); fread(&group, sizeof(group), 1, no);
if (strlen(group) && !Mail) { if (strlen(group) && !Mail) {
if (!strcmp(group, Group)) { if (!strcmp(group, Group)) {
RetVal++; RetVal++;
Syslog('-', "File group %s found in node setup %s", Group, aka2str(nodes.Aka[0])); Syslog('-', "File group %s found in node setup %s", Group, aka2str(nodes.Aka[0]));
}
}
}
groups = nodeshdr.mailgrp / sizeof(group);
for (i = 0; i < groups; i++) {
fread(&group, sizeof(group), 1, no);
if (strlen(group) && Mail) {
if (!strcmp(group, Group)) {
RetVal++;
Syslog('-', "Mail group %s found in node setup %s", Group, aka2str(nodes.Aka[0]));
}
}
} }
}
} }
groups = nodeshdr.mailgrp / sizeof(group);
for (i = 0; i < groups; i++) {
fread(&group, sizeof(group), 1, no);
if (strlen(group) && Mail) {
if (!strcmp(group, Group)) {
RetVal++;
Syslog('-', "Mail group %s found in node setup %s", Group, aka2str(nodes.Aka[0]));
}
}
}
}
fclose(no); fclose(no);
return RetVal; return RetVal;
} }
@ -344,17 +361,18 @@ int GroupInNode(char *Group, int Mail)
int CheckAka(fidoaddr); int CheckAka(fidoaddr);
int CheckAka(fidoaddr A) int CheckAka(fidoaddr A)
{ {
int mcnt, tcnt; int mcnt, tcnt;
working(1, 0, 0); working(1, 0, 0);
mcnt = NodeInMarea(A); mcnt = NodeInMarea(A);
tcnt = NodeInTic(A); tcnt = NodeInTic(A);
working(0, 0, 0); working(0, 0, 0);
if (mcnt || tcnt) { if (mcnt || tcnt) {
errmsg((char *)"Error aka connected to %d message and/or %d tic areas", mcnt, tcnt); errmsg((char *)"Error aka connected to %d message and/or %d tic areas", mcnt, tcnt);
return TRUE; return TRUE;
} }
return FALSE;
return FALSE;
} }