diff options
author | Koichiro IWAO <meta@vmeta.jp> | 2017-05-17 16:23:30 +0900 |
---|---|---|
committer | metalefty <meta@vmeta.jp> | 2017-06-20 14:29:02 +0900 |
commit | 5a7208a15b8fc3efda59dd1ee618cf5127287dd1 (patch) | |
tree | 704e57f3aae8e315788c0c1b2760f3f782e9df9c /sesman/sesman.c | |
parent | 1d89000d90ddb5f6d18dcc8c724a9aeb8954ea07 (diff) | |
download | xrdp-proprietary-5a7208a15b8fc3efda59dd1ee618cf5127287dd1.tar.gz xrdp-proprietary-5a7208a15b8fc3efda59dd1ee618cf5127287dd1.zip |
sesman: exit with failure status if listen failed
Diffstat (limited to 'sesman/sesman.c')
-rw-r--r-- | sesman/sesman.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/sesman/sesman.c b/sesman/sesman.c index 738421ad..7a25482a 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -38,18 +38,58 @@ struct config_sesman *g_cfg; /* defined in config.h */ tintptr g_term_event = 0; /******************************************************************************/ +int sesman_listen_test(struct config_sesman *cfg) +{ + int error; + int sck; + int rv = 0; + + sck = g_tcp_socket(); + if (sck < 0) + { + return 1; + } + + log_message(LOG_LEVEL_DEBUG, "Testing if xrdp-sesman can listen on %s port %s.", + cfg->listen_address, cfg->listen_port); + g_tcp_set_non_blocking(sck); + error = scp_tcp_bind(sck, cfg->listen_address, cfg->listen_port); + if (error == 0) + { + /* try to listen */ + error = g_tcp_listen(sck); + + if (error == 0) + { + /* if listen succeeded, stop listen immediately */ + g_sck_close(sck); + } + else + { + rv = 1; + } + } + else + { + rv = 1; + } + + return rv; +} +/******************************************************************************/ /** * * @brief Starts sesman main loop * */ -static void +int sesman_main_loop(void) { int in_sck; int error; int robjs_count; int cont; + int rv = 0; tbus sck_obj; tbus robjs[8]; @@ -57,7 +97,7 @@ sesman_main_loop(void) if (g_sck < 0) { log_message(LOG_LEVEL_ERROR, "error opening socket, g_tcp_socket() failed..."); - return; + return 1; } g_tcp_set_non_blocking(g_sck); @@ -123,6 +163,7 @@ sesman_main_loop(void) { log_message(LOG_LEVEL_ERROR, "listen error %d (%s)", g_get_errno(), g_get_strerror()); + rv = 1; } } else @@ -130,8 +171,10 @@ sesman_main_loop(void) log_message(LOG_LEVEL_ERROR, "bind error on " "port '%s': %d (%s)", g_cfg->listen_port, g_get_errno(), g_get_strerror()); + rv = 1; } g_tcp_close(g_sck); + return rv; } /******************************************************************************/ @@ -304,6 +347,14 @@ main(int argc, char **argv) if (0 != g_pid) { + if (sesman_listen_test(g_cfg) != 0) + { + + log_message(LOG_LEVEL_ERROR, "Failed to start xrdp-sesman daemon, " + "possibly address already in use."); + g_deinit(); + g_exit(1); + } g_deinit(); g_exit(0); } @@ -380,7 +431,7 @@ main(int argc, char **argv) g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid); g_term_event = g_create_wait_obj(text); - sesman_main_loop(); + error = sesman_main_loop(); /* clean up PID file on exit */ if (daemon) @@ -396,5 +447,6 @@ main(int argc, char **argv) } g_deinit(); + g_exit(error); return 0; } |