Skip to content

Commit

Permalink
Merge pull request #11 from Castaglia/handle-host
Browse files Browse the repository at this point in the history
Make sure to reset internal state when a HOST command has changed the…
  • Loading branch information
Castaglia committed Mar 25, 2017
2 parents 4cfd32c + 2fb9e9e commit 4156080
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions mod_statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ extern xaset_t *server_list;

module statsd_module;

static int statsd_engine = FALSE;
static float statsd_sampling = 1.0F;
#define STATSD_DEFAULT_ENGINE FALSE
#define STATSD_DEFAULT_SAMPLING 1.0F

static int statsd_engine = STATSD_DEFAULT_ENGINE;
static float statsd_sampling = STATSD_DEFAULT_SAMPLING;
static struct statsd *statsd = NULL;

static int statsd_sess_init(void);

static const char *trace_channel = "statsd";

static char *get_cmd_metric(pool *p, const char *cmd) {
Expand Down Expand Up @@ -320,6 +325,31 @@ static void statsd_postparse_ev(const void *event_data, void *user_data) {
}
}

static void statsd_sess_reinit_ev(const void *event_data, void *user_data) {
int res;

/* A HOST command changed the main_server pointer; reinitialize ourselves. */

pr_event_unregister(&statsd_module, "core.exit", statsd_exit_ev);
pr_event_unregister(&statsd_module, "core.session-reinit",
statsd_sess_reinit_ev);

/* Reset internal state. */
statsd_engine = STATSD_DEFAULT_ENGINE;
statsd_sampling = STATSD_DEFAULT_SAMPLING;

if (statsd != NULL) {
statsd_statsd_close(statsd);
statsd = NULL;
}

res = statsd_sess_init();
if (res < 0) {
pr_session_disconnect(&statsd_module, PR_SESS_DISCONNECT_SESSION_INIT_FAILED,
NULL);
}
}

static void statsd_shutdown_ev(const void *event_data, void *user_data) {
if (statsd != NULL) {
statsd_statsd_close(statsd);
Expand Down Expand Up @@ -368,6 +398,9 @@ static int statsd_sess_init(void) {
int port, use_tcp = FALSE;
const pr_netaddr_t *addr;

pr_event_register(&statsd_module, "core.session-reinit", statsd_sess_reinit_ev,
NULL);

c = find_config(main_server->conf, CONF_PARAM, "StatsdEngine", FALSE);
if (c != NULL) {
statsd_engine = *((int *) c->argv[0]);
Expand Down

0 comments on commit 4156080

Please sign in to comment.