From dbef5df121baba167bcb72bfd4c9f4e6da78fc9c Mon Sep 17 00:00:00 2001
From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Mon, 16 Dec 2002 12:27:00 +0000
Subject: [PATCH] Added domainname to contents of error message from smartd.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@378 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/CHANGELOG  |  6 +++++-
 sm5/smartd.c   | 15 ++++++++++-----
 sm5/smartd.cpp | 15 ++++++++++-----
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/sm5/CHANGELOG b/sm5/CHANGELOG
index 4ee3216ad..cc87a8f57 100644
--- a/sm5/CHANGELOG
+++ b/sm5/CHANGELOG
@@ -1,6 +1,6 @@
 CHANGELOG for smartmontools
 
-$Id: CHANGELOG,v 1.69 2002/12/12 13:42:59 ballen4705 Exp $
+$Id: CHANGELOG,v 1.70 2002/12/16 12:27:00 ballen4705 Exp $
 
 Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
 
@@ -32,6 +32,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 CURRENT RELEASE (see VERSION file in this directory):
 
+  ]BA] Use strerror() to generate system call error messages.
+
+  [BA] smartd: fflush() all open streams before fork().
+
   [BA] smartctl, smartd simplified internal handling of checksums
   for simpler porting and less code.
 
diff --git a/sm5/smartd.c b/sm5/smartd.c
index 3d3a56df4..eb66adf5d 100644
--- a/sm5/smartd.c
+++ b/sm5/smartd.c
@@ -50,7 +50,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.c,v 1.87 2002/12/15 21:08:23 ballen4705 Exp $" 
+const char *CVSid6="$Id: smartd.c,v 1.88 2002/12/16 12:27:00 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -111,7 +111,8 @@ void printout(int priority,char *fmt, ...){
 // If address is null, this just prints a warning message.  But if
 // address is non-null then send and log a warning email.
 void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
-  char command[2048], message[256], hostname[256], additional[256], original[256], further[256];
+  char command[2048], message[256], hostname[256], additional[256];
+  char original[256], further[256], domainname[256];
   int status;
   time_t epoch;
   va_list ap;
@@ -154,11 +155,15 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
     mail->firstsent=epoch;
   mail->lastsent=epoch;
   
-  // get system host name (not null terminated if length=MAX) 
+  // get system host & domain names (not null terminated if length=MAX) 
   if (gethostname(hostname, 256))
     sprintf(hostname,"Unknown host");
   else
     hostname[255]='\0';
+  if (getdomainname(domainname, 256))
+    sprintf(hostname,"Unknown domain");
+  else
+    domainname[255]='\0';
   
   // print warning string into message
   va_start(ap, fmt);
@@ -190,14 +195,14 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
   // now construct a command to send this as EMAIL
   snprintf(command, 2048, "mail -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
 	   "This email was generated by the smartd daemon running on host:\n"
-	   "%s\n\n"
+	   "%s in domain: %s\n\n"
 	   "The following warning/error was logged by the smartd daemon:\n"
 	   "%s\n"
 	   "For further details see the syslog (/var/log/messages) on host:\n"
 	   "%s\n\n"
 	   "%s%s%s"
 	   "ENDMAIL\n",
-	   hostname, address, hostname, message, hostname, further, original, additional);
+	   hostname, address, hostname, domainname, message, hostname, further, original, additional);
 
   // issue the command to send email
   status=system(command);
diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp
index da8c47940..72dafec7c 100644
--- a/sm5/smartd.cpp
+++ b/sm5/smartd.cpp
@@ -50,7 +50,7 @@
 
 // CVS ID strings
 extern const char *CVSid1, *CVSid2;
-const char *CVSid6="$Id: smartd.cpp,v 1.87 2002/12/15 21:08:23 ballen4705 Exp $" 
+const char *CVSid6="$Id: smartd.cpp,v 1.88 2002/12/16 12:27:00 ballen4705 Exp $" 
 CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
 
 // global variable used for control of printing, passing arguments, etc.
@@ -111,7 +111,8 @@ void printout(int priority,char *fmt, ...){
 // If address is null, this just prints a warning message.  But if
 // address is non-null then send and log a warning email.
 void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
-  char command[2048], message[256], hostname[256], additional[256], original[256], further[256];
+  char command[2048], message[256], hostname[256], additional[256];
+  char original[256], further[256], domainname[256];
   int status;
   time_t epoch;
   va_list ap;
@@ -154,11 +155,15 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
     mail->firstsent=epoch;
   mail->lastsent=epoch;
   
-  // get system host name (not null terminated if length=MAX) 
+  // get system host & domain names (not null terminated if length=MAX) 
   if (gethostname(hostname, 256))
     sprintf(hostname,"Unknown host");
   else
     hostname[255]='\0';
+  if (getdomainname(domainname, 256))
+    sprintf(hostname,"Unknown domain");
+  else
+    domainname[255]='\0';
   
   // print warning string into message
   va_start(ap, fmt);
@@ -190,14 +195,14 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
   // now construct a command to send this as EMAIL
   snprintf(command, 2048, "mail -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
 	   "This email was generated by the smartd daemon running on host:\n"
-	   "%s\n\n"
+	   "%s in domain: %s\n\n"
 	   "The following warning/error was logged by the smartd daemon:\n"
 	   "%s\n"
 	   "For further details see the syslog (/var/log/messages) on host:\n"
 	   "%s\n\n"
 	   "%s%s%s"
 	   "ENDMAIL\n",
-	   hostname, address, hostname, message, hostname, further, original, additional);
+	   hostname, address, hostname, domainname, message, hostname, further, original, additional);
 
   // issue the command to send email
   status=system(command);
-- 
GitLab