2013-04-13 13:09:53 +02:00
From: Ludwig Nussel <ludwig.nussel@suse.de>
Date: Fri, 20 May 2011 15:38:46 +0200
Subject: optionally warn if nss-myhostname is called
---
configure.ac | 11 +++++++++++
2013-05-29 17:26:40 +02:00
src/nss-myhostname/nss-myhostname.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
2013-04-13 13:09:53 +02:00
diff --git a/configure.ac b/configure.ac
2013-05-29 17:26:40 +02:00
index e1278e8..06eb98d 100644
2013-04-13 13:09:53 +02:00
--- a/configure.ac
+++ b/configure.ac
2013-05-29 17:26:40 +02:00
@@ -725,6 +725,17 @@ if test "x$enable_myhostname" != "xno"; then
2013-04-13 13:09:53 +02:00
fi
AM_CONDITIONAL(HAVE_MYHOSTNAME, [test "$have_myhostname" = "yes"])
+if test "x$have_myhostname" != "xno"; then
+ AC_MSG_CHECKING([log warning messages for nss-myhostname])
+ AC_ARG_WITH(nss-my-hostname-warning, AS_HELP_STRING([--with-nss-my-hostname-warning], [log warning to syslog when nss-myhostname is called (default=no)]),[],[with_nss_my_hostname_warning=no])
+ AC_MSG_RESULT([$with_nss_my_hostname_warning])
+
+ if test x$with_nss_my_hostname_warning != xno; then
+ AC_CHECK_HEADERS([syslog.h])
+ AC_DEFINE([LOG_NSS_MY_HOSTNAME_WARNING],[1],[whether to log warning message for nss-myhostname])
+ fi
+fi
+
# ------------------------------------------------------------------------------
AC_ARG_WITH(firmware-path,
AS_HELP_STRING([--with-firmware-path=DIR[[[:DIR[...]]]]],
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
2013-05-29 17:26:40 +02:00
index e97d4e5..a2a6de8 100644
2013-04-13 13:09:53 +02:00
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
2013-05-29 17:26:40 +02:00
@@ -29,6 +29,9 @@
2013-04-13 13:09:53 +02:00
#include <net/if.h>
#include <stdlib.h>
#include <arpa/inet.h>
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
+#include <syslog.h>
+#endif
#include "ifconf.h"
2013-04-19 22:31:17 +02:00
#include "macro.h"
2013-05-29 17:26:40 +02:00
@@ -47,6 +50,10 @@
2013-04-19 22:31:17 +02:00
#define LOCALADDRESS_IPV6 &in6addr_loopback
#define LOOPBACK_INTERFACE "lo"
2013-04-13 13:09:53 +02:00
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
+static void warn(const char* hn);
+#endif
+
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
2013-05-29 17:26:40 +02:00
@@ -129,6 +136,9 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
return NSS_STATUS_NOTFOUND;
}
2013-04-13 13:09:53 +02:00
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
2013-05-29 17:26:40 +02:00
+ warn(hn);
2013-04-13 13:09:53 +02:00
+#endif
2013-05-29 17:26:40 +02:00
/* If this fails, n_addresses is 0. Which is fine */
ifconf_acquire_addresses(&addresses, &n_addresses);
2013-04-13 13:09:53 +02:00
2013-05-29 17:26:40 +02:00
@@ -382,6 +392,9 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
local_address_ipv4 = LOCALADDRESS_IPV4;
2013-04-13 13:09:53 +02:00
}
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
+ warn(hn);
+#endif
2013-05-29 17:26:40 +02:00
return fill_in_hostent(
canonical, additional,
af,
@@ -509,6 +522,9 @@ found:
canonical = hn;
2013-04-13 13:09:53 +02:00
}
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
+ warn(hn);
+#endif
2013-05-29 17:26:40 +02:00
return fill_in_hostent(
canonical, additional,
af,
@@ -537,3 +553,19 @@ enum nss_status _nss_myhostname_gethostbyaddr_r(
2013-04-13 13:09:53 +02:00
errnop, h_errnop,
NULL);
}
+
+#ifdef LOG_NSS_MY_HOSTNAME_WARNING
+static void warn(const char* hn) {
+ 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