|
|
7c0489 |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
7c0489 |
Date: Tue, 21 Jan 2020 16:25:39 +0000 (+0100)
|
|
|
7c0489 |
Subject: resolv: Enhance __resolv_conf_load to capture file change data
|
|
|
7c0489 |
X-Git-Url: https://sourceware.org/git/?p=glibc.git;a=commitdiff_plain;h=dd0b4df329ff7ff2a656404db271c8ee8379ff9d
|
|
|
7c0489 |
|
|
|
7c0489 |
resolv: Enhance __resolv_conf_load to capture file change data
|
|
|
7c0489 |
|
|
|
7c0489 |
The data is captured after reading the file. This allows callers
|
|
|
7c0489 |
to check the change data against an earlier measurement.
|
|
|
7c0489 |
|
|
|
7c0489 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
7c0489 |
---
|
|
|
7c0489 |
|
|
|
7c0489 |
diff --git a/resolv/res_init.c b/resolv/res_init.c
|
|
|
7c0489 |
index 09345718cd..98d84f264d 100644
|
|
|
7c0489 |
--- a/resolv/res_init.c
|
|
|
7c0489 |
+++ b/resolv/res_init.c
|
|
|
7c0489 |
@@ -103,6 +103,7 @@
|
|
|
7c0489 |
#include <inet/net-internal.h>
|
|
|
7c0489 |
#include <errno.h>
|
|
|
7c0489 |
#include <resolv_conf.h>
|
|
|
7c0489 |
+#include <file_change_detection.h>
|
|
|
7c0489 |
|
|
|
7c0489 |
static uint32_t net_mask (struct in_addr);
|
|
|
7c0489 |
|
|
|
7c0489 |
@@ -549,7 +550,8 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser)
|
|
|
7c0489 |
}
|
|
|
7c0489 |
|
|
|
7c0489 |
struct resolv_conf *
|
|
|
7c0489 |
-__resolv_conf_load (struct __res_state *preinit)
|
|
|
7c0489 |
+__resolv_conf_load (struct __res_state *preinit,
|
|
|
7c0489 |
+ struct file_change_detection *change)
|
|
|
7c0489 |
{
|
|
|
7c0489 |
/* Ensure that /etc/hosts.conf has been loaded (once). */
|
|
|
7c0489 |
_res_hconf_init ();
|
|
|
7c0489 |
@@ -577,7 +579,13 @@ __resolv_conf_load (struct __res_state *preinit)
|
|
|
7c0489 |
resolv_conf_parser_init (&parser, preinit);
|
|
|
7c0489 |
|
|
|
7c0489 |
struct resolv_conf *conf = NULL;
|
|
|
7c0489 |
- if (res_vinit_1 (fp, &parser))
|
|
|
7c0489 |
+ bool ok = res_vinit_1 (fp, &parser);
|
|
|
7c0489 |
+ if (ok && change != NULL)
|
|
|
7c0489 |
+ /* Update the file change information if the configuration was
|
|
|
7c0489 |
+ loaded successfully. */
|
|
|
7c0489 |
+ ok = file_change_detection_for_fp (change, fp);
|
|
|
7c0489 |
+
|
|
|
7c0489 |
+ if (ok)
|
|
|
7c0489 |
{
|
|
|
7c0489 |
parser.template.nameserver_list
|
|
|
7c0489 |
= nameserver_list_begin (&parser.nameserver_list);
|
|
|
7c0489 |
@@ -615,7 +623,7 @@ __res_vinit (res_state statp, int preinit)
|
|
|
7c0489 |
if (preinit && has_preinit_values (statp))
|
|
|
7c0489 |
/* For the preinit case, we cannot use the cached configuration
|
|
|
7c0489 |
because some settings could be different. */
|
|
|
7c0489 |
- conf = __resolv_conf_load (statp);
|
|
|
7c0489 |
+ conf = __resolv_conf_load (statp, NULL);
|
|
|
7c0489 |
else
|
|
|
7c0489 |
conf = __resolv_conf_get_current ();
|
|
|
7c0489 |
if (conf == NULL)
|
|
|
7c0489 |
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
|
|
|
7c0489 |
index d954ba9a5a..bdd2ebb909 100644
|
|
|
7c0489 |
--- a/resolv/resolv_conf.c
|
|
|
7c0489 |
+++ b/resolv/resolv_conf.c
|
|
|
7c0489 |
@@ -136,7 +136,7 @@ __resolv_conf_get_current (void)
|
|
|
7c0489 |
{
|
|
|
7c0489 |
/* Parse configuration while holding the lock. This avoids
|
|
|
7c0489 |
duplicate work. */
|
|
|
7c0489 |
- conf = __resolv_conf_load (NULL);
|
|
|
7c0489 |
+ conf = __resolv_conf_load (NULL, NULL);
|
|
|
7c0489 |
if (conf != NULL)
|
|
|
7c0489 |
{
|
|
|
7c0489 |
if (global_copy->conf_current != NULL)
|
|
|
7c0489 |
diff --git a/resolv/resolv_conf.h b/resolv/resolv_conf.h
|
|
|
7c0489 |
index 01cbff9111..101e14bfe5 100644
|
|
|
7c0489 |
--- a/resolv/resolv_conf.h
|
|
|
7c0489 |
+++ b/resolv/resolv_conf.h
|
|
|
7c0489 |
@@ -63,12 +63,16 @@ struct resolv_conf
|
|
|
7c0489 |
and the struct resolv_context facility. */
|
|
|
7c0489 |
|
|
|
7c0489 |
struct __res_state;
|
|
|
7c0489 |
+struct file_change_detection;
|
|
|
7c0489 |
|
|
|
7c0489 |
/* Read /etc/resolv.conf and return a configuration object, or NULL if
|
|
|
7c0489 |
/etc/resolv.conf cannot be read due to memory allocation errors.
|
|
|
7c0489 |
- If PREINIT is not NULL, some configuration values are taken from the
|
|
|
7c0489 |
- struct __res_state object. */
|
|
|
7c0489 |
-struct resolv_conf *__resolv_conf_load (struct __res_state *preinit)
|
|
|
7c0489 |
+ If PREINIT is not NULL, some configuration values are taken from
|
|
|
7c0489 |
+ the struct __res_state object. If CHANGE is not null, file change
|
|
|
7c0489 |
+ detection data is written to *CHANGE, based on the state of the
|
|
|
7c0489 |
+ file after reading it. */
|
|
|
7c0489 |
+struct resolv_conf *__resolv_conf_load (struct __res_state *preinit,
|
|
|
7c0489 |
+ struct file_change_detection *change)
|
|
|
7c0489 |
attribute_hidden __attribute__ ((warn_unused_result));
|
|
|
7c0489 |
|
|
|
7c0489 |
/* Return a configuration object for the current /etc/resolv.conf
|