tony2001 Sun Apr 8 08:02:02 2007 UTC
Modified files:
/php-src/main main.c
Log:
MFB: Avoid locks when appening to the error log file
http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.724&r2=1.725&diff_format=u
Index: php-src/main/main.c
diff -u php-src/main/main.c:1.724 php-src/main/main.c:1.725
--- php-src/main/main.c:1.724 Wed Mar 28 10:22:32 2007
+++ php-src/main/main.c Sun Apr 8 08:02:02 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.724 2007/03/28 10:22:32 tony2001 Exp $ */
+/* $Id: main.c,v 1.725 2007/04/08 08:02:02 tony2001 Exp $ */
/* {{{ includes
*/
@@ -27,6 +27,7 @@
#include "php.h"
#include <stdio.h>
+#include <fcntl.h>
#ifdef PHP_WIN32
#include "win32/time.h"
#include "win32/signal.h"
@@ -440,7 +441,7 @@
*/
PHPAPI void php_log_err(char *log_message TSRMLS_DC)
{
- FILE *log_file;
+ int fd = -1;
char error_time_str[128];
struct tm tmbuf;
time_t error_time;
@@ -453,14 +454,16 @@
return;
}
#endif
- log_file = VCWD_FOPEN(PG(error_log), "ab");
- if (log_file != NULL) {
+ fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND |
O_WRONLY, 0644);
+ if (fd != -1) {
+ char *tmp;
+ int len;
time(&error_time);
strftime(error_time_str, sizeof(error_time_str),
"%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
- fprintf(log_file, "[%s] ", error_time_str);
- fprintf(log_file, "%s", log_message);
- fprintf(log_file, "%s", PHP_EOL);
- fclose(log_file);
+ len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str,
log_message, PHP_EOL);
+ write(fd, tmp, len);
+ efree(tmp);
+ close(fd);
return;
}
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php