]> granicus.if.org Git - php/commitdiff
Fix bug #8314: sane syslog output to the WinNT event log.
authorWez Furlong <wez@php.net>
Sat, 31 Jul 2004 23:59:46 +0000 (23:59 +0000)
committerWez Furlong <wez@php.net>
Sat, 31 Jul 2004 23:59:46 +0000 (23:59 +0000)
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.

win32/build/Makefile
win32/build/config.w32
win32/build/registersyslog.php [new file with mode: 0755]
win32/build/wsyslog.mc [new file with mode: 0755]
win32/wsyslog.c

index d12d47b4b4f12873c06dd7e3f5aaceb462c64f20..43e5d748581003a908641d70abd8aadf0acb8afa 100644 (file)
@@ -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)
+
+
index 2fc451aa9ed6798ddd2bb7fa3f00a0a05749e911..977bda55be977c5169b133f815ecf340d7382dce 100644 (file)
@@ -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 (executable)
index 0000000..9953b70
--- /dev/null
@@ -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 (executable)
index 0000000..01d4d3a
--- /dev/null
@@ -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
+.
+
index ca1e45b9ca4f029fc8e1f1616b124c0b74a8b944..294b3976c44b5867f46e07f1494d8d4da561c67f 100644 (file)
@@ -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());
 }