aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--daemon/main.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/daemon/main.c b/daemon/main.c
index f45eac3..007ec54 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -251,8 +251,9 @@ static BOOL start_service()
/******************************************************************************
* shutdown_service
*/
-static void winnt_shutdown_service()
+static BOOL winnt_shutdown_service()
{
+ BOOL ret = FALSE;
SC_HANDLE hscm, hsvc;
int i;
@@ -260,7 +261,7 @@ static void winnt_shutdown_service()
if( !hscm )
{
TRACE( "OpenSCManager error %lu\n", GetLastError() );
- return;
+ return FALSE;
}
hsvc = OpenService( hscm, service_name, SERVICE_ALL_ACCESS );
@@ -268,7 +269,7 @@ static void winnt_shutdown_service()
{
TRACE( "OpenService error %lu\n", GetLastError() );
CloseServiceHandle( hscm );
- return;
+ return FALSE;
}
ControlService( hsvc, SERVICE_CONTROL_STOP, &sstatus );
@@ -281,25 +282,32 @@ static void winnt_shutdown_service()
break;
}
if( SERVICE_STOPPED == sstatus.dwCurrentState )
+ {
+ ret = TRUE;
break;
+ }
}
CloseServiceHandle( hsvc );
+ return ret;
}
static void shutdown_service( gboolean quiet )
{
+ BOOL stopped;
+
/* try to stop windows NT service */
- winnt_shutdown_service();
+ stopped = winnt_shutdown_service();
- /* set stop_event and wait for completion */
+ /* try to shutdown using stop_event because daemon may run not as service;
+ set event and wait for completion */
for(;;)
{
BOOL ret;
HANDLE he = OpenEvent( EVENT_MODIFY_STATE, FALSE, service_stop_event_name );
if( !he )
{
- if( !quiet )
+ if( (!quiet) && (!stopped) )
ERR( "cannot open event; error %lu\n", GetLastError() );
return;
}