aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rename_device.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/rename_device.c b/src/rename_device.c
index c39f447d..b4ed69eb 100644
--- a/src/rename_device.c
+++ b/src/rename_device.c
@@ -278,6 +278,14 @@ char *get_config_by_hwaddr(char *hwaddr, char *current) {
return first;
}
+int pid_exist(int pid)
+{
+ char proc_dir[32];
+ sprintf(proc_dir, "/proc/%d/", pid);
+ return !access(proc_dir, F_OK);
+}
+
+
void take_lock() {
int count = 0;
int lockfd;
@@ -309,7 +317,11 @@ void take_lock() {
close(fd);
pid = atoi(buf);
if (pid && pid != 1) {
- kill(pid,SIGKILL);
+ if (pid_exist(pid))
+ kill(pid,SIGKILL);
+ else
+ if (unlink(LOCKFILE) != 0)
+ break;
}
}
usleep(100000);