aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-15 18:26:49 +0000
committerjames <>2008-02-15 18:26:49 +0000
commit9d7ba333e3d966a41302941c49a1477dd61aad21 (patch)
treec02ee6df31caa46349576c23d88746ab2de4bc75
parent80588cc4e79b19ea5b73f100e66ab5e5102dfc65 (diff)
downloadsympathy-9d7ba333e3d966a41302941c49a1477dd61aad21.tar.gz
sympathy-9d7ba333e3d966a41302941c49a1477dd61aad21.tar.bz2
sympathy-9d7ba333e3d966a41302941c49a1477dd61aad21.zip
*** empty log message ***
-rw-r--r--src/lockfile.c59
1 files changed, 59 insertions, 0 deletions
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 <pwd.h>
#include <fcntl.h>
#include <dirent.h>
+#include <errno.h>
#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);
+ }
}