Fix NetNS creation when PID is re-used

Change-Id: I464d769d58998fcb85d1de6ddc6e11cb6525fdf9
This commit is contained in:
Mohammed Naser 2020-11-05 17:32:28 -05:00
parent 5b90bec7de
commit ce39dc5ed7
1 changed files with 10 additions and 3 deletions

View File

@ -83,6 +83,11 @@ def main():
while True:
output = ""
for pid_file in get_pid_files(args.state):
state_path = pid_file.replace('.pid.keepalived-vrrp', '')
state_file = os.path.join(state_path, 'state')
router_id = os.path.basename(state_path)
with open(pid_file) as pid_fd:
pid = int(pid_fd.read())
@ -90,10 +95,12 @@ def main():
if psutil.pid_exists(pid) is False:
continue
state_path = pid_file.replace('.pid.keepalived-vrrp', '')
state_file = os.path.join(state_path, 'state')
# Check if the PID is indeed for the correct router
proc = psutil.Process(pid)
cmdline = " ".join(proc.cmdline())
if router_id not in cmdline:
continue
router_id = os.path.basename(state_path)
with open(state_file) as state_fd:
master = 1 if 'master' in state_fd.read() else 0