Browse Source

Properly terminate server on timeouts

Do a proper cleanup when one of the termination timeouts trigger
rather than just exiting on the spot. This makes sure we don't leave
stray stuff around, e.g. unix socket files.
tags/v1.9.90
Pierre Ossman 5 years ago
parent
commit
10688efcf7

+ 6
- 0
common/rfb/SDesktop.h View File

@@ -75,6 +75,12 @@ namespace rfb {
virtual void queryConnection(network::Socket* sock,
const char* userName) = 0;

// terminate() is called by the server when it wishes to terminate
// itself, e.g. because it was configured to terminate when no one is
// using it.

virtual void terminate() = 0;

// setScreenLayout() requests to reconfigure the framebuffer and/or
// the layout of screens.
virtual unsigned int setScreenLayout(int __unused_attr fb_width,

+ 3
- 3
common/rfb/VNCServerST.cxx View File

@@ -574,13 +574,13 @@ bool VNCServerST::handleTimeout(Timer* t)
return true;
} else if (t == &idleTimer) {
slog.info("MaxIdleTime reached, exiting");
exit(0);
desktop->terminate();
} else if (t == &disconnectTimer) {
slog.info("MaxDisconnectionTime reached, exiting");
exit(0);
desktop->terminate();
} else if (t == &connectTimer) {
slog.info("MaxConnectionTime reached, exiting");
exit(0);
desktop->terminate();
}

return false;

+ 6
- 0
unix/x0vncserver/XDesktop.cxx View File

@@ -19,6 +19,8 @@
*/

#include <assert.h>
#include <signal.h>
#include <unistd.h>

#include <rfb/LogWriter.h>

@@ -273,6 +275,10 @@ void XDesktop::stop() {
pb = 0;
}

void XDesktop::terminate() {
kill(getpid(), SIGTERM);
}

bool XDesktop::isRunning() {
return running;
}

+ 1
- 0
unix/x0vncserver/XDesktop.h View File

@@ -49,6 +49,7 @@ public:
// -=- SDesktop interface
virtual void start(rfb::VNCServer* vs);
virtual void stop();
virtual void terminate();
bool isRunning();
virtual void queryConnection(network::Socket* sock,
const char* userName);

+ 6
- 0
unix/xserver/hw/vnc/XserverDesktop.cc View File

@@ -22,6 +22,7 @@
//

#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
@@ -423,6 +424,11 @@ void XserverDesktop::approveConnection(uint32_t opaqueId, bool accept,
// SDesktop callbacks


void XserverDesktop::terminate()
{
kill(getpid(), SIGTERM);
}

void XserverDesktop::pointerEvent(const Point& pos, int buttonMask)
{
vncPointerMove(pos.x + vncGetScreenX(screenIndex),

+ 1
- 0
unix/xserver/hw/vnc/XserverDesktop.h View File

@@ -87,6 +87,7 @@ public:
// rfb::SDesktop callbacks
virtual void start(rfb::VNCServer* vs);
virtual void stop();
virtual void terminate();
virtual void queryConnection(network::Socket* sock,
const char* userName);
virtual void pointerEvent(const rfb::Point& pos, int buttonMask);

+ 6
- 0
win/rfb_win32/SDisplay.cxx View File

@@ -71,6 +71,7 @@ SDisplay::SDisplay()
statusLocation(0), queryConnectionHandler(0), ledState(0)
{
updateEvent.h = CreateEvent(0, TRUE, FALSE, 0);
terminateEvent.h = CreateEvent(0, TRUE, FALSE, 0);
}

SDisplay::~SDisplay()
@@ -140,6 +141,11 @@ void SDisplay::stop()
if (statusLocation) *statusLocation = false;
}

void SDisplay::terminate()
{
SetEvent(terminateEvent);
}


void SDisplay::queryConnection(network::Socket* sock,
const char* userName)

+ 4
- 0
win/rfb_win32/SDisplay.h View File

@@ -72,6 +72,7 @@ namespace rfb {

virtual void start(VNCServer* vs);
virtual void stop();
virtual void terminate();
virtual void queryConnection(network::Socket* sock,
const char* userName);
virtual void pointerEvent(const Point& pos, int buttonmask);
@@ -89,6 +90,7 @@ namespace rfb {
// -=- EventHandler interface

HANDLE getUpdateEvent() {return updateEvent;}
HANDLE getTerminateEvent() {return terminateEvent;}
virtual void processEvent(HANDLE event);

// -=- Notification of whether or not SDisplay is started
@@ -161,6 +163,8 @@ namespace rfb {

// -=- Event signalled to trigger an update to be flushed
Handle updateEvent;
// -=- Event signalled to terminate the server
Handle terminateEvent;

// -=- Where to write the active/inactive indicator to
bool* statusLocation;

+ 3
- 1
win/winvnc/VNCServerWin32.cxx View File

@@ -76,6 +76,7 @@ VNCServerWin32::VNCServerWin32()

// Register the desktop's event to be handled
sockMgr.addEvent(desktop.getUpdateEvent(), &desktop);
sockMgr.addEvent(desktop.getTerminateEvent(), this);

// Register the queued command event to be handled
sockMgr.addEvent(commandEvent, this);
@@ -335,7 +336,8 @@ void VNCServerWin32::processEvent(HANDLE event_) {
command = NoCommand;
commandSig->signal();
}
} else if (event_ == sessionEvent.h) {
} else if ((event_ == sessionEvent.h) ||
(event_ == desktop.getTerminateEvent())) {
stop();
}
}

Loading…
Cancel
Save