}
#endif /* THREADS_DISABLED */
+/**
+ * Function to set the thread local log ID.
+ * Either the internal thread number, or the LWP ID on Linux based on
+ * configuration.
+ */
+static void
+set_log_thread_id(struct worker* worker, struct config_file* cfg)
+{
+ (void)cfg;
+ log_assert(worker);
+#if defined(HAVE_GETTID) && !defined(THREADS_DISABLED)
+ worker->thread_tid = gettid();
+ if(1/*cfg->log_thread_id*/)
+ log_thread_set(&worker->thread_tid);
+ else
+#endif
+ log_thread_set(&worker->thread_num);
+}
+
/**
* Function to start one thread.
* @param arg: user argument.
{
struct worker* worker = (struct worker*)arg;
int port_num = 0;
- log_thread_set(&worker->thread_num);
+ set_log_thread_id(worker, worker->daemon->cfg);
ub_thread_blocksigs();
#ifdef THREADS_DISABLED
/* close pipe ends used by main */
fatal_exit("RPZ requires the respip module");
/* first create all the worker structures, so we can pass
- * them to the newly created threads.
+ * them to the newly created threads.
*/
daemon_create_workers(daemon);
+ /* Set it for the first (main) worker since it does not take part in
+ * the thread_start() procedure.
+ */
+ set_log_thread_id(daemon->workers[0], daemon->cfg);
#if defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)
/* in libev the first inited base gets signals */
int log_thread_get(void)
{
- unsigned int* tid;
+ int* tid;
if(!key_created) return 0;
- tid = (unsigned int*)ub_thread_key_get(logkey);
- return (int)(tid?*tid:0);
+ tid = ub_thread_key_get(logkey);
+ return (tid?*tid:0);
}
void log_ident_set(const char* id)
const char *format, va_list args)
{
char message[MAXSYSLOGMSGLEN];
- unsigned int* tid = (unsigned int*)ub_thread_key_get(logkey);
+ int tid = log_thread_get();
time_t now;
#if defined(HAVE_STRFTIME) && defined(HAVE_LOCALTIME_R)
char tmbuf[32];
vsnprintf(message, sizeof(message), format, args);
#ifdef HAVE_SYSLOG_H
if(logging_to_syslog) {
- syslog(pri, "[%d:%x] %s: %s",
- (int)getpid(), tid?*tid:0, type, message);
+ syslog(pri, "[%d:%d] %s: %s",
+ (int)getpid(), tid, type, message);
return;
}
#elif defined(UB_ON_WINDOWS)
tp=MSG_GENERIC_SUCCESS;
wt=EVENTLOG_SUCCESS;
}
- snprintf(m, sizeof(m), "[%s:%x] %s: %s",
- ident, tid?*tid:0, type, message);
+ snprintf(m, sizeof(m), "[%s:%d] %s: %s",
+ ident, tid, type, message);
s = RegisterEventSource(NULL, SERVICE_NAME);
if(!s) return;
ReportEvent(s, wt, 0, tp, NULL, 1, 0, &str, NULL);
tzbuf[3] = ':';
tzbuf[6] = 0;
}
- fprintf(logfile, "%s.%3.3d%s %s[%d:%x] %s: %s\n",
+ fprintf(logfile, "%s.%3.3d%s %s[%d:%d] %s: %s\n",
tmbuf, (int)tv.tv_usec/1000, tzbuf,
- ident, (int)getpid(), tid?*tid:0, type, message);
+ ident, (int)getpid(), tid, type, message);
#ifdef UB_ON_WINDOWS
/* line buffering does not work on windows */
fflush(logfile);
if(log_time_asc && strftime(tmbuf, sizeof(tmbuf), "%b %d %H:%M:%S",
localtime_r(&now, &tm))%(sizeof(tmbuf)) != 0) {
/* %sizeof buf!=0 because old strftime returned max on error */
- fprintf(logfile, "%s %s[%d:%x] %s: %s\n", tmbuf,
- ident, (int)getpid(), tid?*tid:0, type, message);
+ fprintf(logfile, "%s %s[%d:%d] %s: %s\n", tmbuf,
+ ident, (int)getpid(), tid, type, message);
} else
#elif defined(UB_ON_WINDOWS)
if(log_time_asc && GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL,
tmbuf, sizeof(tmbuf)) && GetDateFormat(LOCALE_USER_DEFAULT, 0,
NULL, NULL, dtbuf, sizeof(dtbuf))) {
- fprintf(logfile, "%s %s %s[%d:%x] %s: %s\n", dtbuf, tmbuf,
- ident, (int)getpid(), tid?*tid:0, type, message);
+ fprintf(logfile, "%s %s %s[%d:%d] %s: %s\n", dtbuf, tmbuf,
+ ident, (int)getpid(), tid, type, message);
} else
#endif
- fprintf(logfile, "[" ARG_LL "d] %s[%d:%x] %s: %s\n", (long long)now,
- ident, (int)getpid(), tid?*tid:0, type, message);
+ fprintf(logfile, "[" ARG_LL "d] %s[%d:%d] %s: %s\n", (long long)now,
+ ident, (int)getpid(), tid, type, message);
#ifdef UB_ON_WINDOWS
/* line buffering does not work on windows */
fflush(logfile);