Using glibc, why does my gethostbyname fail after I/DHCP has changed the DNS server?

六眼飞鱼酱① 提交于 2019-12-04 05:40:52

It turns out that glibc gethostbyname_r won't automatically reload it's configuration if that configuration changes. You have to manually call res_init. See bug report below.

Note: Neither the man page for gethostbyname_r nor for rer_init mentioned this limitation.

My solution is very specific. It works for our long running server but it is not my ideal solution.

I have a function that checks the mtime of the /etc/resolv.conf against the last known mtime (0 for DNE). If the two mtime differ then I call res_init. This function is called on program startup and then periodically to optionally reload the configuration.


The glibc bug report

libc caches resolv.conf forever

...

That's what res_init() is for, call it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!