Lines Matching refs:env

85 #define VALID_DTENV(env) ISC_MAGIC_VALID(env, DTENV_MAGIC)
152 dns_dtenv_t *env = NULL;
163 env = isc_mem_get(mctx, sizeof(*env));
164 *env = (dns_dtenv_t){
169 isc_mem_attach(mctx, &env->mctx);
170 isc_mutex_init(&env->reopen_lock);
171 env->path = isc_mem_strdup(env->mctx, path);
172 isc_refcount_init(&env->refcount, 1);
173 isc_stats_create(env->mctx, &env->stats, dns_dnstapcounter_max);
189 fstrm_file_options_set_file_path(ffwopt, env->path);
196 env->path);
207 env->iothr = fstrm_iothr_init(*foptp, &fw);
208 if (env->iothr == NULL) {
215 env->mode = mode;
216 env->max_size = 0;
217 env->rolls = ISC_LOG_ROLLINFINITE;
218 env->fopt = *foptp;
221 env->magic = DTENV_MAGIC;
222 *envp = env;
238 isc_mutex_destroy(&env->reopen_lock);
239 isc_mem_free(env->mctx, env->path);
240 if (env->stats != NULL) {
241 isc_stats_detach(&env->stats);
243 isc_mem_putanddetach(&env->mctx, env, sizeof(dns_dtenv_t));
250 dns_dt_setupfile(dns_dtenv_t *env, uint64_t max_size, int rolls,
252 REQUIRE(VALID_DTENV(env));
258 if (env->mode == dns_dtmode_unix) {
268 env->max_size = max_size;
269 env->rolls = rolls;
270 env->suffix = suffix;
276 dns_dt_reopen(dns_dtenv_t *env, int roll) {
286 REQUIRE(VALID_DTENV(env));
288 loopmgr = isc_loop_getloopmgr(env->loop);
305 if (env->mode == dns_dtmode_file) {
308 fstrm_file_options_set_file_path(ffwopt, env->path);
311 } else if (env->mode == dns_dtmode_unix) {
315 env->path);
331 (roll < 0) ? "reopening" : "rolling", env->path);
335 if (env->iothr != NULL) {
336 fstrm_iothr_destroy(&env->iothr);
340 roll = env->rolls;
343 if (env->mode == dns_dtmode_file && roll != 0) {
348 char *filename = isc_mem_strdup(env->mctx, env->path);
354 file.suffix = env->suffix;
356 isc_mem_free(env->mctx, filename);
360 env->iothr = fstrm_iothr_init(env->fopt, &fw);
361 if (env->iothr == NULL) {
391 toregion(dns_dtenv_t *env, isc_region_t *r, const char *str) {
397 p = (unsigned char *)isc_mem_strdup(env->mctx, str);
401 isc_mem_free(env->mctx, r->base);
414 dns_dt_setidentity(dns_dtenv_t *env, const char *identity) {
415 REQUIRE(VALID_DTENV(env));
417 return toregion(env, &env->identity, identity);
421 dns_dt_setversion(dns_dtenv_t *env, const char *version) {
422 REQUIRE(VALID_DTENV(env));
424 return toregion(env, &env->version, version);
434 dt_queue(dns_dtenv_t *env) {
435 REQUIRE(VALID_DTENV(env));
439 if (env->iothr == NULL) {
449 fstrm_iothr_get_input_queue(env->iothr);
466 dns_dt_getstats(dns_dtenv_t *env, isc_stats_t **statsp) {
467 REQUIRE(VALID_DTENV(env));
470 if (env->stats == NULL) {
473 isc_stats_attach(env->stats, statsp);
478 destroy(dns_dtenv_t *env) {
481 env->magic = 0;
485 if (env->iothr != NULL) {
486 fstrm_iothr_destroy(&env->iothr);
488 if (env->fopt != NULL) {
489 fstrm_iothr_options_destroy(&env->fopt);
492 if (env->identity.base != NULL) {
493 isc_mem_free(env->mctx, env->identity.base);
494 env->identity.length = 0;
496 if (env->version.base != NULL) {
497 isc_mem_free(env->mctx, env->version.base);
498 env->version.length = 0;
500 if (env->path != NULL) {
501 isc_mem_free(env->mctx, env->path);
503 if (env->stats != NULL) {
504 isc_stats_detach(&env->stats);
507 isc_mem_putanddetach(&env->mctx, env, sizeof(*env));
513 dns_dtenv_t *env = *envp;
516 if (isc_refcount_decrement(&env->refcount) == 1) {
517 isc_refcount_destroy(&env->refcount);
518 destroy(env);
551 send_dt(dns_dtenv_t *env, void *buf, size_t len) {
555 REQUIRE(env != NULL);
561 ioq = dt_queue(env);
567 res = fstrm_iothr_submit(env->iothr, ioq, buf, len, fstrm_free_wrapper,
570 if (env->stats != NULL) {
571 isc_stats_increment(env->stats, dns_dnstapcounter_drop);
575 if (env->stats != NULL) {
576 isc_stats_increment(env->stats,
583 init_msg(dns_dtenv_t *env, dns_dtmsg_t *dm, Dnstap__Message__Type mtype) {
591 if (env->identity.length != 0) {
592 dm->d.identity.data = env->identity.base;
593 dm->d.identity.len = env->identity.length;
597 if (env->version.length != 0) {
598 dm->d.version.data = env->version.base;
599 dm->d.version.len = env->version.length;
698 dns_dtenv_t *env = (dns_dtenv_t *)arg;
700 REQUIRE(VALID_DTENV(env));
703 dns_dt_reopen(env, env->rolls);
706 LOCK(&env->reopen_lock);
707 env->reopen_queued = false;
708 UNLOCK(&env->reopen_lock);
716 check_file_size_and_maybe_reopen(dns_dtenv_t *env) {
720 if (env->loop == NULL) {
729 LOCK(&env->reopen_lock);
730 if (env->reopen_queued || stat(env->path, &statbuf) < 0 ||
731 statbuf.st_size <= env->max_size)
740 isc_async_run(env->loop, perform_reopen, env);
741 env->reopen_queued = true;
744 UNLOCK(&env->reopen_lock);