-/* Copyright 2001-2004 Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
/* --------------------------------------------------------------------
*
- * wintty : a Apache/WinNT support utility for monitoring and
+ * wintty : a Apache/WinNT support utility for monitoring and
* reflecting user feedback from the Apache process via
* stdin/stdout, even as running within the service context.
*
*
* Also note the isservice detection semantics, which far exceed any
* mechanism we have discovered thus far.
- *
+ *
* --------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
-const char *options =
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#define _CRT_SECURE_NO_DEPRECATE
+#pragma warning(disable: 4996)
+#endif
+
+const char *options =
"\nwintty: a utility for echoing the stdin stream to a new console window,\n"
"\teven when invoked from within a service (such as the Apache server.)\n"
"\tAlso reflects the console input back to the stdout stream, allowing\n"
BOOL verbose = FALSE;
-void printerr(char *fmt, ...)
+void printerr(char *fmt, ...)
{
char str[1024];
va_list args;
}
else {
timeout = 0;
- }
+ }
break;
case 'v':
verbose = TRUE;
case '?':
printf(options, arg0);
exit(1);
- default:
+ default:
printf("wintty option %s not recognized, use -? for help.\n\n", *argv);
exit(1);
}
hstdin = GetStdHandle(STD_INPUT_HANDLE);
if (!hstdin || hstdin == INVALID_HANDLE_VALUE) {
- printerr("GetStdHandle(STD_INPUT_HANDLE) failed (%d)\n",
+ printerr("GetStdHandle(STD_INPUT_HANDLE) failed (%d)\n",
GetLastError());
}
- else if (DuplicateHandle(hproc, hstdin, hproc, &hdup, 0,
+ else if (DuplicateHandle(hproc, hstdin, hproc, &hdup, 0,
isservice, DUPLICATE_SAME_ACCESS)) {
CloseHandle(hstdin);
hstdin = hdup;
}
else {
- printerr("DupHandle(stdin [%x]) failed (%d)\n",
+ printerr("DupHandle(stdin [%x]) failed (%d)\n",
hstdin, GetLastError());
}
hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (!hstdout || hstdout == INVALID_HANDLE_VALUE) {
- printerr("GetStdHandle(STD_OUTPUT_HANDLE) failed (%d)\n",
+ printerr("GetStdHandle(STD_OUTPUT_HANDLE) failed (%d)\n",
GetLastError());
}
- else if (DuplicateHandle(hproc, hstdout, hproc, &hdup, 0,
+ else if (DuplicateHandle(hproc, hstdout, hproc, &hdup, 0,
isservice, DUPLICATE_SAME_ACCESS)) {
CloseHandle(hstdout);
hstdout = hdup;
}
else {
- printerr("DupHandle(stdout [%x]) failed (%d)\n",
+ printerr("DupHandle(stdout [%x]) failed (%d)\n",
hstdout, GetLastError());
}
hstderr = GetStdHandle(STD_ERROR_HANDLE);
if (!hstderr || hstderr == INVALID_HANDLE_VALUE) {
- printerr("GetStdHandle(STD_ERROR_HANDLE) failed (%d)\n",
+ printerr("GetStdHandle(STD_ERROR_HANDLE) failed (%d)\n",
GetLastError());
}
- else if (DuplicateHandle(hproc, hstderr, hproc, &hdup, 0,
+ else if (DuplicateHandle(hproc, hstderr, hproc, &hdup, 0,
isservice, DUPLICATE_SAME_ACCESS)) {
CloseHandle(hstderr);
hstderr = hdup;
}
else {
- printerr("DupHandle(stderr [%x]) failed (%d)\n",
+ printerr("DupHandle(stderr [%x]) failed (%d)\n",
hstderr, GetLastError());
}
*/
if (!FreeConsole())
printerr("FreeConsole() failed (%d)\n", GetLastError());
-
+
if (isservice) {
#ifdef WE_EVER_FIGURE_OUT_WHY_THIS_DOESNT_WORK
- hsavedesk = GetThreadDesktop(GetCurrentThreadId());
+ hsavedesk = GetThreadDesktop(GetCurrentThreadId());
if (!hsavedesk || hsavedesk == INVALID_HANDLE_VALUE) {
printerr("GetThreadDesktop(GetTID()) failed (%d)\n", GetLastError());
}
hdesk = OpenDesktop("Default", 0, TRUE, MAXIMUM_ALLOWED);
if (!hdesk || hdesk == INVALID_HANDLE_VALUE) {
printerr("OpenDesktop(Default) failed (%d)\n", GetLastError());
- }
+ }
else if (!SetThreadDesktop(hdesk)) {
printerr("SetThreadDesktop(Default) failed (%d)\n", GetLastError());
}
char appbuff[MAX_PATH];
char *appname = NULL;
char *cmdline = GetCommandLine();
-
+
if (!GetModuleFileName(NULL, appbuff, sizeof(appbuff))) {
appname = appbuff;
}
-
+
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW
* receive their EOF notification.
*/
if (CreateProcess(appname, cmdline, NULL, NULL, TRUE,
- CREATE_SUSPENDED | CREATE_NEW_CONSOLE,
+ CREATE_SUSPENDED | CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi)) {
CloseHandle(si.hStdInput);
CloseHandle(si.hStdOutput);
printerr("SetConsoleTitle() failed (%d)\n", GetLastError());
}
- conout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
+ conout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
FALSE, OPEN_EXISTING, 0, NULL);
if (!conout || conout == INVALID_HANDLE_VALUE) {
printerr("CreateFile(CONOUT$) failed (%d)\n", GetLastError());
}
else if (!SetConsoleMode(conout, conmode = ((conmode | newoutmode)
& ~notoutmode))) {
- printerr("SetConsoleMode(CONOUT, 0x%x) failed (%d)\n",
+ printerr("SetConsoleMode(CONOUT, 0x%x) failed (%d)\n",
conmode, GetLastError());
}
- conin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
+ conin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
FALSE, OPEN_EXISTING, 0, NULL);
if (!conin || conin == INVALID_HANDLE_VALUE) {
printerr("CreateFile(CONIN$) failed (%d)\n", GetLastError());
else if (!GetConsoleMode(conin, &conmode)) {
printerr("GetConsoleMode(CONIN) failed (%d)\n", GetLastError());
}
- else if (!SetConsoleMode(conin, conmode = ((conmode | newinmode)
+ else if (!SetConsoleMode(conin, conmode = ((conmode | newinmode)
& ~notinmode))) {
- printerr("SetConsoleMode(CONIN, 0x%x) failed (%d)\n",
+ printerr("SetConsoleMode(CONIN, 0x%x) failed (%d)\n",
conmode, GetLastError());
}