From bf2b5cb67102f7f18837848d7a925c181b7fe03b Mon Sep 17 00:00:00 2001 From: vcrhonek Date: Tue, 21 Oct 2008 10:49:17 +0000 Subject: [PATCH] Rewrite binding files only when they are changed --- ypbind-mt-1.20.4-smartwrite.patch | 102 ++++++++++++++++++++++++++++++ ypbind.spec | 8 ++- 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 ypbind-mt-1.20.4-smartwrite.patch diff --git a/ypbind-mt-1.20.4-smartwrite.patch b/ypbind-mt-1.20.4-smartwrite.patch new file mode 100644 index 0000000..9ca688f --- /dev/null +++ b/ypbind-mt-1.20.4-smartwrite.patch @@ -0,0 +1,102 @@ +diff -up ypbind-mt-1.20.4/src/serv_list.c_old ypbind-mt-1.20.4/src/serv_list.c +--- ypbind-mt-1.20.4/src/serv_list.c_old 2008-10-21 11:37:59.000000000 +0200 ++++ ypbind-mt-1.20.4/src/serv_list.c 2008-10-21 11:38:20.000000000 +0200 +@@ -81,6 +81,7 @@ struct binding + struct bound_server server[_MAXSERVER]; + struct bound_server ypset; + CLIENT *client_handle; ++ struct bound_server last; /* last written */ + }; + static inline char * + bound_host(struct binding *bptr) +@@ -133,26 +134,44 @@ update_bindingfile (struct binding *entr + sprintf (path1, "%s/%s.1", BINDINGDIR, entry->domain); + sprintf (path2, "%s/%s.2", BINDINGDIR, entry->domain); + +- iov[0].iov_base = (caddr_t) &sport; +- iov[0].iov_len = sizeof (sport); +- iov[1].iov_base = (caddr_t) &ybres; +- iov[1].iov_len = sizeof ybres; +- + memset(&ybres, 0, sizeof (ybres)); + ybres.ypbind_status = YPBIND_SUCC_VAL; + if (entry->active >= 0) + { ++ if (entry->last.host && ++ !memcmp(&entry->server[entry->active].addr, &entry->last.addr, ++ sizeof(struct in_addr)) && ++ entry->server[entry->active].port == entry->last.port) ++ { ++ if (debug_flag) ++ log_msg (LOG_DEBUG, "Entry for %s unchanged, skipping writeout", ++ entry->domain); ++ return; ++ } ++ + memcpy (&ybres.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, + &entry->server[entry->active].addr, sizeof (struct in_addr)); + memcpy (&ybres.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, + &entry->server[entry->active].port, sizeof (unsigned short int)); ++ entry->last= entry->server[entry->active]; + } + else if (entry->active == -2) /* ypset was used */ + { ++ if (entry->last.host && ++ !memcmp(&entry->ypset.addr, &entry->last.addr, ++ sizeof(struct in_addr)) && ++ entry->ypset.port == entry->last.port) ++ { ++ if (debug_flag) ++ log_msg (LOG_DEBUG, "Entry for %s unchanged, skipping writeout", ++ entry->domain); ++ return; ++ } + memcpy (&ybres.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, + &entry->ypset.addr, sizeof (struct in_addr)); + memcpy (&ybres.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, + &entry->ypset.port, sizeof (unsigned short int)); ++ entry->last= entry->ypset; + } + else + { +@@ -160,10 +179,16 @@ update_bindingfile (struct binding *entr + libc will query ypbind direct. */ + unlink (path1); + unlink (path2); ++ entry->last.host = NULL; + log_msg (LOG_ERR, "INTERNAL ERROR: update_bindingfile called without valid data!"); + return; + } + ++ iov[0].iov_base = (caddr_t) &sport; ++ iov[0].iov_len = sizeof (sport); ++ iov[1].iov_base = (caddr_t) &ybres; ++ iov[1].iov_len = sizeof ybres; ++ + len = iov[0].iov_len + iov[1].iov_len; + + if ((fd = open(path1, O_CREAT | O_RDWR | O_TRUNC, FILE_MODE )) != -1) +@@ -171,6 +196,7 @@ update_bindingfile (struct binding *entr + if (writev (fd, iov, 2) != len ) + { + log_msg (LOG_ERR, "writev (%s): %s", path1, strerror (errno)); ++ entry->last.host = NULL; + unlink (path1); + } + close (fd); +@@ -183,6 +209,7 @@ update_bindingfile (struct binding *entr + if (writev (fd, iov, 2) != len ) + { + log_msg (LOG_ERR, "writev (%s): %s", path2, strerror (errno)); ++ entry->last.host = NULL; + unlink (path2); + } + close (fd); +@@ -403,6 +430,7 @@ get_entry (const char *domain, struct bi + domainlist[max_domains - 1].ypset.host = NULL; + domainlist[max_domains - 1].active = (-1); + domainlist[max_domains - 1].use_broadcast = FALSE; ++ domainlist[max_domains - 1].last.host = NULL; + memset (domainlist[max_domains - 1].server, 0, + (_MAXSERVER * sizeof (struct bound_server))); + *entry = &domainlist[max_domains - 1]; diff --git a/ypbind.spec b/ypbind.spec index 2bbbde1..4c9900f 100644 --- a/ypbind.spec +++ b/ypbind.spec @@ -1,7 +1,7 @@ Summary: The NIS daemon which binds NIS clients to an NIS domain. Name: ypbind Version: 1.20.4 -Release: 7%{?dist} +Release: 8%{?dist} License: GPLv2 Group: System Environment/Daemons Source0: ftp://ftp.us.kernel.org/pub/linux/utils/net/NIS/ypbind-mt-%{PACKAGE_VERSION}.tar.bz2 @@ -12,6 +12,7 @@ Patch2: ypbind-1.11-gettextdomain.patch Patch3: ypbind-mt-1.19-port-leak.patch Patch4: ypbind-mt-1.19-log-binds.patch Patch5: ypbind-1.19-debuginfo.patch +Patch6: ypbind-mt-1.20.4-smartwrite.patch Prereq: /sbin/chkconfig Requires: rpcbind, yp-tools, bash >= 2.0 @@ -45,6 +46,7 @@ also need to install the ypserv package to a machine on your network. %patch3 -p1 %patch4 -p1 #%patch5 -p1 +%patch6 -p1 -b .smartwrite %build autoreconf @@ -91,6 +93,10 @@ exit 0 %doc README NEWS %changelog +* Tue Oct 21 2008 Vitezslav Crhonek - 1.20.4-8 +- Rewrite binding files only when they are changed + Resolves: #454581 + * Mon Aug 11 2008 Jason L Tibbitts III - 1.20.4-7 - Fix license tag.