From patchwork Tue Jan 21 18:41:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 37452 Received: (qmail 92836 invoked by alias); 21 Jan 2020 18:41:58 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 92738 invoked by uid 89); 21 Jan 2020 18:41:57 -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, SPF_PASS 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=1579632114; 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=D2pW2csQf8qYAIay15B+FiED0MItEVoX0ue0BMO3Klw=; b=iDrX7GsIdm7Ox2e+X98PHBdpbE2seFl03Sem+taNucspJCbJo7kkNbxBfStOpaVn7o4kTL 7zMH/cXTv99E+sez72tzq+tWrDQo3EMUQsRqErtu/xTYKvef+EjqxVVXfPvfVmqxv+ptmU RtecjivdFgai5EsvM1EssQDuuZkk1ok= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 2/5] resolv: Use in __resolv_conf_get_current In-Reply-To: References: Message-Id: Date: Tue, 21 Jan 2020 19:41:49 +0100 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 Only minor functional changes (i.e., regarding the handling of directories, which are now treated as empty files). Reviewed-by: Adhemerval Zanella --- resolv/resolv_conf.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c index 08c50ef19e..d954ba9a5a 100644 --- a/resolv/resolv_conf.c +++ b/resolv/resolv_conf.c @@ -24,6 +24,7 @@ #include #include #include +#include /* _res._u._ext.__glibc_extension_index is used as an index into a 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. */ struct resolv_conf *conf_current; - /* These properties of /etc/resolv.conf are used to check if the - configuration needs reloading. */ - struct timespec conf_mtime; - struct timespec conf_ctime; - off64_t conf_size; - ino64_t conf_ino; + /* File system identification for /etc/resolv.conf. */ + struct file_change_detection file_resolve_conf; }; /* Lazily allocated storage for struct resolv_conf_global. */ @@ -123,37 +120,16 @@ conf_decrement (struct resolv_conf *conf) struct resolv_conf * __resolv_conf_get_current (void) { - struct stat64 st; - if (stat64 (_PATH_RESCONF, &st) != 0) - { - 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; - } - } + struct file_change_detection initial; + if (!file_change_detection_for_path (&initial, _PATH_RESCONF)) + return NULL; struct resolv_conf_global *global_copy = get_locked_global (); if (global_copy == NULL) return NULL; struct resolv_conf *conf; if (global_copy->conf_current != NULL - && (global_copy->conf_mtime.tv_sec == st.st_mtim.tv_sec - && 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)) + && file_is_unchanged (&initial, &global_copy->file_resolve_conf)) /* We can reuse the cached configuration object. */ conf = global_copy->conf_current; else @@ -171,10 +147,7 @@ __resolv_conf_get_current (void) read could be a newer version of the file, but this does not matter because this will lead to an extraneous reload later. */ - global_copy->conf_mtime = st.st_mtim; - global_copy->conf_ctime = st.st_ctim; - global_copy->conf_ino = st.st_ino; - global_copy->conf_size = st.st_size; + global_copy->file_resolve_conf = initial; } }