isc_result_t named_log_setdefaultchannels(isc_logconfig_t *lcfg) { isc_result_t result; isc_logdestination_t destination; /* * By default, the logging library makes "default_debug" log to * stderr. In BIND, we want to override this and log to named.run * instead, unless the -g option was given. */ if (! named_g_logstderr) { destination.file.stream = NULL; destination.file.name = "named.run"; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_DEBUGONLY); if (result != ISC_R_SUCCESS) goto cleanup; } if (named_g_logfile != NULL) { destination.file.stream = NULL; destination.file.name = named_g_logfile; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTLEVEL); if (result != ISC_R_SUCCESS) goto cleanup; } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif /* * Set the initial debug level. */ isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); result = ISC_R_SUCCESS; cleanup: return (result); }
isc_result_t named_log_setsafechannels(isc_logconfig_t *lcfg) { isc_result_t result; isc_logdestination_t destination; if (! named_g_logstderr) { result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL, ISC_LOG_DYNAMIC, NULL, 0); if (result != ISC_R_SUCCESS) goto cleanup; /* * Setting the debug level to zero should get the output * discarded a bit faster. */ isc_log_setdebuglevel(named_g_lctx, 0); } else { isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); } if (named_g_logfile != NULL) { destination.file.stream = NULL; destination.file.name = named_g_logfile; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "default_logfile", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTLEVEL); if (result != ISC_R_SUCCESS) goto cleanup; } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif result = ISC_R_SUCCESS; cleanup: return (result); }
/* * Setup logging to use stderr. */ static isc_result_t setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_setcontext(log); dns_log_init(log); dns_log_setcontext(log); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) == ISC_R_SUCCESS); *logp = log; return (ISC_R_SUCCESS); }
static void log_init(void) { isc_logdestination_t destination; unsigned int flags; /* * Setup a logging context. */ RUNTIME_CHECK(isc_log_create(mctx, &lctx, &lcfg) == ISC_R_SUCCESS); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; flags = ISC_LOG_PRINTTIME; RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, flags) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) == ISC_R_SUCCESS); isc_log_setdebuglevel(lctx, level); }
isc_result_t dns_test_begin(FILE *logfile, isc_boolean_t start_managers) { isc_result_t result; if (start_managers) CHECK(isc_app_start()); if (debug_mem_record) isc_mem_debugging |= ISC_MEM_DEBUGRECORD; CHECK(isc_mem_create(0, 0, &mctx)); CHECK(isc_entropy_create(mctx, &ectx)); CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)); hash_active = ISC_TRUE; CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING)); dst_active = ISC_TRUE; if (logfile != NULL) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_registercategories(lctx, categories); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); destination.file.stream = logfile; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); } dns_result_register(); if (start_managers) CHECK(create_managers()); /* * atf-run changes us to a /tmp directory, so tests * that access test data files must first chdir to the proper * location. */ if (chdir(TESTS) == -1) CHECK(ISC_R_FAILURE); return (ISC_R_SUCCESS); cleanup: dns_test_end(); return (result); }
void setup_logging (int verbose, isc_mem_t * mctx, isc_log_t ** logp) { isc_result_t result; isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; isc_log_t *log = NULL; int level; if (verbose < 0) verbose = 0; switch (verbose) { case 0: /* * We want to see warnings about things like out-of-zone * data in the master file even when not verbose. */ level = ISC_LOG_WARNING; break; case 1: level = ISC_LOG_INFO; break; default: level = ISC_LOG_DEBUG (verbose - 2 + 1); break; } RUNTIME_CHECK (isc_log_create (mctx, &log, &logconfig) == ISC_R_SUCCESS); isc_log_setcontext (log); dns_log_init (log); dns_log_setcontext (log); RUNTIME_CHECK (isc_log_settag (logconfig, program) == ISC_R_SUCCESS); /* * Set up a channel similar to default_stderr except: * - the logging level is passed in * - the program name and logging level are printed * - no time stamp is printed */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel (logconfig, "stderr", ISC_LOG_TOFILEDESC, level, &destination, ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL); check_result (result, "isc_log_createchannel()"); RUNTIME_CHECK (isc_log_usechannel (logconfig, "stderr", NULL, NULL) == ISC_R_SUCCESS); *logp = log; }
isc_result_t ns_log_setsafechannels(isc_logconfig_t *lcfg) { isc_result_t result; #if ISC_FACILITY != LOG_DAEMON isc_logdestination_t destination; #endif if (! ns_g_logstderr) { result = isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TONULL, ISC_LOG_DYNAMIC, NULL, 0); if (result != ISC_R_SUCCESS) goto cleanup; /* * Setting the debug level to zero should get the output * discarded a bit faster. */ isc_log_setdebuglevel(ns_g_lctx, 0); } else { isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel); } #if ISC_FACILITY != LOG_DAEMON destination.facility = ISC_FACILITY; result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, ISC_LOG_INFO, &destination, 0); if (result != ISC_R_SUCCESS) goto cleanup; #endif result = ISC_R_SUCCESS; cleanup: return (result); }
isc_result_t isc_test_begin(FILE *logfile, isc_boolean_t start_managers) { isc_result_t result; isc_mem_debugging |= ISC_MEM_DEBUGRECORD; CHECK(isc_mem_create(0, 0, &mctx)); CHECK(isc_entropy_create(mctx, &ectx)); CHECK(isc_hash_create(mctx, ectx, 255)); hash_active = ISC_TRUE; if (logfile != NULL) { isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; CHECK(isc_log_create(mctx, &lctx, &logconfig)); isc_log_registercategories(lctx, categories); isc_log_setcontext(lctx); destination.file.stream = logfile; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, 0)); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); } #ifdef ISC_PLATFORM_USETHREADS ncpus = isc_os_ncpus(); #else ncpus = 1; #endif if (start_managers) CHECK(create_managers()); return (ISC_R_SUCCESS); cleanup: isc_test_end(); return (result); }
/*% * Set up a logging channel according to the named.conf data * in 'cchan' and add it to 'logconfig'. */ static isc_result_t channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig) { isc_result_t result; isc_logdestination_t dest; unsigned int type; unsigned int flags = 0; int level; const char *channelname; const cfg_obj_t *fileobj = NULL; const cfg_obj_t *syslogobj = NULL; const cfg_obj_t *nullobj = NULL; const cfg_obj_t *stderrobj = NULL; const cfg_obj_t *severity = NULL; int i; channelname = cfg_obj_asstring(cfg_map_getname(channel)); (void)cfg_map_get(channel, "file", &fileobj); (void)cfg_map_get(channel, "syslog", &syslogobj); (void)cfg_map_get(channel, "null", &nullobj); (void)cfg_map_get(channel, "stderr", &stderrobj); i = 0; if (fileobj != NULL) i++; if (syslogobj != NULL) i++; if (nullobj != NULL) i++; if (stderrobj != NULL) i++; if (i != 1) { cfg_obj_log(channel, ns_g_lctx, ISC_LOG_ERROR, "channel '%s': exactly one of file, syslog, " "null, and stderr must be present", channelname); return (ISC_R_FAILURE); } type = ISC_LOG_TONULL; if (fileobj != NULL) { const cfg_obj_t *pathobj = cfg_tuple_get(fileobj, "file"); const cfg_obj_t *sizeobj = cfg_tuple_get(fileobj, "size"); const cfg_obj_t *versionsobj = cfg_tuple_get(fileobj, "versions"); isc_int32_t versions = ISC_LOG_ROLLNEVER; isc_offset_t size = 0; type = ISC_LOG_TOFILE; if (versionsobj != NULL && cfg_obj_isuint32(versionsobj)) versions = cfg_obj_asuint32(versionsobj); if (versionsobj != NULL && cfg_obj_isstring(versionsobj) && strcasecmp(cfg_obj_asstring(versionsobj), "unlimited") == 0) versions = ISC_LOG_ROLLINFINITE; if (sizeobj != NULL && cfg_obj_isuint64(sizeobj) && cfg_obj_asuint64(sizeobj) < ISC_OFFSET_MAXIMUM) size = (isc_offset_t)cfg_obj_asuint64(sizeobj); dest.file.stream = NULL; dest.file.name = cfg_obj_asstring(pathobj); dest.file.versions = versions; dest.file.maximum_size = size; } else if (syslogobj != NULL) { int facility = LOG_DAEMON; type = ISC_LOG_TOSYSLOG; if (cfg_obj_isstring(syslogobj)) { const char *facilitystr = cfg_obj_asstring(syslogobj); (void)isc_syslog_facilityfromstring(facilitystr, &facility); } dest.facility = facility; } else if (stderrobj != NULL) { type = ISC_LOG_TOFILEDESC; dest.file.stream = stderr; dest.file.name = NULL; dest.file.versions = ISC_LOG_ROLLNEVER; dest.file.maximum_size = 0; } /* * Munge flags. */ { const cfg_obj_t *printcat = NULL; const cfg_obj_t *printsev = NULL; const cfg_obj_t *printtime = NULL; const cfg_obj_t *buffered = NULL; (void)cfg_map_get(channel, "print-category", &printcat); (void)cfg_map_get(channel, "print-severity", &printsev); (void)cfg_map_get(channel, "print-time", &printtime); (void)cfg_map_get(channel, "buffered", &buffered); if (printcat != NULL && cfg_obj_asboolean(printcat)) flags |= ISC_LOG_PRINTCATEGORY; if (printtime != NULL && cfg_obj_asboolean(printtime)) flags |= ISC_LOG_PRINTTIME; if (printsev != NULL && cfg_obj_asboolean(printsev)) flags |= ISC_LOG_PRINTLEVEL; if (buffered != NULL && cfg_obj_asboolean(buffered)) flags |= ISC_LOG_BUFFERED; } level = ISC_LOG_INFO; if (cfg_map_get(channel, "severity", &severity) == ISC_R_SUCCESS) { if (cfg_obj_isstring(severity)) { const char *str = cfg_obj_asstring(severity); if (strcasecmp(str, "critical") == 0) level = ISC_LOG_CRITICAL; else if (strcasecmp(str, "error") == 0) level = ISC_LOG_ERROR; else if (strcasecmp(str, "warning") == 0) level = ISC_LOG_WARNING; else if (strcasecmp(str, "notice") == 0) level = ISC_LOG_NOTICE; else if (strcasecmp(str, "info") == 0) level = ISC_LOG_INFO; else if (strcasecmp(str, "dynamic") == 0) level = ISC_LOG_DYNAMIC; } else /* debug */ level = cfg_obj_asuint32(severity); } if (logconfig == NULL) result = ISC_R_SUCCESS; else result = isc_log_createchannel(logconfig, channelname, type, level, &dest, flags); if (result == ISC_R_SUCCESS && type == ISC_LOG_TOFILE) { FILE *fp; /* * Test to make sure that file is a plain file. * Fix defect #22771 */ result = isc_file_isplainfile(dest.file.name); if (result == ISC_R_SUCCESS || result == ISC_R_FILENOTFOUND) { /* * Test that the file can be opened, since * isc_log_open() can't effectively report * failures when called in isc_log_doit(). */ result = isc_stdio_open(dest.file.name, "a", &fp); if (result != ISC_R_SUCCESS) { if (logconfig != NULL && !ns_g_nosyslog) syslog(LOG_ERR, "isc_stdio_open '%s' failed: " "%s", dest.file.name, isc_result_totext(result)); fprintf(stderr, "isc_stdio_open '%s' failed: %s\n", dest.file.name, isc_result_totext(result)); } else (void)isc_stdio_close(fp); goto done; } if (logconfig != NULL && !ns_g_nosyslog) syslog(LOG_ERR, "isc_file_isplainfile '%s' failed: %s", dest.file.name, isc_result_totext(result)); fprintf(stderr, "isc_file_isplainfile '%s' failed: %s\n", dest.file.name, isc_result_totext(result)); } done: return (result); }
int main(int argc, char **argv) { isc_boolean_t show_final_mem = ISC_FALSE; isc_result_t result = ISC_R_SUCCESS; isc_taskmgr_t *taskmgr = NULL; isc_task_t *task = NULL; isc_log_t *log = NULL; isc_logconfig_t *logconfig = NULL; isc_logdestination_t logdest; cfg_parser_t *pctx = NULL; cfg_obj_t *config = NULL; const char *keyname = NULL; char *p; size_t argslen; int ch; int i; result = isc_file_progname(*argv, program, sizeof(program)); if (result != ISC_R_SUCCESS) memcpy(program, "rndc", 5); progname = program; admin_conffile = RNDC_CONFFILE; admin_keyfile = RNDC_KEYFILE; result = isc_app_start(); if (result != ISC_R_SUCCESS) fatal("isc_app_start() failed: %s", isc_result_totext(result)); while ((ch = isc_commandline_parse(argc, argv, "c:k:Mmp:s:Vy:")) != -1) { switch (ch) { case 'c': admin_conffile = isc_commandline_argument; break; case 'k': admin_keyfile = isc_commandline_argument; break; case 'M': isc_mem_debugging = ISC_MEM_DEBUGTRACE; break; case 'm': show_final_mem = ISC_TRUE; break; case 'p': remoteport = atoi(isc_commandline_argument); if (remoteport > 65535 || remoteport == 0) fatal("port '%s' out of range", isc_commandline_argument); break; case 's': servername = isc_commandline_argument; break; case 'V': verbose = ISC_TRUE; break; case 'y': keyname = isc_commandline_argument; break; case '?': usage(0); break; default: fatal("unexpected error parsing command arguments: " "got %c\n", ch); break; } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc < 1) usage(1); isc_random_get(&serial); DO("create memory context", isc_mem_create(0, 0, &mctx)); DO("create socket manager", isc_socketmgr_create(mctx, &socketmgr)); DO("create task manager", isc_taskmgr_create(mctx, 1, 0, &taskmgr)); DO("create task", isc_task_create(taskmgr, 0, &task)); DO("create logging context", isc_log_create(mctx, &log, &logconfig)); isc_log_setcontext(log); DO("setting log tag", isc_log_settag(logconfig, progname)); logdest.file.stream = stderr; logdest.file.name = NULL; logdest.file.versions = ISC_LOG_ROLLNEVER; logdest.file.maximum_size = 0; DO("creating log channel", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO, &logdest, ISC_LOG_PRINTTAG|ISC_LOG_PRINTLEVEL)); DO("enabling log channel", isc_log_usechannel(logconfig, "stderr", NULL, NULL)); parse_config(mctx, log, keyname, &pctx, &config); isccc_result_register(); command = *argv; /* * Convert argc/argv into a space-delimited command string * similar to what the user might enter in interactive mode * (if that were implemented). */ argslen = 0; for (i = 0; i < argc; i++) argslen += strlen(argv[i]) + 1; args = isc_mem_get(mctx, argslen); if (args == NULL) DO("isc_mem_get", ISC_R_NOMEMORY); p = args; for (i = 0; i < argc; i++) { size_t len = strlen(argv[i]); memcpy(p, argv[i], len); p += len; *p++ = ' '; } p--; *p++ = '\0'; INSIST(p == args + argslen); notify("%s", command); if (strcmp(command, "restart") == 0) fatal("'%s' is not implemented", command); DO("post event", isc_app_onrun(mctx, task, rndc_start, NULL)); result = isc_app_run(); if (result != ISC_R_SUCCESS) fatal("isc_app_run() failed: %s", isc_result_totext(result)); if (connects > 0 || sends > 0 || recvs > 0) isc_socket_cancel(sock, task, ISC_SOCKCANCEL_ALL); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socketmgr_destroy(&socketmgr); isc_log_destroy(&log); isc_log_setcontext(NULL); cfg_obj_destroy(pctx, &config); cfg_parser_destroy(&pctx); isc_mem_put(mctx, args, argslen); isccc_ccmsg_invalidate(&ccmsg); if (show_final_mem) isc_mem_stats(mctx, stderr); isc_mem_destroy(&mctx); if (failed) return (1); return (0); }
int main(int argc, char **argv) { UNUSED(argc); UNUSED(argv); rsa = RSA_new(); e = BN_new(); pkey = EVP_PKEY_new(); if ((rsa == NULL) || (e == NULL) || (pkey == NULL) || !EVP_PKEY_set1_RSA(pkey, rsa)) { fprintf(stderr, "fatal error: basic OpenSSL failure\n"); exit(1); } /* e = 0x1000000000001 */ BN_set_bit(e, 0); BN_set_bit(e, 48); if (RSA_generate_key_ex(rsa, bits, e, NULL)) { BN_free(e); RSA_free(rsa); } else { fprintf(stderr, "fatal error: RSA_generate_key_ex() fails " "at file %s line %d\n", __FILE__, __LINE__); exit(1); } dns_result_register(); CHECK(isc_mem_create(0, 0, &mctx), "isc_mem_create()"); CHECK(isc_entropy_create(mctx, &ectx), "isc_entropy_create()"); CHECK(isc_entropy_usebestsource(ectx, &source, "../random.data", ISC_ENTROPY_KEYBOARDNO), "isc_entropy_usebestsource(\"../random.data\")"); CHECK(dst_lib_init2(mctx, ectx, NULL, 0), "dst_lib_init2()"); CHECK(isc_log_create(mctx, &log_, &logconfig), "isc_log_create()"); isc_log_setcontext(log_); dns_log_init(log_); dns_log_setcontext(log_); CHECK(isc_log_settag(logconfig, "bigkey"), "isc_log_settag()"); destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; CHECK(isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level, &destination, ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL), "isc_log_createchannel()"); CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_usechannel()"); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); isc_buffer_constinit(&buf, "example.", strlen("example.")); isc_buffer_add(&buf, strlen("example.")); CHECK(dns_name_fromtext(name, &buf, dns_rootname, 0, NULL), "dns_name_fromtext(\"example.\")"); CHECK(dst_key_buildinternal(name, DNS_KEYALG_RSASHA1, bits, DNS_KEYOWNER_ZONE, DNS_KEYPROTO_DNSSEC, dns_rdataclass_in, pkey, mctx, &key), "dst_key_buildinternal(...)"); CHECK(dst_key_tofile(key, DST_TYPE_PRIVATE | DST_TYPE_PUBLIC, NULL), "dst_key_tofile()"); isc_buffer_init(&buf, filename, sizeof(filename) - 1); isc_buffer_clear(&buf); CHECK(dst_key_buildfilename(key, 0, NULL, &buf), "dst_key_buildfilename()"); printf("%s\n", filename); dst_key_free(&key); isc_log_destroy(&log_); isc_log_setcontext(NULL); dns_log_setcontext(NULL); if (source != NULL) isc_entropy_destroysource(&source); isc_entropy_detach(&ectx); dst_lib_destroy(); dns_name_destroy(); isc_mem_destroy(&mctx); return (0); }
static void setup_logging(FILE *errout) { isc_result_t result; isc_logdestination_t destination; isc_logconfig_t *logconfig = NULL; result = isc_log_create(mctx, &lctx, &logconfig); if (result != ISC_R_SUCCESS) fatal("Couldn't set up logging"); isc_log_registercategories(lctx, categories); isc_log_registermodules(lctx, modules); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); cfg_log_init(lctx); destination.file.stream = errout; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'stderr'"); isc_log_setdebuglevel(lctx, loglevel); result = isc_log_settag(logconfig, ";; "); if (result != ISC_R_SUCCESS) fatal("Couldn't set log tag"); result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_DEFAULT, NULL); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'stderr'"); if (resolve_trace && loglevel < 1) { result = isc_log_createchannel(logconfig, "resolver", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(1), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'resolver'"); result = isc_log_usechannel(logconfig, "resolver", DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'resolver'"); } if (validator_trace && loglevel < 3) { result = isc_log_createchannel(logconfig, "validator", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(3), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'validator'"); result = isc_log_usechannel(logconfig, "validator", DNS_LOGCATEGORY_DNSSEC, DNS_LOGMODULE_VALIDATOR); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'validator'"); } if (message_trace && loglevel < 10) { result = isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(10), &destination, ISC_LOG_PRINTPREFIX); if (result != ISC_R_SUCCESS) fatal("Couldn't set up log channel 'messages'"); result = isc_log_usechannel(logconfig, "messages", DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS); if (result != ISC_R_SUCCESS) fatal("Couldn't attach to log channel 'messagse'"); } }
int main(int argc, char **argv) { isc_result_t result; isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; isc_logconfig_t *lcfg = NULL; isc_logdestination_t destination; cfg_parser_t *pctx = NULL; cfg_obj_t *cfg = NULL; cfg_type_t *type = NULL; isc_boolean_t grammar = ISC_FALSE; isc_boolean_t memstats = ISC_FALSE; char *filename = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); result = isc_log_create(mctx, &lctx, &lcfg); check_result(result, "isc_log_create()"); isc_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME); check_result(result, "isc_log_createchannel()"); result = isc_log_usechannel(lcfg, "_default", NULL, NULL); check_result(result, "isc_log_usechannel()"); /* * Set the initial debug level. */ isc_log_setdebuglevel(lctx, 2); if (argc < 3) usage(); while (argc > 1) { if (strcmp(argv[1], "--grammar") == 0) { grammar = ISC_TRUE; } else if (strcmp(argv[1], "--memstats") == 0) { memstats = ISC_TRUE; } else if (strcmp(argv[1], "--named") == 0) { type = &cfg_type_namedconf; } else if (strcmp(argv[1], "--rndc") == 0) { type = &cfg_type_rndcconf; } else if (argv[1][0] == '-') { usage(); } else { filename = argv[1]; } argv++, argc--; } if (grammar) { if (type == NULL) usage(); cfg_print_grammar(type, output, NULL); } else { if (type == NULL || filename == NULL) usage(); RUNTIME_CHECK(cfg_parser_create(mctx, lctx, &pctx) == ISC_R_SUCCESS); result = cfg_parse_file(pctx, filename, type, &cfg); fprintf(stderr, "read config: %s\n", isc_result_totext(result)); if (result != ISC_R_SUCCESS) exit(1); cfg_print(cfg, output, NULL); cfg_obj_destroy(pctx, &cfg); cfg_parser_destroy(&pctx); } isc_log_destroy(&lctx); if (memstats) isc_mem_stats(mctx, stderr); isc_mem_destroy(&mctx); fflush(stdout); if (ferror(stdout)) { fprintf(stderr, "write error\n"); return (1); } else return (0); }
int main(int argc, char *argv[]) { isc_taskmgr_t *taskmgr; isc_timermgr_t *timermgr; isc_socketmgr_t *socketmgr; isc_socket_t *sock; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; dns_dispatchmgr_t *dispatchmgr; dns_dispatch_t *dispatchv4; dns_view_t *view; isc_entropy_t *ectx; isc_task_t *task; isc_log_t *lctx = NULL; isc_logconfig_t *lcfg = NULL; isc_logdestination_t destination; UNUSED(argv); UNUSED(argc); RUNCHECK(isc_app_start()); dns_result_register(); mctx = NULL; RUNCHECK(isc_mem_create(0, 0, &mctx)); RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; RUNCHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME)); RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL)); isc_log_setdebuglevel(lctx, 9); ectx = NULL; RUNCHECK(isc_entropy_create(mctx, &ectx)); RUNCHECK(isc_entropy_createfilesource(ectx, "/dev/urandom")); RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY)); taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr)); task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); timermgr = NULL; RUNCHECK(isc_timermgr_create(mctx, &timermgr)); socketmgr = NULL; RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr)); isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6; dispatchv4 = NULL; RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &bind_any, 4096, 4, 2, 3, 5, attrs, attrmask, &dispatchv4)); requestmgr = NULL; RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr, dispatchmgr, dispatchv4, NULL, &requestmgr)); ring = NULL; RUNCHECK(dns_tsigkeyring_create(mctx, &ring)); view = NULL; RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); dns_view_setkeyring(view, ring); sock = NULL; RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp, &sock)); setup(); RUNCHECK(isc_app_onrun(mctx, task, console, NULL)); (void)isc_app_run(); if (tsigkey) dns_tsigkey_detach(&tsigkey); dns_requestmgr_shutdown(requestmgr); dns_requestmgr_detach(&requestmgr); dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); isc_timermgr_destroy(&timermgr); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socket_detach(&sock); isc_socketmgr_destroy(&socketmgr); isc_mem_stats(mctx, stdout); dns_view_detach(&view); dst_lib_destroy(); isc_entropy_detach(&ectx); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
int main(int argc, char **argv) { isc_result_t result = ISC_R_SUCCESS; isc_boolean_t show_final_mem = ISC_FALSE; isc_taskmgr_t *taskmgr = NULL; isc_task_t *task = NULL; isc_log_t *log = NULL; isc_logconfig_t *logconfig = NULL; isc_logdestination_t logdest; cfg_parser_t *pctx = NULL; cfg_obj_t *config = NULL; const char *keyname = NULL; struct in_addr in; struct in6_addr in6; char *p; size_t argslen; int ch; int i; result = isc_file_progname(*argv, program, sizeof(program)); if (result != ISC_R_SUCCESS) memmove(program, "rndc", 5); progname = program; admin_conffile = RNDC_CONFFILE; admin_keyfile = RNDC_KEYFILE; isc_sockaddr_any(&local4); isc_sockaddr_any6(&local6); result = isc_app_start(); if (result != ISC_R_SUCCESS) fatal("isc_app_start() failed: %s", isc_result_totext(result)); isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, "b:c:hk:Mmp:qrs:Vy:")) != -1) { switch (ch) { case 'b': if (inet_pton(AF_INET, isc_commandline_argument, &in) == 1) { isc_sockaddr_fromin(&local4, &in, 0); local4set = ISC_TRUE; } else if (inet_pton(AF_INET6, isc_commandline_argument, &in6) == 1) { isc_sockaddr_fromin6(&local6, &in6, 0); local6set = ISC_TRUE; } break; case 'c': admin_conffile = isc_commandline_argument; c_flag = ISC_TRUE; break; case 'k': admin_keyfile = isc_commandline_argument; break; case 'M': isc_mem_debugging = ISC_MEM_DEBUGTRACE; break; case 'm': show_final_mem = ISC_TRUE; break; case 'p': remoteport = atoi(isc_commandline_argument); if (remoteport > 65535 || remoteport == 0) fatal("port '%s' out of range", isc_commandline_argument); break; case 'q': quiet = ISC_TRUE; break; case 'r': showresult = ISC_TRUE; break; case 's': servername = isc_commandline_argument; break; case 'V': verbose = ISC_TRUE; break; case 'y': keyname = isc_commandline_argument; break; case '?': if (isc_commandline_option != '?') { fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); usage(1); } /* FALLTHROUGH */ case 'h': usage(0); break; default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); exit(1); } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc < 1) usage(1); isc_random_get(&serial); DO("create memory context", isc_mem_create(0, 0, &rndc_mctx)); DO("create socket manager", isc_socketmgr_create(rndc_mctx, &socketmgr)); DO("create task manager", isc_taskmgr_create(rndc_mctx, 1, 0, &taskmgr)); DO("create task", isc_task_create(taskmgr, 0, &task)); DO("create logging context", isc_log_create(rndc_mctx, &log, &logconfig)); isc_log_setcontext(log); DO("setting log tag", isc_log_settag(logconfig, progname)); logdest.file.stream = stderr; logdest.file.name = NULL; logdest.file.versions = ISC_LOG_ROLLNEVER; logdest.file.maximum_size = 0; DO("creating log channel", isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO, &logdest, ISC_LOG_PRINTTAG|ISC_LOG_PRINTLEVEL)); DO("enabling log channel", isc_log_usechannel(logconfig, "stderr", NULL, NULL)); parse_config(rndc_mctx, log, keyname, &pctx, &config); isccc_result_register(); command = *argv; DO("allocate data buffer", isc_buffer_allocate(rndc_mctx, &databuf, 2048)); /* * Convert argc/argv into a space-delimited command string * similar to what the user might enter in interactive mode * (if that were implemented). */ argslen = 0; for (i = 0; i < argc; i++) argslen += strlen(argv[i]) + 1; args = isc_mem_get(rndc_mctx, argslen); if (args == NULL) DO("isc_mem_get", ISC_R_NOMEMORY); p = args; for (i = 0; i < argc; i++) { size_t len = strlen(argv[i]); memmove(p, argv[i], len); p += len; *p++ = ' '; } p--; *p++ = '\0'; INSIST(p == args + argslen); notify("%s", command); if (strcmp(command, "restart") == 0) fatal("'%s' is not implemented", command); if (nserveraddrs == 0) get_addresses(servername, (in_port_t) remoteport); DO("post event", isc_app_onrun(rndc_mctx, task, rndc_start, NULL)); result = isc_app_run(); if (result != ISC_R_SUCCESS) fatal("isc_app_run() failed: %s", isc_result_totext(result)); if (connects > 0 || sends > 0 || recvs > 0) isc_socket_cancel(sock, task, ISC_SOCKCANCEL_ALL); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socketmgr_destroy(&socketmgr); isc_log_destroy(&log); isc_log_setcontext(NULL); cfg_obj_destroy(pctx, &config); cfg_parser_destroy(&pctx); isc_mem_put(rndc_mctx, args, argslen); isccc_ccmsg_invalidate(&ccmsg); dns_name_destroy(); isc_buffer_free(&databuf); if (show_final_mem) isc_mem_stats(rndc_mctx, stderr); isc_mem_destroy(&rndc_mctx); if (failed) return (1); return (0); }
int main(int argc, char **argv) { isc_result_t result; isc_logdestination_t destination; UNUSED(argc); UNUSED(argv); dns_result_register(); result = isc_app_start(); check_result(result, "isc_app_start()"); isc_stdtime_get(&now); result = isc_mutex_init(&client_lock); check_result(result, "isc_mutex_init(&client_lock)"); ISC_LIST_INIT(clients); /* * EVERYTHING needs a memory context. */ RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); cmp = NULL; RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp) == ISC_R_SUCCESS); isc_mempool_setname(cmp, "adb test clients"); result = isc_entropy_create(mctx, &ectx); check_result(result, "isc_entropy_create()"); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); check_result(result, "isc_hash_create()"); result = isc_log_create(mctx, &lctx, &lcfg); check_result(result, "isc_log_create()"); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Create and install the default channel. */ destination.file.stream = stderr; destination.file.name = NULL; destination.file.versions = ISC_LOG_ROLLNEVER; destination.file.maximum_size = 0; result = isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME); check_result(result, "isc_log_createchannel()"); result = isc_log_usechannel(lcfg, "_default", NULL, NULL); check_result(result, "isc_log_usechannel()"); /* * Set the initial debug level. */ isc_log_setdebuglevel(lctx, 2); create_managers(); t1 = NULL; result = isc_task_create(taskmgr, 0, &t1); check_result(result, "isc_task_create t1"); t2 = NULL; result = isc_task_create(taskmgr, 0, &t2); check_result(result, "isc_task_create t2"); printf("task 1 = %p\n", t1); printf("task 2 = %p\n", t2); create_view(); adb = view->adb; /* * Lock the entire client list here. This will cause all events * for found names to block as well. */ CLOCK(); lookup("f.root-servers.net."); /* Should be in hints */ lookup("www.iengines.com"); /* should fetch */ lookup("www.isc.org"); /* should fetch */ lookup("www.flame.org"); /* should fetch */ lookup("kechara.flame.org."); /* should fetch */ lookup("moghedien.flame.org."); /* should fetch */ lookup("mailrelay.flame.org."); /* should fetch */ lookup("ipv4v6.flame.org."); /* should fetch */ lookup("nonexistant.flame.org."); /* should fail to be found */ lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */ lookup("i.root-servers.net."); /* Should be in hints */ lookup("www.firstcard.com."); lookup("dns04.flame.org."); CUNLOCK(); sleep(10); dns_adb_dump(adb, stderr); sleep(10); CLOCK(); lookup("f.root-servers.net."); /* Should be in hints */ lookup("www.iengines.com"); /* should fetch */ lookup("www.isc.org"); /* should fetch */ lookup("www.flame.org"); /* should fetch */ lookup("kechara.flame.org."); /* should fetch */ lookup("moghedien.flame.org."); /* should fetch */ lookup("mailrelay.flame.org."); /* should fetch */ lookup("ipv4v6.flame.org."); /* should fetch */ lookup("nonexistant.flame.org."); /* should fail to be found */ lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */ lookup("i.root-servers.net."); /* Should be in hints */ CUNLOCK(); sleep(20); dns_adb_dump(adb, stderr); isc_task_detach(&t1); isc_task_detach(&t2); isc_mem_stats(mctx, stdout); dns_adb_dump(adb, stderr); isc_app_run(); dns_adb_dump(adb, stderr); dns_view_detach(&view); adb = NULL; fprintf(stderr, "Destroying socket manager\n"); isc_socketmgr_destroy(&socketmgr); fprintf(stderr, "Destroying timer manager\n"); isc_timermgr_destroy(&timermgr); fprintf(stderr, "Destroying task manager\n"); isc_taskmgr_destroy(&taskmgr); isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mempool_destroy(&cmp); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
int main(int argc, char **argv) { const char *progname, *syslog_file, *message; int ch, i, file_versions, stderr_line; isc_boolean_t show_final_mem = ISC_FALSE; isc_log_t *lctx; isc_logconfig_t *lcfg; isc_mem_t *mctx; isc_result_t result; isc_logdestination_t destination; const isc_logcategory_t *category; const isc_logmodule_t *module; progname = strrchr(*argv, '/'); if (progname != NULL) progname++; else progname = *argv; syslog_file = SYSLOG_FILE; file_versions = FILE_VERSIONS; while ((ch = isc_commandline_parse(argc, argv, "ms:r:")) != -1) { switch (ch) { case 'm': show_final_mem = ISC_TRUE; break; case 's': syslog_file = isc_commandline_argument; break; case 'r': file_versions = atoi(isc_commandline_argument); if (file_versions < 0 && file_versions != ISC_LOG_ROLLNEVER && file_versions != ISC_LOG_ROLLINFINITE) { fprintf(stderr, "%s: file rotations must be " "%d (ISC_LOG_ROLLNEVER),\n\t" "%d (ISC_LOG_ROLLINFINITE) " "or > 0\n", progname, ISC_LOG_ROLLNEVER, ISC_LOG_ROLLINFINITE); exit(1); } break; case '?': fprintf(stderr, usage, progname); exit(1); } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc > 0) { fprintf(stderr, usage, progname); exit(1); } fprintf(stderr, "EXPECT:\n%s%d%s%s%s", "8 lines to stderr (first 4 numbered, #3 repeated)\n", file_versions == 0 || file_versions == ISC_LOG_ROLLNEVER ? 1 : file_versions > 0 ? file_versions + 1 : FILE_VERSIONS + 1, " " TEST_FILE " files, and\n", "2 lines to syslog\n", "lines ending with exclamation marks are errors\n\n"); isc_log_opensyslog(progname, LOG_PID, LOG_DAEMON); mctx = NULL; lctx = NULL; lcfg = NULL; CHECK(isc_mem_create(0, 0, &mctx)); CHECK(isc_log_create(mctx, &lctx, &lcfg)); CHECK(isc_log_settag(lcfg, progname)); isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); /* * Test isc_log_categorybyname and isc_log_modulebyname. */ category = isc_log_categorybyname(lctx, "notify"); if (category != NULL) fprintf(stderr, "%s category found. (expected)\n", category->name); else fprintf(stderr, "notify category not found!\n"); module = isc_log_modulebyname(lctx, "xyzzy"); if (module != NULL) fprintf(stderr, "%s module found!\n", module->name); else fprintf(stderr, "xyzzy module not found. (expected)\n"); /* * Create a file channel to test file opening, size limiting and * version rolling. */ destination.file.name = TEST_FILE; destination.file.maximum_size = 1; destination.file.versions = file_versions; CHECK(isc_log_createchannel(lcfg, "file_test", ISC_LOG_TOFILE, ISC_LOG_INFO, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTTAG| ISC_LOG_PRINTLEVEL| ISC_LOG_PRINTCATEGORY| ISC_LOG_PRINTMODULE)); /* * Create a dynamic debugging channel to a file descriptor. */ destination.file.stream = stderr; CHECK(isc_log_createchannel(lcfg, "debug_test", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME| ISC_LOG_PRINTLEVEL| ISC_LOG_DEBUGONLY)); /* * Test the usability of the four predefined logging channels. */ CHECK(isc_log_usechannel(lcfg, "default_syslog", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "default_stderr", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "default_debug", DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE)); CHECK(isc_log_usechannel(lcfg, "null", DNS_LOGCATEGORY_DATABASE, NULL)); /* * Use the custom channels. */ CHECK(isc_log_usechannel(lcfg, "file_test", DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB)); CHECK(isc_log_usechannel(lcfg, "debug_test", DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB)); fprintf(stderr, "\n==> stderr begin\n"); /* * Write to the internal default by testing both a category for which * no channel has been specified and a category which was specified * but not with the named module. */ stderr_line = 1; isc_log_write(lctx, DNS_LOGCATEGORY_SECURITY, DNS_LOGMODULE_RBT, ISC_LOG_CRITICAL, "%s (%d)", "Unspecified category and unspecified module to stderr", stderr_line++); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBT, ISC_LOG_CRITICAL, "%s (%d)", "Specified category and unspecified module to stderr", stderr_line++); /* * Write to default_syslog, default_stderr and default_debug. */ isc_log_write(lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_WARNING, "%s (%d twice)", "Using the predefined channels to syslog+stderr", stderr_line++); /* * Write to predefined null channel. */ isc_log_write(lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_RBTDB, ISC_LOG_INFO, "This is to null and should not appear!"); /* * Reset the internal default to use syslog instead of stderr, * and test it. */ CHECK(isc_log_usechannel(lcfg, "default_syslog", ISC_LOGCATEGORY_DEFAULT, NULL)); isc_log_write(lctx, DNS_LOGCATEGORY_SECURITY, DNS_LOGMODULE_RBT, ISC_LOG_ERROR, "%s%s", "This message to the redefined default category should ", "be second in syslog"); /* * Write to the file channel. */ if (file_versions >= 0 || file_versions == ISC_LOG_ROLLINFINITE) { /* * If file_versions is 0 or ISC_LOG_ROLLINFINITE, write * the "should not appear" and "should be in file" messages * to ensure they get rolled. */ if (file_versions <= 0) file_versions = FILE_VERSIONS; else isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "This should be rolled over " "and not appear!"); for (i = file_versions - 1; i >= 0; i--) isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "should be in file %d/%d", i, file_versions - 1); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "should be in base file"); } else { file_versions = FILE_VERSIONS; for (i = 1; i <= file_versions; i++) isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_NOTICE, "This is message %d in the log file", i); } /* * Write a debugging message to a category that has no * debugging channels for the named module. */ isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB, ISC_LOG_DEBUG(1), "This debug message should not appear!"); /* * Write debugging messages to a dynamic debugging channel. */ isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, "This critical message should " "not appear because the debug level is 0!"); isc_log_setdebuglevel(lctx, 3); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_DEBUG(1), "%s (%d)", "Dynamic debugging to stderr", stderr_line++); isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_DEBUG(5), "This debug level is too high and should not appear!"); /* * Test out the duplicate filtering using the debug_test channel. */ isc_log_setduplicateinterval(lcfg, 10); message = "This message should appear only once on stderr"; isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, "%s", message); isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); isc_log_setduplicateinterval(lcfg, 1); message = "This message should appear twice on stderr"; isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); sleep(2); isc_log_write1(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_RBTDB, ISC_LOG_CRITICAL, message); /* * Review where everything went. * XXXDCL NT */ fputc('\n', stderr); system("head " TEST_FILE "*; rm -f " TEST_FILE "*"); freopen(syslog_file, "r", stdin); fprintf(stderr, "\n==> %s <==\n", syslog_file); system("tail -2"); fputc('\n', stderr); isc_log_destroy(&lctx); if (show_final_mem) isc_mem_stats(mctx, stderr); return (0); }