Added lockfile age check
This commit is contained in:
parent
932ce5d7a5
commit
cde220ead7
@ -7,6 +7,9 @@ $Id$
|
|||||||
|
|
||||||
v0.37.5 12-Jul-2003
|
v0.37.5 12-Jul-2003
|
||||||
|
|
||||||
|
common.a:
|
||||||
|
Node locking tests for non-stale lockfiles older then 6 hours.
|
||||||
|
|
||||||
|
|
||||||
v0.37.4 10-May-2003 - 12-Jul-2003
|
v0.37.4 10-May-2003 - 12-Jul-2003
|
||||||
|
|
||||||
|
11
TODO
11
TODO
@ -1,6 +1,6 @@
|
|||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
MBSE BBS V0.37.03 TODO list.
|
MBSE BBS V0.37.05 TODO list.
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
These are a list of things that must be implemented one way or
|
These are a list of things that must be implemented one way or
|
||||||
@ -106,9 +106,6 @@ mbcico:
|
|||||||
|
|
||||||
N: Implement binkp resync when getting files. Transmit works.
|
N: Implement binkp resync when getting files. Transmit works.
|
||||||
|
|
||||||
N: Add better check for stale outbound locks, check if the pid is from
|
|
||||||
a non-mbse program or add a age check.
|
|
||||||
|
|
||||||
mbfile:
|
mbfile:
|
||||||
N: Add a check to see if the magic filenames are (still) valid.
|
N: Add a check to see if the magic filenames are (still) valid.
|
||||||
|
|
||||||
@ -133,12 +130,6 @@ mbaff:
|
|||||||
mbindex:
|
mbindex:
|
||||||
N: Add usernames index.
|
N: Add usernames index.
|
||||||
|
|
||||||
mbmon:
|
|
||||||
L: Logfile tail functions.
|
|
||||||
|
|
||||||
mbtask:
|
|
||||||
N: Add events.
|
|
||||||
|
|
||||||
mbnewusr:
|
mbnewusr:
|
||||||
N: On NetBSD, supress error message from mbpasswd.
|
N: On NetBSD, supress error message from mbpasswd.
|
||||||
|
|
||||||
|
202
lib/nodelock.c
202
lib/nodelock.c
@ -4,7 +4,7 @@
|
|||||||
* Purpose ...............: Node locking
|
* Purpose ...............: Node locking
|
||||||
*
|
*
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
* Copyright (C) 1997-2002
|
* Copyright (C) 1997-2003
|
||||||
*
|
*
|
||||||
* Michiel Broek FIDO: 2:280/2802
|
* Michiel Broek FIDO: 2:280/2802
|
||||||
* Beekmansbos 10
|
* Beekmansbos 10
|
||||||
@ -39,120 +39,128 @@
|
|||||||
|
|
||||||
int nodelock(faddr *addr)
|
int nodelock(faddr *addr)
|
||||||
{
|
{
|
||||||
char *fn,*tfn,*p;
|
char *fn, *tfn, *p, tmp[16];
|
||||||
char tmp[16];
|
FILE *fp;
|
||||||
FILE *fp;
|
pid_t pid, mypid;
|
||||||
pid_t pid,mypid;
|
int tmppid, sverr;
|
||||||
int tmppid,sverr;
|
time_t ltime, now;
|
||||||
|
|
||||||
fn = bsyname(addr);
|
fn = bsyname(addr);
|
||||||
tfn = xstrcpy(fn);
|
tfn = xstrcpy(fn);
|
||||||
if ((p=strrchr(tfn,'/')))
|
if ((p=strrchr(tfn,'/')))
|
||||||
*++p='\0';
|
*++p='\0';
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
sprintf(tmp, "aa%d", mypid);
|
sprintf(tmp, "aa%d", mypid);
|
||||||
tfn = xstrcat(tfn, tmp);
|
tfn = xstrcat(tfn, tmp);
|
||||||
mkdirs(tfn, 0770);
|
mkdirs(tfn, 0770);
|
||||||
|
|
||||||
if ((fp = fopen(tfn,"w")) == NULL) {
|
if ((fp = fopen(tfn,"w")) == NULL) {
|
||||||
WriteError("$Can't open tmp file for bsy lock (%s) \"%s\"",ascfnode(addr, 0x1f), tfn);
|
WriteError("$Can't open tmp file for bsy lock (%s) \"%s\"",ascfnode(addr, 0x1f), tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp,"%10d\n", mypid);
|
fprintf(fp,"%10d\n", mypid);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
chmod(tfn, 0440);
|
chmod(tfn, 0440);
|
||||||
if (link(tfn, fn) == 0) {
|
if (link(tfn, fn) == 0) {
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
sverr=errno;
|
sverr = errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sverr != EEXIST) {
|
if (sverr != EEXIST) {
|
||||||
WriteError("$Could not link \"%s\" to \"%s\"",tfn,fn);
|
WriteError("$Could not link \"%s\" to \"%s\"",tfn,fn);
|
||||||
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fp=fopen(fn,"r")) == NULL) {
|
if ((fp = fopen(fn,"r")) == NULL) {
|
||||||
WriteError("$Could not open existing lock file \"%s\"",fn);
|
WriteError("$Could not open existing lock file \"%s\"",fn);
|
||||||
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lock exists, check owner
|
* Lock exists, check owner
|
||||||
*/
|
*/
|
||||||
fscanf(fp, "%d", &tmppid);
|
fscanf(fp, "%d", &tmppid);
|
||||||
pid = tmppid;
|
pid = tmppid;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If lock is our own lock, then it's ok and we are ready.
|
* If lock is our own lock, then it's ok and we are ready.
|
||||||
*/
|
*/
|
||||||
if (getpid() == pid) {
|
if (getpid() == pid) {
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kill(pid, 0) && (errno == ESRCH)) {
|
/*
|
||||||
Syslog('+', "Found stale bsy file for %s, unlink", ascfnode(addr,0x1f));
|
* Stale or old lock tests
|
||||||
unlink(fn);
|
*/
|
||||||
} else {
|
ltime = file_time(fn);
|
||||||
Syslog('+', "Node %s is locked by pid %d", ascfnode(addr, 0x1f), pid);
|
now = time(NULL);
|
||||||
unlink(tfn);
|
if (kill(pid, 0) && (errno == ESRCH)) {
|
||||||
free(tfn);
|
Syslog('+', "Found stale bsy file for %s, unlink", ascfnode(addr,0x1f));
|
||||||
return 1;
|
unlink(fn);
|
||||||
}
|
} else if (((unsigned long)now - (unsigned long)ltime) > 21600) {
|
||||||
|
Syslog('+', "Found lock older then 6 hours for %s, unlink", ascfnode(addr,0x1f));
|
||||||
|
unlink(fn);
|
||||||
|
} else {
|
||||||
|
Syslog('+', "Node %s is locked by pid %d", ascfnode(addr, 0x1f), pid);
|
||||||
|
unlink(tfn);
|
||||||
|
free(tfn);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (link(tfn,fn) == 0) {
|
if (link(tfn,fn) == 0) {
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
WriteError("$Could not link \"%s\" to \"%s\"",tfn,fn);
|
WriteError("$Could not link \"%s\" to \"%s\"",tfn,fn);
|
||||||
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
WriteError("Locking %s failed", ascfnode(addr, 0x1f));
|
||||||
unlink(tfn);
|
unlink(tfn);
|
||||||
free(tfn);
|
free(tfn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int nodeulock(faddr *addr)
|
int nodeulock(faddr *addr)
|
||||||
{
|
{
|
||||||
char *fn;
|
char *fn;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
pid_t pid,mypid;
|
pid_t pid, mypid;
|
||||||
int tmppid;
|
int tmppid;
|
||||||
|
|
||||||
fn = bsyname(addr);
|
fn = bsyname(addr);
|
||||||
if ((fp = fopen(fn, "r")) == NULL) {
|
if ((fp = fopen(fn, "r")) == NULL) {
|
||||||
WriteError("$Can't open lock file (%s) \"%s\"", ascfnode(addr, 0x1f), fn);
|
WriteError("$Can't open lock file (%s) \"%s\"", ascfnode(addr, 0x1f), fn);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fscanf(fp, "%d", &tmppid);
|
fscanf(fp, "%d", &tmppid);
|
||||||
pid = tmppid;
|
pid = tmppid;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|
||||||
if (pid == mypid) {
|
if (pid == mypid) {
|
||||||
unlink(fn);
|
unlink(fn);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
WriteError("Unlock (%s) file failed for process %u, we are %u", ascfnode(addr, 0x1f), pid,mypid);
|
WriteError("Unlock (%s) file failed for process %u, we are %u", ascfnode(addr, 0x1f), pid,mypid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user