aboutsummaryrefslogtreecommitdiff
path: root/libwinmain
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-03-04 11:11:07 +0000
committermarha <marha@users.sourceforge.net>2010-03-04 11:11:07 +0000
commit989660b7f370532c7d4ffe9eeacc6957a31ab98f (patch)
tree72fa3c8226cd2c8b0b1eb21c51ef8264b96a77fa /libwinmain
parent9b93717560ee4a08c6f875b8985e984da20f25a4 (diff)
downloadvcxsrv-989660b7f370532c7d4ffe9eeacc6957a31ab98f.tar.gz
vcxsrv-989660b7f370532c7d4ffe9eeacc6957a31ab98f.tar.bz2
vcxsrv-989660b7f370532c7d4ffe9eeacc6957a31ab98f.zip
Make sure that control C only kills the process when a new console is created.
Do not do it without console or attached do an existing console.
Diffstat (limited to 'libwinmain')
-rw-r--r--libwinmain/winmain.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/libwinmain/winmain.c b/libwinmain/winmain.c
index 7a69dac4a..6df140b10 100644
--- a/libwinmain/winmain.c
+++ b/libwinmain/winmain.c
@@ -4,10 +4,21 @@
#include <fcntl.h>
#include <io.h>
-static void CreateConsole()
+#define MAX_CONSOLE_LINES 500
+
+int main(int argc, char *argv[]);
+
+/* Ignore control c and control break signals */
+static BOOL WINAPI IgnoreControlC(DWORD dwCtrlType)
+{
+ if (dwCtrlType==CTRL_C_EVENT || dwCtrlType==CTRL_BREAK_EVENT)
+ return TRUE;
+ return FALSE;
+}
+
+static void CreateConsole(void)
{
static int ConsoleCreated=0;
- va_list arglist;
if (!ConsoleCreated)
{
int hConHandle;
@@ -15,15 +26,20 @@ static void CreateConsole()
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
- const unsigned int MAX_CONSOLE_LINES = 500;
ConsoleCreated=1;
if (!AttachConsole(ATTACH_PARENT_PROCESS))
AllocConsole();
+ else
+ SetConsoleCtrlHandler(IgnoreControlC,TRUE); // Only allow control C interrupt the program when a console was created
+
// set the screen buffer to be big enough to let us scroll text
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
- coninfo.dwSize.Y = MAX_CONSOLE_LINES;
- SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
+ GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
+ if (coninfo.dwSize.Y < MAX_CONSOLE_LINES)
+ {
+ coninfo.dwSize.Y = MAX_CONSOLE_LINES;
+ SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
+ }
// redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
@@ -45,7 +61,6 @@ static void CreateConsole()
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
-
}
}
@@ -58,12 +73,20 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
char *pTmp;
char *pProgramName;
+ hInstance=hInstance;
+ nCmdShow=nCmdShow;
+ hPrevInstance=hPrevInstance;
+
if (!strncmp(lpCmdLine,"-console",8))
{
CreateConsole();
lpCmdLine+=9;
}
-
+ else
+ {
+ SetConsoleCtrlHandler(IgnoreControlC,TRUE);
+ }
+
GetModuleFileName(NULL,ProgramName,255);
pTmp=strrchr(ProgramName,'\\');
if (pTmp)
@@ -105,6 +128,6 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
break;
}
}
-
+
return main(argc,argv);
-} \ No newline at end of file
+}