aboutsummaryrefslogtreecommitdiffstats
path: root/app/nginx/src/os/win32/ngx_event_log.c
diff options
context:
space:
mode:
authorKonstantin Ananyev <konstantin.ananyev@intel.com>2017-10-31 12:40:17 +0000
committerKonstantin Ananyev <konstantin.ananyev@intel.com>2017-10-31 14:19:39 +0000
commite18a033b921d0d79fa8278f853548e6125b93e0c (patch)
treea6a55edf6ddceef824561818c9836914c326340d /app/nginx/src/os/win32/ngx_event_log.c
parent7e18fa1bf263822c46d7431a911b41d6377d5f69 (diff)
Integrate TLDK with NGINX
Created a clone of nginx (from https://github.com/nginx/nginx) to demonstrate and benchmark TLDK library integrated with real world application. A new nginx module is created and and BSD socket-like API is implemented on top of native TLDK API. Note, that right now only minimalistic subset of socket-like API is provided: - accept - close - readv - recv - writev so only limited nginx functionality is available for a moment. Change-Id: Ie1efe9349a0538da4348a48fb8306cbf636b5a92 Signed-off-by: Mohammad Abdul Awal <mohammad.abdul.awal@intel.com> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com> Signed-off-by: Remy Horton <remy.horton@intel.com> Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Diffstat (limited to 'app/nginx/src/os/win32/ngx_event_log.c')
-rw-r--r--app/nginx/src/os/win32/ngx_event_log.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/app/nginx/src/os/win32/ngx_event_log.c b/app/nginx/src/os/win32/ngx_event_log.c
new file mode 100644
index 0000000..e11ed1e
--- /dev/null
+++ b/app/nginx/src/os/win32/ngx_event_log.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#define NGX_MAX_ERROR_STR 2048
+
+
+void ngx_cdecl
+ngx_event_log(ngx_err_t err, const char *fmt, ...)
+{
+ u_char *p, *last;
+ long types;
+ HKEY key;
+ HANDLE ev;
+ va_list args;
+ u_char text[NGX_MAX_ERROR_STR];
+ const char *msgarg[9];
+ static u_char netmsg[] = "%SystemRoot%\\System32\\netmsg.dll";
+
+ last = text + NGX_MAX_ERROR_STR;
+ p = text + GetModuleFileName(NULL, (char *) text, NGX_MAX_ERROR_STR - 50);
+
+ *p++ = ':';
+ ngx_linefeed(p);
+
+ va_start(args, fmt);
+ p = ngx_vslprintf(p, last, fmt, args);
+ va_end(args);
+
+ if (err) {
+ p = ngx_log_errno(p, last, err);
+ }
+
+ if (p > last - NGX_LINEFEED_SIZE - 1) {
+ p = last - NGX_LINEFEED_SIZE - 1;
+ }
+
+ ngx_linefeed(p);
+
+ *p = '\0';
+
+ /*
+ * we do not log errors here since we use
+ * Event Log only to log our own logs open errors
+ */
+
+ if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\nginx",
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &key, NULL)
+ != 0)
+ {
+ return;
+ }
+
+ if (RegSetValueEx(key, "EventMessageFile", 0, REG_EXPAND_SZ,
+ netmsg, sizeof(netmsg) - 1)
+ != 0)
+ {
+ return;
+ }
+
+ types = EVENTLOG_ERROR_TYPE;
+
+ if (RegSetValueEx(key, "TypesSupported", 0, REG_DWORD,
+ (u_char *) &types, sizeof(long))
+ != 0)
+ {
+ return;
+ }
+
+ RegCloseKey(key);
+
+ ev = RegisterEventSource(NULL, "nginx");
+
+ msgarg[0] = (char *) text;
+ msgarg[1] = NULL;
+ msgarg[2] = NULL;
+ msgarg[3] = NULL;
+ msgarg[4] = NULL;
+ msgarg[5] = NULL;
+ msgarg[6] = NULL;
+ msgarg[7] = NULL;
+ msgarg[8] = NULL;
+
+ /*
+ * the 3299 event id in netmsg.dll has the generic message format:
+ * "%1 %2 %3 %4 %5 %6 %7 %8 %9"
+ */
+
+ ReportEvent(ev, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, 9, 0, msgarg, NULL);
+
+ DeregisterEventSource(ev);
+}