+ ret = filelist_new ();
+
+ lockfile_add_name_from_dev (ret, dev_stat.st_rdev);
+
+ lockfile_add_name_from_path (ret, device);
+
+ lockfile_check_dir_for_dev (ret, "/dev/", dev_stat.st_rdev);
+ lockfile_check_dir_for_dev (ret, "/dev/usb/", dev_stat.st_rdev);
+ lockfile_check_dir_for_dev (ret, "/dev/tts/", dev_stat.st_rdev);
+
+ 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);
+ }
+
+
+}