diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /devtools/dbmon/dbmon.c | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'devtools/dbmon/dbmon.c')
| -rw-r--r-- | devtools/dbmon/dbmon.c | 163 |
1 files changed, 163 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); + + } + + } +} |