mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
resolv: Use <file_change_detection.h> in __resolv_conf_get_current
Only minor functional changes (i.e., regarding the handling of directories, which are now treated as empty files). Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
#include <resolv-internal.h>
|
#include <resolv-internal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <libc-symbols.h>
|
#include <libc-symbols.h>
|
||||||
|
#include <file_change_detection.h>
|
||||||
|
|
||||||
/* _res._u._ext.__glibc_extension_index is used as an index into a
|
/* _res._u._ext.__glibc_extension_index is used as an index into a
|
||||||
struct resolv_conf_array object. The intent of this construction
|
struct resolv_conf_array object. The intent of this construction
|
||||||
@ -68,12 +69,8 @@ struct resolv_conf_global
|
|||||||
/* Cached current configuration object for /etc/resolv.conf. */
|
/* Cached current configuration object for /etc/resolv.conf. */
|
||||||
struct resolv_conf *conf_current;
|
struct resolv_conf *conf_current;
|
||||||
|
|
||||||
/* These properties of /etc/resolv.conf are used to check if the
|
/* File system identification for /etc/resolv.conf. */
|
||||||
configuration needs reloading. */
|
struct file_change_detection file_resolve_conf;
|
||||||
struct timespec conf_mtime;
|
|
||||||
struct timespec conf_ctime;
|
|
||||||
off64_t conf_size;
|
|
||||||
ino64_t conf_ino;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Lazily allocated storage for struct resolv_conf_global. */
|
/* Lazily allocated storage for struct resolv_conf_global. */
|
||||||
@ -123,37 +120,16 @@ conf_decrement (struct resolv_conf *conf)
|
|||||||
struct resolv_conf *
|
struct resolv_conf *
|
||||||
__resolv_conf_get_current (void)
|
__resolv_conf_get_current (void)
|
||||||
{
|
{
|
||||||
struct stat64 st;
|
struct file_change_detection initial;
|
||||||
if (stat64 (_PATH_RESCONF, &st) != 0)
|
if (!file_change_detection_for_path (&initial, _PATH_RESCONF))
|
||||||
{
|
|
||||||
switch (errno)
|
|
||||||
{
|
|
||||||
case EACCES:
|
|
||||||
case EISDIR:
|
|
||||||
case ELOOP:
|
|
||||||
case ENOENT:
|
|
||||||
case ENOTDIR:
|
|
||||||
case EPERM:
|
|
||||||
/* Ignore errors due to file system contents. */
|
|
||||||
memset (&st, 0, sizeof (st));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Other errors are fatal. */
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct resolv_conf_global *global_copy = get_locked_global ();
|
struct resolv_conf_global *global_copy = get_locked_global ();
|
||||||
if (global_copy == NULL)
|
if (global_copy == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
struct resolv_conf *conf;
|
struct resolv_conf *conf;
|
||||||
if (global_copy->conf_current != NULL
|
if (global_copy->conf_current != NULL
|
||||||
&& (global_copy->conf_mtime.tv_sec == st.st_mtim.tv_sec
|
&& file_is_unchanged (&initial, &global_copy->file_resolve_conf))
|
||||||
&& global_copy->conf_mtime.tv_nsec == st.st_mtim.tv_nsec
|
|
||||||
&& global_copy->conf_ctime.tv_sec == st.st_ctim.tv_sec
|
|
||||||
&& global_copy->conf_ctime.tv_nsec == st.st_ctim.tv_nsec
|
|
||||||
&& global_copy->conf_ino == st.st_ino
|
|
||||||
&& global_copy->conf_size == st.st_size))
|
|
||||||
/* We can reuse the cached configuration object. */
|
/* We can reuse the cached configuration object. */
|
||||||
conf = global_copy->conf_current;
|
conf = global_copy->conf_current;
|
||||||
else
|
else
|
||||||
@ -171,10 +147,7 @@ __resolv_conf_get_current (void)
|
|||||||
read could be a newer version of the file, but this does
|
read could be a newer version of the file, but this does
|
||||||
not matter because this will lead to an extraneous reload
|
not matter because this will lead to an extraneous reload
|
||||||
later. */
|
later. */
|
||||||
global_copy->conf_mtime = st.st_mtim;
|
global_copy->file_resolve_conf = initial;
|
||||||
global_copy->conf_ctime = st.st_ctim;
|
|
||||||
global_copy->conf_ino = st.st_ino;
|
|
||||||
global_copy->conf_size = st.st_size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user