It turns out that glibc gethostbyname_r will not automatically reload its configuration if this configuration changes. You must manually call res_init. See error report below.
Note. Neither the man page for gethostbyname_r nor rer_init mentioned this limitation.
My solution is very specific. It runs on our server with a long service life, but this is not my ideal solution.
I have a function that checks the mtime of the /etc/resolv.conf file for the last known time mtime (0 for DNE). If the two times are different, then I call res_init. This function is called when the program starts, and then periodically to additionally reload the configuration.
Glibc error message
libc caches resolv.conf forever
...
Why res_init () is needed, name it.
mat_geek
source share