Permalink
Browse files

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.
  • Loading branch information...
1 parent d45d690 commit 2c9d87c2f684b9b574b478d1f921fc056853a488 @wez wez committed Jul 31, 2004
Showing with 79 additions and 7 deletions.
  1. +17 −5 win32/build/Makefile
  2. +1 −0 win32/build/config.w32
  3. +26 −0 win32/build/registersyslog.php
  4. +28 −0 win32/build/wsyslog.mc
  5. +7 −2 win32/wsyslog.c
View
@@ -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)
+
+
View
@@ -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');
@@ -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";
+}
+
+?>
View
@@ -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
+.
+
View
@@ -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());
}

0 comments on commit 2c9d87c

Please sign in to comment.