mkoppanen               Fri Oct  3 13:59:33 2008 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /php-src/ext/standard       mail.c 
  Log:
  Adds signal handling around popen/pclose in mail.c.
  Related information on bugs #8992 and #14032
  Original patch by D. Parthey
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1237&r2=1.2027.2.547.2.1238&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1237 php-src/NEWS:1.2027.2.547.2.1238
--- php-src/NEWS:1.2027.2.547.2.1237    Thu Oct  2 03:41:24 2008
+++ php-src/NEWS        Fri Oct  3 13:59:32 2008
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2008, PHP 5.2.7
+- Fixed bug #14032 (Mail() always returns false but mail is sent). (Mikko)
+
 - Reverted fix for bug #44197 due to behaviour change in minor version.
   (Felipe)
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/mail.c?r1=1.87.2.1.2.9&r2=1.87.2.1.2.10&diff_format=u
Index: php-src/ext/standard/mail.c
diff -u php-src/ext/standard/mail.c:1.87.2.1.2.9 
php-src/ext/standard/mail.c:1.87.2.1.2.10
--- php-src/ext/standard/mail.c:1.87.2.1.2.9    Mon Dec 31 07:20:12 2007
+++ php-src/ext/standard/mail.c Fri Oct  3 13:59:33 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: mail.c,v 1.87.2.1.2.9 2007/12/31 07:20:12 sebastian Exp $ */
+/* $Id: mail.c,v 1.87.2.1.2.10 2008/10/03 13:59:33 mkoppanen Exp $ */
 
 #include <stdlib.h>
 #include <ctype.h>
@@ -31,6 +31,12 @@
 #include <sys/sysexits.h>
 #endif
 
+#if PHP_SIGCHILD
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#endif
+
 #include "php_mail.h"
 #include "php_ini.h"
 #include "safe_mode.h"
@@ -200,6 +206,9 @@
        int ret;
        char *sendmail_path = INI_STR("sendmail_path");
        char *sendmail_cmd = NULL;
+#if PHP_SIGCHILD
+       void (*sig_handler)() = NULL;
+#endif
 
        if (!sendmail_path) {
 #if (defined PHP_WIN32 || defined NETWARE)
@@ -224,6 +233,16 @@
                sendmail_cmd = sendmail_path;
        }
 
+#if PHP_SIGCHILD
+       /* Set signal handler of SIGCHLD to default to prevent other signal 
handlers
+        * from being called and reaping the return code when our child exits.
+        * The original handler needs to be restored after pclose() */
+       sig_handler = (void *)signal(SIGCHLD, SIG_DFL);
+       if (sig_handler == SIG_ERR) {
+               sig_handler = NULL;
+       }
+#endif
+
 #ifdef PHP_WIN32
        sendmail = popen(sendmail_cmd, "wb");
 #else
@@ -241,6 +260,13 @@
                if (EACCES == errno) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission 
denied: unable to execute shell to run mail delivery binary '%s'", 
sendmail_path);
                        pclose(sendmail);
+#if PHP_SIGCHILD
+                       /* Restore handler in case of error on Windows
+                          Not sure if this applicable on Win but just in case. 
*/
+                       if (sig_handler) {
+                               signal(SIGCHLD, sig_handler);
+                       }
+#endif 
                        return 0;
                }
 #endif
@@ -251,6 +277,12 @@
                }
                fprintf(sendmail, "\n%s\n", message);
                ret = pclose(sendmail);
+#if PHP_SIGCHILD
+               if (sig_handler) {
+                       signal(SIGCHLD, sig_handler);
+               }
+#endif
+
 #ifdef PHP_WIN32
                if (ret == -1)
 #else
@@ -269,6 +301,11 @@
                }
        } else {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute 
mail delivery program '%s'", sendmail_path);
+#if PHP_SIGCHILD
+               if (sig_handler) {
+                       signal(SIGCHLD, sig_handler);                           
                
+               }
+#endif
                return 0;
        }
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to