summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-09-28 18:08:07 -0400
committerAdam <Adam@anope.org>2010-09-28 18:08:07 -0400
commite990259d6dc53ed33cc3153ca6ad39db3ad51db2 (patch)
treee565aceb8441b5f4b7b222b6d80dacb3d56abeb1
parent5a4de87df122302d5e6e739e5e1a425d33d71060 (diff)
Rewrote the mail forking code to use pipes, sometimes mails wouldn't work with the old method
-rw-r--r--include/services.h3
-rw-r--r--src/mail.c66
-rw-r--r--version.log3
3 files changed, 65 insertions, 7 deletions
diff --git a/include/services.h b/include/services.h
index 93e0561ea..53b6ea6d2 100644
--- a/include/services.h
+++ b/include/services.h
@@ -1059,6 +1059,9 @@ typedef struct ignore_data {
struct mailinfo_ {
FILE *pipe;
+ /* Used only with mail forking */
+ FILE *writepipe;
+ FILE *readpipe;
User *sender;
NickCore *recipient;
NickRequest *recip;
diff --git a/src/mail.c b/src/mail.c
index 590518e69..1f092ebc1 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -43,13 +43,23 @@ MailInfo *MailRegBegin(User * u, NickRequest * nr, char *subject,
notice_lang(service, u, MAIL_INVALID, nr->nick);
} else {
MailInfo *mail;
+ int pipefds[2];
mail = scalloc(sizeof(MailInfo), 1);
mail->sender = u;
mail->recipient = NULL;
mail->recip = nr;
+ mail->pipe = mail->writepipe = mail->readpipe = NULL;
- if (!(mail->pipe = popen(SendMailPath, "w"))) {
+#if HAVE_FORK
+ if (ForkForMail && !pipe(pipefds))
+ {
+ mail->writepipe = fdopen(pipefds[1], "w");
+ mail->readpipe = fdopen(pipefds[0], "r");
+ mail->pipe = mail->writepipe;
+ }
+#endif
+ if (!mail->pipe && !(mail->pipe = popen(SendMailPath, "w"))) {
free(mail);
notice_lang(service, u, MAIL_LATER);
return NULL;
@@ -96,13 +106,23 @@ MailInfo *MailBegin(User * u, NickCore * nc, char *subject, char *service)
notice_lang(service, u, MAIL_INVALID, nc->display);
} else {
MailInfo *mail;
+ int pipefds[2];
mail = scalloc(sizeof(MailInfo), 1);
mail->sender = u;
mail->recipient = nc;
mail->recip = NULL;
+ mail->pipe = mail->writepipe = mail->readpipe = NULL;
- if (!(mail->pipe = popen(SendMailPath, "w"))) {
+#if HAVE_FORK
+ if (ForkForMail && !pipe(pipefds))
+ {
+ mail->writepipe = fdopen(pipefds[1], "w");
+ mail->readpipe = fdopen(pipefds[0], "r");
+ mail->pipe = mail->writepipe;
+ }
+#endif
+ if (!mail->pipe && !(mail->pipe = popen(SendMailPath, "w"))) {
free(mail);
notice_lang(service, u, MAIL_LATER);
return NULL;
@@ -141,13 +161,23 @@ MailInfo *MailMemoBegin(NickCore * nc)
} else {
MailInfo *mail;
+ int pipefds[2];
mail = scalloc(sizeof(MailInfo), 1);
mail->sender = NULL;
mail->recipient = nc;
mail->recip = NULL;
+ mail->pipe = mail->writepipe = mail->readpipe = NULL;
- if (!(mail->pipe = popen(SendMailPath, "w"))) {
+#if HAVE_FORK
+ if (ForkForMail && !pipe(pipefds))
+ {
+ mail->writepipe = fdopen(pipefds[1], "w");
+ mail->readpipe = fdopen(pipefds[0], "r");
+ mail->pipe = mail->writepipe;
+ }
+#endif
+ if (!mail->pipe && !(mail->pipe = popen(SendMailPath, "w"))) {
free(mail);
return NULL;
}
@@ -189,14 +219,38 @@ void MailEnd(MailInfo * mail)
}
#if HAVE_FORK
- if (ForkForMail && !(pid = fork()))
+ if (ForkForMail && mail->writepipe && mail->readpipe && !(pid = fork()))
{
- pclose(mail->pipe);
+ FILE *fd;
+ int ret;
+
+ fputc(255, mail->writepipe);
+ fclose(mail->writepipe);
+
+ fd = popen(SendMailPath, "w");
+ if (!fd)
+ return;
+
+ while ((ret = fgetc(mail->readpipe)) != 255)
+ fputc(ret, fd);
+
+ fclose(mail->readpipe);
+ pclose(fd);
exit(EXIT_SUCCESS);
}
else if (pid < 0)
#endif
- pclose(mail->pipe);
+ {
+ if (mail->pipe != mail->writepipe)
+ pclose(mail->pipe);
+ else
+ {
+ if (mail->writepipe)
+ fclose(mail->writepipe);
+ if (mail->readpipe)
+ fclose(mail->readpipe);
+ }
+ }
if (mail->sender) /* added sender check */
mail->sender->lastmail = time(NULL);
diff --git a/version.log b/version.log
index 8a1766b1f..aac1588ac 100644
--- a/version.log
+++ b/version.log
@@ -8,9 +8,10 @@ VERSION_MAJOR="1"
VERSION_MINOR="8"
VERSION_PATCH="5"
VERSION_EXTRA="-git"
-VERSION_BUILD="3040"
+VERSION_BUILD="3041"
# $Log$ # Changes since 1.8.5 Release
+#Revision 3041 - Rewrote the mail forking code to use pipes, sometimes mails wouldn't work with the old method
#Revision 3040 - Fixed configure failing on some systems which have a partial MySQL installation
#Revision 3039 - Fixed db-merger handling some hostserv collisions
#Revision 3038 - Initialise git for 1.8-git