summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilsimo <ilsimo>2008-02-20 22:02:24 +0000
committerilsimo <ilsimo>2008-02-20 22:02:24 +0000
commit4c9d3862e55ab5d6fa734549478bb0a00be9f7ed (patch)
tree2efde9a8872ed90ea14521702614768aaf0b765b
parent8f0045c19b03d5c9a0baea6b72037ec226db8343 (diff)
downloadxrdp-proprietary-4c9d3862e55ab5d6fa734549478bb0a00be9f7ed.tar.gz
xrdp-proprietary-4c9d3862e55ab5d6fa734549478bb0a00be9f7ed.zip
updating logging subsystem
-rw-r--r--common/log.c69
-rw-r--r--common/log.h22
-rw-r--r--sesman/access.c10
-rw-r--r--sesman/config.c14
-rw-r--r--sesman/config.h4
-rw-r--r--sesman/env.c6
-rw-r--r--sesman/scp.c19
-rw-r--r--sesman/scp_v0.c8
-rw-r--r--sesman/scp_v1.c28
-rw-r--r--sesman/sesman.c19
-rw-r--r--sesman/session.c62
-rw-r--r--sesman/sig.c20
-rw-r--r--sesman/thread.c34
-rw-r--r--sesman/verify_user.c16
14 files changed, 160 insertions, 171 deletions
diff --git a/common/log.c b/common/log.c
index d6da363d..d4923900 100644
--- a/common/log.c
+++ b/common/log.c
@@ -29,18 +29,6 @@
#include "log.h"
-/* this gets created in log_start and freed in log_end */
-static struct log_config* l_cfg;
-
-/* threading additions */
-#ifdef LOG_ENABLE_THREAD
-#include "pthread.h"
-/* these get initalized in log_start, they don't need
- to get freed */
-static pthread_mutex_t log_lock;
-static pthread_mutexattr_t log_lock_attr;
-#endif
-
/**
*
* @brief Opens log file
@@ -115,7 +103,7 @@ log_lvl2str(int lvl, char* str)
/******************************************************************************/
int DEFAULT_CC
-log_message(const unsigned int lvl, const char* msg, ...)
+log_message(struct log_config* l_cfg, const unsigned int lvl, const char* msg, ...)
{
char buff[LOG_BUFFER_SIZE + 31]; /* 19 (datetime) 4 (space+cr+lf+\0) */
va_list ap;
@@ -151,7 +139,7 @@ log_message(const unsigned int lvl, const char* msg, ...)
/* checking for truncated messages */
if (len > LOG_BUFFER_SIZE)
{
- log_message(LOG_LEVEL_WARNING, "next message will be truncated");
+ log_message(l_cfg, LOG_LEVEL_WARNING, "next message will be truncated");
}
/* forcing the end of message string */
@@ -182,11 +170,11 @@ log_message(const unsigned int lvl, const char* msg, ...)
/* log to application logfile */
#ifdef LOG_ENABLE_THREAD
- pthread_mutex_lock(&log_lock);
+ pthread_mutex_lock(&(l_cfg->log_lock));
#endif
rv = g_file_write(l_cfg->fd, (char*)buff, g_strlen((char*)buff));
#ifdef LOG_ENABLE_THREAD
- pthread_mutex_unlock(&log_lock);
+ pthread_mutex_unlock(&(l_cfg->log_lock));
#endif
}
return rv;
@@ -194,44 +182,24 @@ log_message(const unsigned int lvl, const char* msg, ...)
/******************************************************************************/
int DEFAULT_CC
-log_start(const char* progname, const char* logfile, const unsigned int loglvl,
- const int syslog, const unsigned int syslvl)
+log_start(struct log_config* l_cfg)
{
- /* setup log struct */
- l_cfg = (struct log_config*)g_malloc(sizeof(struct log_config), 1);
-
if (0 == l_cfg)
{
return LOG_ERROR_MALLOC;
}
/* if logfile is NULL, we use a default logfile */
- if (0 == logfile)
+ if (0 == l_cfg->log_file)
{
l_cfg->log_file = g_strdup("./myprogram.log");
}
- else
- {
- l_cfg->log_file = g_strdup(logfile);
- }
/* if progname is NULL, we use a default name */
- if (0 == progname)
+ if (0 == l_cfg->program_name)
{
l_cfg->program_name = g_strdup("myprogram");
}
- else
- {
- l_cfg->program_name = g_strdup(progname);
- }
-
- /* setting log level */
- l_cfg->log_level = loglvl;
-
- /* 0 disables syslog, everything else enables it */
- l_cfg->enable_syslog = (syslog ? 1 : 0);
- /* forcing syslog_level to be always <= app logging level */
- l_cfg->syslog_level = (syslvl>loglvl ? loglvl : syslvl);
/* open file */
l_cfg->fd = log_file_open(l_cfg->log_file);
@@ -248,8 +216,8 @@ log_start(const char* progname, const char* logfile, const unsigned int loglvl,
}
#ifdef LOG_ENABLE_THREAD
- pthread_mutexattr_init(&log_lock_attr);
- pthread_mutex_init(&log_lock, &log_lock_attr);
+ pthread_mutexattr_init(&(l_cfg->log_lock_attr));
+ pthread_mutex_init(&(l_cfg->log_lock), &(l_cfg->log_lock_attr));
#endif
return LOG_STARTUP_OK;
@@ -257,7 +225,7 @@ log_start(const char* progname, const char* logfile, const unsigned int loglvl,
/******************************************************************************/
void DEFAULT_CC
-log_end(void)
+log_end(struct log_config* l_cfg)
{
/* if log is closed, quit silently */
if (0 == l_cfg)
@@ -266,7 +234,7 @@ log_end(void)
}
/* closing log file */
- log_message(LOG_LEVEL_ALWAYS, "shutting down log subsystem...");
+ log_message(l_cfg, LOG_LEVEL_ALWAYS, "shutting down log subsystem...");
if (0 > l_cfg->fd)
{
@@ -287,11 +255,16 @@ log_end(void)
}
/* freeing allocated memory */
- g_free(l_cfg->log_file);
- g_free(l_cfg->program_name);
- g_free(l_cfg);
-
- l_cfg = 0;
+ if (0 != l_cfg->log_file)
+ {
+ g_free(l_cfg->log_file);
+ l_cfg->log_file = 0;
+ }
+ if (0 != l_cfg->program_name)
+ {
+ g_free(l_cfg->program_name);
+ l_cfg->program_name = 0;
+ }
}
/******************************************************************************/
diff --git a/common/log.h b/common/log.h
index 93328044..18bdd623 100644
--- a/common/log.h
+++ b/common/log.h
@@ -20,6 +20,8 @@
#ifndef LOG_H
#define LOG_H
+#include <pthread.h>
+
#include "arch.h"
/* logging buffer size */
@@ -44,9 +46,9 @@
/*#define LOG_ENABLE_THREAD*/
#ifdef DEBUG
- #define LOG_DBG(s,args...) log_message(LOG_LEVEL_DEBUG,s,args);
+ #define LOG_DBG(lcfg,args...) log_message((lcfg), LOG_LEVEL_DEBUG, args);
#else
- #define LOG_DBG(s,args...)
+ #define LOG_DBG(lcfg,args...)
#endif
struct log_config
@@ -57,6 +59,8 @@ struct log_config
unsigned int log_level;
int enable_syslog;
unsigned int syslog_level;
+ pthread_mutex_t log_lock;
+ pthread_mutexattr_t log_lock_attr;
};
/**
@@ -68,30 +72,26 @@ struct log_config
*
*/
int DEFAULT_CC
-log_message(const unsigned int lvl, const char* msg, ...);
+log_message(struct log_config* l_cfg, const unsigned int lvl, const char* msg, ...);
/**
*
* @brief Starts the logging subsystem
- * @param progname string to prepend to syslog messages
- * @param logfile log file path
- * @param loglvl level of messages to log
- * @param syslog if set to 0, disables the use of syslog
- * @param syslvl level of messages to log to syslog
+ * @param l_cfg loggging system configuration
* @return
*
*/
int DEFAULT_CC
-log_start(const char* progname, const char* logfile, const unsigned int loglvl,
- const int syslog, const unsigned int syslvl);
+log_start(struct log_config* l_cfg);
/**
*
* @brief Shuts down the logging subsystem
+ * @param l_cfg pointer to the logging subsystem to stop
*
*/
void DEFAULT_CC
-log_end(void);
+log_end(struct log_config* l_cfg);
/**
*
diff --git a/sesman/access.c b/sesman/access.c
index 0e50bea7..e5ce2f13 100644
--- a/sesman/access.c
+++ b/sesman/access.c
@@ -38,21 +38,21 @@ access_login_allowed(char* user)
if ((0 == g_strncmp(user, "root", 5)) && (0 == g_cfg.sec.allow_root))
{
- log_message(LOG_LEVEL_WARNING,
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING,
"ROOT login attempted, but root login is disabled");
return 0;
}
if (0 == g_cfg.sec.ts_users_enable)
{
- LOG_DBG("Terminal Server Users group is disabled, allowing authentication",
+ LOG_DBG(&(g_cfg.log), "Terminal Server Users group is disabled, allowing authentication",
1);
return 1;
}
if (0 != g_getuser_info(user, &gid, 0, 0, 0, 0))
{
- log_message(LOG_LEVEL_ERROR, "Cannot read user info! - login denied");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "Cannot read user info! - login denied");
return 0;
}
@@ -64,7 +64,7 @@ access_login_allowed(char* user)
if (0 != g_check_user_in_group(user, g_cfg.sec.ts_users, &ok))
{
- log_message(LOG_LEVEL_ERROR, "Cannot read group info! - login denied");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "Cannot read group info! - login denied");
return 0;
}
@@ -73,7 +73,7 @@ access_login_allowed(char* user)
return 1;
}
- log_message(LOG_LEVEL_INFO, "login denied for user %s", user);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "login denied for user %s", user);
return 0;
}
diff --git a/sesman/config.c b/sesman/config.c
index fc6b7d51..4be3975c 100644
--- a/sesman/config.c
+++ b/sesman/config.c
@@ -30,6 +30,8 @@
#include "file.h"
#include "sesman.h"
+extern struct config_sesman g_cfg;
+
/******************************************************************************/
/**
*
@@ -62,8 +64,16 @@ config_read(struct config_sesman* cfg)
fd = g_file_open(SESMAN_CFG_FILE);
if (-1 == fd)
{
- log_message(LOG_LEVEL_ALWAYS, "error opening %s in \
-config_read", SESMAN_CFG_FILE);
+ if (g_cfg.log.fd >= 0)
+ {
+ /* logging is already active */
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "error opening %s in \
+ config_read", SESMAN_CFG_FILE);
+ }
+ else
+ {
+ g_printf("error opening %s in config_read", SESMAN_CFG_FILE);
+ }
return 1;
}
g_memset(cfg, 0, sizeof(struct config_sesman));
diff --git a/sesman/config.h b/sesman/config.h
index a174e532..11b3e586 100644
--- a/sesman/config.h
+++ b/sesman/config.h
@@ -180,12 +180,12 @@ struct config_sesman
* @var vnc_params
* @brief Xvnc additional parameter list
*/
-struct list* vnc_params;
+ struct list* vnc_params;
/**
* @var rdp_params
* @brief X11rdp additional parameter list
*/
-struct list* rdp_params;
+ struct list* rdp_params;
/**
* @var log
* @brief Log configuration struct
diff --git a/sesman/env.c b/sesman/env.c
index e2b4fe96..72b01fdb 100644
--- a/sesman/env.c
+++ b/sesman/env.c
@@ -47,7 +47,7 @@ env_check_password_file(char* filename, char* password)
fd = g_file_open(filename);
if (fd == -1)
{
- log_message(LOG_LEVEL_WARNING, "can't read vnc password file - %s",
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "can't read vnc password file - %s",
filename);
return 1;
}
@@ -110,13 +110,13 @@ env_set_user(char* username, char* passwd_file, int display)
/* we use auth_file_path as requested */
g_sprintf(passwd_file, g_cfg.auth_file_path, username);
}
- LOG_DBG("pass file: %s", passwd_file);
+ LOG_DBG(&(g_cfg.log), "pass file: %s", passwd_file);
}
}
}
else
{
- log_message(LOG_LEVEL_ERROR, "error getting user info for user %s", username);
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "error getting user info for user %s", username);
}
return error;
}
diff --git a/sesman/scp.c b/sesman/scp.c
index 40ff09dc..e964bed2 100644
--- a/sesman/scp.c
+++ b/sesman/scp.c
@@ -31,6 +31,7 @@
#include "sesman.h"
extern int thread_sck;
+extern struct config_sesman g_cfg;
/******************************************************************************/
void* DEFAULT_CC
@@ -42,7 +43,7 @@ scp_process_start(void* sck)
/* making a local copy of the socket (it's on the stack) */
/* probably this is just paranoia */
scon.in_sck = thread_sck;
- LOG_DBG("started scp thread on socket %d", scon.in_sck);
+ LOG_DBG(&(g_cfg.log), "started scp thread on socket %d", scon.in_sck);
/* unlocking thread_sck */
lock_socket_release();
@@ -59,34 +60,34 @@ scp_process_start(void* sck)
if (sdata->version == 0)
{
/* starts processing an scp v0 connection */
- LOG_DBG("accept ok, go on with scp v0\n",0);
+ LOG_DBG(&(g_cfg.log), "accept ok, go on with scp v0\n",0);
scp_v0_process(&scon, sdata);
}
else
{
- LOG_DBG("accept ok, go on with scp v1\n",0);
- LOG_DBG("user: %s\npass: %s",sdata->username, sdata->password);
+ LOG_DBG(&(g_cfg.log), "accept ok, go on with scp v1\n",0);
+ /*LOG_DBG(&(g_cfg.log), "user: %s\npass: %s",sdata->username, sdata->password);*/
scp_v1_process(&scon, sdata);
}
break;
case SCP_SERVER_STATE_VERSION_ERR:
/* an unknown scp version was requested, so we shut down the */
/* connection (and log the fact) */
- log_message(LOG_LEVEL_WARNING,
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING,
"unknown protocol version specified. connection refused.");
break;
case SCP_SERVER_STATE_NETWORK_ERR:
- log_message(LOG_LEVEL_WARNING, "libscp network error.");
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp network error.");
break;
case SCP_SERVER_STATE_SEQUENCE_ERR:
- log_message(LOG_LEVEL_WARNING, "libscp sequence error.");
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp sequence error.");
break;
case SCP_SERVER_STATE_INTERNAL_ERR:
/* internal error occurred (eg. malloc() error, ecc.) */
- log_message(LOG_LEVEL_ERROR, "libscp internal error occurred.");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "libscp internal error occurred.");
break;
default:
- log_message(LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()");
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()");
}
g_tcp_close(scon.in_sck);
free_stream(scon.in_s);
diff --git a/sesman/scp_v0.c b/sesman/scp_v0.c
index 490b50b4..942bf46c 100644
--- a/sesman/scp_v0.c
+++ b/sesman/scp_v0.c
@@ -27,6 +27,8 @@
#include "sesman.h"
+extern struct config_sesman g_cfg;
+
/******************************************************************************/
void DEFAULT_CC
scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
@@ -51,16 +53,16 @@ scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
g_printf("pre auth");
if (1 == access_login_allowed(s->username))
{
- log_message(LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
if (SCP_SESSION_TYPE_XVNC == s->type)
{
- log_message(LOG_LEVEL_INFO, "starting Xvnc session...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username, s->password,
data, SESMAN_SESSION_TYPE_XVNC);
}
else
{
- log_message(LOG_LEVEL_INFO, "starting Xrdp session...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "starting Xrdp session...");
display = session_start(s->width, s->height, s->bpp, s->username, s->password,
data, SESMAN_SESSION_TYPE_XRDP);
}
diff --git a/sesman/scp_v1.c b/sesman/scp_v1.c
index 23d94035..3f974b90 100644
--- a/sesman/scp_v1.c
+++ b/sesman/scp_v1.c
@@ -83,7 +83,7 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (!data)
{
scp_v1s_deny_connection(c, "Login failed");
- log_message(LOG_LEVEL_INFO,
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO,
"Login failed for user %s. Connection terminated", s->username);
free_session(s);
return;
@@ -93,7 +93,7 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (0 == access_login_allowed(s->username))
{
scp_v1s_deny_connection(c, "Access to Terminal Server not allowed.");
- log_message(LOG_LEVEL_INFO,
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO,
"User %s not allowed on TS. Connection terminated", s->username);
free_session(s);
return;
@@ -107,16 +107,16 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (scount == 0)
{
/* no disconnected sessions - start a new one */
- log_message(LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
if (SCP_SESSION_TYPE_XVNC == s->type)
{
- log_message(LOG_LEVEL_INFO, "starting Xvnc session...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XVNC);
}
else
{
- log_message(LOG_LEVEL_INFO, "starting Xrdp session...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "starting Xrdp session...");
display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XRDP);
}
@@ -145,7 +145,7 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
/*case SCP_SERVER_STATE_FORCE_NEW:*/
/* we should check for MaxSessions */
case SCP_SERVER_STATE_SELECTION_CANCEL:
- log_message(LOG_LEVEL_INFO, "Connection cancelled after session listing");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "Connection cancelled after session listing");
break;
case SCP_SERVER_STATE_OK:
/* ok, reconnecting... */
@@ -153,14 +153,14 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (0==sitem)
{
e=scp_v1s_connection_error(c, "Internal error");
- log_message(LOG_LEVEL_INFO, "Cannot find session item on the chain");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "Cannot find session item on the chain");
}
else
{
display=sitem->display;
/*e=scp_v1s_reconnect_session(c, sitem, display);*/
e=scp_v1s_reconnect_session(c, display);
- log_message(LOG_LEVEL_INFO, "User %s reconnected to session %d on port %d", \
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "User %s reconnected to session %d on port %d", \
s->username, sitem->pid, display);
}
break;
@@ -188,27 +188,27 @@ static void parseCommonStates(enum SCP_SERVER_STATES_E e, char* f)
switch (e)
{
case SCP_SERVER_STATE_VERSION_ERR:
- LOG_DBG("version error", 0)
+ LOG_DBG(&(g_cfg.log), "version error")
case SCP_SERVER_STATE_SIZE_ERR:
/* an unknown scp version was requested, so we shut down the */
/* connection (and log the fact) */
- log_message(LOG_LEVEL_WARNING,
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING,
"protocol violation. connection closed.");
break;
case SCP_SERVER_STATE_NETWORK_ERR:
- log_message(LOG_LEVEL_WARNING, "libscp network error.");
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp network error.");
break;
case SCP_SERVER_STATE_SEQUENCE_ERR:
- log_message(LOG_LEVEL_WARNING, "libscp sequence error.");
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp sequence error.");
break;
case SCP_SERVER_STATE_INTERNAL_ERR:
/* internal error occurred (eg. malloc() error, ecc.) */
- log_message(LOG_LEVEL_ERROR, "libscp internal error occurred.");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "libscp internal error occurred.");
break;
default:
/* dummy: scp_v1s_request_password won't generate any other */
/* error other than the ones before */
- log_message(LOG_LEVEL_ALWAYS, "unknown return from %s", f);
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "unknown return from %s", f);
break;
}
}
diff --git a/sesman/sesman.c b/sesman/sesman.c
index 34462113..3aa13748 100644
--- a/sesman/sesman.c
+++ b/sesman/sesman.c
@@ -47,7 +47,7 @@ sesman_main_loop(void)
int error;
/*main program loop*/
- log_message(LOG_LEVEL_INFO, "listening...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "listening...");
g_sck = g_tcp_socket();
g_tcp_set_non_blocking(g_sck);
error = scp_tcp_bind(g_sck, g_cfg.listen_address, g_cfg.listen_port);
@@ -81,12 +81,12 @@ sesman_main_loop(void)
}
else
{
- log_message(LOG_LEVEL_ERROR, "listen error");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "listen error");
}
}
else
{
- log_message(LOG_LEVEL_ERROR, "bind error");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "bind error");
}
g_tcp_close(g_sck);
}
@@ -188,6 +188,7 @@ main(int argc, char** argv)
}
/* reading config */
+ g_cfg.log.fd = -1; /* don't use logging before reading its config */
if (0 != config_read(&g_cfg))
{
g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
@@ -195,9 +196,7 @@ main(int argc, char** argv)
}
/* starting logging subsystem */
- error = log_start(g_cfg.log.program_name, g_cfg.log.log_file,
- g_cfg.log.log_level, g_cfg.log.enable_syslog,
- g_cfg.log.syslog_level);
+ error = log_start(&(g_cfg.log));
if (error != LOG_STARTUP_OK)
{
@@ -256,9 +255,9 @@ main(int argc, char** argv)
fd = g_file_open(SESMAN_PID_FILE);
if (-1 == fd)
{
- log_message(LOG_LEVEL_ERROR, "error opening pid file: %s",
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "error opening pid file: %s",
g_get_strerror());
- log_end();
+ log_end(&(g_cfg.log));
g_exit(1);
}
g_sprintf(pid_s, "%d", g_pid);
@@ -266,7 +265,7 @@ main(int argc, char** argv)
g_file_close(fd);
/* start program main loop */
- log_message(LOG_LEVEL_ALWAYS, "starting sesman with pid %d", g_pid);
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "starting sesman with pid %d", g_pid);
/* make sure the /tmp/.X11-unix directory exist */
if (!g_directory_exist("/tmp/.X11-unix"))
@@ -279,7 +278,7 @@ main(int argc, char** argv)
if (!daemon)
{
- log_end();
+ log_end(&(g_cfg.log));
}
return 0;
diff --git a/sesman/session.c b/sesman/session.c
index 4e415cd6..bd1fb966 100644
--- a/sesman/session.c
+++ b/sesman/session.c
@@ -124,7 +124,7 @@ session_start_sessvc(int xpid, int wmpid, long data)
/* new style waiting for clients */
g_sprintf(wmpid_str, "%d", wmpid);
g_sprintf(xpid_str, "%d", xpid);
- log_message(LOG_LEVEL_INFO, "starting sessvc - xpid=%s - wmpid=%s",xpid_str, wmpid_str);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "starting sessvc - xpid=%s - wmpid=%s",xpid_str, wmpid_str);
sessvc_params = list_create();
sessvc_params->auto_free = 1;
@@ -142,16 +142,16 @@ session_start_sessvc(int xpid, int wmpid, long data)
g_execvp(exe_path, ((char**)sessvc_params->items));
/* should not get here */
- log_message(LOG_LEVEL_ALWAYS, "error starting sessvc - pid %d - xpid=%s - wmpid=%s",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "error starting sessvc - pid %d - xpid=%s - wmpid=%s",
g_getpid(), xpid_str, wmpid_str);
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
- log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
- log_message(LOG_LEVEL_DEBUG,"execve parameter list:");
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG,"execve parameter list:");
for (i=0; i < (sessvc_params->count); i++)
{
- log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(sessvc_params, i));
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(sessvc_params, i));
}
list_delete(sessvc_params);
@@ -191,7 +191,7 @@ session_start(int width, int height, int bpp, char* username, char* password,
{
/*THREAD-FIX unlock chain*/
lock_chain_release();
- log_message(LOG_LEVEL_INFO, "max concurrent session limit exceeded. login \
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "max concurrent session limit exceeded. login \
for user %s denied", username);
return 0;
}
@@ -202,7 +202,7 @@ for user %s denied", username);
temp = (struct session_chain*)g_malloc(sizeof(struct session_chain), 0);
if (temp == 0)
{
- log_message(LOG_LEVEL_ERROR, "cannot create new chain element - user %s",
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "cannot create new chain element - user %s",
username);
return 0;
}
@@ -210,7 +210,7 @@ for user %s denied", username);
if (temp->item == 0)
{
g_free(temp);
- log_message(LOG_LEVEL_ERROR, "cannot create new session item - user %s",
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "cannot create new session item - user %s",
username);
return 0;
}
@@ -263,15 +263,15 @@ for user %s denied", username);
if (g_file_exist(text))
{
g_execlp3(text, g_cfg.user_wm, 0);
- log_message(LOG_LEVEL_ALWAYS,"error starting user wm for user %s - pid %d",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS,"error starting user wm for user %s - pid %d",
username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
- log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
g_get_strerror());
- log_message(LOG_LEVEL_DEBUG,"execlp3 parameter list:");
- log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text);
- log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg.user_wm);
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG,"execlp3 parameter list:");
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[0] = %s", text);
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg.user_wm);
}
}
/* if we're here something happened to g_execlp3
@@ -279,31 +279,31 @@ for user %s denied", username);
g_sprintf(text, "%s/%s", cur_dir, g_cfg.default_wm);
g_execlp3(text, g_cfg.default_wm, 0);
- log_message(LOG_LEVEL_ALWAYS,"error starting default wm for user %s - pid %d",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS,"error starting default wm for user %s - pid %d",
username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
- log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno,
g_get_strerror());
- log_message(LOG_LEVEL_DEBUG,"execlp3 parameter list:");
- log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text);
- log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg.default_wm);
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG,"execlp3 parameter list:");
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[0] = %s", text);
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg.default_wm);
/* still a problem starting window manager just start xterm */
g_execlp3("xterm", "xterm", 0);
/* should not get here */
- log_message(LOG_LEVEL_ALWAYS,"error starting xterm for user %s - pid %d",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS,"error starting xterm for user %s - pid %d",
username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
- log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
}
else
{
- log_message(LOG_LEVEL_ERROR, "another Xserver is already active on display %d", display);
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "another Xserver is already active on display %d", display);
}
- log_message(LOG_LEVEL_DEBUG,"aborting connection...");
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG,"aborting connection...");
g_exit(0);
}
else /* parent (child sesman) */
@@ -364,23 +364,23 @@ for user %s denied", username);
}
else
{
- log_message(LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "bad session type - user %s - pid %d",
username, g_getpid());
g_exit(1);
}
/* should not get here */
- log_message(LOG_LEVEL_ALWAYS, "error starting X server - user %s - pid %d",
+ log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "error starting X server - user %s - pid %d",
username, g_getpid());
/* logging parameters */
/* no problem calling strerror for thread safety: other threads are blocked */
- log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
- log_message(LOG_LEVEL_DEBUG, "execve parameter list: %d", (xserver_params)->count);
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror());
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, "execve parameter list: %d", (xserver_params)->count);
for (i=0; i<(xserver_params->count); i++)
{
- log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(xserver_params, i));
+ log_message(&(g_cfg.log), LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char*)list_get_item(xserver_params, i));
}
list_delete(xserver_params);
g_exit(1);
@@ -479,7 +479,7 @@ session_kill(int pid)
{
if (tmp->item == 0)
{
- log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
pid);
if (prev == 0)
{
@@ -499,7 +499,7 @@ session_kill(int pid)
if (tmp->item->pid == pid)
{
/* deleting the session */
- log_message(LOG_LEVEL_INFO, "session %d - user %s - terminated",
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "session %d - user %s - terminated",
tmp->item->pid, tmp->item->name);
g_free(tmp->item);
if (prev == 0)
@@ -544,7 +544,7 @@ session_sigkill_all()
{
if (tmp->item == 0)
{
- log_message(LOG_LEVEL_ERROR, "found null session descriptor!");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "found null session descriptor!");
}
else
{
@@ -573,7 +573,7 @@ session_get_bypid(int pid)
{
if (tmp->item == 0)
{
- log_message(LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "session descriptor for pid %d is null!",
pid);
/*THREAD-FIX release chain lock */
lock_chain_release();
diff --git a/sesman/sig.c b/sesman/sig.c
index 2f67a18f..8f37e767 100644
--- a/sesman/sig.c
+++ b/sesman/sig.c
@@ -37,7 +37,7 @@ extern struct config_sesman g_cfg;
void DEFAULT_CC
sig_sesman_shutdown(int sig)
{
- log_message(LOG_LEVEL_INFO, "shutting down sesman %d", 1);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "shutting down sesman %d", 1);
if (g_getpid() != g_pid)
{
@@ -60,22 +60,23 @@ sig_sesman_reload_cfg(int sig)
{
struct config_sesman cfg;
- log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);
+#warning FIXME reload configuration must NOT damage logging!
+ log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);
if (g_getpid() != g_pid)
{
- LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
+ LOG_DBG(&(g_cfg.log), "g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
return;
}
if (config_read(&cfg) != 0)
{
- log_message(LOG_LEVEL_ERROR, "error reading config - keeping old cfg");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "error reading config - keeping old cfg");
return;
}
g_cfg = cfg;
- log_message(LOG_LEVEL_INFO, "configuration reloaded");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "configuration reloaded");
}
/******************************************************************************/
@@ -121,19 +122,20 @@ sig_handler_thread(void* arg)
do
{
- LOG_DBG("calling sigwait()",0);
+ LOG_DBG(&(g_cfg.log), "calling sigwait()",0);
sigwait(&waitmask, &recv_signal);
switch (recv_signal)
{
case SIGHUP:
//reload cfg
- LOG_DBG("sesman received SIGHUP",0);
+ //we must stop & restart logging, or copy logging cfg!!!!
+ LOG_DBG(&(g_cfg.log), "sesman received SIGHUP",0);
//return 0;
break;
case SIGCHLD:
/* a session died */
- LOG_DBG("sesman received SIGCHLD",0);
+ LOG_DBG(&(g_cfg.log), "sesman received SIGCHLD",0);
sig_sesman_session_end(SIGCHLD);
break;
/*case SIGKILL;
@@ -143,7 +145,7 @@ sig_handler_thread(void* arg)
break;*/
case SIGTERM:
/* we die */
- LOG_DBG("sesman received SIGTERM",0);
+ LOG_DBG(&(g_cfg.log), "sesman received SIGTERM",0);
sig_sesman_shutdown(recv_signal);
break;
}
diff --git a/sesman/thread.c b/sesman/thread.c
index 082e1d6b..632c546f 100644
--- a/sesman/thread.c
+++ b/sesman/thread.c
@@ -31,6 +31,8 @@
#include <signal.h>
#include <pthread.h>
+extern struct config_sesman g_cfg;
+
static pthread_t thread_sighandler;
//static pthread_t thread_updater;
@@ -60,14 +62,14 @@ thread_sighandler_start(void)
sigaddset(&waitmask, SIGFPE);
pthread_sigmask(SIG_UNBLOCK, &waitmask, NULL);
- log_message(LOG_LEVEL_INFO,"starting signal handling thread...");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO,"starting signal handling thread...");
ret = pthread_create(&thread_sighandler, NULL, sig_handler_thread, "");
pthread_detach(thread_sighandler);
if (ret == 0)
{
- log_message(LOG_LEVEL_INFO, "signal handler thread started successfully");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "signal handler thread started successfully");
return 0;
}
@@ -75,16 +77,16 @@ thread_sighandler_start(void)
switch (ret)
{
case EINVAL:
- log_message(LOG_LEVEL_ERROR, "invalid attributes for signal handling thread (creation returned EINVAL)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for signal handling thread (creation returned EINVAL)");
break;
case EAGAIN:
- log_message(LOG_LEVEL_ERROR, "not enough resources to start signal handling thread (creation returned EAGAIN)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start signal handling thread (creation returned EAGAIN)");
break;
case EPERM:
- log_message(LOG_LEVEL_ERROR, "invalid permissions for signal handling thread (creation returned EPERM)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for signal handling thread (creation returned EPERM)");
break;
default:
- log_message(LOG_LEVEL_ERROR, "unknown error starting signal handling thread");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting signal handling thread");
}
return 1;
@@ -106,7 +108,7 @@ thread_session_update_start(void)
if (ret==0)
{
- log_message(LOG_LEVEL_INFO, "session update thread started successfully");
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "session update thread started successfully");
return 0;
}
@@ -114,16 +116,16 @@ thread_session_update_start(void)
switch (ret)
{
case EINVAL:
- log_message(LOG_LEVEL_ERROR, "invalid attributes for session update thread (creation returned EINVAL)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for session update thread (creation returned EINVAL)");
break;
case EAGAIN:
- log_message(LOG_LEVEL_ERROR, "not enough resources to start session update thread (creation returned EAGAIN)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start session update thread (creation returned EAGAIN)");
break;
case EPERM:
- log_message(LOG_LEVEL_ERROR, "invalid permissions for session update thread (creation returned EPERM)");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for session update thread (creation returned EPERM)");
break;
default:
- log_message(LOG_LEVEL_ERROR, "unknown error starting session update thread");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting session update thread");
}
return 1;
@@ -148,7 +150,7 @@ thread_scp_start(int skt)
if (ret == 0)
{
- log_message(LOG_LEVEL_INFO, "scp thread on sck %d started successfully", skt);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "scp thread on sck %d started successfully", skt);
return 0;
}
@@ -156,16 +158,16 @@ thread_scp_start(int skt)
switch (ret)
{
case EINVAL:
- log_message(LOG_LEVEL_ERROR, "invalid attributes for scp thread on sck %d (creation returned EINVAL)", skt);
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for scp thread on sck %d (creation returned EINVAL)", skt);
break;
case EAGAIN:
- log_message(LOG_LEVEL_ERROR, "not enough resources to start scp thread on sck %d (creation returned EAGAIN)", skt);
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start scp thread on sck %d (creation returned EAGAIN)", skt);
break;
case EPERM:
- log_message(LOG_LEVEL_ERROR, "invalid permissions for scp thread on sck %d (creation returned EPERM)", skt);
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for scp thread on sck %d (creation returned EPERM)", skt);
break;
default:
- log_message(LOG_LEVEL_ERROR, "unknown error starting scp thread on sck %d");
+ log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting scp thread on sck %d");
}
return 1;
diff --git a/sesman/verify_user.c b/sesman/verify_user.c
index f40a9f05..b783724c 100644
--- a/sesman/verify_user.c
+++ b/sesman/verify_user.c
@@ -73,7 +73,7 @@ auth_userpass(char* user, char* pass)
}
if (1==auth_account_disabled(stp))
{
- log_message(LOG_LEVEL_INFO, "account %s is disabled", user);
+ log_message(&(g_cfg.log), LOG_LEVEL_INFO, "account %s is disabled", user);
return 0;
}
g_strncpy(hash, stp->sp_pwdp, 34);
@@ -306,13 +306,13 @@ auth_account_disabled(struct spwd* stp)
today=g_time1()/SECS_PER_DAY;
- LOG_DBG("last %d",stp->sp_lstchg);
- LOG_DBG("min %d",stp->sp_min);
- LOG_DBG("max %d",stp->sp_max);
- LOG_DBG("inact %d",stp->sp_inact);
- LOG_DBG("warn %d",stp->sp_warn);
- LOG_DBG("expire %d",stp->sp_expire);
- LOG_DBG("today %d",today);
+ LOG_DBG(&(g_cfg.log), "last %d",stp->sp_lstchg);
+ LOG_DBG(&(g_cfg.log), "min %d",stp->sp_min);
+ LOG_DBG(&(g_cfg.log), "max %d",stp->sp_max);
+ LOG_DBG(&(g_cfg.log), "inact %d",stp->sp_inact);
+ LOG_DBG(&(g_cfg.log), "warn %d",stp->sp_warn);
+ LOG_DBG(&(g_cfg.log), "expire %d",stp->sp_expire);
+ LOG_DBG(&(g_cfg.log), "today %d",today);
if ((stp->sp_expire != -1) && (today >= stp->sp_expire))
{