updating logging subsystem

ulab-original
ilsimo 17 years ago
parent 8f0045c19b
commit 4c9d3862e5

@ -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 */
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);
g_free(l_cfg);
l_cfg = 0;
l_cfg->program_name = 0;
}
}
/******************************************************************************/

@ -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);
/**
*

@ -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;
}

@ -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));

@ -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

@ -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;
}

@ -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);

@ -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);
}

@ -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;
}
}

@ -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;

@ -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();

@ -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;
}

@ -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;

@ -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))
{

Loading…
Cancel
Save