2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 01:22:00 +00:00

Rework resolv watcher

Handle symlinks better and do not trigger overly
eagerly
This commit is contained in:
Jarrod Johnson 2022-05-05 09:26:55 -04:00
parent 754cdfdd78
commit 86891eb2e5

View File

@ -502,8 +502,17 @@ class SockApi(object):
def watch_resolv(self):
while True:
watcher = libc.inotify_init1(os.O_NONBLOCK)
if libc.inotify_add_watch(watcher, b'/etc/resolv.conf', 0xcda) <= -1:
break
resolvpath = '/etc/resolv.conf'
while True:
try:
resolvpath = os.readlink(resolvpath)
except Exception:
break
if not isinstance(resolvpath, bytes):
resolvpath = resolvpath.encode('utf8')
if libc.inotify_add_watch(watcher, resolvpath, 0xcc2) <= -1:
eventlet.sleep(15)
continue
select.select((watcher,), (), (), 86400)
try:
os.read(watcher, 1024)