Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize disconnect-timer to one-shot #144

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 46 additions & 54 deletions module/rdpClientCon.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ rdpClientConGotConnection(ScreenPtr pScreen, rdpPtr dev)
}
#endif

/* reset disconnectTimer if reconnection */
if(dev->disconnect_scheduled)
{
if (dev->disconnectTimer != NULL)
{
LLOGLN(0, ("rdpDeferredDisconnectCallback: disengaging disconnect timer"));
TimerCancel(dev->disconnectTimer);
TimerFree(dev->disconnectTimer);
dev->disconnectTimer = NULL;
}
dev->disconnect_scheduled = FALSE;
}

/* set idle timer to disconnect */
if (dev->idle_disconnect_timeout_s > 0)
{
Expand All @@ -274,37 +287,13 @@ rdpClientConGotConnection(ScreenPtr pScreen, rdpPtr dev)
static CARD32
rdpDeferredDisconnectCallback(OsTimerPtr timer, CARD32 now, pointer arg)
{
rdpPtr dev;

dev = (rdpPtr) arg;
LLOGLN(10, ("rdpDeferredDisconnectCallback"));
if (dev->clientConHead != NULL)
{
/* this should not happen */
LLOGLN(0, ("rdpDeferredDisconnectCallback: connected"));
if (dev->disconnectTimer != NULL)
{
LLOGLN(0, ("rdpDeferredDisconnectCallback: disengaging disconnect timer"));
TimerCancel(dev->disconnectTimer);
TimerFree(dev->disconnectTimer);
dev->disconnectTimer = NULL;
}
dev->disconnect_scheduled = FALSE;
return 0;
}
else
{
LLOGLN(10, ("rdpDeferredDisconnectCallback: not connected"));
}
if (now - dev->disconnect_time_ms > dev->disconnect_timeout_s * 1000)
{
LLOGLN(0, ("rdpDeferredDisconnectCallback: "
/* time's up, kill the session */
LLOGLN(10, ("rdpDeferredDisconnectCallback: not connected"));
LLOGLN(0, ("rdpDeferredDisconnectCallback: "
"disconnect timeout exceeded, exiting"));
kill(getpid(), SIGTERM);
return 0;
}
dev->disconnectTimer = TimerSet(dev->disconnectTimer, 0, 1000 * 10,
rdpDeferredDisconnectCallback, dev);
kill(getpid(), SIGTERM);

/* not reached */
return 0;
}

Expand Down Expand Up @@ -365,19 +354,6 @@ rdpClientConDisconnect(rdpPtr dev, rdpClientCon *clientCon)
dev->idleDisconnectTimer = NULL;
}

if (dev->do_kill_disconnected)
{
if (dev->disconnect_scheduled == FALSE)
{
LLOGLN(0, ("rdpClientConDisconnect: engaging disconnect timer, "
"exit after %d seconds", dev->disconnect_timeout_s));
dev->disconnectTimer = TimerSet(dev->disconnectTimer, 0, 1000 * 10,
rdpDeferredDisconnectCallback, dev);
dev->disconnect_scheduled = TRUE;
}
dev->disconnect_time_ms = GetTimeInMillis();
}

rdpClientConRemoveEnabledDevice(clientCon->sck);
g_sck_close(clientCon->sck);
if (clientCon->maxOsBitmaps > 0)
Expand Down Expand Up @@ -407,6 +383,26 @@ rdpClientConDisconnect(rdpPtr dev, rdpClientCon *clientCon)
free_stream(clientCon->out_s);
free_stream(clientCon->in_s);
free(clientCon);

/* kill session after disconnect ? */
if (dev->do_kill_disconnected)
{
/* kill immediate or after timeout? */
if(dev->disconnect_timeout_s == 0)
{
LLOGLN(0, ("rdpClientConDisconnect: disconnected, immediate session kill"));
kill(getpid(), SIGTERM);
}
else
{
LLOGLN(0, ("rdpClientConDisconnect: engaging disconnect timer, "
"exit after %d seconds", dev->disconnect_timeout_s));
dev->disconnectTimer = TimerSet(dev->disconnectTimer, 0, dev->disconnect_timeout_s * 1000,
rdpDeferredDisconnectCallback, dev);
dev->disconnect_scheduled = TRUE;
}
}

return 0;
}

Expand Down Expand Up @@ -1353,31 +1349,27 @@ rdpClientConInit(rdpPtr dev)
dev->idle_disconnect_timeout_s));

/* kill disconnected */
ptext = getenv("XRDP_SESMAN_MAX_DISC_TIME");
ptext = getenv("XRDP_SESMAN_KILL_DISCONNECTED");
if (ptext != 0)
{
i = atoi(ptext);
if (i > 0)
if (i != 0)
{
dev->do_kill_disconnected = 1;
dev->disconnect_timeout_s = atoi(ptext);
}
}
ptext = getenv("XRDP_SESMAN_KILL_DISCONNECTED");

/* kill timeout */
ptext = getenv("XRDP_SESMAN_MAX_DISC_TIME");
if (ptext != 0)
{
i = atoi(ptext);
if (i != 0)
if (i > 0)
{
dev->do_kill_disconnected = 1;
dev->disconnect_timeout_s = atoi(ptext);
}
}

if (dev->do_kill_disconnected && (dev->disconnect_timeout_s < 60))
{
dev->disconnect_timeout_s = 60;
}

LLOGLN(0, ("rdpClientConInit: kill disconnected [%d] timeout [%d] sec",
dev->do_kill_disconnected, dev->disconnect_timeout_s));

Expand Down