Skip to content

Commit

Permalink
prepare for 0.11.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey Austin committed Jan 25, 2020
1 parent 705813a commit da74807
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-01-25 Mikey Austin <[email protected]>

* Improved file logging module
* Updated logger to always write to stderr

2020-01-24 Mikey Austin <[email protected]>

* Added new log_to_file configuration
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ([2.68])
AC_INIT([greyd], [0.11.5], [[email protected]])
AC_INIT([greyd], [0.11.6], [[email protected]])
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE
LT_INIT([dlopen])
Expand Down
2 changes: 2 additions & 0 deletions packages/docker/Dockerfile.greyd.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ RUN rpm --import https://greyd.org/repo/greyd_pkg_sign_pub.asc && \

EXPOSE 8025/tcp

RUN ln -sf /dev/stdout /tmp/greyd.log

# Override config at /etc/greyd/greyd.conf
ENTRYPOINT [ "/usr/sbin/greyd", "-F" ]
53 changes: 41 additions & 12 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @file log.c
* @brief Logging interface implementation.
* @author Mikey Austin
* @date 2014
* @date 2014-2020
*/

#include "constants.h"
Expand All @@ -35,15 +35,21 @@
static short Log_debug = 0;
static short Log_syslog = 0;
static const char* Log_ident = NULL;
static FILE* log_file = NULL;
static struct flock lock;

extern void Log_reinit(Config_T config)
{
char *log_file = NULL;
if ((log_file = Config_get_str(config, "log_to_file", NULL, NULL)) != NULL) {
int fd = open(log_file, O_WRONLY);
if (fd >= 0) {
dup2(fd, STDOUT_FILENO);
}
// Lock the entire file.
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_len = 0;
lock.l_start = 0;
lock.l_pid = 0;

char* path = NULL;
if ((path = Config_get_str(config, "log_to_file", NULL, NULL)) != NULL) {
log_file = fopen(path, "a");
}
}

Expand All @@ -61,10 +67,31 @@ Log_setup(Config_T config, const char* prog_name)
Log_reinit(config);
}

static void
write_to(FILE* f, const char* msg, va_list args)
{
// Lock the file for writing.
lock.l_type = F_WRLCK;
if (fcntl(fileno(f), F_SETLK, &lock) == -1) {
return;
}

fprintf(f, "%s[%d]: ", Log_ident, getpid());
vfprintf(f, msg, args);
fprintf(f, "\n");
fflush(f);

// Release the lock.
lock.l_type = F_UNLCK;
if (fcntl(fileno(f), F_SETLK, &lock) == -1) {
return;
}
}

extern void
Log_write(int severity, const char* msg, va_list args)
{
va_list syslog_args;
va_list syslog_args, file_args;

if (Log_debug || (!Log_debug && severity < LOG_DEBUG)) {
if (Log_syslog) {
Expand All @@ -73,9 +100,11 @@ Log_write(int severity, const char* msg, va_list args)
va_end(syslog_args);
}

/* Always write to console. */
printf("%s[%d]: ", Log_ident, getpid());
vprintf(msg, args);
printf("\n");
if (log_file != NULL) {
va_copy(file_args, args);
write_to(log_file, msg, file_args);
}

write_to(stderr, msg, args);
}
}
5 changes: 4 additions & 1 deletion website/downloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<p>Grab the latest distribution:</p>
<ul>
<li>
<a href="https://github.com/mikey-austin/greyd/releases/download/v0.11.6/greyd-0.11.6.tar.gz">greyd-0.11.6.tar.gz</a> - 2020-01-25
</li>
<li>
<a href="https://github.com/mikey-austin/greyd/releases/download/v0.11.5/greyd-0.11.5.tar.gz">greyd-0.11.5.tar.gz</a> - 2020-01-24
</li>
Expand Down Expand Up @@ -80,7 +83,7 @@
</p>

<div class="highlight">
<code>$ tar xzf greyd-0.11.5.tar.gz && cd greyd-0.11.5
<code>$ tar xzf greyd-0.11.6.tar.gz && cd greyd-0.11.6
$ ./configure --with-sqlite --with-netfilter
$ make
$ sudo make install</code>
Expand Down

0 comments on commit da74807

Please sign in to comment.