mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-14 22:34:41 +00:00
log: function cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
This commit is contained in:
parent
3b6fd3271e
commit
8273ba47c1
103
src/lxc/log.c
103
src/lxc/log.c
@ -167,7 +167,7 @@ static int log_append_stderr(const struct lxc_log_appender *appender,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time)
|
static int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time)
|
||||||
{
|
{
|
||||||
int64_t epoch_to_days, z, era, doe, yoe, year, doy, mp, day, month,
|
int64_t epoch_to_days, z, era, doe, yoe, year, doy, mp, day, month,
|
||||||
d_in_s, hours, h_in_s, minutes, seconds;
|
d_in_s, hours, h_in_s, minutes, seconds;
|
||||||
@ -324,7 +324,6 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
|
|||||||
event->category,
|
event->category,
|
||||||
event->locinfo->file, event->locinfo->func,
|
event->locinfo->file, event->locinfo->func,
|
||||||
event->locinfo->line);
|
event->locinfo->line);
|
||||||
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return n;
|
return n;
|
||||||
|
|
||||||
@ -493,23 +492,6 @@ static char *build_log_path(const char *name, const char *lxcpath)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lxc_log_close(void)
|
|
||||||
{
|
|
||||||
closelog();
|
|
||||||
|
|
||||||
free(log_vmname);
|
|
||||||
log_vmname = NULL;
|
|
||||||
|
|
||||||
if (lxc_log_fd == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
close(lxc_log_fd);
|
|
||||||
lxc_log_fd = -1;
|
|
||||||
|
|
||||||
free(log_fname);
|
|
||||||
log_fname = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This can be called:
|
* This can be called:
|
||||||
* 1. when a program calls lxc_log_init with no logfile parameter (in which
|
* 1. when a program calls lxc_log_init with no logfile parameter (in which
|
||||||
@ -567,39 +549,6 @@ static int _lxc_log_set_file(const char *name, const char *lxcpath, int create_d
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lxc_log_syslog(int facility)
|
|
||||||
{
|
|
||||||
struct lxc_log_appender *appender;
|
|
||||||
|
|
||||||
openlog(log_prefix, LOG_PID, facility);
|
|
||||||
if (!lxc_log_category_lxc.appender) {
|
|
||||||
lxc_log_category_lxc.appender = &log_appender_syslog;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
appender = lxc_log_category_lxc.appender;
|
|
||||||
/* Check if syslog was already added, to avoid creating a loop */
|
|
||||||
while (appender) {
|
|
||||||
if (appender == &log_appender_syslog) {
|
|
||||||
/* not an error: openlog re-opened the connection */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
appender = appender->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
appender = lxc_log_category_lxc.appender;
|
|
||||||
while (appender->next != NULL)
|
|
||||||
appender = appender->next;
|
|
||||||
appender->next = &log_appender_syslog;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void lxc_log_enable_syslog(void)
|
|
||||||
{
|
|
||||||
syslog_enable = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* lxc_log_init:
|
* lxc_log_init:
|
||||||
* Called from lxc front-end programs (like lxc-create, lxc-start) to
|
* Called from lxc front-end programs (like lxc-create, lxc-start) to
|
||||||
@ -675,6 +624,56 @@ int lxc_log_init(struct lxc_log *log)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lxc_log_close(void)
|
||||||
|
{
|
||||||
|
closelog();
|
||||||
|
|
||||||
|
free(log_vmname);
|
||||||
|
log_vmname = NULL;
|
||||||
|
|
||||||
|
if (lxc_log_fd == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
close(lxc_log_fd);
|
||||||
|
lxc_log_fd = -1;
|
||||||
|
|
||||||
|
free(log_fname);
|
||||||
|
log_fname = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_log_syslog(int facility)
|
||||||
|
{
|
||||||
|
struct lxc_log_appender *appender;
|
||||||
|
|
||||||
|
openlog(log_prefix, LOG_PID, facility);
|
||||||
|
if (!lxc_log_category_lxc.appender) {
|
||||||
|
lxc_log_category_lxc.appender = &log_appender_syslog;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
appender = lxc_log_category_lxc.appender;
|
||||||
|
/* Check if syslog was already added, to avoid creating a loop */
|
||||||
|
while (appender) {
|
||||||
|
if (appender == &log_appender_syslog) {
|
||||||
|
/* not an error: openlog re-opened the connection */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
appender = appender->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
appender = lxc_log_category_lxc.appender;
|
||||||
|
while (appender->next != NULL)
|
||||||
|
appender = appender->next;
|
||||||
|
appender->next = &log_appender_syslog;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void lxc_log_enable_syslog(void)
|
||||||
|
{
|
||||||
|
syslog_enable = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is called when we read a lxc.log.level entry in a lxc.conf file. This
|
* This is called when we read a lxc.log.level entry in a lxc.conf file. This
|
||||||
* happens after processing command line arguments, which override the .conf
|
* happens after processing command line arguments, which override the .conf
|
||||||
|
@ -431,14 +431,14 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
|
|||||||
|
|
||||||
extern int lxc_log_fd;
|
extern int lxc_log_fd;
|
||||||
|
|
||||||
extern int lxc_log_set_file(int *fd, const char *fname);
|
|
||||||
extern int lxc_log_syslog(int facility);
|
extern int lxc_log_syslog(int facility);
|
||||||
extern void lxc_log_enable_syslog(void);
|
extern void lxc_log_enable_syslog(void);
|
||||||
extern int lxc_log_set_level(int *dest, int level);
|
extern int lxc_log_set_level(int *dest, int level);
|
||||||
extern void lxc_log_set_prefix(const char *prefix);
|
|
||||||
extern const char *lxc_log_get_file(void);
|
|
||||||
extern int lxc_log_get_level(void);
|
extern int lxc_log_get_level(void);
|
||||||
extern bool lxc_log_has_valid_level(void);
|
extern bool lxc_log_has_valid_level(void);
|
||||||
|
extern int lxc_log_set_file(int *fd, const char *fname);
|
||||||
|
extern const char *lxc_log_get_file(void);
|
||||||
|
extern void lxc_log_set_prefix(const char *prefix);
|
||||||
extern const char *lxc_log_get_prefix(void);
|
extern const char *lxc_log_get_prefix(void);
|
||||||
extern void lxc_log_options_no_override();
|
extern void lxc_log_options_no_override();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user