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

View File

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