Fix for FreeBSD LastRead pointers
This commit is contained in:
parent
a1ae304588
commit
0a70980608
16
lib/jammsg.c
16
lib/jammsg.c
@ -591,7 +591,7 @@ int JAM_Open(char *Msgbase)
|
|||||||
void JAM_Pack(void)
|
void JAM_Pack(void)
|
||||||
{
|
{
|
||||||
int fdnHdr, fdnJdx, fdnJdt, fdnJlr;
|
int fdnHdr, fdnJdx, fdnJdt, fdnJlr;
|
||||||
int ToRead, Readed;
|
int ToRead, Readed, i, count;
|
||||||
char *File, *New, *Subfield, *Temp;
|
char *File, *New, *Subfield, *Temp;
|
||||||
JAMIDXREC jamIdx;
|
JAMIDXREC jamIdx;
|
||||||
unsigned long NewNumber = 0, RefNumber = 0, Written = 0;
|
unsigned long NewNumber = 0, RefNumber = 0, Written = 0;
|
||||||
@ -608,6 +608,12 @@ void JAM_Pack(void)
|
|||||||
sprintf(File, "%s%s", BaseName, ".$lr");
|
sprintf(File, "%s%s", BaseName, ".$lr");
|
||||||
fdnJlr = open(File, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
|
fdnJlr = open(File, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the number of LastRead records, this number is needed to prevent
|
||||||
|
* that FreeBSD makes garbage of the LastRead pointers for some reason.
|
||||||
|
*/
|
||||||
|
count = lseek(fdJlr, 0, SEEK_END) / sizeof(lastread);
|
||||||
|
|
||||||
if (fdnHdr != -1 && fdnJdt != -1 && fdnJdx != -1 && fdnJlr != -1) {
|
if (fdnHdr != -1 && fdnJdt != -1 && fdnJdx != -1 && fdnJlr != -1) {
|
||||||
lseek(fdHdr, 0L, SEEK_SET);
|
lseek(fdHdr, 0L, SEEK_SET);
|
||||||
if (read(fdHdr, &jamHdrInfo, sizeof(JAMHDRINFO)) == sizeof(JAMHDRINFO)) {
|
if (read(fdHdr, &jamHdrInfo, sizeof(JAMHDRINFO)) == sizeof(JAMHDRINFO)) {
|
||||||
@ -642,7 +648,8 @@ void JAM_Pack(void)
|
|||||||
Written++;
|
Written++;
|
||||||
|
|
||||||
lseek(fdJlr, 0, SEEK_SET);
|
lseek(fdJlr, 0, SEEK_SET);
|
||||||
while ((read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread))) {
|
for (i = 0; i < count; i++) {
|
||||||
|
if ((read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread))) {
|
||||||
/*
|
/*
|
||||||
* Test if one of the lastread pointer is the current
|
* Test if one of the lastread pointer is the current
|
||||||
* old message number.
|
* old message number.
|
||||||
@ -659,6 +666,7 @@ void JAM_Pack(void)
|
|||||||
write(fdJlr, &LR, sizeof(lastread));
|
write(fdJlr, &LR, sizeof(lastread));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
jamHdr.MsgNum = NewNumber;
|
jamHdr.MsgNum = NewNumber;
|
||||||
write(fdnHdr, &jamHdr, sizeof(JAMHDR));
|
write(fdnHdr, &jamHdr, sizeof(JAMHDR));
|
||||||
|
|
||||||
@ -704,9 +712,11 @@ void JAM_Pack(void)
|
|||||||
* Now copy the lastread file
|
* Now copy the lastread file
|
||||||
*/
|
*/
|
||||||
lseek(fdJlr, 0, SEEK_SET);
|
lseek(fdJlr, 0, SEEK_SET);
|
||||||
while (read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread)) {
|
for (i = 0; i < count; i++) {
|
||||||
|
if (read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread)) {
|
||||||
write(fdnJlr, &LR, sizeof(lastread));
|
write(fdnJlr, &LR, sizeof(lastread));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close all files
|
* Close all files
|
||||||
|
Reference in New Issue
Block a user