xrdp: exit main process with failure status if listen failed (daemon mode)
This commit is contained in:
parent
7aad2c83c6
commit
1d89000d90
12
xrdp/xrdp.c
12
xrdp/xrdp.c
@ -550,7 +550,17 @@ main(int argc, char **argv)
|
||||
|
||||
if (0 != pid)
|
||||
{
|
||||
g_writeln("process %d started ok", pid);
|
||||
/* if can't listen, exit with failure status */
|
||||
if (xrdp_listen_test() != 0)
|
||||
{
|
||||
log_message(LOG_LEVEL_ERROR, "Failed to start xrdp daemon, "
|
||||
"possibly address already in use.");
|
||||
g_deinit();
|
||||
/* must exit with failure status,
|
||||
or systemd cannot detect xrdp daemon couldn't start properly */
|
||||
g_exit(1);
|
||||
}
|
||||
g_writeln("daemon process %d started ok", pid);
|
||||
/* exit, this is the main process */
|
||||
g_deinit();
|
||||
g_exit(0);
|
||||
|
@ -163,6 +163,8 @@ void
|
||||
xrdp_listen_delete(struct xrdp_listen* self);
|
||||
int
|
||||
xrdp_listen_main_loop(struct xrdp_listen* self);
|
||||
int
|
||||
xrdp_listen_test(void);
|
||||
|
||||
/* xrdp_region.c */
|
||||
struct xrdp_region*
|
||||
|
@ -550,3 +550,54 @@ xrdp_listen_main_loop(struct xrdp_listen *self)
|
||||
self->status = -1;
|
||||
return error;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* returns 0 if xrdp can listen
|
||||
returns 1 if xrdp cannot listen */
|
||||
int
|
||||
xrdp_listen_test(void)
|
||||
{
|
||||
int rv = 0;
|
||||
char port[128];
|
||||
char address[256];
|
||||
int tcp_nodelay;
|
||||
int tcp_keepalive;
|
||||
struct xrdp_listen *xrdp_listen;
|
||||
struct xrdp_startup_params *startup_params;
|
||||
|
||||
|
||||
startup_params = (struct xrdp_startup_params *)
|
||||
g_malloc(sizeof(struct xrdp_startup_params), 1);
|
||||
xrdp_listen = xrdp_listen_create();
|
||||
xrdp_listen->startup_params = startup_params;
|
||||
|
||||
|
||||
if (xrdp_listen_get_port_address(port, sizeof(port),
|
||||
address, sizeof(address),
|
||||
&tcp_nodelay, &tcp_keepalive,
|
||||
xrdp_listen->startup_params) != 0)
|
||||
{
|
||||
log_message(LOG_LEVEL_DEBUG, "xrdp_listen_test: "
|
||||
"xrdp_listen_get_port_address failed");
|
||||
rv = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* try to listen */
|
||||
log_message(LOG_LEVEL_DEBUG, "Testing if xrdp can listen on %s port %s.",
|
||||
address, port);
|
||||
rv = trans_listen_address(xrdp_listen->listen_trans, port, address);
|
||||
if (rv == 0)
|
||||
{
|
||||
/* if listen succeeded, stop listen immediately */
|
||||
trans_delete(xrdp_listen->listen_trans);
|
||||
xrdp_listen->listen_trans = 0;
|
||||
}
|
||||
|
||||
goto done;
|
||||
|
||||
done:
|
||||
xrdp_listen_delete(xrdp_listen);
|
||||
g_free(startup_params);
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user