diff options
author | Michi Henning <michi@zeroc.com> | 2002-10-10 03:00:17 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2002-10-10 03:00:17 +0000 |
commit | 4d46221fb476cbc58c7d05e5df320f746580f7f9 (patch) | |
tree | e2c4e349dc65ed4181edffd7c9c986bd1a5a0ff7 /cpp/src/Ice/Application.cpp | |
parent | flattening output (diff) | |
download | ice-4d46221fb476cbc58c7d05e5df320f746580f7f9.tar.bz2 ice-4d46221fb476cbc58c7d05e5df320f746580f7f9.tar.xz ice-4d46221fb476cbc58c7d05e5df320f746580f7f9.zip |
Added holdInterrupt() and releaseInterrupt() members.
Diffstat (limited to 'cpp/src/Ice/Application.cpp')
-rw-r--r-- | cpp/src/Ice/Application.cpp | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/cpp/src/Ice/Application.cpp b/cpp/src/Ice/Application.cpp index aacfce755eb..d34addd9362 100644 --- a/cpp/src/Ice/Application.cpp +++ b/cpp/src/Ice/Application.cpp @@ -122,11 +122,15 @@ Ice::interruptHandler(DWORD) return TRUE; } +enum InterruptDisposition { Shutdown, Ignore, Default }; +static InterruptDisposition currentDisposition = Default; + void Ice::Application::shutdownOnInterrupt() { SetConsoleCtrlHandler(NULL, FALSE); SetConsoleCtrlHandler(interruptHandler, TRUE); + currentDisposition = Shutdown; } void @@ -134,6 +138,7 @@ Ice::Application::ignoreInterrupt() { SetConsoleCtrlHandler(interruptHandler, FALSE); SetConsoleCtrlHandler(NULL, TRUE); + currentDisposition = Ignore; } void @@ -141,6 +146,51 @@ Ice::Application::defaultInterrupt() { SetConsoleCtrlHandler(interruptHandler, FALSE); SetConsoleCtrlHandler(NULL, FALSE); + currentDisposition = Default; +} + +void +Ice::Application::holdInterrupt() +{ + // + // With Windows, we can't block signals and + // remember them the way we can with UNIX, + // so "holding" an interrupt is the same as + // ignoring it. + // + SetConsoleCtrlHandler(interruptHandler, FALSE); + SetConsoleCtrlHandler(NULL, TRUE); +} + +void +Ice::Application::releaseInterrupt() +{ + // + // Restore current signal disposition. + // + switch(currentDisposition) + { + case Shutdown: + { + shutdownOnInterrupt(); + break; + } + case Ignore: + { + ignoreInterrupt(); + break; + } + case Default: + { + defaultInterrupt(); + break; + } + default: + { + assert(false); + break; + } + } } #else @@ -159,12 +209,13 @@ void Ice::Application::shutdownOnInterrupt() { struct sigaction action; + memset(&action, 0, sizeof(action)); action.sa_handler = interruptHandler; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGHUP); sigaddset(&action.sa_mask, SIGINT); sigaddset(&action.sa_mask, SIGTERM); - action.sa_flags = 0; + action.sa_flags = SA_RESTART; sigaction(SIGHUP, &action, 0); sigaction(SIGINT, &action, 0); sigaction(SIGTERM, &action, 0); @@ -174,9 +225,10 @@ void Ice::Application::ignoreInterrupt() { struct sigaction action; + memset(&action, 0, sizeof(action)); action.sa_handler = SIG_IGN; sigemptyset(&action.sa_mask); - action.sa_flags = 0; + action.sa_flags = SA_RESTART; sigaction(SIGHUP, &action, 0); sigaction(SIGINT, &action, 0); sigaction(SIGTERM, &action, 0); @@ -186,12 +238,35 @@ void Ice::Application::defaultInterrupt() { struct sigaction action; + memset(&action, 0, sizeof(action)); action.sa_handler = SIG_DFL; sigemptyset(&action.sa_mask); - action.sa_flags = 0; + action.sa_flags = SA_RESTART; sigaction(SIGHUP, &action, 0); sigaction(SIGINT, &action, 0); sigaction(SIGTERM, &action, 0); } +void +Ice::Application::holdInterrupt() +{ + sigset_t sigset; + sigprocmask(0, 0, &sigset); + sigaddset(&sigset, SIGHUP); + sigaddset(&sigset, SIGINT); + sigaddset(&sigset, SIGTERM); + sigprocmask(SIG_BLOCK, &sigset, 0); +} + +void +Ice::Application::releaseInterrupt() +{ + sigset_t sigset; + sigprocmask(0, 0, &sigset); + sigdelset(&sigset, SIGHUP); + sigdelset(&sigset, SIGINT); + sigdelset(&sigset, SIGTERM); + sigprocmask(SIG_BLOCK, &sigset, 0); +} + #endif |