|
|
7c0489 |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
7c0489 |
Date: Tue, 21 Jan 2020 15:52:33 +0000 (+0100)
|
|
|
7c0489 |
Subject: resolv: Use <file_change_detection.h> in __resolv_conf_get_current
|
|
|
7c0489 |
X-Git-Url: https://sourceware.org/git/?p=glibc.git;a=commitdiff_plain;h=9642b85fd0dfa5731020a3271c08e33e1dc05c85
|
|
|
7c0489 |
|
|
|
7c0489 |
resolv: Use <file_change_detection.h> in __resolv_conf_get_current
|
|
|
7c0489 |
|
|
|
7c0489 |
Only minor functional changes (i.e., regarding the handling of
|
|
|
7c0489 |
directories, which are now treated as empty files).
|
|
|
7c0489 |
|
|
|
7c0489 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
7c0489 |
---
|
|
|
7c0489 |
|
|
|
7c0489 |
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
|
|
|
7c0489 |
index 08c50ef19e..d954ba9a5a 100644
|
|
|
7c0489 |
--- a/resolv/resolv_conf.c
|
|
|
7c0489 |
+++ b/resolv/resolv_conf.c
|
|
|
7c0489 |
@@ -24,6 +24,7 @@
|
|
|
7c0489 |
#include <resolv-internal.h>
|
|
|
7c0489 |
#include <sys/stat.h>
|
|
|
7c0489 |
#include <libc-symbols.h>
|
|
|
7c0489 |
+#include <file_change_detection.h>
|
|
|
7c0489 |
|
|
|
7c0489 |
/* _res._u._ext.__glibc_extension_index is used as an index into a
|
|
|
7c0489 |
struct resolv_conf_array object. The intent of this construction
|
|
|
7c0489 |
@@ -68,12 +69,8 @@ struct resolv_conf_global
|
|
|
7c0489 |
/* Cached current configuration object for /etc/resolv.conf. */
|
|
|
7c0489 |
struct resolv_conf *conf_current;
|
|
|
7c0489 |
|
|
|
7c0489 |
- /* These properties of /etc/resolv.conf are used to check if the
|
|
|
7c0489 |
- configuration needs reloading. */
|
|
|
7c0489 |
- struct timespec conf_mtime;
|
|
|
7c0489 |
- struct timespec conf_ctime;
|
|
|
7c0489 |
- off64_t conf_size;
|
|
|
7c0489 |
- ino64_t conf_ino;
|
|
|
7c0489 |
+ /* File system identification for /etc/resolv.conf. */
|
|
|
7c0489 |
+ struct file_change_detection file_resolve_conf;
|
|
|
7c0489 |
};
|
|
|
7c0489 |
|
|
|
7c0489 |
/* Lazily allocated storage for struct resolv_conf_global. */
|
|
|
7c0489 |
@@ -123,37 +120,16 @@ conf_decrement (struct resolv_conf *conf)
|
|
|
7c0489 |
struct resolv_conf *
|
|
|
7c0489 |
__resolv_conf_get_current (void)
|
|
|
7c0489 |
{
|
|
|
7c0489 |
- struct stat64 st;
|
|
|
7c0489 |
- if (stat64 (_PATH_RESCONF, &st) != 0)
|
|
|
7c0489 |
- {
|
|
|
7c0489 |
- switch (errno)
|
|
|
7c0489 |
- {
|
|
|
7c0489 |
- case EACCES:
|
|
|
7c0489 |
- case EISDIR:
|
|
|
7c0489 |
- case ELOOP:
|
|
|
7c0489 |
- case ENOENT:
|
|
|
7c0489 |
- case ENOTDIR:
|
|
|
7c0489 |
- case EPERM:
|
|
|
7c0489 |
- /* Ignore errors due to file system contents. */
|
|
|
7c0489 |
- memset (&st, 0, sizeof (st));
|
|
|
7c0489 |
- break;
|
|
|
7c0489 |
- default:
|
|
|
7c0489 |
- /* Other errors are fatal. */
|
|
|
7c0489 |
- return NULL;
|
|
|
7c0489 |
- }
|
|
|
7c0489 |
- }
|
|
|
7c0489 |
+ struct file_change_detection initial;
|
|
|
7c0489 |
+ if (!file_change_detection_for_path (&initial, _PATH_RESCONF))
|
|
|
7c0489 |
+ return NULL;
|
|
|
7c0489 |
|
|
|
7c0489 |
struct resolv_conf_global *global_copy = get_locked_global ();
|
|
|
7c0489 |
if (global_copy == NULL)
|
|
|
7c0489 |
return NULL;
|
|
|
7c0489 |
struct resolv_conf *conf;
|
|
|
7c0489 |
if (global_copy->conf_current != NULL
|
|
|
7c0489 |
- && (global_copy->conf_mtime.tv_sec == st.st_mtim.tv_sec
|
|
|
7c0489 |
- && global_copy->conf_mtime.tv_nsec == st.st_mtim.tv_nsec
|
|
|
7c0489 |
- && global_copy->conf_ctime.tv_sec == st.st_ctim.tv_sec
|
|
|
7c0489 |
- && global_copy->conf_ctime.tv_nsec == st.st_ctim.tv_nsec
|
|
|
7c0489 |
- && global_copy->conf_ino == st.st_ino
|
|
|
7c0489 |
- && global_copy->conf_size == st.st_size))
|
|
|
7c0489 |
+ && file_is_unchanged (&initial, &global_copy->file_resolve_conf))
|
|
|
7c0489 |
/* We can reuse the cached configuration object. */
|
|
|
7c0489 |
conf = global_copy->conf_current;
|
|
|
7c0489 |
else
|
|
|
7c0489 |
@@ -171,10 +147,7 @@ __resolv_conf_get_current (void)
|
|
|
7c0489 |
read could be a newer version of the file, but this does
|
|
|
7c0489 |
not matter because this will lead to an extraneous reload
|
|
|
7c0489 |
later. */
|
|
|
7c0489 |
- global_copy->conf_mtime = st.st_mtim;
|
|
|
7c0489 |
- global_copy->conf_ctime = st.st_ctim;
|
|
|
7c0489 |
- global_copy->conf_ino = st.st_ino;
|
|
|
7c0489 |
- global_copy->conf_size = st.st_size;
|
|
|
7c0489 |
+ global_copy->file_resolve_conf = initial;
|
|
|
7c0489 |
}
|
|
|
7c0489 |
}
|
|
|
7c0489 |
|