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
Branches
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@
// CVS ID strings
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;
// global variable used for control of printing, passing arguments, etc.
......@@ -90,42 +90,23 @@ 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(char *address, mailinfo *mail, int priority, char *fmt, ...){
int pid;
char command[1024], message[256], hostname[256];
int status;
va_list ap;
// See if user wants us to send mail
if (!address)
return;
// Have we already sent a message about this?
if (mail->logged)
// See if user wants us to send mail, or if we already have
if (!address || mail->logged)
return;
// Need to send a message -- fork and send
pid=fork();
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.
// record the time of the mail message, and increment counter. This
// is for later use if we decide to implement multiple email warning
// messages after some delay time.
mail->logged++;
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)){
sprintf(hostname,"hostname: unknown");
sprintf(hostname,"Unknown host");
}
// print warning string into message
......@@ -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.
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address);
status=system(command);
// we should uninstall exit handler!
exit(system(command));
}
if (WEXITSTATUS(status))
printout(LOG_CRIT,"Email warning message to %s failed\n",address);
else
return;
}
// Printing function for watching ataprint commands, or losing them
......
......@@ -45,7 +45,7 @@
// CVS ID strings
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;
// global variable used for control of printing, passing arguments, etc.
......@@ -90,42 +90,23 @@ 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(char *address, mailinfo *mail, int priority, char *fmt, ...){
int pid;
char command[1024], message[256], hostname[256];
int status;
va_list ap;
// See if user wants us to send mail
if (!address)
return;
// Have we already sent a message about this?
if (mail->logged)
// See if user wants us to send mail, or if we already have
if (!address || mail->logged)
return;
// Need to send a message -- fork and send
pid=fork();
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.
// record the time of the mail message, and increment counter. This
// is for later use if we decide to implement multiple email warning
// messages after some delay time.
mail->logged++;
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)){
sprintf(hostname,"hostname: unknown");
sprintf(hostname,"Unknown host");
}
// print warning string into message
......@@ -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.
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address);
status=system(command);
// we should uninstall exit handler!
exit(system(command));
}
if (WEXITSTATUS(status))
printout(LOG_CRIT,"Email warning message to %s failed\n",address);
else
return;
}
// 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