summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2012-07-26 12:42:33 +0800
committerXinchen Hui <laruence@php.net>2012-07-26 12:42:33 +0800
commitba27e0888a3bb91eba3266c71003df045c4d2091 (patch)
tree5a773576efc7efb7ab402242a94b495d0aee3cc4
parentb4b3a65f5518803c4a3bca34ac67e139b2547133 (diff)
parent5f224412fa6892645ca548ac75f20ff8743ed916 (diff)
downloadphp-git-ba27e0888a3bb91eba3266c71003df045c4d2091.tar.gz
Merge branch 'PHP-5.4' of git.php.net:php-src into PHP-5.4
-rw-r--r--ext/standard/mail.c55
-rw-r--r--php.ini-development2
-rw-r--r--php.ini-production2
-rw-r--r--sapi/fpm/fpm/fpm_sockets.c6
4 files changed, 52 insertions, 13 deletions
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index 36568c508e..364f7fc399 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -39,6 +39,7 @@
#endif
#endif
+#include "php_syslog.h"
#include "php_mail.h"
#include "php_ini.h"
#include "php_string.h"
@@ -189,6 +190,37 @@ PHP_FUNCTION(mail)
}
/* }}} */
+
+void php_mail_log_crlf_to_spaces(char *message) {
+ /* Find all instances of carriage returns or line feeds and
+ * replace them with spaces. Thus, a log line is always one line
+ * long
+ */
+ char *p = message;
+ while ((p = strpbrk(p, "\r\n"))) {
+ *p = ' ';
+ }
+}
+
+void php_mail_log_to_syslog(char *message) {
+ /* Write 'message' to syslog. */
+#ifdef HAVE_SYSLOG_H
+ php_syslog(LOG_NOTICE, "%s", message);
+#endif
+}
+
+
+void php_mail_log_to_file(char *filename, char *message, size_t message_size TSRMLS_DC) {
+ /* Write 'message' to the given file. */
+ uint flags = IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR;
+ php_stream *stream = php_stream_open_wrapper(filename, "a", flags, NULL);
+ if (stream) {
+ php_stream_write(stream, message, message_size);
+ php_stream_close(stream);
+ }
+}
+
+
/* {{{ php_mail
*/
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
@@ -216,19 +248,22 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
if (mail_log && *mail_log) {
char *tmp;
int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
- php_stream *stream = php_stream_open_wrapper(mail_log, "a", IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR, NULL);
- if (hdr) { /* find all \r\n instances and replace them with spaces, so a log line is always one line long */
- char *p = tmp;
- while ((p = strpbrk(p, "\r\n"))) {
- *p = ' ';
- }
- tmp[l - 1] = '\n';
+ if (hdr) {
+ php_mail_log_crlf_to_spaces(tmp);
}
- if (stream) {
- php_stream_write(stream, tmp, l);
- php_stream_close(stream);
+
+ if (!strcmp(mail_log, "syslog")) {
+ /* Drop the final space when logging to syslog. */
+ tmp[l - 1] = 0;
+ php_mail_log_to_syslog(tmp);
+ }
+ else {
+ /* Convert the final space to a newline when logging to file. */
+ tmp[l - 1] = '\n';
+ php_mail_log_to_file(mail_log, tmp, l TSRMLS_CC);
}
+
efree(tmp);
}
if (PG(mail_x_header)) {
diff --git a/php.ini-development b/php.ini-development
index 298cb06a72..4ff4192f6f 100644
--- a/php.ini-development
+++ b/php.ini-development
@@ -1020,6 +1020,8 @@ mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
+; Log mail to syslog (Event Log on NT, not valid in Windows 95).
+;mail.log = syslog
[SQL]
; http://php.net/sql.safe-mode
diff --git a/php.ini-production b/php.ini-production
index d4c1261fcd..814455bbbb 100644
--- a/php.ini-production
+++ b/php.ini-production
@@ -1020,6 +1020,8 @@ mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
+; Log mail to syslog (Event Log on NT, not valid in Windows 95).
+;mail.log = syslog
[SQL]
; http://php.net/sql.safe-mode
diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c
index d24dcccc9a..f56b9cfbd1 100644
--- a/sapi/fpm/fpm/fpm_sockets.c
+++ b/sapi/fpm/fpm/fpm_sockets.c
@@ -455,11 +455,11 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq)
#endif
-int fpm_socket_unix_test_connect(struct sockaddr_un *sun, size_t socklen) /* {{{ */
+int fpm_socket_unix_test_connect(struct sockaddr_un *sock, size_t socklen) /* {{{ */
{
int fd;
- if (!sun || sun->sun_family != AF_UNIX) {
+ if (!sock || sock->sun_family != AF_UNIX) {
return -1;
}
@@ -467,7 +467,7 @@ int fpm_socket_unix_test_connect(struct sockaddr_un *sun, size_t socklen) /* {{{
return -1;
}
- if (connect(fd, (struct sockaddr *)sun, socklen) == -1) {
+ if (connect(fd, (struct sockaddr *)sock, socklen) == -1) {
return -1;
}