[syslog-ng]template() and template_escape() extension for all destination drivers

Balazs Scheidler bazsi@balabit.hu
Wed, 30 Oct 2002 20:47:55 +0100


On Thu, Sep 12, 2002 at 11:29:11AM +0200, Achim Gsell wrote:
> Hi,
> 
> We need the "template()" and "template_escape()" options in all destination 
> drivers, not only in the "file" driver. The attached patch adds these options 
> to all other destination drivers in syslog-ng 1.5.20. We test the patch on 
> Linux 2.2.20 and Solaris 8.
> 
> Is there a reason to have these options available only in the "file" 
> destination driver?

Hi,

I came to having some time to integrate pending patches, and found your
patch. I have a couple of comments, which needs to be fixed before releasing
a syslog-ng with these parts integrated.

* expand_macro & friends should be declared in a header file instead of
  declaring it in every referencing module.  maybe a new file called
  macros.c would be a good way of resolving this problem.

* expand_macros returns a newly allocated string, which must be freed, so
  constructs like this cause memory leaks:

+               if (self->template_output)
+                       A_WRITE_STRING(&self->dest_buf->super,
+                                      c_format("<%i>%S\n",
+                                               msg->pri, expand_macros(self->cfg, self->template_output, self->template_escape, msg)));

c_format() has an option to free an ol_string by specifying 'f' like this:

c_format("%fS", expand_macros()) ...

Otherwise your patch looks ok to me. If you want to have it integrated prior
to 1.6.0 is being released, please send a modified diff.

Thanks in advance,

-- 
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1