From 1e135330486ef5d5fa164872a99785ccd86ac68f Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Mon, 28 Dec 2020 11:03:36 +0000 Subject: [PATCH] Remove output on stdout by default on daemon startuip --- common/log.c | 7 ++++--- common/log.h | 8 ++++++-- docs/man/xrdp-sesman.8.in | 6 +++++- docs/man/xrdp.8.in | 6 +++++- sesman/sesman.c | 30 +++++++++++++++--------------- sesman/sig.c | 2 +- xrdp/xrdp.c | 22 ++++++++++++++-------- xrdp/xrdp_types.h | 1 + 8 files changed, 51 insertions(+), 31 deletions(-) diff --git a/common/log.c b/common/log.c index c7747397..0c5465d3 100644 --- a/common/log.c +++ b/common/log.c @@ -304,7 +304,7 @@ internal_config_read_logging(int file, lc->console_level = LOG_LEVEL_INFO; lc->enable_syslog = 0; lc->syslog_level = LOG_LEVEL_INFO; - lc->dump_on_start = 1; + lc->dump_on_start = 0; lc->enable_pid = 0; g_snprintf(section_name, 511, "%s%s", section_prefix, SESMAN_CFG_LOGGING); @@ -616,7 +616,6 @@ log_config_init_for_console(enum logLevels lvl, const char *override_name) { config->console_level = lvl; } - config->dump_on_start = 0; /* Don't need dump for console only */ } return config; } @@ -721,7 +720,8 @@ log_start_from_param(const struct log_config *src_log_config) * @return 0 on success */ enum logReturns -log_start(const char *iniFile, const char *applicationName) +log_start(const char *iniFile, const char *applicationName, + bool_t dump_on_start) { enum logReturns ret = LOG_GENERAL_ERROR; struct log_config *config; @@ -730,6 +730,7 @@ log_start(const char *iniFile, const char *applicationName) if (config != NULL) { + config->dump_on_start = dump_on_start; ret = log_start_from_param(config); log_config_free(config); diff --git a/common/log.h b/common/log.h index f9304fcf..6cbd0a62 100644 --- a/common/log.h +++ b/common/log.h @@ -263,11 +263,15 @@ internal_log_location_overrides_level(const char *function_name, * This function initialize the log facilities according to the configuration * file, that is described by the in parameter. * @param iniFile - * @param applicationName, the name that is used in the log for the running application + * @param applicationName the name that is used in the log for the running + * application + * @param dump_on_start Whether to dump the config on stdout before + * logging is started * @return LOG_STARTUP_OK on success */ enum logReturns -log_start(const char *iniFile, const char *applicationName); +log_start(const char *iniFile, const char *applicationName, + bool_t dump_on_start); /** * An alternative log_start where the caller gives the params directly. diff --git a/docs/man/xrdp-sesman.8.in b/docs/man/xrdp-sesman.8.in index d90251db..b6be46af 100644 --- a/docs/man/xrdp-sesman.8.in +++ b/docs/man/xrdp-sesman.8.in @@ -13,7 +13,7 @@ xrdp\-sesman \- \fBxrdp\fR(8) session manager \-\-version .br .B xrdp\-sesman -[ \-\-nodaemon ] [ --config /path/to/sesman.ini ] +[\-\-nodaemon] [\-\-dump\-config] [\-\-config /path/to/sesman.ini] .SH "DESCRIPTION" \fBxrdp\-sesman\fR is \fBxrdp\fR(8) session manager. @@ -34,6 +34,10 @@ Output version information and exit. \fB\-n\fR, \fB\-\-nodaemon\fR Starts \fBxrdp\-sesman\fR in foreground instead of starting it as a daemon. .TP +\fB\-\-dump\-config\fR +Print the configuration on stdout before starting the daemon. +The default is not to do this. +.TP \fB\-c\fR, \fB\-\-config\fR Specify a path to a different \fIsesman.ini\fR file. This option is intended to be used primarily for testing or for unusual configurations. diff --git a/docs/man/xrdp.8.in b/docs/man/xrdp.8.in index 6cd6bd47..ce194246 100644 --- a/docs/man/xrdp.8.in +++ b/docs/man/xrdp.8.in @@ -13,7 +13,7 @@ \-\-version .br .B xrdp -[ \-\-nodaemon ] [ --port port ] [ --fork ] [ --config /path/to/xrdp.ini ] +[\-\-nodaemon] [\-\-port port] [\-\-fork] [\-\-dump\-config] [\-\-config /path/to/xrdp.ini] .SH "DESCRIPTION" \fBxrdp\fR is a Remote Desktop Protocol (RDP) Server. @@ -45,6 +45,10 @@ Fork a new process on a new connection. If not enabled, use a new thread for every connection. This overrides \fIfork\fR setting in \fIxrdp.ini\fR file. .TP +\fB\-\-dump\-config\fR +Print the configuration on stdout before starting the daemon. +The default is not to do this. +.TP \fB\-c\fR, \fB\-\-config\fR Specify a path to a different \fIxrdp.ini\fR file. This option is intended to be used primarily for testing or for unusual configurations. diff --git a/sesman/sesman.c b/sesman/sesman.c index 88ed884f..1b90547a 100644 --- a/sesman/sesman.c +++ b/sesman/sesman.c @@ -41,6 +41,7 @@ struct sesman_startup_params int no_daemon; int help; int version; + int dump_config; }; int g_sck; @@ -127,6 +128,10 @@ sesman_process_params(int argc, char **argv, { startup_params->version = 1; } + else if (nocase_matches(option, "--dump-config", NULL)) + { + startup_params->dump_config = 1; + } else if (nocase_matches(option, "-c", "--config", NULL)) { index++; @@ -305,11 +310,12 @@ static void print_help(void) { g_printf("Usage: xrdp-sesman [options]\n"); - g_printf(" -k, --kill shut down xrdp-sesman\n"); - g_printf(" -h, --help show help\n"); - g_printf(" -v, --version show version\n"); - g_printf(" -n, --nodaemon don't fork into background\n"); - g_printf(" -c, --config specify new path to sesman.ini\n"); + g_printf(" -k, --kill shut down xrdp-sesman\n"); + g_printf(" -h, --help show help\n"); + g_printf(" -v, --version show version\n"); + g_printf(" -n, --nodaemon don't fork into background\n"); + g_printf(" -c, --config specify new path to sesman.ini\n"); + g_writeln(" --dump-config display config on stdout on startup"); g_deinit(); } @@ -415,12 +421,6 @@ main(int argc, char **argv) g_exit(kill_running_sesman(pid_file)); } - daemon = !startup_params.no_daemon; - if (!daemon) - { - g_printf("starting sesman in foreground...\n"); - } - if (g_file_exist(pid_file)) { g_printf("xrdp-sesman is already running.\n"); @@ -440,15 +440,14 @@ main(int argc, char **argv) g_exit(1); } - /* not to spit on the console, show config summary only when running - * in foreground */ - if (!daemon) + if (startup_params.dump_config) { config_dump(g_cfg); } /* starting logging subsystem */ - log_error = log_start(startup_params.sesman_ini, "xrdp-sesman"); + log_error = log_start(startup_params.sesman_ini, "xrdp-sesman", + startup_params.dump_config); if (log_error != LOG_STARTUP_OK) { @@ -481,6 +480,7 @@ main(int argc, char **argv) LOG(LOG_LEVEL_TRACE, " reconnect_sh = %s", g_cfg->reconnect_sh); LOG(LOG_LEVEL_TRACE, " auth_file_path = %s", g_cfg->auth_file_path); + daemon = !startup_params.no_daemon; if (daemon) { /* not to spit on the console, shut up stdout/stderr before anything's logged */ diff --git a/sesman/sig.c b/sesman/sig.c index 3d56298c..d3703741 100644 --- a/sesman/sig.c +++ b/sesman/sig.c @@ -92,7 +92,7 @@ sig_sesman_reload_cfg(int sig) g_cfg = cfg; /* start again logging subsystem */ - error = log_start(g_cfg->sesman_ini, "xrdp-sesman"); + error = log_start(g_cfg->sesman_ini, "xrdp-sesman", 0); if (error != LOG_STARTUP_OK) { diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index d9eb30bc..fa639c43 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -74,13 +74,14 @@ static void print_help(void) { g_writeln("Usage: xrdp [options]"); - g_writeln(" -k, --kill shut down xrdp"); - g_writeln(" -h, --help show help"); - g_writeln(" -v, --version show version"); - g_writeln(" -n, --nodaemon don't fork into background"); - g_writeln(" -p, --port tcp listen port"); - g_writeln(" -f, --fork fork on new connection"); - g_writeln(" -c, --config Specify new path to xrdp.ini"); + g_writeln(" -k, --kill shut down xrdp"); + g_writeln(" -h, --help show help"); + g_writeln(" -v, --version show version"); + g_writeln(" -n, --nodaemon don't fork into background"); + g_writeln(" -p, --port tcp listen port"); + g_writeln(" -f, --fork fork on new connection"); + g_writeln(" -c, --config specify new path to xrdp.ini"); + g_writeln(" --dump-config display config on stdout on startup"); } /*****************************************************************************/ @@ -361,6 +362,10 @@ xrdp_process_params(int argc, char **argv, startup_params->fork = 1; g_writeln("--fork parameter found, ini override"); } + else if (nocase_matches(option, "--dump-config", NULL)) + { + startup_params->dump_config = 1; + } else if (nocase_matches(option, "-c", "--config", NULL)) { index++; @@ -536,7 +541,8 @@ main(int argc, char **argv) } /* starting logging subsystem */ - error = log_start(startup_params.xrdp_ini, "xrdp"); + error = log_start(startup_params.xrdp_ini, "xrdp", + startup_params.dump_config); if (error != LOG_STARTUP_OK) { diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index 86b2d41a..8d7710a3 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -539,6 +539,7 @@ struct xrdp_startup_params int help; int version; int fork; + int dump_config; int tcp_send_buffer_bytes; int tcp_recv_buffer_bytes; int tcp_nodelay;