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
virtual void queryConnection(network::Socket* sock, | virtual void queryConnection(network::Socket* sock, | ||||
const char* userName) = 0; | 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 | // setScreenLayout() requests to reconfigure the framebuffer and/or | ||||
// the layout of screens. | // the layout of screens. | ||||
virtual unsigned int setScreenLayout(int __unused_attr fb_width, | virtual unsigned int setScreenLayout(int __unused_attr fb_width, |
return true; | return true; | ||||
} else if (t == &idleTimer) { | } else if (t == &idleTimer) { | ||||
slog.info("MaxIdleTime reached, exiting"); | slog.info("MaxIdleTime reached, exiting"); | ||||
exit(0); | |||||
desktop->terminate(); | |||||
} else if (t == &disconnectTimer) { | } else if (t == &disconnectTimer) { | ||||
slog.info("MaxDisconnectionTime reached, exiting"); | slog.info("MaxDisconnectionTime reached, exiting"); | ||||
exit(0); | |||||
desktop->terminate(); | |||||
} else if (t == &connectTimer) { | } else if (t == &connectTimer) { | ||||
slog.info("MaxConnectionTime reached, exiting"); | slog.info("MaxConnectionTime reached, exiting"); | ||||
exit(0); | |||||
desktop->terminate(); | |||||
} | } | ||||
return false; | return false; |
*/ | */ | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <signal.h> | |||||
#include <unistd.h> | |||||
#include <rfb/LogWriter.h> | #include <rfb/LogWriter.h> | ||||
pb = 0; | pb = 0; | ||||
} | } | ||||
void XDesktop::terminate() { | |||||
kill(getpid(), SIGTERM); | |||||
} | |||||
bool XDesktop::isRunning() { | bool XDesktop::isRunning() { | ||||
return running; | return running; | ||||
} | } |
// -=- SDesktop interface | // -=- SDesktop interface | ||||
virtual void start(rfb::VNCServer* vs); | virtual void start(rfb::VNCServer* vs); | ||||
virtual void stop(); | virtual void stop(); | ||||
virtual void terminate(); | |||||
bool isRunning(); | bool isRunning(); | ||||
virtual void queryConnection(network::Socket* sock, | virtual void queryConnection(network::Socket* sock, | ||||
const char* userName); | const char* userName); |
// | // | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <signal.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
// SDesktop callbacks | // SDesktop callbacks | ||||
void XserverDesktop::terminate() | |||||
{ | |||||
kill(getpid(), SIGTERM); | |||||
} | |||||
void XserverDesktop::pointerEvent(const Point& pos, int buttonMask) | void XserverDesktop::pointerEvent(const Point& pos, int buttonMask) | ||||
{ | { | ||||
vncPointerMove(pos.x + vncGetScreenX(screenIndex), | vncPointerMove(pos.x + vncGetScreenX(screenIndex), |
// rfb::SDesktop callbacks | // rfb::SDesktop callbacks | ||||
virtual void start(rfb::VNCServer* vs); | virtual void start(rfb::VNCServer* vs); | ||||
virtual void stop(); | virtual void stop(); | ||||
virtual void terminate(); | |||||
virtual void queryConnection(network::Socket* sock, | virtual void queryConnection(network::Socket* sock, | ||||
const char* userName); | const char* userName); | ||||
virtual void pointerEvent(const rfb::Point& pos, int buttonMask); | virtual void pointerEvent(const rfb::Point& pos, int buttonMask); |
statusLocation(0), queryConnectionHandler(0), ledState(0) | statusLocation(0), queryConnectionHandler(0), ledState(0) | ||||
{ | { | ||||
updateEvent.h = CreateEvent(0, TRUE, FALSE, 0); | updateEvent.h = CreateEvent(0, TRUE, FALSE, 0); | ||||
terminateEvent.h = CreateEvent(0, TRUE, FALSE, 0); | |||||
} | } | ||||
SDisplay::~SDisplay() | SDisplay::~SDisplay() | ||||
if (statusLocation) *statusLocation = false; | if (statusLocation) *statusLocation = false; | ||||
} | } | ||||
void SDisplay::terminate() | |||||
{ | |||||
SetEvent(terminateEvent); | |||||
} | |||||
void SDisplay::queryConnection(network::Socket* sock, | void SDisplay::queryConnection(network::Socket* sock, | ||||
const char* userName) | const char* userName) |
virtual void start(VNCServer* vs); | virtual void start(VNCServer* vs); | ||||
virtual void stop(); | virtual void stop(); | ||||
virtual void terminate(); | |||||
virtual void queryConnection(network::Socket* sock, | virtual void queryConnection(network::Socket* sock, | ||||
const char* userName); | const char* userName); | ||||
virtual void pointerEvent(const Point& pos, int buttonmask); | virtual void pointerEvent(const Point& pos, int buttonmask); | ||||
// -=- EventHandler interface | // -=- EventHandler interface | ||||
HANDLE getUpdateEvent() {return updateEvent;} | HANDLE getUpdateEvent() {return updateEvent;} | ||||
HANDLE getTerminateEvent() {return terminateEvent;} | |||||
virtual void processEvent(HANDLE event); | virtual void processEvent(HANDLE event); | ||||
// -=- Notification of whether or not SDisplay is started | // -=- Notification of whether or not SDisplay is started | ||||
// -=- Event signalled to trigger an update to be flushed | // -=- Event signalled to trigger an update to be flushed | ||||
Handle updateEvent; | Handle updateEvent; | ||||
// -=- Event signalled to terminate the server | |||||
Handle terminateEvent; | |||||
// -=- Where to write the active/inactive indicator to | // -=- Where to write the active/inactive indicator to | ||||
bool* statusLocation; | bool* statusLocation; |
// Register the desktop's event to be handled | // Register the desktop's event to be handled | ||||
sockMgr.addEvent(desktop.getUpdateEvent(), &desktop); | sockMgr.addEvent(desktop.getUpdateEvent(), &desktop); | ||||
sockMgr.addEvent(desktop.getTerminateEvent(), this); | |||||
// Register the queued command event to be handled | // Register the queued command event to be handled | ||||
sockMgr.addEvent(commandEvent, this); | sockMgr.addEvent(commandEvent, this); | ||||
command = NoCommand; | command = NoCommand; | ||||
commandSig->signal(); | commandSig->signal(); | ||||
} | } | ||||
} else if (event_ == sessionEvent.h) { | |||||
} else if ((event_ == sessionEvent.h) || | |||||
(event_ == desktop.getTerminateEvent())) { | |||||
stop(); | stop(); | ||||
} | } | ||||
} | } |