summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2004-07-31 23:59:46 +0000
committerWez Furlong <wez@php.net>2004-07-31 23:59:46 +0000
commit2c9d87c2f684b9b574b478d1f921fc056853a488 (patch)
treedb95ad8a5dfa10747b06c277ea74d477b3dfee22
parentd45d690164d6c03c858bb375ea74a85694812fa9 (diff)
downloadphp-git-2c9d87c2f684b9b574b478d1f921fc056853a488.tar.gz
Fix bug #8314: sane syslog output to the WinNT event log.
Big fat note: if you're building from a .dsp, you need to replicate the custom build step that uses MC to generate the message catalog To make use of this fix, you need to register the event source; running "nmake install" will handle this for you (if you also build the win32std extension from pecl). I'll arrange with Phil to have the installer handle this registration too.
-rw-r--r--win32/build/Makefile22
-rw-r--r--win32/build/config.w321
-rwxr-xr-xwin32/build/registersyslog.php26
-rwxr-xr-xwin32/build/wsyslog.mc28
-rw-r--r--win32/wsyslog.c9
5 files changed, 79 insertions, 7 deletions
diff --git a/win32/build/Makefile b/win32/build/Makefile
index d12d47b4b4..43e5d74858 100644
--- a/win32/build/Makefile
+++ b/win32/build/Makefile
@@ -19,6 +19,7 @@
CC="$(CL)"
LD="$(LINK)"
+MC="$(MC)"
all: $(BUILD_DIR) $(BUILD_DIRS_SUB) generated_files $(EXT_TARGETS) $(PECL_TARGETS) $(SAPI_TARGETS)
@@ -48,13 +49,19 @@ ext\standard\parsedate.c ext\standard\parsedate.h: ext\standard\parsedate.y
PHPDLL_RES=$(BUILD_DIR)\$(PHPDLL).res
+MCFILE=$(BUILD_DIR)\wsyslog.res
+
+$(MCFILE): win32\build\wsyslog.mc
+ $(MC) -h win32\ -r $(BUILD_DIR)\ -x $(BUILD_DIR)\ win32\build\wsyslog.mc
+ $(RC) /fo $(MCFILE) $(BUILD_DIR)\wsyslog.rc
+
$(PHPDLL_RES): win32\build\template.rc
$(RC) /fo $(PHPDLL_RES) /d FILE_DESCRIPTION="\"PHP Script Interpreter\"" \
/d FILE_NAME="\"$(PHPDLL)\"" /d PRODUCT_NAME="\"PHP Script Interpreter\"" \
- win32\build\template.rc
+ win32\build\template.rc
-$(BUILD_DIR)\$(PHPDLL): $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES)
- $(LD) /out:$(BUILD_DIR)\$(PHPDLL) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES)
+$(BUILD_DIR)\$(PHPDLL): $(PHPDEF) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(PHPDLL_RES) $(MCFILE)
+ $(LD) /out:$(BUILD_DIR)\$(PHPDLL) $(PHP_LDFLAGS) $(LDFLAGS) $(STATIC_EXT_LDFLAGS) $(PHP_GLOBAL_OBJS) $(STATIC_EXT_OBJS) $(STATIC_EXT_LIBS) $(LIBS) $(PHPDLL_RES) $(MCFILE)
$(BUILD_DIR)\$(PHPLIB): $(BUILD_DIR)\$(PHPDLL)
@@ -113,8 +120,13 @@ $(BUILD_DIR)\deplister.exe: win32\build\deplister.c
msi-installer: dist
$(BUILD_DIR)\php.exe ..\php-installer\build-installer.php "$(BUILD_DIR)" "$(PHPDLL)" "$(SAPI_TARGETS)" "$(EXT_TARGETS)" "$(PECL_TARGETS)"
-install: all
+# need to redirect, since INSTALL is a file in the root...
+install: really-install
+
+really-install:
@if not exist $(PHP_PREFIX) mkdir $(PHP_PREFIX)
@copy $(BUILD_DIR)\*.exe $(PHP_PREFIX) /y >nul
@copy $(BUILD_DIR)\*.dll $(PHP_PREFIX) /y >nul
-
+ $(PHP_PREFIX)\php.exe -n -dextension_dir=$(PHP_PREFIX) win32/build/registersyslog.php $(PHP_PREFIX)\$(PHPDLL)
+
+
diff --git a/win32/build/config.w32 b/win32/build/config.w32
index 2fc451aa9e..977bda55be 100644
--- a/win32/build/config.w32
+++ b/win32/build/config.w32
@@ -16,6 +16,7 @@ PATH_PROG('flex');
PATH_PROG('re2c');
PATH_PROG('zip');
PATH_PROG('lemon');
+PATH_PROG('mc');
ARG_ENABLE('debug', 'Compile with debugging symbols', "no");
ARG_ENABLE('zts', 'Thread safety', 'yes');
diff --git a/win32/build/registersyslog.php b/win32/build/registersyslog.php
new file mode 100755
index 0000000000..9953b703e8
--- /dev/null
+++ b/win32/build/registersyslog.php
@@ -0,0 +1,26 @@
+<?php
+
+/* This script sets up an event source for use by the php syslog() function. */
+
+if (!extension_loaded("win32std")) {
+ dl("php_win32std.dll") or die("b0rk");
+}
+
+$PATH = "SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\PHP-" . phpversion();
+
+$key = @reg_create_key(HKEY_LOCAL_MACHINE, $PATH, KEY_ALL_ACCESS);
+
+if (!$key)
+ $key = reg_open_key(HKEY_LOCAL_MACHINE, $PATH, KEY_ALL_ACCESS);
+
+if ($key) {
+ reg_set_value($key, "TypesSupported", REG_DWORD, 7) or die("Types");
+ reg_set_value($key, "EventMessageFile", REG_SZ, $argv[1]) or die("EventMessageFile");
+
+ define_syslog_variables();
+ syslog(LOG_NOTICE, "Registered PHP Event source");
+} else {
+ echo "Could not register event source\n";
+}
+
+?>
diff --git a/win32/build/wsyslog.mc b/win32/build/wsyslog.mc
new file mode 100755
index 0000000000..01d4d3a86b
--- /dev/null
+++ b/win32/build/wsyslog.mc
@@ -0,0 +1,28 @@
+MessageId=1
+Severity=Success
+SymbolicName=PHP_SYSLOG_SUCCESS_TYPE
+Language=English
+%1 %2
+.
+
+MessageId=2
+Severity=Informational
+SymbolicName=PHP_SYSLOG_INFO_TYPE
+Language=English
+%1 %2
+.
+
+MessageId=3
+Severity=Warning
+SymbolicName=PHP_SYSLOG_WARNING_TYPE
+Language=English
+%1 %2
+.
+
+MessageId=4
+Severity=Error
+SymbolicName=PHP_SYSLOG_ERROR_TYPE
+Language=English
+%1 %2
+.
+
diff --git a/win32/wsyslog.c b/win32/wsyslog.c
index ca1e45b9ca..294b3976c4 100644
--- a/win32/wsyslog.c
+++ b/win32/wsyslog.c
@@ -57,6 +57,7 @@
#include <process.h>
#include "php_win32_globals.h"
+#include "wsyslog.h"
void closelog(void)
{
@@ -78,6 +79,7 @@ void syslog(int priority, const char *message, ...)
LPTSTR strs[2];
unsigned short etype;
char *tmp = NULL;
+ DWORD evid;
TSRMLS_FETCH();
/* default event source */
@@ -87,19 +89,22 @@ void syslog(int priority, const char *message, ...)
switch (priority) { /* translate UNIX type into NT type */
case LOG_ALERT:
etype = EVENTLOG_ERROR_TYPE;
+ evid = PHP_SYSLOG_ERROR_TYPE;
break;
case LOG_INFO:
etype = EVENTLOG_INFORMATION_TYPE;
+ evid = PHP_SYSLOG_INFO_TYPE;
break;
default:
etype = EVENTLOG_WARNING_TYPE;
+ evid = PHP_SYSLOG_WARNING_TYPE;
}
va_start(args, message); /* initialize vararg mechanism */
vspprintf(&tmp, 0, message, args); /* build message */
strs[0] = PW32G(log_header); /* write header */
strs[1] = tmp; /* then the message */
/* report the event */
- ReportEvent(PW32G(log_source), etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL);
+ ReportEvent(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strs, NULL);
va_end(args);
efree(tmp);
}
@@ -121,6 +126,6 @@ void openlog(const char *ident, int logopt, int facility)
STR_FREE(PW32G(log_header));
- PW32G(log_source) = RegisterEventSource(NULL, ident);
+ PW32G(log_source) = RegisterEventSource(NULL, "PHP-" PHP_VERSION);
spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
}