Syslog Unix socket patch

SplitIce mat999 at gmail.com
Thu Oct 29 10:02:35 UTC 2015


In case its relevant we have been running a very similar patch Nils since
the introduction of the syslog feature.

Since the default and expected format on the /dev/log socket is to write
without hostname perhaps unix socket should default to hostname=0 ?

On Wed, Oct 28, 2015 at 6:21 AM, Nils Hermansson <3tnica at gmail.com> wrote:

> Created a new patch as disabling hostame as a configuration option.
>
> # HG changeset patch
> # User Nils Hermansson <3tnica at gmail.com>
> # Date 1445973553 -3600
> #      Tue Oct 27 20:19:13 2015 +0100
> # Node ID 7e4f788192183a3053cd9478ee136bad269a2375
> # Parent  f1424eef1966c966e5403c44e3d9470e0af5b7e9
> Syslog configuration for disabling sending of hostname.
> hostname=(on/off) default on
>
> diff -r f1424eef1966 -r 7e4f78819218 src/core/ngx_syslog.c
> --- a/src/core/ngx_syslog.c     Tue Oct 27 16:47:30 2015 +0300
> +++ b/src/core/ngx_syslog.c     Tue Oct 27 20:19:13 2015 +0100
> @@ -42,6 +42,7 @@
>      peer->pool = cf->pool;
>      peer->facility = NGX_CONF_UNSET_UINT;
>      peer->severity = NGX_CONF_UNSET_UINT;
> +    peer->hostname = NGX_CONF_UNSET_UINT;
>
>      if (ngx_syslog_parse_args(cf, peer) != NGX_CONF_OK) {
>          return NGX_CONF_ERROR;
> @@ -53,6 +54,10 @@
>          return NGX_CONF_ERROR;
>      }
>
> +    if (peer->hostname == NGX_CONF_UNSET_UINT) {
> +        peer->hostname = 1; /* enabled */
> +    }
> +
>      if (peer->facility == NGX_CONF_UNSET_UINT) {
>          peer->facility = 23; /* local7 */
>      }
> @@ -193,6 +198,12 @@
>
>              peer->tag.data = p + 4;
>              peer->tag.len = len - 4;
> +        } else if (ngx_strncmp(p, "hostname=", 9) == 0) {
> +               if (ngx_strcmp(p + 9, "off") == 0) {
> +                    peer->hostname = 0;
> +               } else {
> +                    peer->hostname = 1;
> +                }
>
>          } else {
>              ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> @@ -220,6 +231,11 @@
>
>      pri = peer->facility * 8 + peer->severity;
>
> +    if (peer->hostname == 0) {
> +        return ngx_sprintf(buf, "<%ui>%V %V: ", pri,
> &ngx_cached_syslog_time,
> +                           &peer->tag);
> +    }
> +
>      return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri,
> &ngx_cached_syslog_time,
>                         &ngx_cycle->hostname, &peer->tag);
>  }
> diff -r f1424eef1966 -r 7e4f78819218 src/core/ngx_syslog.h
> --- a/src/core/ngx_syslog.h     Tue Oct 27 16:47:30 2015 +0300
> +++ b/src/core/ngx_syslog.h     Tue Oct 27 20:19:13 2015 +0100
> @@ -12,6 +12,7 @@
>      ngx_pool_t       *pool;
>      ngx_uint_t        facility;
>      ngx_uint_t        severity;
> +    ngx_uint_t        hostname;
>      ngx_str_t         tag;
>
>      ngx_addr_t        server;
>
> On Tue, Oct 27, 2015 at 3:14 PM, Vladimir Homutov <vl at nginx.com> wrote:
>
>> On Fri, Oct 23, 2015 at 08:51:56PM +0200, Nils Hermansson wrote:
>> > # HG changeset patch
>> > # User Nils Hermansson <3tnica at gmail.com>
>> > # Date 1445625283 -7200
>> > #      Fri Oct 23 20:34:43 2015 +0200
>> > # Node ID 868fc6b3bf69be611118c597578e749c65698b8c
>> > # Parent  ee16fb0db905cfb858a929374cf623cdf1a0f9d3
>> > Most standard syslog facilicties do not expect hostname when logging to
>> > Unix Sockets.
>> > This patch removes hostname from syslog message when logging to Unix
>> Socket.
>> > Tested on rsyslog and syslog-ng
>> >
>> > diff -r ee16fb0db905 -r 868fc6b3bf69 src/core/ngx_syslog.c
>> > --- a/src/core/ngx_syslog.c     Tue Oct 20 21:28:38 2015 +0300
>> > +++ b/src/core/ngx_syslog.c     Fri Oct 23 20:34:43 2015 +0200
>> > @@ -219,9 +219,17 @@
>> >      ngx_uint_t  pri;
>> >
>> >      pri = peer->facility * 8 + peer->severity;
>> > -
>> > -    return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri,
>> > &ngx_cached_syslog_time,
>> > +#if (NGX_HAVE_UNIX_DOMAIN)
>> > +    if  (peer->server.sockaddr->sa_family == AF_UNIX) {
>> > +        return ngx_sprintf(buf, "<%ui>%V %V: ", pri,
>> > &ngx_cached_syslog_time,
>> > +                       &peer->tag);
>> > +    } else {
>> > +#endif
>> > +        return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri,
>> > &ngx_cached_syslog_time,
>> >                         &ngx_cycle->hostname, &peer->tag);
>> > +#if (NGX_HAVE_UNIX_DOMAIN)
>> > +    }
>> > +#endif
>> >  }
>>
>> Hi Nils,
>>
>> we agree that there is some inconvenience with local syslog and are
>> considering adding configuration option to select desired behaviour
>> at this place.
>>
>> Note that there is a simple solution - to setup your syslog daemon
>> to expect hostname. See https://trac.nginx.org/nginx/ticket/677
>> and https://trac.nginx.org/nginx/ticket/783.
>>
>> Your suggested patch would breaks existing setups and make message
>> content depend on transport, what is undesirable.
>>
>> _______________________________________________
>> nginx-devel mailing list
>> nginx-devel at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>>
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20151029/fae4f101/attachment.html>


More information about the nginx-devel mailing list