Skip to content

Commit

Permalink
backported syslog-ng core changes from the Premium Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
bazsi committed Dec 20, 2007
1 parent f4eebb5 commit b629b4f
Show file tree
Hide file tree
Showing 54 changed files with 1,253 additions and 431 deletions.
10 changes: 6 additions & 4 deletions contrib/init.d.SuSE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# hacked for syslog-ng from above dudes' syslog script
# Darth Elmo <[email protected]>, 13 Sept 2001
#
# updated for OpenSuse 10 by
# Tamas Pal <[email protected]>, 3, Nov 2006
# NOTES:
#
# Add the new variable SYSLOGNG_PARAMS to /etc/rc.config. Set it equal to
Expand All @@ -31,17 +33,17 @@
# /sbin/init.d/syslog-ng
#
### BEGIN INIT INFO
# Provides: syslog
# Provides: syslog-ng
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Default-Stop: 0 1 6
# Description: Start the system logging daemons
### END INIT INFO

. /etc/rc.config
. /etc/rc.status || exit 1

NGBINDIR=/usr/local/sbin
NGBINDIR=/sbin
BINDIR=/sbin

test -x ${NGBINDIR}/syslog-ng || exit 0
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ libsyslog_ng_a_SOURCES = \
afsocket.c afsocket.h afunix.c afunix.h afinet.c afinet.h afinter.c afinter.h \
children.c children.h stats.c stats.h \
gsockaddr.c gsockaddr.h fdwrite.c fdwrite.h fdread.c fdread.h memtrace.c memtrace.h \
dnscache.c dnscache.h
dnscache.c dnscache.h apphook.c apphook.h serialize.c serialize.h logqueue.c logqueue.h \
atomic.h

cfg-lex.c: cfg-grammar.c

Expand Down
30 changes: 15 additions & 15 deletions src/affile.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ struct _AFFileDestWriter
static gboolean
affile_dw_reapable(AFFileDestWriter *self)
{
return ((LogWriter *) self->writer)->queue->length == 0;
return log_queue_get_length(((LogWriter *) self->writer)->queue) == 0;
}

static gboolean
Expand Down Expand Up @@ -385,7 +385,6 @@ static void
affile_dw_queue(LogPipe *s, LogMessage *lm, gint path_flags)
{
AFFileDestWriter *self = (AFFileDestWriter *) s;

self->last_msg_stamp = time(NULL);
if (!s->pipe_next && self->last_open_stamp < self->last_msg_stamp - self->time_reopen)
{
Expand Down Expand Up @@ -659,9 +658,9 @@ affile_dd_init(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist)
}
else
{
self->writer = persist_config_fetch(persist, affile_dd_format_persist_name(self));
if (self->writer)
affile_dw_set_owner(self->writer, self);
self->single_writer = persist_config_fetch(persist, affile_dd_format_persist_name(self));
if (self->single_writer)
affile_dw_set_owner(self->single_writer, self);
}


Expand Down Expand Up @@ -712,17 +711,18 @@ affile_dd_deinit(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist)
{
AFFileDestDriver *self = (AFFileDestDriver *) s;

/* writer & writer_hash cannot be non-NULL at the same time */
if (self->writer)
/* NOTE: we free all AFFileDestWriter instances here as otherwise we'd
* have circular references between AFFileDestDriver and file writers */
if (self->single_writer)
{
g_assert(self->writer_hash == NULL);

persist_config_add(persist, affile_dd_format_persist_name(self), self->writer, affile_dd_destroy_writer);
self->writer = NULL;
persist_config_add(persist, affile_dd_format_persist_name(self), self->single_writer, affile_dd_destroy_writer);
self->single_writer = NULL;
}
else if (self->writer_hash)
{
g_assert(self->writer == NULL);
g_assert(self->single_writer == NULL);

persist_config_add(persist, affile_dd_format_persist_name(self), self->writer_hash, affile_dd_destroy_writer_hash);
self->writer_hash = NULL;
Expand All @@ -741,12 +741,12 @@ affile_dd_queue(LogPipe *s, LogMessage *msg, gint path_flags)

if (self->flags & AFFILE_NO_EXPAND)
{
if (!self->writer)
if (!self->single_writer)
{
next = affile_dw_new(self, g_string_new(self->filename_template->template->str));
if (next && log_pipe_init(&next->super, self->cfg, NULL))
{
self->writer = next;
self->single_writer = next;
}
else
{
Expand All @@ -756,7 +756,7 @@ affile_dd_queue(LogPipe *s, LogMessage *msg, gint path_flags)
}
else
{
next = self->writer;
next = self->single_writer;
}
}
else
Expand Down Expand Up @@ -801,8 +801,8 @@ affile_dd_free(LogPipe *s)
AFFileDestDriver *self = (AFFileDestDriver *) s;

/* NOTE: this must be NULL as deinit has freed it, otherwise we'd have circular references */
g_assert(self->writer == NULL && self->writer_hash == NULL);
g_assert(self->single_writer == NULL && self->writer_hash == NULL);

log_template_unref(self->filename_template);
log_writer_options_destroy(&self->writer_options);
log_drv_free_instance(&self->super);
Expand Down
2 changes: 1 addition & 1 deletion src/affile.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct _AFFileDestDriver
{
LogDriver super;
LogTemplate *filename_template;
AFFileDestWriter *writer;
AFFileDestWriter *single_writer;
guint32 flags;
uid_t file_uid;
gid_t file_gid;
Expand Down
8 changes: 4 additions & 4 deletions src/afinet.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ afinet_resolve_name(GSockAddr **addr, gchar *name)
break;
#if ENABLE_IPV6
case AF_INET6:
*g_sockaddr_inet6_get_sa((*addr)) = *((struct sockaddr_in6 *) res->ai_addr);
*g_sockaddr_inet6_get_sa(*addr) = *((struct sockaddr_in6 *) res->ai_addr);
break;
#endif
default:
Expand Down Expand Up @@ -499,8 +499,7 @@ afinet_dd_queue(LogPipe *s, LogMessage *msg, gint path_flags)
if (libnet_write(self->lnet_ctx) >= 0)
{
/* we have finished processing msg */
if ((path_flags & PF_FLOW_CTL_OFF) == 0)
log_msg_ack(msg);
log_msg_ack(msg, path_flags);
log_msg_unref(msg);
g_string_free(msg_line, TRUE);

Expand All @@ -519,12 +518,13 @@ afinet_dd_queue(LogPipe *s, LogMessage *msg, gint path_flags)
log_pipe_forward_msg(s, msg, path_flags);
}


LogDriver *
afinet_dd_new(gint af, gchar *host, gint port, guint flags)
{
AFInetDestDriver *self = g_new0(AFInetDestDriver, 1);

afsocket_dd_init_instance(&self->super, &self->sock_options.super, flags);
afsocket_dd_init_instance(&self->super, host, &self->sock_options.super, flags);
self->super.super.super.init = afinet_dd_init;
self->super.super.super.queue = afinet_dd_queue;
if (af == AF_INET)
Expand Down
7 changes: 3 additions & 4 deletions src/afinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "messages.h"


extern GQueue *internal_msg_queue;
static gint next_mark_target = -1;

void
Expand Down Expand Up @@ -71,7 +70,7 @@ afinter_source_prepare(GSource *source, gint *timeout)
{
*timeout = -1;
}
return !g_queue_is_empty(internal_msg_queue);
return msg_queue_length(internal_msg_queue) > 0;
}

static gboolean
Expand All @@ -83,7 +82,7 @@ afinter_source_check(GSource *source)

if (next_mark_target != -1 && next_mark_target <= tv.tv_sec)
return TRUE;
return !g_queue_is_empty(internal_msg_queue);
return msg_queue_length(internal_msg_queue) > 0;
}

static gboolean
Expand All @@ -104,7 +103,7 @@ afinter_source_dispatch(GSource *source,
}
else
{
msg = g_queue_pop_head(internal_msg_queue);
msg = msg_queue_pop(internal_msg_queue);
}


Expand Down
36 changes: 24 additions & 12 deletions src/afsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "afsocket.h"
#include "messages.h"
#include "driver.h"
Expand Down Expand Up @@ -222,8 +222,12 @@ static gboolean
afsocket_sc_init(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist)
{
AFSocketSourceConnection *self = (AFSocketSourceConnection *) s;
gint read_flags = (self->owner->flags & AFSOCKET_DGRAM) ? FR_RECV : 0;
FDRead *reader;

reader = fd_read_new(self->sock, read_flags);

self->reader = log_reader_new(fd_read_new(self->sock, (self->owner->flags & AFSOCKET_DGRAM) ? FR_RECV : 0),
self->reader = log_reader_new(reader,
((self->owner->flags & AFSOCKET_LOCAL) ? LR_LOCAL : 0) |
((self->owner->flags & AFSOCKET_DGRAM) ? LR_PKTTERM : 0),
s, &self->owner->reader_options);
Expand Down Expand Up @@ -342,6 +346,7 @@ afsocket_sd_set_max_connections(LogDriver *s, gint max_connections)
self->max_connections = max_connections;
}


static inline gchar *
afsocket_sd_format_persist_name(AFSocketSourceDriver *self, gboolean listener_name)
{
Expand Down Expand Up @@ -714,6 +719,7 @@ afsocket_dd_reconnect_timer(gpointer s)
return FALSE;
}


static void
afsocket_dd_start_reconnect_timer(AFSocketDestDriver *self)
{
Expand All @@ -728,6 +734,7 @@ afsocket_dd_connected(AFSocketDestDriver *self)
gchar buf1[256], buf2[256];
int error = 0;
socklen_t errorlen = sizeof(error);
FDWrite *write;

if (self->flags & AFSOCKET_STREAM)
{
Expand All @@ -738,20 +745,17 @@ afsocket_dd_connected(AFSocketDestDriver *self)
evt_tag_int("reconnect", self->time_reopen),
NULL);
close(self->fd);

afsocket_dd_start_reconnect_timer(self);
return FALSE;
goto error_reconnect;
}
if (error)
{
msg_error("Connection failed",
evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2))),
evt_tag_errno(EVT_TAG_OSERROR, error),
evt_tag_int("time_reopen", self->time_reopen),
NULL);
close(self->fd);

afsocket_dd_start_reconnect_timer(self);
return FALSE;
goto error_reconnect;
}
}
msg_verbose("Syslog connection established",
Expand All @@ -765,8 +769,13 @@ afsocket_dd_connected(AFSocketDestDriver *self)
self->source_id = 0;
}

log_writer_reopen(self->writer, fd_write_new(self->fd));
write = fd_write_new(self->fd);

log_writer_reopen(self->writer, write);
return TRUE;
error_reconnect:
afsocket_dd_start_reconnect_timer(self);
return FALSE;
}

gboolean
Expand Down Expand Up @@ -814,6 +823,7 @@ afsocket_dd_start_connect(AFSocketDestDriver *self)
evt_tag_errno(EVT_TAG_OSERROR, errno),
NULL);
close(sock);
afsocket_dd_start_reconnect_timer(self);
return FALSE;
}

Expand Down Expand Up @@ -915,14 +925,15 @@ afsocket_dd_free(LogPipe *s)

g_sockaddr_unref(self->bind_addr);
g_sockaddr_unref(self->dest_addr);
log_drv_free_instance(&self->super);
log_pipe_unref(self->writer);
g_free(self->hostname);
log_writer_options_destroy(&self->writer_options);
log_drv_free_instance(&self->super);
g_free(s);
}

void
afsocket_dd_init_instance(AFSocketDestDriver *self, SocketOptions *sock_options, guint32 flags)
afsocket_dd_init_instance(AFSocketDestDriver *self, const gchar *hostname, SocketOptions *sock_options, guint32 flags)
{
log_drv_init_instance(&self->super);

Expand All @@ -934,5 +945,6 @@ afsocket_dd_init_instance(AFSocketDestDriver *self, SocketOptions *sock_options,
self->super.super.notify = afsocket_dd_notify;
self->setup_socket = afsocket_dd_setup_socket;
self->sock_options_ptr = sock_options;
self->hostname = g_strdup(hostname);
self->flags = flags;
}
5 changes: 4 additions & 1 deletion src/afsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct _AFSocketDestDriver
LogPipe *writer;
LogWriterOptions writer_options;

gchar *hostname;
GSockAddr *bind_addr;
GSockAddr *dest_addr;
gint time_reopen;
Expand All @@ -96,7 +97,9 @@ struct _AFSocketDestDriver
gboolean (*setup_socket)(AFSocketDestDriver *s, gint fd);
};

void afsocket_dd_init_instance(AFSocketDestDriver *self, SocketOptions *sock_options, guint32 flags);


void afsocket_dd_init_instance(AFSocketDestDriver *self, const gchar *hostname, SocketOptions *sock_options, guint32 flags);
gboolean afsocket_dd_init(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist);

#endif
1 change: 1 addition & 0 deletions src/afstreams.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ streams_read_new(gint fd)
self->fd = fd;
self->cond = G_IO_IN;
self->read = streams_read_read_method;
self->free_fn = fd_read_free_method;
return self;
}

Expand Down
2 changes: 1 addition & 1 deletion src/afunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ afunix_dd_new(gchar *filename, guint flags)
{
AFUnixDestDriver *self = g_new0(AFUnixDestDriver, 1);

afsocket_dd_init_instance(&self->super, &self->sock_options, flags);
afsocket_dd_init_instance(&self->super, NULL, &self->sock_options, flags);
self->super.bind_addr = g_sockaddr_unix_new(NULL);
self->super.dest_addr = g_sockaddr_unix_new(filename);
return &self->super.super;
Expand Down
3 changes: 1 addition & 2 deletions src/afuser.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ afuser_dd_queue(LogPipe *s, LogMessage *msg, gint path_flags)
}
}
endutent();
if ((path_flags & PF_FLOW_CTL_OFF) == 0)
log_msg_ack(msg);
log_msg_ack(msg, path_flags);
log_msg_unref(msg);
}

Expand Down
Loading

0 comments on commit b629b4f

Please sign in to comment.