aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwangxp006 <wangxiaopeng7@huawei.com>2021-01-13 18:21:50 +0800
committerGitHub <noreply@github.com>2021-01-13 11:21:50 +0100
commitdbff71b664c7536d09dc3172259d8984005b60fa (patch)
treecc65d856028396b90b26214a8219147e63242f74
parent0151112bd52a813620213c2e958aa89f556fdbb3 (diff)
downloadinitscripts-dbff71b664c7536d09dc3172259d8984005b60fa.tar
initscripts-dbff71b664c7536d09dc3172259d8984005b60fa.tar.gz
initscripts-dbff71b664c7536d09dc3172259d8984005b60fa.tar.bz2
initscripts-dbff71b664c7536d09dc3172259d8984005b60fa.tar.xz
initscripts-dbff71b664c7536d09dc3172259d8984005b60fa.zip
remove rename_device_lock when process does not exist
if rename_device is killed during fopen period in take_lock ,LOCKFILE will not be remove in sighandler. Excute rename_device again, LOCKFILE is exist ,but the process with pid in LOCKFILE is not running, take_lock will never return.
-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);