Merge pull request #2168 from matt335672/fix_sesman_signals

Fix sesman signal processing
This commit is contained in:
matt335672 2022-03-15 09:53:16 +00:00 committed by GitHub
commit 2ec28aca62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 353 additions and 254 deletions

View File

@ -224,7 +224,7 @@ internal_log_end(struct log_config *l_cfg)
}
/**
* Converts a string representing th log level to a value
* Converts a string representing the log level to a value
* @param buf
* @return
*/
@ -470,6 +470,7 @@ internalInitAndAllocStruct(void)
{
ret->fd = -1;
ret->enable_syslog = 0;
#ifdef LOG_PER_LOGGER_LEVEL
ret->per_logger_level = list_create();
if (ret->per_logger_level != NULL)
{
@ -481,6 +482,7 @@ internalInitAndAllocStruct(void)
g_free(ret);
ret = NULL;
}
#endif
}
else
{
@ -490,34 +492,21 @@ internalInitAndAllocStruct(void)
return ret;
}
void
internal_log_config_copy(struct log_config *dest, const struct log_config *src)
/**
* Copies logging levels only from one log_config structure to another
**/
static void
internal_log_config_copy_levels(struct log_config *dest,
const struct log_config *src)
{
int i;
if (src == NULL || dest == NULL)
{
return;
}
dest->enable_syslog = src->enable_syslog;
dest->fd = src->fd;
dest->log_file = g_strdup(src->log_file);
dest->log_level = src->log_level;
dest->log_lock = src->log_lock;
dest->log_lock_attr = src->log_lock_attr;
dest->program_name = src->program_name;
dest->enable_syslog = src->enable_syslog;
dest->syslog_level = src->syslog_level;
dest->enable_console = src->enable_console;
dest->console_level = src->console_level;
dest->enable_pid = src->enable_pid;
dest->dump_on_start = src->dump_on_start;
if (src->per_logger_level == NULL)
{
return;
}
#ifdef LOG_PER_LOGGER_LEVEL
if (dest->per_logger_level == NULL)
{
dest->per_logger_level = list_create();
@ -527,17 +516,47 @@ internal_log_config_copy(struct log_config *dest, const struct log_config *src)
}
dest->per_logger_level->auto_free = 1;
}
else
{
list_clear(dest->per_logger_level);
}
if (src->per_logger_level == NULL)
{
return;
}
int i;
for (i = 0; i < src->per_logger_level->count; ++i)
{
struct log_logger_level *dst_logger =
(struct log_logger_level *)g_malloc(sizeof(struct log_logger_level), 1);
g_memcpy(dst_logger,
(struct log_logger_level *) list_get_item(src->per_logger_level, i),
sizeof(struct log_logger_level));
*dst_logger = *(struct log_logger_level *) list_get_item(src->per_logger_level, i),
list_add_item(dest->per_logger_level, (tbus) dst_logger);
list_add_item(dest->per_logger_level, (tbus) dst_logger);
}
#endif
}
void
internal_log_config_copy(struct log_config *dest, const struct log_config *src)
{
if (src != NULL && dest != NULL)
{
dest->fd = src->fd;
g_free(dest->log_file);
dest->log_file = g_strdup(src->log_file);
#ifdef LOG_ENABLE_THREAD
dest->log_lock = src->log_lock;
dest->log_lock_attr = src->log_lock_attr;
#endif
dest->program_name = src->program_name;
dest->enable_pid = src->enable_pid;
dest->dump_on_start = src->dump_on_start;
internal_log_config_copy_levels(dest, src);
}
}
@ -591,6 +610,7 @@ internal_log_location_overrides_level(const char *function_name,
const char *file_name,
enum logLevels *log_level_return)
{
#ifdef LOG_PER_LOGGER_LEVEL
struct log_logger_level *logger = NULL;
int i;
@ -611,6 +631,7 @@ internal_log_location_overrides_level(const char *function_name,
return 1;
}
}
#endif
return 0;
}
@ -682,11 +703,13 @@ log_config_free(struct log_config *config)
{
if (config != NULL)
{
#ifdef LOG_PER_LOGGER_LEVEL
if (config->per_logger_level != NULL)
{
list_delete(config->per_logger_level);
config->per_logger_level = NULL;
}
#endif
if (0 != config->log_file)
{
@ -700,6 +723,62 @@ log_config_free(struct log_config *config)
return LOG_STARTUP_OK;
}
/**
* Restarts the logging.
*
* The logging file is never changed, as it is common in xrdp to share a
* log file between parents and children. The end result would be
* confusing for the user.
*/
static enum logReturns
log_restart_from_param(const struct log_config *lc)
{
enum logReturns rv = LOG_GENERAL_ERROR;
if (g_staticLogConfig == NULL)
{
log_message(LOG_LEVEL_ALWAYS, "Log not already initialized");
}
else if (lc == NULL)
{
g_writeln("lc to log_start_from_param is NULL");
}
else
{
if (g_staticLogConfig->fd >= 0 &&
g_strcmp(g_staticLogConfig->log_file, lc->log_file) != 0)
{
log_message(LOG_LEVEL_WARNING,
"Unable to change log file name from %s to %s",
g_staticLogConfig->log_file,
lc->log_file);
}
/* Reconfigure syslog logging, allowing for a program_name change */
if (g_staticLogConfig->enable_syslog)
{
closelog();
}
if (lc->enable_syslog)
{
openlog(lc->program_name, LOG_CONS | LOG_PID, LOG_DAEMON);
}
/* Copy over simple values... */
#ifdef LOG_ENABLE_THREAD
g_staticLogConfig->log_lock = lc->log_lock;
g_staticLogConfig->log_lock_attr = lc->log_lock_attr;
#endif
g_staticLogConfig->program_name = lc->program_name;
g_staticLogConfig->enable_pid = lc->enable_pid;
g_staticLogConfig->dump_on_start = lc->dump_on_start;
/* ... and the log levels */
internal_log_config_copy_levels(g_staticLogConfig, lc);
rv = LOG_STARTUP_OK;
}
return rv;
}
enum logReturns
log_start_from_param(const struct log_config *src_log_config)
{
@ -748,7 +827,7 @@ log_start_from_param(const struct log_config *src_log_config)
*/
enum logReturns
log_start(const char *iniFile, const char *applicationName,
bool_t dump_on_start)
unsigned int flags)
{
enum logReturns ret = LOG_GENERAL_ERROR;
struct log_config *config;
@ -757,14 +836,24 @@ 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);
if (ret != LOG_STARTUP_OK)
config->dump_on_start = (flags & LOG_START_DUMP_CONFIG) ? 1 : 0;
if (flags & LOG_START_RESTART)
{
g_writeln("Could not start log");
ret = log_restart_from_param(config);
if (ret != LOG_STARTUP_OK)
{
g_writeln("Could not restart log");
}
}
else
{
ret = log_start_from_param(config);
if (ret != LOG_STARTUP_OK)
{
g_writeln("Could not start log");
}
}
log_config_free(config);
}
else
{
@ -814,7 +903,7 @@ log_hexdump_with_location(const char *function_name,
{
char *dump_buffer;
enum logReturns rv = LOG_STARTUP_OK;
enum logLevels override_log_level;
enum logLevels override_log_level = LOG_LEVEL_NEVER;
bool_t override_destination_level = 0;
override_destination_level = internal_log_location_overrides_level(

View File

@ -162,6 +162,23 @@ enum logReturns
#endif
/* Flags values for log_start() */
/**
* Dump the log config on startup
*/
#define LOG_START_DUMP_CONFIG (1<<0)
/**
* Restart the logging system.
*
* On a restart, existing files are not closed. This is because the
* files may be shared by sub-processes, and the result will not be what the
* user expects
*/
#define LOG_START_RESTART (1<<1)
#ifdef LOG_PER_LOGGER_LEVEL
enum log_logger_type
{
LOG_TYPE_FILE = 0,
@ -174,22 +191,27 @@ struct log_logger_level
enum log_logger_type logger_type;
char logger_name[LOGGER_NAME_SIZE + 1];
};
#endif
struct log_config
{
const char *program_name;
char *log_file;
const char *program_name; /* Pointer to static storage */
char *log_file; /* Dynamically allocated */
int fd;
enum logLevels log_level;
int enable_console;
enum logLevels console_level;
int enable_syslog;
enum logLevels syslog_level;
#ifdef LOG_PER_LOGGER_LEVEL
struct list *per_logger_level;
#endif
int dump_on_start;
int enable_pid;
#ifdef LOG_ENABLE_THREAD
pthread_mutex_t log_lock;
pthread_mutexattr_t log_lock_attr;
#endif
};
/* internal functions, only used in log.c if this ifdef is defined.*/
@ -294,13 +316,12 @@ internal_log_location_overrides_level(const char *function_name,
* @param iniFile
* @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
* @param flags Flags to affect the operation of the call
* @return LOG_STARTUP_OK on success
*/
enum logReturns
log_start(const char *iniFile, const char *applicationName,
bool_t dump_on_start);
unsigned int flags);
/**
* An alternative log_start where the caller gives the params directly.

View File

@ -31,8 +31,6 @@
#include "sesman.h"
#include "string_calls.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
int
access_login_allowed(const char *user)

View File

@ -36,9 +36,6 @@
#include "ssl_calls.h"
#include "string_calls.h"
extern unsigned char g_fixedkey[8]; /* in sesman.c */
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
int
env_check_password_file(const char *filename, const char *passwd)

View File

@ -33,8 +33,6 @@
#include "sesman.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
enum SCP_SERVER_STATES_E
scp_process(struct trans *t, struct SCP_SESSION *sdata)

View File

@ -30,8 +30,6 @@
#include "sesman.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
enum SCP_SERVER_STATES_E
scp_v0_process(struct trans *t, struct SCP_SESSION *s)

View File

@ -33,8 +33,6 @@
//#include "libscp_types.h"
#include "libscp.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
static void
parseCommonStates(enum SCP_SERVER_STATES_E e, const char *f);

View File

@ -32,8 +32,6 @@
#include "libscp.h"
extern struct config_sesman *g_cfg; /* in sesman.c */
static void parseCommonStates(enum SCP_SERVER_STATES_E e, const char *f);
/******************************************************************************/

View File

@ -52,11 +52,11 @@ struct sesman_startup_params
int dump_config;
};
int g_pid;
struct config_sesman *g_cfg;
unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };
struct config_sesman *g_cfg; /* defined in config.h */
tintptr g_term_event = 0;
tintptr g_sigchld_event = 0;
tintptr g_reload_event = 0;
/**
* Items stored on the g_con_list
@ -67,8 +67,9 @@ struct sesman_con
struct SCP_SESSION *s;
};
static struct trans *g_list_trans = NULL;
static struct trans *g_list_trans;
static struct list *g_con_list = NULL;
static int g_pid;
/*****************************************************************************/
/**
@ -263,7 +264,7 @@ sesman_close_all(void)
struct sesman_con *sc;
LOG_DEVEL(LOG_LEVEL_TRACE, "sesman_close_all:");
trans_delete(g_list_trans);
sesman_delete_listening_transport();
for (index = 0; index < g_con_list->count; index++)
{
sc = (struct sesman_con *) list_get_item(g_con_list, index);
@ -340,6 +341,86 @@ sesman_listen_conn_in(struct trans *self, struct trans *new_self)
return 0;
}
/******************************************************************************/
/**
* Informs the main loop a termination signal has been received
*/
static void
set_term_event(int sig)
{
/* Don't try to use a wait obj in a child process */
if (g_getpid() == g_pid)
{
g_set_wait_obj(g_term_event);
}
}
/******************************************************************************/
/**
* Informs the main loop a SIGCHLD has been received
*/
static void
set_sigchld_event(int sig)
{
/* Don't try to use a wait obj in a child process */
if (g_getpid() == g_pid)
{
g_set_wait_obj(g_sigchld_event);
}
}
/******************************************************************************/
/**
* Informs the main loop a SIGHUP has been received
*/
static void
set_reload_event(int sig)
{
/* Don't try to use a wait obj in a child process */
if (g_getpid() == g_pid)
{
g_set_wait_obj(g_reload_event);
}
}
/******************************************************************************/
void
sesman_delete_listening_transport(void)
{
trans_delete(g_list_trans);
g_list_trans = NULL;
}
/******************************************************************************/
int
sesman_create_listening_transport(const struct config_sesman *cfg)
{
int rv = 1;
g_list_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
if (g_list_trans == NULL)
{
LOG(LOG_LEVEL_ERROR, "%s: trans_create failed", __func__);
}
else
{
LOG(LOG_LEVEL_DEBUG, "%s: address %s port %s",
__func__, cfg->listen_address, cfg->listen_port);
rv = trans_listen_address(g_list_trans, cfg->listen_port,
cfg->listen_address);
if (rv != 0)
{
LOG(LOG_LEVEL_ERROR, "%s: trans_listen_address failed", __func__);
sesman_delete_listening_transport();
}
else
{
g_list_trans->trans_conn_in = sesman_listen_conn_in;
}
}
return rv;
}
/******************************************************************************/
/**
*
@ -352,7 +433,6 @@ sesman_main_loop(void)
int error;
int robjs_count;
int wobjs_count;
int cont;
int timeout;
int index;
intptr_t robjs[32];
@ -365,33 +445,22 @@ sesman_main_loop(void)
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: list_create failed");
return 1;
}
g_list_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
if (g_list_trans == NULL)
if (sesman_create_listening_transport(g_cfg) != 0)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: trans_create failed");
LOG(LOG_LEVEL_ERROR,
"sesman_main_loop: sesman_create_listening_transport failed");
list_delete(g_con_list);
return 1;
}
LOG(LOG_LEVEL_DEBUG, "sesman_main_loop: address %s port %s",
g_cfg->listen_address, g_cfg->listen_port);
error = trans_listen_address(g_list_trans, g_cfg->listen_port,
g_cfg->listen_address);
if (error != 0)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: trans_listen_address "
"failed");
trans_delete(g_list_trans);
list_delete(g_con_list);
return 1;
}
g_list_trans->trans_conn_in = sesman_listen_conn_in;
cont = 1;
while (cont)
error = 0;
while (!error)
{
timeout = -1;
robjs_count = 0;
robjs[robjs_count++] = g_term_event;
robjs[robjs_count++] = g_sigchld_event;
robjs[robjs_count++] = g_reload_event;
wobjs_count = 0;
for (index = 0; index < g_con_list->count; index++)
{
@ -413,34 +482,53 @@ sesman_main_loop(void)
{
break;
}
error = trans_get_wait_objs_rw(g_list_trans, robjs, &robjs_count,
wobjs, &wobjs_count, &timeout);
if (error != 0)
if (g_list_trans != NULL)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
"trans_get_wait_objs_rw failed");
break;
/* g_list_trans might be NULL on a reconfigure if sesman
* is unable to listen again */
error = trans_get_wait_objs_rw(g_list_trans, robjs, &robjs_count,
wobjs, &wobjs_count, &timeout);
if (error != 0)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
"trans_get_wait_objs_rw failed");
break;
}
}
error = g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout);
if (error != 0)
if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)
{
/* error, should not get here */
/* should not get here */
LOG(LOG_LEVEL_WARNING, "sesman_main_loop: "
"Unexpected error from g_obj_wait()");
g_sleep(100);
}
if (g_is_wait_obj_set(g_term_event)) /* term */
{
LOG(LOG_LEVEL_INFO, "sesman_main_loop: "
"sesman asked to terminate");
break;
}
if (g_is_wait_obj_set(g_sigchld_event)) /* A child has exited */
{
g_reset_wait_obj(g_sigchld_event);
sig_sesman_session_end();
}
if (g_is_wait_obj_set(g_reload_event)) /* We're asked to reload */
{
g_reset_wait_obj(g_reload_event);
sig_sesman_reload_cfg();
}
for (index = 0; index < g_con_list->count; index++)
{
scon = (struct sesman_con *)list_get_item(g_con_list, index);
if (scon != NULL)
{
error = trans_check_wait_objs(scon->t);
if (error != 0)
if (trans_check_wait_objs(scon->t) != 0)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
"trans_check_wait_objs failed, removing trans");
@ -451,12 +539,16 @@ sesman_main_loop(void)
}
}
}
error = trans_check_wait_objs(g_list_trans);
if (error != 0)
if (g_list_trans != NULL)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
"trans_check_wait_objs failed");
break;
error = trans_check_wait_objs(g_list_trans);
if (error != 0)
{
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
"trans_check_wait_objs failed");
break;
}
}
}
for (index = 0; index < g_con_list->count; index++)
@ -465,7 +557,7 @@ sesman_main_loop(void)
delete_connection(scon);
}
list_delete(g_con_list);
trans_delete(g_list_trans);
sesman_delete_listening_transport();
return 0;
}
@ -627,8 +719,9 @@ main(int argc, char **argv)
}
/* starting logging subsystem */
log_error = log_start(startup_params.sesman_ini, "xrdp-sesman",
startup_params.dump_config);
log_error = log_start(
startup_params.sesman_ini, "xrdp-sesman",
(startup_params.dump_config) ? LOG_START_DUMP_CONFIG : 0);
if (log_error != LOG_STARTUP_OK)
{
@ -709,20 +802,17 @@ main(int argc, char **argv)
/* signal handling */
g_pid = g_getpid();
/* old style signal handling is now managed synchronously by a
* separate thread. uncomment this block if you need old style
* signal handling and comment out thread_sighandler_start()
* going back to old style for the time being
* problem with the sigaddset functions in sig.c - jts */
#if 1
g_signal_hang_up(sig_sesman_reload_cfg); /* SIGHUP */
g_signal_user_interrupt(sig_sesman_shutdown); /* SIGINT */
g_signal_terminate(sig_sesman_shutdown); /* SIGTERM */
g_signal_child_stop(sig_sesman_session_end); /* SIGCHLD */
#endif
#if 0
thread_sighandler_start();
#endif
g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
g_term_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_sesman_%8.8x_sigchld", g_pid);
g_sigchld_event = g_create_wait_obj(text);
g_snprintf(text, 255, "xrdp_sesman_%8.8x_reload", g_pid);
g_reload_event = g_create_wait_obj(text);
g_signal_hang_up(set_reload_event); /* SIGHUP */
g_signal_user_interrupt(set_term_event); /* SIGINT */
g_signal_terminate(set_term_event); /* SIGTERM */
g_signal_child_stop(set_sigchld_event); /* SIGCHLD */
if (daemon)
{
@ -764,9 +854,6 @@ main(int argc, char **argv)
g_chmod_hex("/tmp/.X11-unix", 0x1777);
}
g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
g_term_event = g_create_wait_obj(text);
error = sesman_main_loop();
/* clean up PID file on exit */
@ -775,6 +862,8 @@ main(int argc, char **argv)
g_file_delete(pid_file);
}
g_delete_wait_obj(g_reload_event);
g_delete_wait_obj(g_sigchld_event);
g_delete_wait_obj(g_term_event);
if (!daemon)

View File

@ -41,6 +41,13 @@
#include "libscp.h"
/* Globals */
extern struct config_sesman *g_cfg;
extern unsigned char g_fixedkey[8];
extern tintptr g_term_event;
extern tintptr g_sigchld_event;
extern tintptr g_reload_event;
/*
* Close all file descriptors used by sesman.
*
@ -53,4 +60,20 @@
int
sesman_close_all(void);
/*
* Remove the listening transport
*
* Needed if reloading the config and the listener has changed
*/
void
sesman_delete_listening_transport(void);
/*
* Create the listening socket transport
*
* @return 0 for success
*/
int
sesman_create_listening_transport(const struct config_sesman *cfg);
#endif

View File

@ -47,12 +47,8 @@
#define PR_SET_NO_NEW_PRIVS 38
#endif
extern unsigned char g_fixedkey[8];
extern struct config_sesman *g_cfg; /* in sesman.c */
struct session_chain *g_sessions;
int g_session_count;
extern tbus g_term_event; /* in sesman.c */
static struct session_chain *g_sessions;
static int g_session_count;
/**
* Creates a string consisting of all parameters that is hosted in the param list
@ -524,8 +520,13 @@ session_start_fork(tbus data, tui8 type, struct SCP_SESSION *s)
"Failed to clone the session data - out of memory");
g_exit(1);
}
auth_start_session(data, display);
/* Wait objects created in a parent are not valid in a child */
g_delete_wait_obj(g_reload_event);
g_delete_wait_obj(g_sigchld_event);
g_delete_wait_obj(g_term_event);
auth_start_session(data, display);
sesman_close_all();
g_sprintf(geometry, "%dx%d", s->width, s->height);
g_sprintf(depth, "%d", s->bpp);

View File

@ -28,52 +28,17 @@
#include <config_ac.h>
#endif
#include <signal.h>
#include "string_calls.h"
#include "sesman.h"
extern int g_pid;
extern struct config_sesman *g_cfg; /* in sesman.c */
extern tbus g_term_event;
/******************************************************************************/
void
sig_sesman_shutdown(int sig)
{
char pid_file[256];
LOG(LOG_LEVEL_INFO, "shutting down sesman %d", 1);
if (g_getpid() != g_pid)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "g_getpid() [%d] differs from g_pid [%d]", (g_getpid()), g_pid);
return;
}
LOG_DEVEL(LOG_LEVEL_DEBUG, " - getting signal %d pid %d", sig, g_getpid());
g_set_wait_obj(g_term_event);
session_sigkill_all();
g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
g_file_delete(pid_file);
}
/******************************************************************************/
void
sig_sesman_reload_cfg(int sig)
sig_sesman_reload_cfg(void)
{
int error;
struct config_sesman *cfg;
LOG(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);
if (g_getpid() != g_pid)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
return;
}
LOG(LOG_LEVEL_INFO, "receiving SIGHUP");
if ((cfg = config_read(g_cfg->sesman_ini)) == NULL)
{
@ -81,8 +46,18 @@ sig_sesman_reload_cfg(int sig)
return;
}
/* stop logging subsystem */
log_end();
/* Deal with significant config changes */
if (g_strcmp(g_cfg->listen_address, cfg->listen_address) != 0 ||
g_strcmp(g_cfg->listen_port, cfg->listen_port) != 0)
{
LOG(LOG_LEVEL_INFO, "sesman listen address changed to %s:%s",
cfg->listen_address, cfg->listen_port);
/* We have to delete the old port before listening to the new one
* in case they overlap in scope */
sesman_delete_listening_transport();
sesman_create_listening_transport(cfg);
}
/* free old config data */
config_free(g_cfg);
@ -90,8 +65,8 @@ sig_sesman_reload_cfg(int sig)
/* replace old config with newly read one */
g_cfg = cfg;
/* start again logging subsystem */
error = log_start(g_cfg->sesman_ini, "xrdp-sesman", 0);
/* Restart logging subsystem */
error = log_start(g_cfg->sesman_ini, "xrdp-sesman", LOG_START_RESTART);
if (error != LOG_STARTUP_OK)
{
@ -113,84 +88,21 @@ sig_sesman_reload_cfg(int sig)
/******************************************************************************/
void
sig_sesman_session_end(int sig)
sig_sesman_session_end(void)
{
int pid;
if (g_getpid() != g_pid)
{
return;
}
LOG(LOG_LEVEL_DEBUG, "receiving SIGCHLD");
do
{
pid = g_waitchild();
if (pid > 0)
{
LOG(LOG_LEVEL_INFO, "Process %d has exited", pid);
session_kill(pid);
}
}
while (pid > 0);
}
/******************************************************************************/
void *
sig_handler_thread(void *arg)
{
int recv_signal;
sigset_t sigmask;
sigset_t oldmask;
sigset_t waitmask;
/* mask signals to be able to wait for them... */
sigfillset(&sigmask);
/* it is a good idea not to block SIGILL SIGSEGV */
/* SIGFPE -- see sigaction(2) NOTES */
pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask);
/* building the signal wait mask... */
sigemptyset(&waitmask);
sigaddset(&waitmask, SIGHUP);
sigaddset(&waitmask, SIGCHLD);
sigaddset(&waitmask, SIGTERM);
sigaddset(&waitmask, SIGINT);
// sigaddset(&waitmask, SIGFPE);
// sigaddset(&waitmask, SIGILL);
// sigaddset(&waitmask, SIGSEGV);
do
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "calling sigwait()");
sigwait(&waitmask, &recv_signal);
switch (recv_signal)
{
case SIGHUP:
//reload cfg
//we must stop & restart logging, or copy logging cfg!!!!
LOG_DEVEL(LOG_LEVEL_DEBUG, "sesman received SIGHUP");
//return 0;
break;
case SIGCHLD:
/* a session died */
LOG_DEVEL(LOG_LEVEL_DEBUG, "sesman received SIGCHLD");
sig_sesman_session_end(SIGCHLD);
break;
case SIGINT:
/* we die */
LOG_DEVEL(LOG_LEVEL_DEBUG, "sesman received SIGINT");
sig_sesman_shutdown(recv_signal);
break;
case SIGTERM:
/* we die */
LOG_DEVEL(LOG_LEVEL_DEBUG, "sesman received SIGTERM");
sig_sesman_shutdown(recv_signal);
break;
}
}
while (1);
return 0;
}

View File

@ -27,39 +27,20 @@
#ifndef SIG_H
#define SIG_H
/**
*
* @brief Shutdown signal code
* @param sig The received signal
*
*/
void
sig_sesman_shutdown(int sig);
/**
*
* @brief SIGHUP handling code
* @param sig The received signal
*
*/
void
sig_sesman_reload_cfg(int sig);
sig_sesman_reload_cfg(void);
/**
*
* @brief SIGCHLD handling code
* @param sig The received signal
*
*/
void
sig_sesman_session_end(int sig);
/**
*
* @brief signal handling thread
*
*/
void *
sig_handler_thread(void *arg);
sig_sesman_session_end(void);
#endif

View File

@ -42,8 +42,6 @@
#define SECS_PER_DAY (24L*3600L)
#endif
extern struct config_sesman *g_cfg; /* in sesman.c */
static int
auth_crypt_pwd(const char *pwd, const char *pln, char *crp);

View File

@ -43,8 +43,6 @@
#define SECS_PER_DAY (24L*3600L)
#endif
extern struct config_sesman *g_cfg; /* in sesman.c */
/******************************************************************************/
/* returns boolean */
long

View File

@ -538,7 +538,7 @@ main(int argc, char **argv)
/* starting logging subsystem */
error = log_start(startup_params.xrdp_ini, "xrdp",
startup_params.dump_config);
(startup_params.dump_config) ? LOG_START_DUMP_CONFIG : 0);
if (error != LOG_STARTUP_OK)
{