Improved mbfido locking
This commit is contained in:
parent
5cc97ad5f1
commit
19f9ba962a
@ -63,6 +63,13 @@ v0.35.03 06-Jul-2002
|
|||||||
there is now better filtering to get that garbage out of the
|
there is now better filtering to get that garbage out of the
|
||||||
received tic files. We will forward plain ascii of course.
|
received tic files. We will forward plain ascii of course.
|
||||||
Fixed the outbound queue to send to nodes not in the setup.
|
Fixed the outbound queue to send to nodes not in the setup.
|
||||||
|
When mbfido stops with error 110 it doesn't remove any locks
|
||||||
|
because this error is only being used before that main lock is
|
||||||
|
made.
|
||||||
|
Changed the error codes during init until the main lock is
|
||||||
|
made, this must prevent destroying a another lock.
|
||||||
|
Added extra check to unlock directory function to check that
|
||||||
|
only the owned lock is removed.
|
||||||
|
|
||||||
newuser:
|
newuser:
|
||||||
Check for Unix accounts is now case sensitive.
|
Check for Unix accounts is now case sensitive.
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put a lock on this program.
|
* Put a lock on a directory.
|
||||||
*/
|
*/
|
||||||
int lockdir(char *directory)
|
int lockdir(char *directory)
|
||||||
{
|
{
|
||||||
@ -116,14 +116,36 @@ int lockdir(char *directory)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unlock directory, make extra check to see if it is our own lock.
|
||||||
|
*/
|
||||||
void ulockdir(char *directory)
|
void ulockdir(char *directory)
|
||||||
{
|
{
|
||||||
char *lockfile;
|
char *lockfile;
|
||||||
|
FILE *fp;
|
||||||
|
pid_t oldpid;
|
||||||
|
|
||||||
lockfile = calloc(PATH_MAX, sizeof(char));
|
lockfile = calloc(PATH_MAX, sizeof(char));
|
||||||
sprintf(lockfile, "%s/", directory);
|
sprintf(lockfile, "%s/", directory);
|
||||||
sprintf(lockfile + strlen(lockfile), "%s", LCKNAME);
|
sprintf(lockfile + strlen(lockfile), "%s", LCKNAME);
|
||||||
(void)unlink(lockfile);
|
|
||||||
|
if ((fp = fopen(lockfile, "r")) == NULL) {
|
||||||
|
Syslog('-', "Lockfile \"%s\" doesn't exist", lockfile);
|
||||||
|
free(lockfile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fscanf(fp, "%u", &oldpid) != 1) {
|
||||||
|
WriteError("$Can't read old pid from \"%s\"", lockfile);
|
||||||
|
} else {
|
||||||
|
if (getpid() != oldpid) {
|
||||||
|
WriteError("Attempt to remove lock %s of pid %d", lockfile, oldpid);
|
||||||
|
} else {
|
||||||
|
unlink(lockfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
free(lockfile);
|
free(lockfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,8 @@ void die(int onsig)
|
|||||||
system("stty sane");
|
system("stty sane");
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseDupes();
|
if (onsig != 110)
|
||||||
|
CloseDupes();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for locked and open message base.
|
* Check for locked and open message base.
|
||||||
@ -239,11 +240,15 @@ void die(int onsig)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* There should be no locks anymore, but in case of a crash try to unlock
|
* There should be no locks anymore, but in case of a crash try to unlock
|
||||||
* all possible directories.
|
* all possible directories. Only if onsig <> 110, this was a lock error
|
||||||
|
* and there should be no lock. We prevent removing the lock of another
|
||||||
|
* mbfido this way.
|
||||||
*/
|
*/
|
||||||
ulockdir(CFG.inbound);
|
if (onsig != 110) {
|
||||||
ulockdir(CFG.pinbound);
|
ulockdir(CFG.inbound);
|
||||||
ulockdir(CFG.out_queue);
|
ulockdir(CFG.pinbound);
|
||||||
|
ulockdir(CFG.out_queue);
|
||||||
|
}
|
||||||
|
|
||||||
t_end = time(NULL);
|
t_end = time(NULL);
|
||||||
Syslog(' ', "MBFIDO finished in %s", t_elapsed(t_start, t_end));
|
Syslog(' ', "MBFIDO finished in %s", t_elapsed(t_start, t_end));
|
||||||
@ -427,10 +432,11 @@ int main(int argc, char **argv)
|
|||||||
Syslog(' ', cmd);
|
Syslog(' ', cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
InitDupes();
|
/*
|
||||||
|
* Not yet locked, if anything goes wrong, exit with die(110)
|
||||||
|
*/
|
||||||
if (!diskfree(CFG.freespace))
|
if (!diskfree(CFG.freespace))
|
||||||
die(101);
|
die(110);
|
||||||
|
|
||||||
if (do_mail) {
|
if (do_mail) {
|
||||||
/*
|
/*
|
||||||
@ -452,7 +458,7 @@ int main(int argc, char **argv)
|
|||||||
i--;
|
i--;
|
||||||
if (! i) {
|
if (! i) {
|
||||||
WriteError("Lock timeout, aborting");
|
WriteError("Lock timeout, aborting");
|
||||||
die(101);
|
die(110);
|
||||||
}
|
}
|
||||||
sleep(20);
|
sleep(20);
|
||||||
Nopper();
|
Nopper();
|
||||||
@ -464,13 +470,17 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (do_unprot) {
|
if (do_unprot) {
|
||||||
if (! lockdir(CFG.inbound))
|
if (! lockdir(CFG.inbound))
|
||||||
die(101);
|
die(110);
|
||||||
} else {
|
} else {
|
||||||
if (! lockdir(CFG.pinbound))
|
if (! lockdir(CFG.pinbound))
|
||||||
die(101);
|
die(110);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Locking succeeded, no more abort alowed with die(110)
|
||||||
|
*/
|
||||||
|
|
||||||
if (initnl())
|
if (initnl())
|
||||||
die(101);
|
die(101);
|
||||||
if (!do_mail && !do_uucp)
|
if (!do_mail && !do_uucp)
|
||||||
@ -513,6 +523,8 @@ int main(int argc, char **argv)
|
|||||||
die(0);
|
die(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InitDupes();
|
||||||
|
|
||||||
if (do_notify)
|
if (do_notify)
|
||||||
if (Notify(Options)) {
|
if (Notify(Options)) {
|
||||||
do_flush = TRUE;
|
do_flush = TRUE;
|
||||||
|
Reference in New Issue
Block a user