syslog: cs/minor changes

This commit is contained in:
Jay Sorg 2012-06-04 12:51:22 -07:00
parent 5cd7e29a9f
commit dbd2cbca8e
4 changed files with 243 additions and 254 deletions

View File

@ -1,20 +1,24 @@
/* /*
This program is free software; you can redistribute it and/or modify Copyright (c) 2005-2012 Jay Sorg
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, Permission is hereby granted, free of charge, to any person obtaining a
but WITHOUT ANY WARRANTY; without even the implied warranty of copy of this software and associated documentation files (the "Software"),
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the to deal in the Software without restriction, including without limitation
GNU General Public License for more details. the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
You should have received a copy of the GNU General Public License The above copyright notice and this permission notice shall be included
along with this program; if not, write to the Free Software in all copies or substantial portions of the Software.
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2010
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -25,37 +29,40 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include "list.h" #include "list.h"
#include "file.h"
#include "os_calls.h" #include "os_calls.h"
#include "thread_calls.h"
/* Add a define here so that the log.h will hold more information /* Add a define here so that the log.h will hold more information
* when compiled from this C file. * when compiled from this C file.
* When compiled normally the log.h file only contain the public parts * When compiled normally the log.h file only contain the public parts
* of the operators in this file. */ * of the operators in this file. */
#define LOGINTERNALSTUFF #define LOGINTERNALSTUFF
#include "log.h" #include "log.h"
/* Here we store the current state and configuration of the log */ /* Here we store the current state and configuration of the log */
static struct log_config* staticLogConfig = NULL; static struct log_config* staticLogConfig = NULL;
/*This file first start with all private functions. /* This file first start with all private functions.
In the end of the file the public functions is defined*/ In the end of the file the public functions is defined */
/** /**
* *
* @brief Opens log file * @brief Opens log file
* @param fname log file name * @param fname log file name
* @return see open(2) return values * @return see open(2) return values
* *
*/ */
int DEFAULT_CC int DEFAULT_CC
internal_log_file_open(const char* fname) internal_log_file_open(const char* fname)
{ {
int ret = -1 ; int ret = -1;
if(fname!=NULL) if (fname != NULL)
{ {
ret = open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, S_IRUSR |S_IWUSR); ret = open(fname, O_WRONLY | O_CREAT | O_APPEND | O_SYNC,
S_IRUSR | S_IWUSR);
} }
return ret ; return ret;
} }
/** /**
@ -79,7 +86,7 @@ internal_log_xrdp2syslog(const enum logLevels lvl)
case LOG_LEVEL_INFO: case LOG_LEVEL_INFO:
return LOG_INFO; return LOG_INFO;
case LOG_LEVEL_DEBUG: case LOG_LEVEL_DEBUG:
return LOG_DEBUG; return LOG_DEBUG;
default: default:
g_writeln("Undefined log level - programming error"); g_writeln("Undefined log level - programming error");
return LOG_DEBUG; return LOG_DEBUG;
@ -110,17 +117,15 @@ internal_log_lvl2str(const enum logLevels lvl, char* str)
case LOG_LEVEL_INFO: case LOG_LEVEL_INFO:
snprintf(str, 9, "%s", "[INFO ] "); snprintf(str, 9, "%s", "[INFO ] ");
break; break;
case LOG_LEVEL_DEBUG: case LOG_LEVEL_DEBUG:
snprintf(str, 9, "%s", "[DEBUG] "); snprintf(str, 9, "%s", "[DEBUG] ");
break; break;
default: default:
snprintf(str, 9, "%s", "PRG ERR!"); snprintf(str, 9, "%s", "PRG ERR!");
g_writeln("Programming error - undefined log level!!!"); g_writeln("Programming error - undefined log level!!!");
} }
} }
/******************************************************************************/
/******************************************************************************/ /******************************************************************************/
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internal_log_start(struct log_config* l_cfg) internal_log_start(struct log_config* l_cfg)
@ -136,14 +141,14 @@ internal_log_start(struct log_config* l_cfg)
if (0 == l_cfg->log_file) if (0 == l_cfg->log_file)
{ {
g_writeln("log_file not properly assigned"); g_writeln("log_file not properly assigned");
return ret ; return ret;
} }
/* if progname is NULL, we ureturn error */ /* if progname is NULL, we ureturn error */
if (0 == l_cfg->program_name) if (0 == l_cfg->program_name)
{ {
g_writeln("program_name not properly assigned"); g_writeln("program_name not properly assigned");
return ret ; return ret;
} }
/* open file */ /* open file */
@ -172,7 +177,7 @@ internal_log_start(struct log_config* l_cfg)
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internal_log_end(struct log_config* l_cfg) internal_log_end(struct log_config* l_cfg)
{ {
enum logReturns ret = LOG_GENERAL_ERROR ; enum logReturns ret = LOG_GENERAL_ERROR;
/* if log is closed, quit silently */ /* if log is closed, quit silently */
if (0 == l_cfg) if (0 == l_cfg)
{ {
@ -186,7 +191,7 @@ internal_log_end(struct log_config* l_cfg)
{ {
/* closing logfile... */ /* closing logfile... */
g_file_close(l_cfg->fd); g_file_close(l_cfg->fd);
} }
/* if syslog is enabled, close it */ /* if syslog is enabled, close it */
if (l_cfg->enable_syslog) if (l_cfg->enable_syslog)
@ -205,14 +210,14 @@ internal_log_end(struct log_config* l_cfg)
g_free(l_cfg->program_name); g_free(l_cfg->program_name);
l_cfg->program_name = 0; l_cfg->program_name = 0;
} }
ret = LOG_STARTUP_OK ; ret = LOG_STARTUP_OK;
return ret ; return ret;
} }
/** /**
* Converts a string representing th log level to a value * Converts a string representing th log level to a value
* @param buf * @param buf
* @return * @return
*/ */
enum logLevels DEFAULT_CC enum logLevels DEFAULT_CC
internal_log_text2level(char* buf) internal_log_text2level(char* buf)
@ -247,31 +252,33 @@ internal_log_text2level(char* buf)
return LOG_LEVEL_DEBUG; return LOG_LEVEL_DEBUG;
} }
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internalReadConfiguration(const char *inFilename,const char *applicationName) internalReadConfiguration(const char* inFilename, const char* applicationName)
{ {
int fd; int fd;
enum logReturns ret = LOG_GENERAL_ERROR ; enum logReturns ret = LOG_GENERAL_ERROR;
struct list* sec; struct list* sec;
struct list* param_n; struct list* param_n;
struct list* param_v; struct list* param_v;
if(inFilename==NULL) if (inFilename == NULL)
{ {
g_writeln("The inifile is null to readConfiguration!"); g_writeln("The inifile is null to readConfiguration!");
return ret ; return ret;
} }
fd = g_file_open(inFilename); fd = g_file_open(inFilename);
if (-1 == fd) if (-1 == fd)
{ {
ret = LOG_ERROR_NO_CFG ; ret = LOG_ERROR_NO_CFG;
g_writeln("We could not open the configuration file to read log parameters"); g_writeln("We could not open the configuration file to read log parameters");
return ret ; return ret;
} }
// we initialize the memory for the configuration and set all content to zero. /* we initialize the memory for the configuration and set all content
ret = internalInitAndAllocStruct(); to zero. */
if(ret!=LOG_STARTUP_OK){ ret = internalInitAndAllocStruct();
return ret ; if (ret != LOG_STARTUP_OK)
{
return ret;
} }
sec = list_create(); sec = list_create();
@ -281,27 +288,28 @@ internalReadConfiguration(const char *inFilename,const char *applicationName)
param_n->auto_free = 1; param_n->auto_free = 1;
param_v = list_create(); param_v = list_create();
param_v->auto_free = 1; param_v->auto_free = 1;
/* read logging config */ /* read logging config */
ret = internal_config_read_logging(fd, staticLogConfig, param_n, ret = internal_config_read_logging(fd, staticLogConfig, param_n,
param_v, applicationName); param_v, applicationName);
if(ret!=LOG_STARTUP_OK) if (ret != LOG_STARTUP_OK)
{ {
return ret ; return ret;
} }
/* cleanup */ /* cleanup */
list_delete(sec); list_delete(sec);
list_delete(param_v); list_delete(param_v);
list_delete(param_n); list_delete(param_n);
g_file_close(fd); g_file_close(fd);
return ret ; return ret;
} }
/******************************************************************************/ /******************************************************************************/
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internal_config_read_logging(int file, struct log_config* lc, struct list* param_n, internal_config_read_logging(int file, struct log_config* lc,
struct list* param_v,const char *applicationName) struct list* param_n,
struct list* param_v,
const char* applicationName)
{ {
int i; int i;
char* buf; char* buf;
@ -341,38 +349,38 @@ internal_config_read_logging(int file, struct log_config* lc, struct list* param
if (0 == lc->log_file) if (0 == lc->log_file)
{ {
lc->log_file=g_strdup("./sesman.log"); lc->log_file = g_strdup("./sesman.log");
} }
g_printf("logging configuration:\r\n"); g_printf("logging configuration:\r\n");
g_printf("\tLogFile: %s\r\n",lc->log_file); g_printf("\tLogFile: %s\r\n", lc->log_file);
g_printf("\tLogLevel: %i\r\n", lc->log_level); g_printf("\tLogLevel: %i\r\n", lc->log_level);
g_printf("\tEnableSyslog: %i\r\n", lc->enable_syslog); g_printf("\tEnableSyslog: %i\r\n", lc->enable_syslog);
g_printf("\tSyslogLevel: %i\r\n", lc->syslog_level); g_printf("\tSyslogLevel: %i\r\n", lc->syslog_level);
return LOG_STARTUP_OK; return LOG_STARTUP_OK;
} }
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internalInitAndAllocStruct() internalInitAndAllocStruct(void)
{ {
enum logReturns ret = LOG_GENERAL_ERROR ; enum logReturns ret = LOG_GENERAL_ERROR;
staticLogConfig = g_malloc(sizeof(struct log_config),1); staticLogConfig = g_malloc(sizeof(struct log_config), 1);
if(staticLogConfig!=NULL) if (staticLogConfig != NULL)
{ {
staticLogConfig->fd = -1; staticLogConfig->fd = -1;
staticLogConfig->enable_syslog = 0 ; staticLogConfig->enable_syslog = 0;
ret = LOG_STARTUP_OK ; ret = LOG_STARTUP_OK;
} }
else else
{ {
g_writeln("could not allocate memory for log struct") ; g_writeln("could not allocate memory for log struct");
ret = LOG_ERROR_MALLOC ; ret = LOG_ERROR_MALLOC;
} }
return ret ; return ret;
} }
/* /*
* Here below the public functions * Here below the public functions
*/ */
@ -395,123 +403,121 @@ text2bool(char* s)
return 0; return 0;
} }
enum logReturns DEFAULT_CC
enum logReturns DEFAULT_CC
log_start_from_param(const struct log_config* iniParams) log_start_from_param(const struct log_config* iniParams)
{ {
enum logReturns ret = LOG_GENERAL_ERROR ; enum logReturns ret = LOG_GENERAL_ERROR;
if(staticLogConfig!=NULL) if (staticLogConfig != NULL)
{
log_message(LOG_LEVEL_ALWAYS, "Log already initialized");
return ret;
}
if (iniParams == NULL)
{
g_writeln("inparam to log_start_from_param is NULL");
return ret;
}
else
{
/*Copy the struct information*/
ret = internalInitAndAllocStruct();
if (ret != LOG_STARTUP_OK)
{ {
log_message(LOG_LEVEL_ALWAYS,"Log already initialized"); return ret;
return ret ;
} }
if(iniParams==NULL) staticLogConfig->enable_syslog = iniParams->enable_syslog;
staticLogConfig->fd = iniParams->fd;
staticLogConfig->log_file = g_strdup(iniParams->log_file);
staticLogConfig->log_level = iniParams->log_level;
staticLogConfig->log_lock = iniParams->log_lock;
staticLogConfig->log_lock_attr = iniParams->log_lock_attr;
staticLogConfig->program_name = g_strdup(iniParams->program_name);
staticLogConfig->syslog_level = iniParams->syslog_level;
ret = internal_log_start(staticLogConfig);
if (ret != LOG_STARTUP_OK)
{ {
g_writeln("inparam to log_start_from_param is NULL"); g_writeln("Could not start log");
return ret ; if (staticLogConfig != NULL)
}
else
{
/*Copy the struct information*/
ret = internalInitAndAllocStruct();
if(ret!=LOG_STARTUP_OK)
{ {
return ret ; g_free(staticLogConfig);
staticLogConfig = NULL;
} }
staticLogConfig->enable_syslog = iniParams->enable_syslog;
staticLogConfig->fd = iniParams->fd;
staticLogConfig->log_file = g_strdup(iniParams->log_file);
staticLogConfig->log_level = iniParams->log_level ;
staticLogConfig->log_lock = iniParams->log_lock ;
staticLogConfig->log_lock_attr = iniParams->log_lock_attr ;
staticLogConfig->program_name = g_strdup(iniParams->program_name);
staticLogConfig->syslog_level = iniParams->syslog_level;
ret = internal_log_start(staticLogConfig);
if(ret!=LOG_STARTUP_OK)
{
g_writeln("Could not start log");
if(staticLogConfig!=NULL)
{
g_free(staticLogConfig);
staticLogConfig = NULL ;
}
}
} }
return ret ; }
return ret;
} }
/** /**
* This function initialize the log facilities according to the configuration * This function initialize the log facilities according to the configuration
* file, that is described by the in parameter. * file, that is described by the in parameter.
* @param iniFile * @param iniFile
* @param applicationName, the name that is used in the log for the running application * @param applicationName, the name that is used in the log for the running application
* @return 0 on success * @return 0 on success
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_start(const char *iniFile, const char *applicationName) log_start(const char* iniFile, const char* applicationName)
{ {
enum logReturns ret = LOG_GENERAL_ERROR ; enum logReturns ret = LOG_GENERAL_ERROR;
if(applicationName==NULL) if (applicationName == NULL)
{
g_writeln("Programming error your application name cannot be null");
return ret;
}
ret = internalReadConfiguration(iniFile, applicationName);
if (ret == LOG_STARTUP_OK)
{
ret = internal_log_start(staticLogConfig);
if (ret != LOG_STARTUP_OK)
{ {
g_writeln("Programming error your application name cannot be null"); g_writeln("Could not start log");
return ret ; if (staticLogConfig != NULL)
}
ret = internalReadConfiguration(iniFile, applicationName) ;
if(ret==LOG_STARTUP_OK)
{
ret = internal_log_start(staticLogConfig);
if(ret!=LOG_STARTUP_OK)
{ {
g_writeln("Could not start log"); g_free(staticLogConfig);
if(staticLogConfig!=NULL){ staticLogConfig = NULL;
g_free(staticLogConfig);
staticLogConfig = NULL ;
}
} }
} }
else }
{ else
g_writeln("Error reading configuration for log based on config: %s",iniFile); {
} g_writeln("Error reading configuration for log based on config: %s",
return ret ; iniFile);
}
return ret;
} }
/** /**
* Function that terminates all logging * Function that terminates all logging
* @return * @return
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_end() log_end(void)
{ {
enum logReturns ret = LOG_GENERAL_ERROR; enum logReturns ret = LOG_GENERAL_ERROR;
ret = internal_log_end(staticLogConfig); ret = internal_log_end(staticLogConfig);
if(staticLogConfig!=NULL) if (staticLogConfig != NULL)
{ {
g_free(staticLogConfig); g_free(staticLogConfig);
staticLogConfig = NULL ; staticLogConfig = NULL;
} }
return ret ; return ret;
} }
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_message( const enum logLevels lvl, log_message(const enum logLevels lvl, const char* msg, ...)
const char* msg, ...)
{ {
char buff[LOG_BUFFER_SIZE + 31]; /* 19 (datetime) 4 (space+cr+lf+\0) */ char buff[LOG_BUFFER_SIZE + 31]; /* 19 (datetime) 4 (space+cr+lf+\0) */
va_list ap; va_list ap;
int len = 0; int len = 0;
enum logReturns rv = LOG_STARTUP_OK; enum logReturns rv = LOG_STARTUP_OK;
int writereply = 0 ; int writereply = 0;
time_t now_t; time_t now_t;
struct tm* now; struct tm* now;
enum logReturns ret = LOG_GENERAL_ERROR; if (staticLogConfig == NULL)
if(staticLogConfig==NULL) {
{ g_writeln("The log reference is NULL - log not initialized properly");
g_writeln("The log reference is NULL - log not initialized properly");
return LOG_ERROR_NO_CFG; return LOG_ERROR_NO_CFG;
} }
if (0 > staticLogConfig->fd && staticLogConfig->enable_syslog==0) if (0 > staticLogConfig->fd && staticLogConfig->enable_syslog == 0)
{ {
return LOG_ERROR_FILE_NOT_OPEN; return LOG_ERROR_FILE_NOT_OPEN;
} }
@ -519,8 +525,8 @@ const char* msg, ...)
now_t = time(&now_t); now_t = time(&now_t);
now = localtime(&now_t); now = localtime(&now_t);
snprintf(buff, 21, "[%.4d%.2d%.2d-%.2d:%.2d:%.2d] ", (now->tm_year) + 1900, snprintf(buff, 21, "[%.4d%.2d%.2d-%.2d:%.2d:%.2d] ", now->tm_year + 1900,
(now->tm_mon) + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min,
now->tm_sec); now->tm_sec);
internal_log_lvl2str(lvl, buff + 20); internal_log_lvl2str(lvl, buff + 20);
@ -529,49 +535,50 @@ const char* msg, ...)
len = vsnprintf(buff + 28, LOG_BUFFER_SIZE, msg, ap); len = vsnprintf(buff + 28, LOG_BUFFER_SIZE, msg, ap);
va_end(ap); va_end(ap);
/* checking for truncated messages */ /* checking for truncated messages */
if (len > LOG_BUFFER_SIZE) if (len > LOG_BUFFER_SIZE)
{ {
log_message(LOG_LEVEL_WARNING,"next message will be truncated"); log_message(LOG_LEVEL_WARNING, "next message will be truncated");
} }
/* forcing the end of message string */ /* forcing the end of message string */
#ifdef _WIN32 #ifdef _WIN32
buff[len + 28] = '\r'; buff[len + 28] = '\r';
buff[len + 29] = '\n'; buff[len + 29] = '\n';
buff[len + 30] = '\0'; buff[len + 30] = '\0';
#else #else
#ifdef _MACOS #ifdef _MACOS
buff[len + 28] = '\r'; buff[len + 28] = '\r';
buff[len + 29] = '\0'; buff[len + 29] = '\0';
#else #else
buff[len + 28] = '\n'; buff[len + 28] = '\n';
buff[len + 29] = '\0'; buff[len + 29] = '\0';
#endif #endif
#endif #endif
if (staticLogConfig->enable_syslog && (lvl <= staticLogConfig->syslog_level)) if (staticLogConfig->enable_syslog && (lvl <= staticLogConfig->syslog_level))
{ {
/* log to syslog*/ /* log to syslog*/
/* %s fix compiler warning 'not a string literal' */ /* %s fix compiler warning 'not a string literal' */
syslog(internal_log_xrdp2syslog(lvl), "(%d)(%d)%s",g_getpid(),g_gettid(),(char *)(buff + 20)); syslog(internal_log_xrdp2syslog(lvl), "(%d)(%ld)%s", g_getpid(),
tc_get_threadid(), buff + 20);
} }
if (lvl <= staticLogConfig->log_level) if (lvl <= staticLogConfig->log_level)
{ {
/* log to console */ /* log to console */
g_printf((char*)buff); g_printf(buff);
/* log to application logfile */ /* log to application logfile */
#ifdef LOG_ENABLE_THREAD #ifdef LOG_ENABLE_THREAD
pthread_mutex_lock(&(staticLogConfig->log_lock)); pthread_mutex_lock(&(staticLogConfig->log_lock));
#endif #endif
if(staticLogConfig->fd>0) if (staticLogConfig->fd > 0)
{ {
writereply = g_file_write(staticLogConfig->fd, (char*)buff, g_strlen((char*)buff)); writereply = g_file_write(staticLogConfig->fd, buff, g_strlen(buff));
if(writereply <= 0) if (writereply <= 0)
{ {
rv = LOG_ERROR_NULL_FILE; rv = LOG_ERROR_NULL_FILE;
} }
} }
#ifdef LOG_ENABLE_THREAD #ifdef LOG_ENABLE_THREAD
@ -581,29 +588,27 @@ const char* msg, ...)
return rv; return rv;
} }
/** /**
* Return the configured log file name * Return the configured log file name
* @return * @return
*/ */
char *getLogFile(char *replybuf, int bufsize) char* DEFAULT_CC
getLogFile(char* replybuf, int bufsize)
{ {
if(staticLogConfig ) if (staticLogConfig)
{
if (staticLogConfig->log_file)
{ {
if(staticLogConfig->log_file) g_strncpy(replybuf, staticLogConfig->log_file, bufsize);
{
g_strncpy(replybuf, staticLogConfig->log_file,bufsize);
}
else
{
g_sprintf(replybuf,"The log_file name is NULL");
}
} }
else else
{ {
g_snprintf(replybuf,bufsize,"The log is not properly started"); g_sprintf(replybuf, "The log_file name is NULL");
} }
return replybuf ; }
else
{
g_snprintf(replybuf, bufsize, "The log is not properly started");
}
return replybuf;
} }

View File

@ -1,20 +1,24 @@
/* /*
This program is free software; you can redistribute it and/or modify Copyright (c) 2005-2012 Jay Sorg
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, Permission is hereby granted, free of charge, to any person obtaining a
but WITHOUT ANY WARRANTY; without even the implied warranty of copy of this software and associated documentation files (the "Software"),
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the to deal in the Software without restriction, including without limitation
GNU General Public License for more details. the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
You should have received a copy of the GNU General Public License The above copyright notice and this permission notice shall be included
along with this program; if not, write to the Free Software in all copies or substantial portions of the Software.
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2010
*/ */
#ifndef LOG_H #ifndef LOG_H
@ -28,7 +32,8 @@
#define LOG_BUFFER_SIZE 1024 #define LOG_BUFFER_SIZE 1024
/* logging levels */ /* logging levels */
enum logLevels{ enum logLevels
{
LOG_LEVEL_ALWAYS = 0, LOG_LEVEL_ALWAYS = 0,
LOG_LEVEL_ERROR, LOG_LEVEL_ERROR,
LOG_LEVEL_WARNING, LOG_LEVEL_WARNING,
@ -37,7 +42,8 @@ enum logLevels{
}; };
/* startup return values */ /* startup return values */
enum logReturns{ enum logReturns
{
LOG_STARTUP_OK = 0, LOG_STARTUP_OK = 0,
LOG_ERROR_MALLOC, LOG_ERROR_MALLOC,
LOG_ERROR_NULL_FILE, LOG_ERROR_NULL_FILE,
@ -57,12 +63,11 @@ enum logReturns{
/*#define LOG_ENABLE_THREAD*/ /*#define LOG_ENABLE_THREAD*/
#ifdef DEBUG #ifdef DEBUG
#define LOG_DBG(args...) log_message(LOG_LEVEL_DEBUG, args); #define LOG_DBG(args...) log_message(LOG_LEVEL_DEBUG, args);
#else #else
#define LOG_DBG(args...) #define LOG_DBG(args...)
#endif #endif
struct log_config struct log_config
{ {
char* program_name; char* program_name;
@ -99,7 +104,7 @@ internal_log_end(struct log_config* l_cfg);
/** /**
* Converts a log level to a string * Converts a log level to a string
* @param lvl, the loglevel * @param lvl, the loglevel
* @param str pointer where the string will be stored. * @param str pointer where the string will be stored.
*/ */
void DEFAULT_CC void DEFAULT_CC
@ -116,12 +121,12 @@ enum logLevels DEFAULT_CC
internal_log_text2level(char* s); internal_log_text2level(char* s);
/** /**
* A function that init our struct that holds all state and * A function that init our struct that holds all state and
* also init its content. * also init its content.
* @return LOG_STARTUP_OK or LOG_ERROR_MALLOC * @return LOG_STARTUP_OK or LOG_ERROR_MALLOC
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internalInitAndAllocStruct(); internalInitAndAllocStruct(void);
/** /**
* Read configuration from a file and store the values in lists. * Read configuration from a file and store the values in lists.
@ -130,51 +135,53 @@ internalInitAndAllocStruct();
* @param param_n * @param param_n
* @param param_v * @param param_v
* @param applicationName, the application name used in the log events. * @param applicationName, the application name used in the log events.
* @return * @return
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
internal_config_read_logging(int file, struct log_config* lc, struct list* param_n, internal_config_read_logging(int file, struct log_config* lc,
struct list* param_v,const char *applicationName) ; struct list* param_n,
struct list* param_v,
const char *applicationName);
/*End of internal functions*/ /*End of internal functions*/
#endif #endif
/** /**
* This function initialize the log facilities according to the configuration * This function initialize the log facilities according to the configuration
* file, that is described by the in parameter. * file, that is described by the in parameter.
* @param iniFile * @param iniFile
* @param applicationName, the name that is used in the log for the running application * @param applicationName, the name that is used in the log for the running application
* @return LOG_STARTUP_OK on success * @return LOG_STARTUP_OK on success
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_start(const char *iniFile, const char *applicationName) ; log_start(const char* iniFile, const char* applicationName);
/** /**
* An alternative log_start where the caller gives the params directly. * An alternative log_start where the caller gives the params directly.
* @param iniParams * @param iniParams
* @return * @return
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_start_from_param(const struct log_config *iniParams); log_start_from_param(const struct log_config *iniParams);
/** /**
* Function that terminates all logging * Function that terminates all logging
* @return * @return
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_end() ; log_end(void);
/** /**
* the log function that all files use to log an event. * the log function that all files use to log an event.
* @param lvl, the loglevel * @param lvl, the loglevel
* @param msg, the logtext. * @param msg, the logtext.
* @param ... * @param ...
* @return * @return
*/ */
enum logReturns DEFAULT_CC enum logReturns DEFAULT_CC
log_message(const enum logLevels lvl, const char* msg, ...) ; log_message(const enum logLevels lvl, const char* msg, ...);
/** /**
* *
* @brief Reads configuration * @brief Reads configuration
* @param s translates the strings "1", "true" and "yes" in 1 (true) and * @param s translates the strings "1", "true" and "yes" in 1 (true) and
* other strings in 0 * other strings in 0
* @return 0 on success, 1 on failure * @return 0 on success, 1 on failure
* *
@ -185,8 +192,7 @@ int APP_CC text2bool(char* s);
* This function returns the configured file name for the logfile * This function returns the configured file name for the logfile
* @param replybuf the buffer where the reply is stored * @param replybuf the buffer where the reply is stored
* @param bufsize how big is the reply buffer. * @param bufsize how big is the reply buffer.
* @return * @return
*/ */
char *getLogFile(char *replybuf, int bufsize); char *getLogFile(char *replybuf, int bufsize);
#endif #endif

View File

@ -2218,22 +2218,6 @@ g_getpid(void)
#endif #endif
} }
/*****************************************************************************/
int APP_CC
g_gettid(void)
{
#if defined(_WIN32)
return (int)GetCurrentThreadId();
#else
#if defined(__linux__)
/* This is Linux specific way of getting the thread id.
* Function is not part of GLIB so therefore this syscall*/
return (int)syscall(__NR_gettid);
#else
return (int)pthread_self();
#endif
#endif
}
/*****************************************************************************/ /*****************************************************************************/
/* does not work in win32 */ /* does not work in win32 */
int APP_CC int APP_CC

View File

@ -252,12 +252,6 @@ int APP_CC
g_exit(int exit_code); g_exit(int exit_code);
int APP_CC int APP_CC
g_getpid(void); g_getpid(void);
/**
* Returns the current thread ID
* @return
*/
int APP_CC
g_gettid(void);
int APP_CC int APP_CC
g_sigterm(int pid); g_sigterm(int pid);
int APP_CC int APP_CC