syslog: cs/minor changes
This commit is contained in:
parent
5cd7e29a9f
commit
dbd2cbca8e
83
common/log.c
83
common/log.c
@ -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,7 +29,9 @@
|
|||||||
#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.
|
||||||
@ -53,7 +59,8 @@ 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;
|
||||||
}
|
}
|
||||||
@ -119,8 +126,6 @@ internal_log_lvl2str(const enum logLevels lvl, char* str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
enum logReturns DEFAULT_CC
|
enum logReturns DEFAULT_CC
|
||||||
internal_log_start(struct log_config* l_cfg)
|
internal_log_start(struct log_config* l_cfg)
|
||||||
@ -268,9 +273,11 @@ internalReadConfiguration(const char *inFilename,const char *applicationName)
|
|||||||
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
|
||||||
|
to zero. */
|
||||||
ret = internalInitAndAllocStruct();
|
ret = internalInitAndAllocStruct();
|
||||||
if(ret!=LOG_STARTUP_OK){
|
if (ret != LOG_STARTUP_OK)
|
||||||
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,11 +304,12 @@ internalReadConfiguration(const char *inFilename,const char *applicationName)
|
|||||||
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;
|
||||||
@ -353,7 +361,7 @@ internal_config_read_logging(int file, struct log_config* lc, struct list* param
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -395,7 +403,6 @@ 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)
|
||||||
{
|
{
|
||||||
@ -440,7 +447,6 @@ log_start_from_param(const struct log_config* iniParams)
|
|||||||
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.
|
||||||
@ -464,7 +470,8 @@ log_start(const char *iniFile, const char *applicationName)
|
|||||||
if (ret != LOG_STARTUP_OK)
|
if (ret != LOG_STARTUP_OK)
|
||||||
{
|
{
|
||||||
g_writeln("Could not start log");
|
g_writeln("Could not start log");
|
||||||
if(staticLogConfig!=NULL){
|
if (staticLogConfig != NULL)
|
||||||
|
{
|
||||||
g_free(staticLogConfig);
|
g_free(staticLogConfig);
|
||||||
staticLogConfig = NULL;
|
staticLogConfig = NULL;
|
||||||
}
|
}
|
||||||
@ -472,7 +479,8 @@ log_start(const char *iniFile, const char *applicationName)
|
|||||||
}
|
}
|
||||||
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",
|
||||||
|
iniFile);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -482,7 +490,7 @@ log_start(const char *iniFile, const char *applicationName)
|
|||||||
* @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);
|
||||||
@ -495,8 +503,7 @@ log_end()
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -505,7 +512,6 @@ const char* msg, ...)
|
|||||||
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");
|
||||||
@ -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);
|
||||||
@ -554,13 +560,14 @@ const char* msg, ...)
|
|||||||
{
|
{
|
||||||
/* 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
|
||||||
@ -568,7 +575,7 @@ const char* msg, ...)
|
|||||||
#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;
|
||||||
@ -581,12 +588,12 @@ 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)
|
||||||
{
|
{
|
||||||
@ -605,5 +612,3 @@ char *getLogFile(char *replybuf, int bufsize)
|
|||||||
}
|
}
|
||||||
return replybuf;
|
return replybuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
48
common/log.h
48
common/log.h
@ -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,
|
||||||
@ -62,7 +68,6 @@ enum logReturns{
|
|||||||
#define LOG_DBG(args...)
|
#define LOG_DBG(args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct log_config
|
struct log_config
|
||||||
{
|
{
|
||||||
char* program_name;
|
char* program_name;
|
||||||
@ -121,7 +126,7 @@ internal_log_text2level(char* s);
|
|||||||
* @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.
|
||||||
@ -133,8 +138,10 @@ internalInitAndAllocStruct();
|
|||||||
* @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
|
||||||
/**
|
/**
|
||||||
@ -159,7 +166,7 @@ log_start_from_param(const struct log_config *iniParams);
|
|||||||
* @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.
|
||||||
@ -189,4 +196,3 @@ int APP_CC text2bool(char* s);
|
|||||||
*/
|
*/
|
||||||
char *getLogFile(char *replybuf, int bufsize);
|
char *getLogFile(char *replybuf, int bufsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user