diff --git a/module/rdpClientCon.c b/module/rdpClientCon.c index bc3d0c10..179b48f3 100644 --- a/module/rdpClientCon.c +++ b/module/rdpClientCon.c @@ -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) { @@ -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; } @@ -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) @@ -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; } @@ -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));