From 9bd6ab8d0e7bbb8a0a6ae35815bfc51f8e51f61f Mon Sep 17 00:00:00 2001 From: james Date: Fri, 15 Feb 2008 18:26:49 +0000 Subject: [PATCH] *** empty log message *** --- src/lockfile.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/lockfile.c b/src/lockfile.c index aa39f7b..7a2849b 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/02/15 18:26:49 james + * *** empty log message *** + * * Revision 1.4 2008/02/15 18:16:48 james * *** empty log message *** * @@ -38,6 +41,7 @@ static char rcsid[] = "$Id$"; #include #include #include +#include #include "lockfile.h" @@ -333,9 +337,64 @@ lockfile_make_list (char *device) return ret; } +static void +remove_stale_lock (char *path) +{ + int fd; + int pid; + char apid[20]; + int length; + + fd = open (path, O_RDONLY); + if (fd < 0) + return; + + length = read (fd, apid, sizeof (apid) - 1); + if (length < 0) + length = 0; + apid[length] = 0; + + pid = 0; + if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) + { + pid = *((int *) apid); +#ifdef LOCK_ASCII + fprintf (stderr, + "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", + length, pid); +#endif + } +#ifdef LOCK_BINARY + else + { + fprintf (stderr, + "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", + length, pid); + } +#endif + + close (fd); + + if ((kill (pid, 0) < 0) && (errno == ESRCH)) + { + fprintf (stderr, "removing stale lock file %s\n", path); + unlink (path); + } + +} + void lockfile_remove_stale (Filelist * fl) { + Filelist_ent *fle; + struct stat buf; + + for (fle = fl->head; fle; fle = fle->next) + { + if (stat (fle->name, &buf)) + continue; + remove_stale_lock (fle->name); + } } -- 2.30.2