shutdown gotcha with Win32 host

Andrew van der Stock ajv "at"
Wed, 06 Mar 2002 13:27:40 +0000

It's not the way VNC hooks itself to the video driver, it's the way VNC
responds to the Service Control Manager's SERVICE_CONTROL_SHUTDOWN
message - in that we don't. VNC (correctly) dies as soon as the service
shutdown message is given. But there's a difference between stopping and
shutting down, and we can leverage that to try and remedy this issue. 

Here's the relevant bits from the VNCService.cpp file:

1020		// STOP : The service must stop
1021		g_srvstatus.dwCurrentState = SERVICE_STOP_PENDING;
1022		ServiceStop();
1023	break;

And we do not assert that we are interested in SERVICE_ACCEPT_SHUTDOWN
in the next function:

1052	g_srvstatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;


VNC must tell the SCM that it is interested in SERVICE_ACCEPT_SHUTDOWN.
This will postpone VNC's exit until after the services that do not
assert this flag, but since VNC has no other service dependencies, it
will be asked to go down as soon as the other services handlers have
been called. 

We simply ignore the message and set a dwWaitHint of five seconds and
keep the dwCheckpoint flag incrementing to ensure that we are not
killed. To ensure that the box goes down fairly promptly, VNC must watch
if another process (best bet: csrss.exe) from the current desktop dies,
or hook into the desktop logoff sequence. Once the trigger has been
given, it's time to go down. 

And we need a watchdog - if the shutdown hasn't occurred in say 20
seconds (roughly the time the NT lets services live for without killing
them), VNC re-enters the land of the living by completely ignoring the
SERVICE_CONTROL_SHUTDOWN message. This makes the VNC process unkillable
if it survives the SCM trying to kill it, and it's the bane of all
system administrators everywhere.

A potential problem is if the solution gets too complex. The more
complex it is to cover off all the corner situations, the harder it'll
be to make it reliable and robust. 


-----Original Message-----
From: owner-vnc-list "at"
[mailto:owner-vnc-list "at"] On Behalf Of Keith Hall
Sent: Wednesday, 6 March 2002 8:14 PM
To: 'vnc-list "at"'
Subject: RE: shutdown gotcha with Win32 host


Naturally it would be nice for someone to have a real good think about
way VNC hooks into the display driver (reason I've been told that it
be done easily) and ensure that it cannot be shut down until almost the
thing before reboot.
To unsubscribe, mail majordomo "at" with the line:
'unsubscribe vnc-list' in the message BODY
See also: