]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Introduce the 'log-thread-id' configuration option to manage logging 1396/head
authorYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Fri, 23 Jan 2026 16:15:14 +0000 (17:15 +0100)
committerYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Fri, 23 Jan 2026 16:15:14 +0000 (17:15 +0100)
  the system-wide Linux thread ID for easier debugging with system
  tools.

daemon/daemon.c
daemon/remote.c
dnstap/dtstream.c
doc/example.conf.in
doc/unbound.conf.rst
util/config_file.c
util/config_file.h
util/configlexer.lex
util/configparser.y

index eb27fd3ab6c90119e24e1572686fa52cc8e1e4bb..dd9afa3d0b8f7f7d62792667a13e692de0c026e1 100644 (file)
@@ -643,7 +643,7 @@ set_log_thread_id(struct worker* worker, struct config_file* cfg)
        log_assert(worker);
 #if defined(HAVE_GETTID) && !defined(THREADS_DISABLED)
        worker->thread_tid = gettid();
-       if(1/*cfg->log_thread_id*/)
+       if(cfg->log_thread_id)
                log_thread_set(&worker->thread_tid);
        else
 #endif
index 9732ace6df2a105b57076538ac944001d5f84e1f..1754cc84a6e0e0427e92c4189bb723d74ff1cda7 100644 (file)
@@ -5968,6 +5968,7 @@ fr_atomic_copy_cfg(struct config_file* oldcfg, struct config_file* cfg,
        COPY_VAR_int(log_servfail);
        COPY_VAR_ptr(log_identity);
        COPY_VAR_int(log_destaddr);
+       COPY_VAR_int(log_thread_id);
        COPY_VAR_int(hide_identity);
        COPY_VAR_int(hide_version);
        COPY_VAR_int(hide_trustanchor);
@@ -7023,7 +7024,7 @@ fast_reload_thread_setup(struct worker* worker, int fr_verb, int fr_nopause,
        lock_protect(&fr->fr_output_lock, fr->fr_output,
                sizeof(*fr->fr_output));
 #ifdef HAVE_GETTID
-       fr->thread_tid_log = 1; /* worker->env->cfg->log_thread_id */
+       fr->thread_tid_log = worker->env.cfg->log_thread_id;
 #endif
        return 1;
 }
index 748305ce79a7e6d1c60e0b5acabdbc3f95e23ef4..30db6f219402263afd7cd0875caca483f5a1d8b0 100644 (file)
@@ -449,7 +449,7 @@ int dt_io_thread_apply_cfg(struct dt_io_thread* dtio, struct config_file *cfg)
 #endif /* HAVE_SSL */
        }
 #ifdef HAVE_GETTID
-       dtio->thread_tid_log = 1 /*cfg->log_thread_id*/;
+       dtio->thread_tid_log = cfg->log_thread_id;
 #endif
        return 1;
 }
index 296dabbd291ccf69050b7c6b035e8085c9aeb630..d84c8b3fa01358ac10e3d0f5478a47b77f450999 100644 (file)
@@ -496,6 +496,10 @@ server:
        # print log lines that say why queries return SERVFAIL to clients.
        # log-servfail: no
 
+       # log system-wide Linux thread ID, insted of Unbound's internal thread
+       # counter. Only on Linux and only when threads are available.
+       # log-thread-id: no
+
        # the pid file. Can be an absolute path outside of chroot/work dir.
        # pidfile: "@UNBOUND_PIDFILE@"
 
index 8f78fb31d60ce1bdc596e4144356d61587355799..e2ea16ce318f2254073b3598847e5fdcfdb2c8c8 100644 (file)
@@ -1714,6 +1714,15 @@ These options are part of the ``server:`` section.
     Default: no
 
 
+@@UAHL@unbound.conf@log-thread-id@@: *<yes or no>*
+    (Only on Linux and only when threads are available)
+    Logs the system-wide Linux thread ID instead of Unbound's internal thread
+    counter.
+    Can be useful when debugging with system tools.
+
+    Default: no
+
+
 @@UAHL@unbound.conf@pidfile@@: *<filename>*
     The process id is written to the file.
     Default is :file:`"@UNBOUND_PIDFILE@"`.
index 8fd0abba98f92eea7e77d23fffc2562b63ad334b..8f3e46289f565cff14c4e702a5ccc2fd6f88c1d8 100644 (file)
@@ -148,6 +148,7 @@ config_create(void)
        cfg->log_local_actions = 0;
        cfg->log_servfail = 0;
        cfg->log_destaddr = 0;
+       cfg->log_thread_id = 0;
 #ifndef USE_WINSOCK
 #  ifdef USE_MINI_EVENT
        /* select max 1024 sockets */
@@ -748,6 +749,7 @@ int config_set_option(struct config_file* cfg, const char* opt,
        else S_YNO("log-local-actions:", log_local_actions)
        else S_YNO("log-servfail:", log_servfail)
        else S_YNO("log-destaddr:", log_destaddr)
+       else S_YNO("log-thread-id:", log_thread_id)
        else S_YNO("val-permissive-mode:", val_permissive_mode)
        else S_YNO("aggressive-nsec:", aggressive_nsec)
        else S_YNO("ignore-cd-flag:", ignore_cd)
@@ -1205,6 +1207,7 @@ config_get_option(struct config_file* cfg, const char* opt,
        else O_YNO(opt, "log-local-actions", log_local_actions)
        else O_YNO(opt, "log-servfail", log_servfail)
        else O_YNO(opt, "log-destaddr", log_destaddr)
+       else O_YNO(opt, "log-thread-id", log_thread_id)
        else O_STR(opt, "pidfile", pidfile)
        else O_YNO(opt, "hide-identity", hide_identity)
        else O_YNO(opt, "hide-version", hide_version)
index ebdc1b34d30d1c41ec09495fbec81ca6fbd86380..aff3fd78b43ace6cdcbf689ee95c4aa899284fd9 100644 (file)
@@ -367,6 +367,8 @@ struct config_file {
        char* log_identity;
        /** log dest addr for log_replies */
        int log_destaddr;
+       /** log linux thread ID */
+       int log_thread_id;
 
        /** do not report identity (id.server, hostname.bind) */
        int hide_identity;
index 22f98e46429eefb7384aeae1318569479381f65e..566de49abc73462342d4a0ba3c3ca62424280087 100644 (file)
@@ -441,6 +441,7 @@ log-tag-queryreply{COLON}   { YDVAR(1, VAR_LOG_TAG_QUERYREPLY) }
 log-local-actions{COLON}       { YDVAR(1, VAR_LOG_LOCAL_ACTIONS) }
 log-servfail{COLON}            { YDVAR(1, VAR_LOG_SERVFAIL) }
 log-destaddr{COLON}            { YDVAR(1, VAR_LOG_DESTADDR) }
+log-thread-id{COLON}           { YDVAR(1, VAR_LOG_THREAD_ID) }
 local-zone{COLON}              { YDVAR(2, VAR_LOCAL_ZONE) }
 local-data{COLON}              { YDVAR(1, VAR_LOCAL_DATA) }
 local-data-ptr{COLON}          { YDVAR(1, VAR_LOCAL_DATA_PTR) }
index bf9c196fcf2230f5e534ba03be3b05582bd57c89..1bb9d84b534ea74b7c965c5022188ced83e3f753 100644 (file)
@@ -216,7 +216,7 @@ extern struct config_parser_state* cfg_parser;
 %token VAR_LOG_DESTADDR VAR_CACHEDB_CHECK_WHEN_SERVE_EXPIRED
 %token VAR_COOKIE_SECRET_FILE VAR_ITER_SCRUB_NS VAR_ITER_SCRUB_CNAME
 %token VAR_MAX_GLOBAL_QUOTA VAR_HARDEN_UNVERIFIED_GLUE VAR_LOG_TIME_ISO
-%token VAR_ITER_SCRUB_PROMISCUOUS
+%token VAR_ITER_SCRUB_PROMISCUOUS VAR_LOG_THREAD_ID
 
 %%
 toplevelvars: /* empty */ | toplevelvars toplevelvar ;
@@ -288,7 +288,7 @@ content_server: server_num_threads | server_verbosity | server_port |
        server_edns_buffer_size | server_prefetch | server_prefetch_key |
        server_so_sndbuf | server_harden_below_nxdomain | server_ignore_cd_flag |
        server_log_queries | server_log_replies | server_tcp_upstream | server_ssl_upstream |
-       server_log_local_actions |
+       server_log_local_actions | server_log_thread_id |
        server_ssl_service_key | server_ssl_service_pem | server_ssl_port |
        server_https_port | server_http_endpoint | server_http_max_streams |
        server_http_query_buffer_size | server_http_response_buffer_size |
@@ -1347,6 +1347,15 @@ server_log_destaddr: VAR_LOG_DESTADDR STRING_ARG
                free($2);
        }
        ;
+server_log_thread_id: VAR_LOG_THREAD_ID STRING_ARG
+       {
+               OUTYY(("P(server_log_thread_id:%s)\n", $2));
+               if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0)
+                       yyerror("expected yes or no.");
+               else cfg_parser->cfg->log_thread_id = (strcmp($2, "yes")==0);
+               free($2);
+       }
+       ;
 server_log_local_actions: VAR_LOG_LOCAL_ACTIONS STRING_ARG
        {
                OUTYY(("P(server_log_local_actions:%s)\n", $2));