File 0001-optionally-warn-if-nss-myhostname-is-called.diff of Package nss-myhostname
From 84a26d4ad7e43bd1c6675b8bd59e856b7e938f71 Mon Sep 17 00:00:00 2001
From: Ludwig Nussel <ludwig.nussel@suse.de>
Date: Fri, 20 May 2011 15:38:46 +0200
Subject: [PATCH nss-myhostname] optionally warn if nss-myhostname is called
---
configure.ac | 9 +++++++++
nss-myhostname.c | 28 +++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index 38cd58f..e8c1503 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,6 +72,15 @@ AC_CHECK_FUNCS([gethostbyaddr gethostbyname gettimeofday inet_ntoa memset select
# LYNX documentation generation
ZP_LYNX_DOC
+AC_MSG_CHECKING([log warning messages])
+AC_ARG_WITH(warning, AS_HELP_STRING([--with-warning], [log warning to syslog when nss-myhostname is called (default=no)]),[],[with_warning=no])
+AC_MSG_RESULT([$with_warning])
+
+if test x$with_warning != xno; then
+ AC_CHECK_HEADERS([syslog.h])
+ AC_DEFINE([LOG_WARNING],[1],[whether to log warning message])
+fi
+
AC_CONFIG_FILES([Makefile doc/Makefile doc/README.html ])
AC_OUTPUT
diff --git a/nss-myhostname.c b/nss-myhostname.c
index 293166c..9d0e688 100644
--- a/nss-myhostname.c
+++ b/nss-myhostname.c
@@ -31,6 +31,9 @@
#include <net/if.h>
#include <stdlib.h>
#include <arpa/inet.h>
+#if LOG_WARNING
+#include <syslog.h>
+#endif
#include "netlink.h"
@@ -45,6 +48,8 @@
#define ALIGN(a) (((a+sizeof(void*)-1)/sizeof(void*))*sizeof(void*))
+static void warn(const char* hn);
+
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
@@ -117,6 +122,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
return NSS_STATUS_NOTFOUND;
}
+ warn(hn);
+
/* If this fails, n_addresses is 0. Which is fine */
netlink_acquire_addresses(&addresses, &n_addresses);
@@ -333,6 +340,8 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_NOTFOUND;
}
+ warn(hn);
+
return fill_in_hostent(hn, af, host, buffer, buflen, errnop, h_errnop, ttlp, canonp);
}
@@ -430,8 +439,9 @@ found:
return NSS_STATUS_UNAVAIL;
}
- return fill_in_hostent(hn, af, host, buffer, buflen, errnop, h_errnop, ttlp, NULL);
+ warn(hn);
+ return fill_in_hostent(hn, af, host, buffer, buflen, errnop, h_errnop, ttlp, NULL);
}
enum nss_status _nss_myhostname_gethostbyaddr_r(
@@ -449,3 +459,19 @@ enum nss_status _nss_myhostname_gethostbyaddr_r(
errnop, h_errnop,
NULL);
}
+
+void warn(const char* hn) {
+#if LOG_WARNING
+ if (strstr(program_invocation_short_name, "nscd")) {
+ syslog(LOG_WARNING,
+ "Some application tried to resolve hostname \"%s\" which is not in DNS. Stop nscd to find out which one.\n",
+ hn);
+ } else {
+ syslog(LOG_WARNING,
+ "%s(%u) tried to resolve hostname \"%s\" which is not in DNS. This might be the reason for the delays you experience.\n",
+ program_invocation_short_name,
+ getpid(),
+ hn);
+ }
+#endif
+}
--
1.7.3.4