Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
optionally log the thread-id
  • Loading branch information
Fabian Mauchle committed Mar 22, 2018
1 parent 715bad0 commit e8d99c2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -9,6 +9,7 @@ Changes between 1.6.9 and the master branch
(RADSECPROXY-66, RADSECPROXY-74).
- Reload TLS certificate CRLs on SIGHUP (RADSECPROXY-78).
- Make use of SO_KEEPALIVE for tcp sockets (RADSECPROXY-12).
- Optionally include the thread-id in log messages

Misc:
- libnettle is now an unconditional dependency.
Expand Down
17 changes: 16 additions & 1 deletion debug.c
Expand Up @@ -15,6 +15,7 @@
#include <syslog.h>
#include <errno.h>
#include <assert.h>
#include <pthread.h>
#include "debug.h"
#include "util.h"

Expand All @@ -25,6 +26,7 @@ static FILE *debug_file = NULL;
static int debug_syslogfacility = 0;
static int fticks_syslogfacility = 0;
static uint8_t debug_timestamp = 0;
static uint8_t debug_tid = 0;

void debug_init(char *ident) {
debug_file = stderr;
Expand Down Expand Up @@ -56,6 +58,10 @@ void debug_timestamp_on() {
debug_timestamp = 1;
}

void debug_tid_on() {
debug_tid = 1;
}

uint8_t debug_get_level() {
return debug_level;
}
Expand Down Expand Up @@ -142,9 +148,17 @@ void debug_reopen_log() {

void debug_logit(uint8_t level, const char *format, va_list ap) {
struct timeval now;
char *timebuf;
char *timebuf, *tidbuf;
int priority;

if (debug_tid) {
tidbuf = malloc((3*sizeof(pthread_t)+5)+strlen(format));
sprintf(tidbuf, "(%ld) %s", pthread_self(), format);
format = tidbuf;
} else
tidbuf = NULL;


if (debug_syslogfacility) {
switch (level) {
case DBG_DBG:
Expand Down Expand Up @@ -177,6 +191,7 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
vfprintf(debug_file, format, ap);
fprintf(debug_file, "\n");
}
free(tidbuf);
}

void debug(uint8_t level, char *format, ...) {
Expand Down
1 change: 1 addition & 0 deletions debug.h
Expand Up @@ -18,6 +18,7 @@
void debug_init(char *ident);
void debug_set_level(uint8_t level);
void debug_timestamp_on();
void debug_tid_on();
uint8_t debug_get_level();
void debug(uint8_t level, char *format, ...);
void debugx(int status, uint8_t level, char *format, ...);
Expand Down
3 changes: 3 additions & 0 deletions radsecproxy.c
Expand Up @@ -3133,6 +3133,7 @@ void getmainconfig(const char *configfile) {
"addTTL", CONF_LINT, &addttl,
"LogLevel", CONF_LINT, &loglevel,
"LogDestination", CONF_STR, &options.logdestination,
"LogThreadId", CONF_BLN, &options.logtid,
"LoopPrevention", CONF_BLN, &options.loopprevention,
"Client", CONF_CBK, confclient_cb, NULL,
"Server", CONF_CBK, confserver_cb, NULL,
Expand Down Expand Up @@ -3325,6 +3326,8 @@ int radsecproxy_main(int argc, char **argv) {
}
}
free(options.logdestination);
if (options.logtid)
debug_tid_on();

if (!list_first(clconfs))
debugx(1, DBG_ERR, "No clients configured, nothing to do, exiting");
Expand Down
13 changes: 11 additions & 2 deletions radsecproxy.conf.5.xml
Expand Up @@ -2,7 +2,7 @@
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<refentry>
<refentryinfo>
<date>2016-03-23</date>
<date>2018-03-13</date>
</refentryinfo>
<refmeta>
<refentrytitle>radsecproxy.conf</refentrytitle>
Expand Down Expand Up @@ -177,6 +177,15 @@ blocktype name {
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>LogThreadId</literal></term>
<listitem>
<para>
This can be set to <literal>on</literal> to include the
thread-id in the log messages (useful for debugging).
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><literal>FTicksReporting</literal></term>
Expand Down Expand Up @@ -712,7 +721,7 @@ blocktype name {
<literal>tls</literal>, <literal>certificateNameCheck</literal>,
<literal>matchCertificateAttribute</literal>,
<literal>AddTTL</literal>, <literal>tcpKeepalive</literal>,
<literal>rewrite</literal>,
<literal>rewrite</literal>,
<literal>rewriteIn</literal> and <literal>rewriteOut</literal>
are just as specified for the <literal>client block</literal>
above, except that <literal>defaultServer</literal> (and not
Expand Down
1 change: 1 addition & 0 deletions radsecproxy.h
Expand Up @@ -73,6 +73,7 @@ struct options {
uint32_t ttlattrtype[2];
uint8_t addttl;
uint8_t loglevel;
uint8_t logtid;
uint8_t loopprevention;
enum rsp_fticks_reporting_type fticks_reporting;
enum rsp_fticks_mac_type fticks_mac;
Expand Down

0 comments on commit e8d99c2

Please sign in to comment.