handle Ctrl-C from win32 console
This commit is contained in:
parent
7e9dfbdead
commit
79fd6782fb
3 changed files with 18 additions and 9 deletions
|
@ -47,12 +47,6 @@ Component *component_ = NULL;
|
|||
UserManager *userManager_ = NULL;
|
||||
Config *config_ = NULL;
|
||||
|
||||
void stop() {
|
||||
userManager_->removeAllUsers(false);
|
||||
component_->stop();
|
||||
eventLoop_->stop();
|
||||
}
|
||||
|
||||
static void stop_spectrum() {
|
||||
userManager_->removeAllUsers(false);
|
||||
component_->stop();
|
||||
|
@ -67,6 +61,16 @@ static void spectrum_sigterm_handler(int sig) {
|
|||
eventLoop_->postEvent(&stop_spectrum);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
BOOL spectrum_control_handler( DWORD fdwCtrlType ) {
|
||||
if (fdwCtrlType == CTRL_C_EVENT || fdwCtrlType == CTRL_CLOSE_EVENT) {
|
||||
eventLoop_->postEvent(&stop_spectrum);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void removeOldIcons(std::string iconDir) {
|
||||
std::vector<std::string> dirs;
|
||||
dirs.push_back(iconDir);
|
||||
|
@ -126,7 +130,6 @@ static void daemonize(const char *cwd, const char *lock_file) {
|
|||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int mainloop() {
|
||||
|
@ -291,6 +294,12 @@ int main(int argc, char **argv)
|
|||
std::cout << "SIGTERM handler can't be set\n";
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if( !SetConsoleCtrlHandler( (PHANDLER_ROUTINE) spectrum_control_handler, TRUE ) )
|
||||
{
|
||||
std::cout << "control handler can't be set\n";
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
boost::program_options::options_description desc(std::string("Spectrum version: ") + SPECTRUM_VERSION + "\nUsage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
|
||||
desc.add_options()
|
||||
|
|
|
@ -87,7 +87,7 @@ void WINAPI ServiceControlHandler(DWORD controlCode) {
|
|||
break;
|
||||
}
|
||||
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
||||
stop();
|
||||
spectrum_control_handler(CTRL_CLOSE_EVENT);
|
||||
}
|
||||
|
||||
void WINAPI ServiceMain(DWORD argc, LPSTR *argv) {
|
||||
|
|
|
@ -15,5 +15,5 @@ public:
|
|||
};
|
||||
|
||||
int mainloop();
|
||||
void stop();
|
||||
BOOL spectrum_control_handler( DWORD fdwCtrlType );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue