deamon shutdown

ulab-original
jsorg71 20 years ago
parent ed041b7983
commit 013c114995

@ -23,45 +23,39 @@
#include "xrdp.h" #include "xrdp.h"
static struct xrdp_listen* g_listen = 0; static struct xrdp_listen* g_listen = 0;
static int g_threadid = 0; /* main threadid */
/*****************************************************************************/ /*****************************************************************************/
/* i can't get stupid in_val to work, hum using global var for now */ void shutdown(int sig)
THREAD_RV THREAD_CC xrdp_listen_run(void* in_val)
{ {
DEBUG(("listener started\n\r")); struct xrdp_listen* listen;
xrdp_listen_main_loop(g_listen);
DEBUG(("listener done\n\r"));
return 0;
}
#define CLEAN_CLOSE if (g_get_threadid() != g_threadid)
{
return;
}
g_printf("shutting down\n\r");
g_printf("signal %d threadid %d\n\r", sig, g_get_threadid());
listen = g_listen;
g_listen = 0;
if (listen != 0)
{
g_set_term(1);
g_sleep(1000);
xrdp_listen_delete(listen);
g_exit_system();
}
}
/*****************************************************************************/ /*****************************************************************************/
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int rv;
g_init_system(); g_init_system();
rv = 0; g_threadid = g_get_threadid();
g_listen = xrdp_listen_create(); g_listen = xrdp_listen_create();
#ifdef CLEAN_CLOSE g_signal(2, shutdown);
if (g_thread_create(xrdp_listen_run, 0) == 0) g_signal(9, shutdown);
{ g_signal(15, shutdown);
g_getchar();
g_set_term(1);
while (g_listen->status > 0)
{
g_sleep(100);
}
}
else
{
rv = 1;
}
#else
xrdp_listen_main_loop(g_listen); xrdp_listen_main_loop(g_listen);
#endif return 0;
xrdp_listen_delete(g_listen);
g_exit_system();
return rv;
} }

@ -144,6 +144,7 @@ int xrdp_listen_main_loop(struct xrdp_listen* self)
{ {
g_printf("bind error in xrdp_listen_main_loop\n\r"); g_printf("bind error in xrdp_listen_main_loop\n\r");
g_tcp_close(self->sck); g_tcp_close(self->sck);
self->status = -1;
return 1; return 1;
} }
error = g_tcp_listen(self->sck); error = g_tcp_listen(self->sck);

Loading…
Cancel
Save