fix possible crash on user deletion
[srvx.git] / src / mail-sendmail.c
index d6530b4e95ad22277885dc3f5790979aafcfe49c..5da1fc96e0b485a35806b8de8b2401ca8d673a0d 100644 (file)
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
+#include "mail-common.c"
+
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
 
-#include "mail-common.c"
-
 /* This function sends the given "paragraph" as flowed text, as
  * defined in RFC 2646.  It lets us only worry about line wrapping
  * here, and not in the code that generates mail.
@@ -68,9 +68,11 @@ send_flowed_text(FILE *where, const char *para)
 void
 mail_send(struct userNode *from, struct handle_info *to, const char *subject, const char *body, int first_time)
 {
+    struct sigaction sv;
     pid_t child;
     int infds[2], outfds[2];
-    const char *fromaddr, *str;
+    const char *fromaddr;
+    const char *str;
 
     /* Grab some config items first. */
     str = conf_get_data("mail/enable", RECDB_QSTRING);
@@ -92,6 +94,11 @@ mail_send(struct userNode *from, struct handle_info *to, const char *subject, co
     } else if (child > 0) {
         return;
     }
+    /* Reset the SIGCHLD signal handler to the default. */
+    memset(&sv, 0, sizeof(sv));
+    sigemptyset(&sv.sa_mask);
+    sv.sa_handler = SIG_DFL;
+    sigaction(SIGCHLD, &sv, NULL);
     /* We're in a child now; must _exit() to die properly. */
     if (pipe(infds) < 0) {
         log_module(MAIN_LOG, LOG_ERROR, "sendmail() child to %s couldn't pipe(infds): %s (%d)", to->email_addr, strerror(errno), errno);