summaryrefslogtreecommitdiff
path: root/devtools/dbmon
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/dbmon')
-rw-r--r--devtools/dbmon/dbmon.c163
-rw-r--r--devtools/dbmon/dbmon.vpc35
2 files changed, 198 insertions, 0 deletions
diff --git a/devtools/dbmon/dbmon.c b/devtools/dbmon/dbmon.c
new file mode 100644
index 0000000..d10a199
--- /dev/null
+++ b/devtools/dbmon/dbmon.c
@@ -0,0 +1,163 @@
+/*++
+
+Copyright (c) 1990 Microsoft Corporation
+
+Module Name:
+
+ dbmon.c
+
+Abstract:
+
+ A simple program to print strings passed to OutputDebugString when
+ the app printing the strings is not being debugged.
+
+Author:
+
+ Kent Forschmiedt (kentf) 30-Sep-1994
+
+Revision History:
+
+--*/
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int _cdecl
+main(
+ int,
+ char **
+ )
+/*++
+
+Routine Description:
+
+
+Arguments:
+
+
+Return Value:
+
+
+--*/
+{
+ HANDLE AckEvent;
+ HANDLE ReadyEvent;
+ HANDLE SharedFile;
+ LPVOID SharedMem;
+ LPSTR String;
+ DWORD ret;
+ DWORD LastPid;
+ LPDWORD pThisPid;
+ BOOL DidCR;
+
+ SECURITY_ATTRIBUTES sa;
+ SECURITY_DESCRIPTOR sd;
+
+ sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+ sa.bInheritHandle = TRUE;
+ sa.lpSecurityDescriptor = &sd;
+
+ if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
+ fprintf(stderr,"unable to InitializeSecurityDescriptor, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ if(!SetSecurityDescriptorDacl(&sd, TRUE, (PACL)NULL, FALSE)) {
+ fprintf(stderr,"unable to SetSecurityDescriptorDacl, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ AckEvent = CreateEvent(&sa, FALSE, FALSE, "DBWIN_BUFFER_READY");
+
+ if (!AckEvent) {
+ fprintf(stderr,
+ "dbmon: Unable to create synchronization object, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ if (GetLastError() == ERROR_ALREADY_EXISTS) {
+ fprintf(stderr, "dbmon: already running\n");
+ exit(1);
+ }
+
+ ReadyEvent = CreateEvent(&sa, FALSE, FALSE, "DBWIN_DATA_READY");
+
+ if (!ReadyEvent) {
+ fprintf(stderr,
+ "dbmon: Unable to create synchronization object, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ SharedFile = CreateFileMapping(
+ (HANDLE)-1,
+ &sa,
+ PAGE_READWRITE,
+ 0,
+ 4096,
+ "DBWIN_BUFFER");
+
+ if (!SharedFile) {
+ fprintf(stderr,
+ "dbmon: Unable to create file mapping object, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ SharedMem = MapViewOfFile(
+ SharedFile,
+ FILE_MAP_READ,
+ 0,
+ 0,
+ 512);
+
+ if (!SharedMem) {
+ fprintf(stderr,
+ "dbmon: Unable to map shared memory, err == %d\n",
+ GetLastError());
+ exit(1);
+ }
+
+ String = (LPSTR)SharedMem + sizeof(DWORD);
+ pThisPid = (LPDWORD)SharedMem;
+
+ LastPid = 0xffffffff;
+ DidCR = TRUE;
+
+ SetEvent(AckEvent);
+
+ for (;;) {
+
+ ret = WaitForSingleObject(ReadyEvent, INFINITE);
+
+ if (ret != WAIT_OBJECT_0) {
+
+ fprintf(stderr, "dbmon: wait failed; err == %d\n", GetLastError());
+ exit(1);
+
+ } else {
+
+ if (LastPid != *pThisPid) {
+ LastPid = *pThisPid;
+ if (!DidCR) {
+ putchar('\n');
+ DidCR = TRUE;
+ }
+ }
+
+ if (DidCR) {
+ printf("%3u: ", LastPid);
+ }
+
+ printf("%s", String);
+ DidCR = (*String && (String[strlen(String) - 1] == '\n'));
+ SetEvent(AckEvent);
+
+ }
+
+ }
+}
diff --git a/devtools/dbmon/dbmon.vpc b/devtools/dbmon/dbmon.vpc
new file mode 100644
index 0000000..1ec8354
--- /dev/null
+++ b/devtools/dbmon/dbmon.vpc
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------------
+// DBMON.VPC
+//
+// Project Script
+//-----------------------------------------------------------------------------
+
+$Macro SRCDIR "..\.."
+$Macro OUTBINDIR "..\bin"
+
+$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc"
+
+$Configuration
+{
+ $Compiler
+ {
+ $PreprocessorDefinitions "$BASE;MACRO_MATHLIB;PROTECTED_THINGS_DISABLE"
+ }
+
+ $Linker
+ {
+ $AdditionalDependencies "$BASE ws2_32.lib odbc32.lib odbccp32.lib winmm.lib"
+ }
+}
+
+$Project "dbmon"
+{
+ $Folder "Source Files"
+ {
+ $File "dbmon.c"
+ }
+
+ $Folder "Header Files"
+ {
+ }
+}