From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94743 invoked by alias); 21 Jan 2020 18:42:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 94661 invoked by uid 89); 21 Jan 2020 18:42:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579632130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Io4NRBaCBzCGRUf6gmyJKiuHnucTxwsHVtsqiIzdCw=; b=LpW4JXTk03UMAfp2Nj+p154VR16wXV7wCrjq1k2G0da9PazNtfmGE1umf0D0llsJO5Tcil Dgyu1LvzFUuKRYhqg37Zr/ihx0XowT5k0blohwOmX+Sd+0/qqtvYSim3ohoWUjZBqmTCfv pbiJ9FAcIPoAo9OxURiwQtwNxBC1LFI= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 4/5] resolv: Enhance __resolv_conf_load to capture file change data In-Reply-To: References: Message-Id: <39fc4b71f02884315d1dacd5a5a0f1ee45009f12.1579631655.git.fweimer@redhat.com> Date: Tue, 21 Jan 2020 18:42:00 -0000 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-SW-Source: 2020-01/txt/msg00495.txt.bz2 The data is captured after reading the file. This allows callers to check the change data against an earlier measurement. --- resolv/res_init.c | 14 +++++++++++--- resolv/resolv_conf.c | 2 +- resolv/resolv_conf.h | 10 +++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/resolv/res_init.c b/resolv/res_init.c index 09345718cd..98d84f264d 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -103,6 +103,7 @@ #include #include #include +#include =20 static uint32_t net_mask (struct in_addr); =20 @@ -549,7 +550,8 @@ res_vinit_1 (FILE *fp, struct resolv_conf_parser *parse= r) } =20 struct resolv_conf * -__resolv_conf_load (struct __res_state *preinit) +__resolv_conf_load (struct __res_state *preinit, + struct file_change_detection *change) { /* Ensure that /etc/hosts.conf has been loaded (once). */ _res_hconf_init (); @@ -577,7 +579,13 @@ __resolv_conf_load (struct __res_state *preinit) resolv_conf_parser_init (&parser, preinit); =20 struct resolv_conf *conf =3D NULL; - if (res_vinit_1 (fp, &parser)) + bool ok =3D res_vinit_1 (fp, &parser); + if (ok && change !=3D NULL) + /* Update the file change information if the configuration was + loaded successfully. */ + ok =3D file_change_detection_for_fp (change, fp); + + if (ok) { parser.template.nameserver_list =3D nameserver_list_begin (&parser.nameserver_list); @@ -615,7 +623,7 @@ __res_vinit (res_state statp, int preinit) if (preinit && has_preinit_values (statp)) /* For the preinit case, we cannot use the cached configuration because some settings could be different. */ - conf =3D __resolv_conf_load (statp); + conf =3D __resolv_conf_load (statp, NULL); else conf =3D __resolv_conf_get_current (); if (conf =3D=3D NULL) diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c index d954ba9a5a..bdd2ebb909 100644 --- a/resolv/resolv_conf.c +++ b/resolv/resolv_conf.c @@ -136,7 +136,7 @@ __resolv_conf_get_current (void) { /* Parse configuration while holding the lock. This avoids duplicate work. */ - conf =3D __resolv_conf_load (NULL); + conf =3D __resolv_conf_load (NULL, NULL); if (conf !=3D NULL) { if (global_copy->conf_current !=3D NULL) diff --git a/resolv/resolv_conf.h b/resolv/resolv_conf.h index 01cbff9111..101e14bfe5 100644 --- a/resolv/resolv_conf.h +++ b/resolv/resolv_conf.h @@ -63,12 +63,16 @@ struct resolv_conf and the struct resolv_context facility. */ =20 struct __res_state; +struct file_change_detection; =20 /* Read /etc/resolv.conf and return a configuration object, or NULL if /etc/resolv.conf cannot be read due to memory allocation errors. - If PREINIT is not NULL, some configuration values are taken from the - struct __res_state object. */ -struct resolv_conf *__resolv_conf_load (struct __res_state *preinit) + If PREINIT is not NULL, some configuration values are taken from + the struct __res_state object. If CHANGE is not null, file change + detection data is written to *CHANGE, based on the state of the + file after reading it. */ +struct resolv_conf *__resolv_conf_load (struct __res_state *preinit, + struct file_change_detection *chan= ge) attribute_hidden __attribute__ ((warn_unused_result)); =20 /* Return a configuration object for the current /etc/resolv.conf --=20 2.24.1