<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="Osso Notes">
<title></title></head>
<body>
<p>Hi,
<br>
<br>I recall something related, but I need to check. In that case the clone method wasn't properly initializing all the fields of an object in case it is referenced multiple times.
<br>
<br>Which version are you using?
<br>
<br>I see you have implemented a number of interesting template functions, I'd like to integrate them to syslog-ng if you are permitted to contribute them.
<br>
<br>Also, you might be able to get rid of rewrite rules and simply use the template option for file destinations, that'd get your config much simpler.
<br>
<br>And another note, 3.4 offers junctions and channels that again can make it possible to enclose your rewrites into reusable blocks, and by the use of inline objects, would also simplify the configuration a lot.
<br>
<br>Cheers,
<br>
<br>----- Original message -----
<br>> Hi all,
<br>> I've come across a problem when using the rewrite set function with a
<br>> template function. I've created a custom template function
<br>> 'audit-TPTI-to-Email' and use it in a rewrite: rewrite r_audit_EMail {
<br>>  set("$(audit-TPTI-to-EMail ${MSG})", value("MSG"));
<br>> };
<br>>
<br>> Then call it:
<br>> filter f_audit_pgm{program("AUDIT-*" type("glob"));};
<br>> log {
<br>>  source(s_local);
<br>>  filter(f_audit_pgm);
<br>>  log {
<br>>  destination(d_logID_02);
<br>>  };
<br>>  log {
<br>>  rewrite(r_audit_EMail);
<br>>  rewrite(r_quote_newlines);
<br>>  destination(d_logID_13);
<br>>  };
<br>>  flags(final);
<br>> };
<br>> Everything work fine.
<br>> Then if I add another call to rewrite (i.e. add a second email
<br>> destination): filter f_audit_pgm{program("AUDIT-*" type("glob"));};
<br>> log {
<br>>  source(s_local);
<br>>  filter(f_audit_pgm);
<br>>  log {
<br>>  destination(d_logID_02);
<br>>  };
<br>>  log {
<br>>  rewrite(r_audit_EMail);
<br>>  rewrite(r_quote_newlines);
<br>>  destination(d_logID_13);
<br>>  };
<br>>  log {
<br>>  rewrite(r_audit_EMail);
<br>>  rewrite(r_quote_newlines);
<br>>  destination(d_logID_14);
<br>>  };
<br>>  flags(final);
<br>> };
<br>> Syslog-ng crashes with a segfault.
<br>> I've narrowed in down to any template function (just to make sure *I*
<br>> wasn't screwing something up in my custom function): rewrite r_echo {
<br>> set("$(echo $PROGRAM)" value("PROGRAM")); }; destination d_test1{
<br>> file("/var/log/test1.log"); }; destination d_test2{
<br>> file("/var/log/test2.log"); };
<br>>
<br>> log {
<br>>  source(s_local);
<br>>  log {
<br>>  rewrite(r_echo);
<br>>  destination(d_test1);
<br>>  };
<br>>  log {
<br>>  rewrite(r_echo);
<br>>  destination(d_test2);
<br>>  };
<br>> };
<br>>
<br>> The backtrace:
<br>> Backtrace:
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(plugin_find+0x39)[0x7f3eb76ff019]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(log_template_compile+0x84f)[0x7f3eb7703baf]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(log_rewrite_set_new+0x99)[0x7f3eb76f3349]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so[0x7f3eb76f3371]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(log_center_init_pipe_line+0x35d)[0x7f3eb76dfecd]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(log_center_init_pipe_line+0xd2)[0x7f3eb76dfc42]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(log_center_init+0x56)[0x7f3eb76e0226]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(cfg_init+0xb0)[0x7f3eb76e1530]
<br>> /usr/local/lib/libsyslog-ng-3.3.3.so(main_loop_init+0x11b)[0x7f3eb76f9abb]
<br>> /usr/local/sbin/syslog-ng(main+0x11f)[0x40168f]
<br>> /lib/libc.so.6(__libc_start_main+0xe6)[0x7f3eb6240126]
<br>> /usr/local/sbin/syslog-ng[0x401379]
<br>>
<br>> I threw in some debug statements:
<br>> LogRewrite *
<br>> log_rewrite_set_new(const gchar *new_value)
<br>> {
<br>>  fprintf(stderr, "%s('%s'):\n", __FUNCTION__, new_value);
<br>>
<br>> Plugin *
<br>> plugin_find(GlobalConfig *cfg, gint plugin_type, const gchar
<br>> *plugin_name) {
<br>>  fprintf(stderr, "%s(%p, %d, '%s'): '\n", __FUNCTION__, cfg,
<br>> plugin_type, plugin_name);
<br>>
<br>> Which showed that the 'cfg' pointer is null when rewrite is called the
<br>> second time: log_rewrite_set_new('$(echo $PROGRAM)'):
<br>> plugin_find(0x60e210, 13, 'echo'): '
<br>> plugin_find:  plugin->name = 'sys-to-EMail'
<br>> plugin_find:  plugin->name = 'audit-TPTI-to-EMail'
<br>> plugin_find:  plugin->name = 'quar-TPTI-to-EMail'
<br>> plugin_find:  plugin->name = 'quar-TPTI-to-CEF'
<br>> plugin_find:  plugin->name = 'tab-to-bar'
<br>> plugin_find:  plugin->name = 'tab-to-semicolon'
<br>> plugin_find:  plugin->name = 'tab-to-comma'
<br>> plugin_find:  plugin->name = 'to-upper-case'
<br>> plugin_find:  plugin->name = 'to-lower-case'
<br>> plugin_find:  plugin->name = 'ipv4-to-int'
<br>> plugin_find:  plugin->name = 'log-session-seqnum'
<br>> plugin_find:  plugin->name = 'indent-multi-line'
<br>> plugin_find:  plugin->name = 'if'
<br>> plugin_find:  plugin->name = 'grep'
<br>> plugin_find:  plugin->name = 'echo'
<br>> plugin_find(0x60e210, 2, 'file'): '
<br>> [...]
<br>> log_rewrite_set_new('$(echo $PROGRAM)'):
<br>> plugin_find((nil), 13, 'echo'): '
<br>> *** Segmentation fault
<br>>
<br>> Sooo, my questions are:
<br>> Is this expected behavior?
<br>> Has this been patched already?
<br>> Is there another way I can call a custom function to reformat the
<br>> message field on a destination-by-destination basis?
<br>>
<br>> Thanks,
<br>> Chris
<br>>
<br>> ----------------------------------------
<br>> Christopher Johnson
<br>> <a href="mailto:chris.johnson3@hp.com">chris.johnson3@hp.com</a><<a href="mailto:chris.johnson3@hp.com">mailto:chris.johnson3@hp.com</a>>
<br>> HP Software - Security Product Group
<br>> (916) 785-2817
<br>> ----------------------------------------
<br>>
<br><br></p>
</body>
</html>