]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
expr: log: do not print prefix if it is not set
authorLiping Zhang <liping.zhang@spreadtrum.com>
Sun, 25 Sep 2016 08:54:34 +0000 (16:54 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 4 Oct 2016 06:49:50 +0000 (08:49 +0200)
This will avoid the following ugly display output:
  [ log prefix (null) ]

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/expr/log.c

index e965448442b903d9f78a0fd5b73663b0f4b9b9cf..a231bac9327ec41e532afdaa667d3027aac7e37f 100644 (file)
@@ -230,8 +230,10 @@ static int nftnl_expr_log_snprintf_default(char *buf, size_t size,
        struct nftnl_expr_log *log = nftnl_expr_data(e);
        int ret, offset = 0, len = size;
 
-       ret = snprintf(buf, len, "prefix %s ", log->prefix);
-       SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+       if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX)) {
+               ret = snprintf(buf, len, "prefix %s ", log->prefix);
+               SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+       }
 
        if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP)) {
                ret = snprintf(buf + offset, len,