- add comments to logfile library
This commit is contained in:
parent
96409f2ca6
commit
c2f04b5a43
23
logfile.c
23
logfile.c
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2015, Babak Farrokhi
|
* Copyright (c) 2015, Babak Farrokhi
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -32,6 +33,9 @@
|
|||||||
#define _PROGNAME getprogname()
|
#define _PROGNAME getprogname()
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create/open given logfile and initialize appropriate struct
|
||||||
|
*/
|
||||||
log_t *
|
log_t *
|
||||||
log_open(const char *path, mode_t mode)
|
log_open(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -72,6 +76,9 @@ log_open(const char *path, mode_t mode)
|
|||||||
return (lh);
|
return (lh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* close logfile handle and free up allocated struct
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
log_close(const log_t *log)
|
log_close(const log_t *log)
|
||||||
{
|
{
|
||||||
@ -82,6 +89,9 @@ log_close(const log_t *log)
|
|||||||
free((void *)log);
|
free((void *)log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether or not the logfile is opened
|
||||||
|
*/
|
||||||
inline bool
|
inline bool
|
||||||
log_isopen(const log_t *log)
|
log_isopen(const log_t *log)
|
||||||
{
|
{
|
||||||
@ -90,6 +100,9 @@ log_isopen(const log_t *log)
|
|||||||
return (log->fd != -1);
|
return (log->fd != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* close and open logfile, used when a HUP signal is received (mosly in case of log roration)
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
log_reopen(log_t **log)
|
log_reopen(log_t **log)
|
||||||
{
|
{
|
||||||
@ -105,6 +118,10 @@ log_reopen(log_t **log)
|
|||||||
free(newlog);
|
free(newlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* printf given text into logfile
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
log_printf(const log_t *log, const char *format,...)
|
log_printf(const log_t *log, const char *format,...)
|
||||||
{
|
{
|
||||||
@ -123,6 +140,9 @@ log_printf(const log_t *log, const char *format,...)
|
|||||||
write(log->fd, newline, sizeof(*newline));
|
write(log->fd, newline, sizeof(*newline));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* printf into a logfile with timestamp prefix
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
log_tsprintf(const log_t *log, const char *format,...)
|
log_tsprintf(const log_t *log, const char *format,...)
|
||||||
{
|
{
|
||||||
@ -150,6 +170,9 @@ log_tsprintf(const log_t *log, const char *format,...)
|
|||||||
write(log->fd, newline, sizeof(*newline));
|
write(log->fd, newline, sizeof(*newline));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check integrity of logfile with comparing filesystem stat with our use-specified settings
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
log_verify(const log_t *log)
|
log_verify(const log_t *log)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user