Commit 62edca27 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add trace proxy source settings to dt_host.

trace_proxy uses the new functions to select its trace sources.
This allows cascading of proxies.
parent 3dd26868
......@@ -21,6 +21,7 @@
#include <stdbool.h>
#include <string.h>
#include "dt_host.h"
#include "dt_port_numbers.h"
/* Default values if no config file is found */
static char *controller_host = "localhost";
......@@ -31,6 +32,8 @@ static char *traces_path = "/var/log/dt/traces/";
static unsigned short htdocs_port = 80;
static bool trace_proxy = true;
static bool command_proxy = true;
static char *trace_proxy_src_host = NULL;
static unsigned short trace_proxy_src_port = 0;
static bool init_done = false;
......@@ -81,6 +84,16 @@ static int load_config(void)
g_key_file_get_boolean(keyfile, groups[i], "command_proxy", NULL);
}
}
if (!strcmp(groups[i], "trace_proxy")) {
if (g_key_file_has_key(keyfile, groups[i], "src_host", NULL)) {
trace_proxy_src_host = strdup(
g_key_file_get_string(keyfile, groups[i], "src_host", NULL));
}
if (g_key_file_has_key(keyfile, groups[i], "src_port", NULL)) {
trace_proxy_src_port =
g_key_file_get_integer(keyfile, groups[i], "src_port", NULL);
}
}
if (!strcmp(groups[i], "log")) {
if (g_key_file_has_key(keyfile, groups[i], "path", NULL)) {
log_path = strdup(
......@@ -163,10 +176,38 @@ unsigned short dt_host_htdocs_port(void)
bool dt_host_trace_proxy(void)
{
if (!init_done)
load_config();
return trace_proxy;
}
bool dt_host_command_proxy(void)
{
if (!init_done)
load_config();
return command_proxy;
}
char *dt_host_trace_proxy_src_host(void)
{
if (!init_done)
load_config();
if (!trace_proxy_src_host)
return dt_host_controller();
return trace_proxy_src_host;
}
unsigned short dt_host_trace_proxy_src_port(void)
{
if (!init_done)
load_config();
if (!trace_proxy_src_port)
return CTRL_TRACE_PORT;
return trace_proxy_src_port;
}
......@@ -31,4 +31,7 @@ unsigned short dt_host_htdocs_port(void);
bool dt_host_trace_proxy(void);
bool dt_host_command_proxy(void);
char *dt_host_trace_proxy_src_host(void);
unsigned short dt_host_trace_proxy_src_port(void);
#endif /* _INCLUDE_DT_HOST_H_ */
......@@ -257,13 +257,15 @@ static bool check_client(struct private *priv, int nr)
static bool timespec_mod(struct timespec *t, struct timespec *tdiv)
{
/* TODO: make a proper mod taking both fields into account */
if (tdiv->tv_sec) {
return t->tv_sec % tdiv->tv_sec || t->tv_nsec;
} else if (tdiv->tv_nsec) {
return t->tv_nsec % tdiv->tv_nsec;
}
return false;
uint64_t t64, tdiv64;
t64 = (uint64_t)t->tv_sec * 1000000000ull + (uint64_t)t->tv_nsec;
tdiv64 = (uint64_t)tdiv->tv_sec * 1000000000ull + (uint64_t)tdiv->tv_nsec;
if (!tdiv64)
return false;
return t64 % tdiv64;
}
static void server_value(struct trace *trace,
......@@ -522,8 +524,8 @@ int main (int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
/* determine socket on dt_ctrl */
tr_host = dt_host_controller();
tr_port = CTRL_TRACE_PORT;
tr_host = dt_host_trace_proxy_src_host();
tr_port = dt_host_trace_proxy_src_port();
/* Get list of all traces */
printf("Going to retrieve list of traces\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment