Skip to content
Snippets Groups Projects
Commit f49cbe92 authored by ballen4705's avatar ballen4705
Browse files

Decided not to fork another process just to send email

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@248 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent 5d3be5a1
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
// CVS ID strings // CVS ID strings
extern const char *CVSid1, *CVSid2; extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.c,v 1.57 2002/11/12 21:53:52 ballen4705 Exp $" const char *CVSid6="$Id: smartd.c,v 1.58 2002/11/12 22:34:06 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -90,42 +90,23 @@ void printout(int priority,char *fmt, ...){ ...@@ -90,42 +90,23 @@ void printout(int priority,char *fmt, ...){
// If address is null, this just prints a warning message. But if // If address is null, this just prints a warning message. But if
// address is non-null then send and log a warning email. // address is non-null then send and log a warning email.
void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
int pid; char command[1024], message[256], hostname[256];
int status;
va_list ap; va_list ap;
// See if user wants us to send mail // See if user wants us to send mail, or if we already have
if (!address) if (!address || mail->logged)
return;
// Have we already sent a message about this?
if (mail->logged)
return; return;
// Need to send a message -- fork and send // record the time of the mail message, and increment counter. This
pid=fork(); // is for later use if we decide to implement multiple email warning
// messages after some delay time.
if (pid<0){
// We are parent, and were unable to fork to send email. Log
// warning then return.
if (errno<sys_nerr)
printout(LOG_CRIT,"Unable to send email, %s, fork() failed\n", sys_errlist[errno]);
else
printout(LOG_CRIT,"Unable to send email, fork() failed\n");
return;
}
else if (pid) {
// we are the parent process, record the time of the mail message,
// and increment counter, then return.
mail->logged++; mail->logged++;
mail->lastsent=time(NULL); mail->lastsent=time(NULL);
return;
}
else {
// We are the child process, send email
char command[1024], message[256], hostname[256];
// get system host name
if (gethostname(hostname, 256)){ if (gethostname(hostname, 256)){
sprintf(hostname,"hostname: unknown"); sprintf(hostname,"Unknown host");
} }
// print warning string into message // print warning string into message
...@@ -136,10 +117,12 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ ...@@ -136,10 +117,12 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
// now construct a command to send this as EMAIL, and issue it. // now construct a command to send this as EMAIL, and issue it.
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null", snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address); message, hostname, address);
status=system(command);
// we should uninstall exit handler! if (WEXITSTATUS(status))
exit(system(command)); printout(LOG_CRIT,"Email warning message to %s failed\n",address);
} else
return;
} }
// Printing function for watching ataprint commands, or losing them // Printing function for watching ataprint commands, or losing them
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
// CVS ID strings // CVS ID strings
extern const char *CVSid1, *CVSid2; extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.cpp,v 1.57 2002/11/12 21:53:52 ballen4705 Exp $" const char *CVSid6="$Id: smartd.cpp,v 1.58 2002/11/12 22:34:06 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -90,42 +90,23 @@ void printout(int priority,char *fmt, ...){ ...@@ -90,42 +90,23 @@ void printout(int priority,char *fmt, ...){
// If address is null, this just prints a warning message. But if // If address is null, this just prints a warning message. But if
// address is non-null then send and log a warning email. // address is non-null then send and log a warning email.
void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
int pid; char command[1024], message[256], hostname[256];
int status;
va_list ap; va_list ap;
// See if user wants us to send mail // See if user wants us to send mail, or if we already have
if (!address) if (!address || mail->logged)
return;
// Have we already sent a message about this?
if (mail->logged)
return; return;
// Need to send a message -- fork and send // record the time of the mail message, and increment counter. This
pid=fork(); // is for later use if we decide to implement multiple email warning
// messages after some delay time.
if (pid<0){
// We are parent, and were unable to fork to send email. Log
// warning then return.
if (errno<sys_nerr)
printout(LOG_CRIT,"Unable to send email, %s, fork() failed\n", sys_errlist[errno]);
else
printout(LOG_CRIT,"Unable to send email, fork() failed\n");
return;
}
else if (pid) {
// we are the parent process, record the time of the mail message,
// and increment counter, then return.
mail->logged++; mail->logged++;
mail->lastsent=time(NULL); mail->lastsent=time(NULL);
return;
}
else {
// We are the child process, send email
char command[1024], message[256], hostname[256];
// get system host name
if (gethostname(hostname, 256)){ if (gethostname(hostname, 256)){
sprintf(hostname,"hostname: unknown"); sprintf(hostname,"Unknown host");
} }
// print warning string into message // print warning string into message
...@@ -136,10 +117,12 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ ...@@ -136,10 +117,12 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
// now construct a command to send this as EMAIL, and issue it. // now construct a command to send this as EMAIL, and issue it.
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null", snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address); message, hostname, address);
status=system(command);
// we should uninstall exit handler! if (WEXITSTATUS(status))
exit(system(command)); printout(LOG_CRIT,"Email warning message to %s failed\n",address);
} else
return;
} }
// Printing function for watching ataprint commands, or losing them // Printing function for watching ataprint commands, or losing them
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment