[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[monit-dev] [monit] r342 committed - * Try harder to get FQDN hostname f
From: |
monit |
Subject: |
[monit-dev] [monit] r342 committed - * Try harder to get FQDN hostname for the host where monit is running.... |
Date: |
Wed, 23 Mar 2011 10:16:39 +0000 |
Revision: 342
Author: address@hidden
Date: Wed Mar 23 03:15:53 2011
Log: * Try harder to get FQDN hostname for the host where monit is
running.
The hostname in the $HOST variable which is used in the mail sender
may thus change. Thanks to Sergey B Kirpichev for patch.
http://code.google.com/p/monit/source/detail?r=342
Modified:
/trunk/CHANGES.txt
/trunk/p.y
/trunk/sendmail.c
/trunk/util.c
/trunk/util.h
=======================================
--- /trunk/CHANGES.txt Tue Mar 22 14:55:02 2011
+++ /trunk/CHANGES.txt Wed Mar 23 03:15:53 2011
@@ -23,6 +23,10 @@
* Fix bug #32583: Multiple SIP OPTIONS messages use the same header data.
Thanks to Hugh Waite for patch.
+* Try harder to get FQDN hostname for the host where monit is running.
+ The hostname in the $HOST variable which is used in the mail sender
+ may thus change. Thanks to Sergey B Kirpichev for patch.
+
* AIX: Fix the time display which was off by GMT difference. Thanks to
Helen Chen for report.
@@ -32,6 +36,7 @@
+
Version 5.2.4
NEW FEATURES AND FUNCTIONS:
=======================================
--- /trunk/p.y Wed Jan 19 10:40:32 2011
+++ /trunk/p.y Wed Mar 23 03:15:53 2011
@@ -1866,7 +1866,7 @@
/*
* Get the localhost name
*/
- if (gethostname(localhost, sizeof(localhost)) < 0)
+ if (Util_getfqdnhostname(localhost, sizeof(localhost)))
snprintf(localhost, STRLEN, "%s", LOCALHOST);
/* Set instance incarnation ID */
=======================================
--- /trunk/sendmail.c Mon Feb 28 08:00:47 2011
+++ /trunk/sendmail.c Wed Mar 23 03:15:53 2011
@@ -135,9 +135,7 @@
Util_getRFC822Date(NULL, now, STRLEN);
- if(Run.mail_hostname || gethostname(S.localhost, sizeof(S.localhost)) <
0) {
- snprintf(S.localhost, sizeof(S.localhost), "%s",
Run.mail_hostname?Run.mail_hostname:LOCALHOST);
- }
+ snprintf(S.localhost, sizeof(S.localhost), "%s", Run.mail_hostname ?
Run.mail_hostname : Run.localhostname);
do_status(&S);
=======================================
--- /trunk/util.c Mon Mar 21 08:32:15 2011
+++ /trunk/util.c Wed Mar 23 03:15:53 2011
@@ -88,6 +88,10 @@
#include <sys/types.h>
#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
@@ -2004,6 +2008,30 @@
FREE(buf);
}
}
+
+
+int Util_getfqdnhostname(char *buf, unsigned len) {
+ int status;
+ char hostname[STRLEN];
+ struct addrinfo hints, *info;
+
+ if (gethostname(hostname, sizeof(hostname))) {
+ LogError("%s: Error getting hostname -- %s\n", prog, STRERROR);
+ return -1;
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_CANONNAME;
+ if ((status = getaddrinfo(hostname, NULL, &hints, &info))) {
+ LogError("%s: Cannot translate '%s' to FQDN name -- %s\n", prog,
hostname, gai_strerror(status));
+ snprintf(buf, len, "%s", hostname); // fallback to gethostname()
+ } else
+ snprintf(buf, len, "%s", info->ai_canonname);
+
+ return 0;
+}
/* -----------------------------------------------------------------
Private */
=======================================
--- /trunk/util.h Mon Mar 21 08:32:15 2011
+++ /trunk/util.h Wed Mar 23 03:15:53 2011
@@ -516,4 +516,13 @@
void Util_stringbuffer(Buffer_T *b, const char *m, ...);
+/**
+ * Returns the FQDN hostname or fallback to gethostname() output
+ * @param buf the character array for hostname
+ * @param len the length of buf
+ * @return zero on success
+ */
+int Util_getfqdnhostname(char *buf, unsigned len);
+
+
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [monit-dev] [monit] r342 committed - * Try harder to get FQDN hostname for the host where monit is running....,
monit <=