xrdp: enable listen_test, other parameter fixes about listen_test

This commit is contained in:
Jay Sorg 2019-07-01 00:53:11 -07:00
parent 0bc7803eaa
commit f42e38125e
3 changed files with 46 additions and 18 deletions

View File

@ -575,6 +575,16 @@ main(int argc, char **argv)
if (!no_daemon) if (!no_daemon)
{ {
/* if can't listen, exit with failure status */
if (xrdp_listen_test(startup_params) != 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);
}
/* start of daemonizing code */ /* start of daemonizing code */
pid = g_fork(); pid = g_fork();
@ -587,16 +597,6 @@ main(int argc, char **argv)
if (0 != pid) if (0 != 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); g_writeln("daemon process %d started ok", pid);
/* exit, this is the main process */ /* exit, this is the main process */
g_deinit(); g_deinit();

View File

@ -170,7 +170,7 @@ xrdp_listen_delete(struct xrdp_listen* self);
int int
xrdp_listen_main_loop(struct xrdp_listen* self); xrdp_listen_main_loop(struct xrdp_listen* self);
int int
xrdp_listen_test(void); xrdp_listen_test(struct xrdp_startup_params *startup_params);
/* xrdp_region.c */ /* xrdp_region.c */
struct xrdp_region* struct xrdp_region*

View File

@ -157,6 +157,8 @@ xrdp_listen_get_startup_params(struct xrdp_listen *self)
{ {
int fd; int fd;
int index; int index;
int port_override;
int fork_override;
char *val; char *val;
struct list *names; struct list *names;
struct list *values; struct list *values;
@ -164,6 +166,8 @@ xrdp_listen_get_startup_params(struct xrdp_listen *self)
struct xrdp_startup_params *startup_params; struct xrdp_startup_params *startup_params;
startup_params = self->startup_params; startup_params = self->startup_params;
port_override = startup_params->port[0] != 0;
fork_override = startup_params->fork;
g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH); g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
fd = g_file_open(cfg_file); fd = g_file_open(cfg_file);
if (fd != -1) if (fd != -1)
@ -181,13 +185,20 @@ xrdp_listen_get_startup_params(struct xrdp_listen *self)
{ {
if (g_strcasecmp(val, "port") == 0) if (g_strcasecmp(val, "port") == 0)
{ {
val = (char *)list_get_item(values, index); if (port_override == 0)
g_strncpy(startup_params->port, val, sizeof(startup_params->port) - 1); {
val = (char *) list_get_item(values, index);
g_strncpy(startup_params->port, val,
sizeof(startup_params->port) - 1);
}
} }
if (g_strcasecmp(val, "fork") == 0) if (g_strcasecmp(val, "fork") == 0)
{ {
val = (char *)list_get_item(values, index); if (fork_override == 0)
startup_params->fork = g_text2bool(val); {
val = (char *) list_get_item(values, index);
startup_params->fork = g_text2bool(val);
}
} }
if (g_strcasecmp(val, "tcp_nodelay") == 0) if (g_strcasecmp(val, "tcp_nodelay") == 0)
@ -591,7 +602,7 @@ xrdp_listen_pp(struct xrdp_listen *self, int *index,
static int static int
xrdp_listen_process_startup_params(struct xrdp_listen *self) xrdp_listen_process_startup_params(struct xrdp_listen *self)
{ {
int mode; /* TRANS_MODE_TCP, TRANS_MODE_UNIX, TRANS_MODE_VSOCK */ int mode; /* TRANS_MODE_TCP*, TRANS_MODE_UNIX, TRANS_MODE_VSOCK */
int error; int error;
int cont; int cont;
int bytes; int bytes;
@ -631,7 +642,9 @@ xrdp_listen_process_startup_params(struct xrdp_listen *self)
xrdp_listen_stop_all_listen(self); xrdp_listen_stop_all_listen(self);
return 1; return 1;
} }
if (mode == TRANS_MODE_TCP) if ((mode == TRANS_MODE_TCP) ||
(mode == TRANS_MODE_TCP4) ||
(mode == TRANS_MODE_TCP6))
{ {
if (startup_params->tcp_nodelay) if (startup_params->tcp_nodelay)
{ {
@ -928,7 +941,22 @@ xrdp_listen_main_loop(struct xrdp_listen *self)
/* returns 0 if xrdp can listen /* returns 0 if xrdp can listen
returns 1 if xrdp cannot listen */ returns 1 if xrdp cannot listen */
int int
xrdp_listen_test(void) xrdp_listen_test(struct xrdp_startup_params *startup_params)
{ {
struct xrdp_listen *xrdp_listen;
xrdp_listen = xrdp_listen_create();
xrdp_listen->startup_params = startup_params;
if (xrdp_listen_get_startup_params(xrdp_listen) != 0)
{
xrdp_listen_delete(xrdp_listen);
return 1;
}
if (xrdp_listen_process_startup_params(xrdp_listen) != 0)
{
xrdp_listen_delete(xrdp_listen);
return 1;
}
xrdp_listen_delete(xrdp_listen);
return 0; return 0;
} }