summaryrefslogtreecommitdiff
path: root/usr.sbin/nsd/util.c
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2014-09-16 17:01:39 +0000
committerBrad Smith <brad@cvs.openbsd.org>2014-09-16 17:01:39 +0000
commit2da82e684cba143b3500a53b71b59ff5bb1350ed (patch)
treece7147be3b7917773809419106a2efaf449b1c0c /usr.sbin/nsd/util.c
parentffd18e58ec16ffa88fbdf29eaf698da450af7402 (diff)
merge conflicts
Diffstat (limited to 'usr.sbin/nsd/util.c')
-rw-r--r--usr.sbin/nsd/util.c107
1 files changed, 62 insertions, 45 deletions
diff --git a/usr.sbin/nsd/util.c b/usr.sbin/nsd/util.c
index 6b58b7472b5..7d93f54b55b 100644
--- a/usr.sbin/nsd/util.c
+++ b/usr.sbin/nsd/util.c
@@ -51,6 +51,7 @@ int verbosity = 0;
static const char *global_ident = NULL;
static log_function_type *current_log_function = log_file;
static FILE *current_log_file = NULL;
+int log_time_asc = 1;
void
log_init(const char *ident)
@@ -135,7 +136,24 @@ log_file(int priority, const char *message)
}
/* Bug #104, add time_t timestamp */
- fprintf(current_log_file, "[%d] %s[%d]: %s: %s",
+#if defined(HAVE_STRFTIME) && defined(HAVE_LOCALTIME_R)
+ if(log_time_asc) {
+ struct timeval tv;
+ char tmbuf[32];
+ tmbuf[0]=0;
+ tv.tv_usec = 0;
+ if(gettimeofday(&tv, NULL) == 0) {
+ struct tm tm;
+ time_t now = (time_t)tv.tv_sec;
+ strftime(tmbuf, sizeof(tmbuf), "%Y-%m-%d %H:%M:%S",
+ localtime_r(&now, &tm));
+ }
+ fprintf(current_log_file, "[%s.%3.3d] %s[%d]: %s: %s",
+ tmbuf, (int)tv.tv_usec/1000,
+ global_ident, (int) getpid(), priority_text, message);
+ } else
+#endif /* have time functions */
+ fprintf(current_log_file, "[%d] %s[%d]: %s: %s",
(int)time(NULL), global_ident, (int) getpid(), priority_text, message);
length = strlen(message);
if (length == 0 || message[length - 1] != '\n') {
@@ -855,9 +873,8 @@ compare_serial(uint32_t a, uint32_t b)
uint16_t
qid_generate(void)
{
-#ifdef HAVE_ARC4RANDOM_UNIFORM
- return (uint16_t) arc4random_uniform(65536);
-#elif HAVE_ARC4RANDOM
+ /* arc4random_uniform not needed because range is a power of 2 */
+#ifdef HAVE_ARC4RANDOM
return (uint16_t) arc4random();
#else
return (uint16_t) random();
@@ -908,59 +925,59 @@ set_previous_owner(struct state_pretty_rr *state, const dname_type *dname)
int
print_rr(FILE *out,
struct state_pretty_rr *state,
- rr_type *record)
+ rr_type *record,
+ region_type* rr_region,
+ buffer_type* output)
{
- region_type *region = region_create(xalloc, free);
- buffer_type *output = buffer_create(region, MAX_RDLENGTH);
rrtype_descriptor_type *descriptor
= rrtype_descriptor_by_type(record->type);
int result;
const dname_type *owner = domain_dname(record->owner);
- const dname_type *owner_origin
- = dname_origin(region, owner);
+ buffer_clear(output);
if (state) {
- if (!state->previous_owner
- || dname_compare(state->previous_owner, owner) != 0) {
- int origin_changed = (!state->previous_owner_origin
- || dname_compare(state->previous_owner_origin,
- owner_origin) != 0);
- if (origin_changed) {
- buffer_printf(output, "$ORIGIN %s\n",
- dname_to_string(owner_origin, NULL));
- }
-
- set_previous_owner(state, owner);
- buffer_printf(output, "%s",
- dname_to_string(owner,
- state->previous_owner_origin));
+ if (!state->previous_owner
+ || dname_compare(state->previous_owner, owner) != 0) {
+ const dname_type *owner_origin
+ = dname_origin(rr_region, owner);
+ int origin_changed = (!state->previous_owner_origin
+ || dname_compare(state->previous_owner_origin,
+ owner_origin) != 0);
+ if (origin_changed) {
+ buffer_printf(output, "$ORIGIN %s\n",
+ dname_to_string(owner_origin, NULL));
}
- } else {
- buffer_printf(output, "%s", dname_to_string(owner, NULL));
- }
-
- buffer_printf(output, "\t%lu\t%s\t%s",
- (unsigned long) record->ttl,
- rrclass_to_string(record->klass),
- rrtype_to_string(record->type));
- result = print_rdata(output, descriptor, record);
- if (!result) {
- /*
- * Some RDATA failed to print, so print the record's
- * RDATA in unknown format.
- */
- result = rdata_atoms_to_unknown_string(output,
- descriptor, record->rdata_count, record->rdatas);
+ set_previous_owner(state, owner);
+ buffer_printf(output, "%s",
+ dname_to_string(owner,
+ state->previous_owner_origin));
+ region_free_all(rr_region);
}
+ } else {
+ buffer_printf(output, "%s", dname_to_string(owner, NULL));
+ }
+
+ buffer_printf(output, "\t%lu\t%s\t%s",
+ (unsigned long) record->ttl,
+ rrclass_to_string(record->klass),
+ rrtype_to_string(record->type));
- if (result) {
- buffer_printf(output, "\n");
- buffer_flip(output);
- result = write_data(out, buffer_current(output),
- buffer_remaining(output));
+ result = print_rdata(output, descriptor, record);
+ if (!result) {
+ /*
+ * Some RDATA failed to print, so print the record's
+ * RDATA in unknown format.
+ */
+ result = rdata_atoms_to_unknown_string(output,
+ descriptor, record->rdata_count, record->rdatas);
}
- region_destroy(region);
+ if (result) {
+ buffer_printf(output, "\n");
+ buffer_flip(output);
+ result = write_data(out, buffer_current(output),
+ buffer_remaining(output));
+ }
return result;
}