summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2020-02-10 19:48:35 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2020-02-10 19:48:35 (GMT)
commit0d94627836643e7ea3a6a874b20505613041dc19 (patch)
tree909e62600a0173310ae78b21e9774101c2e6aa4d /src
parent6500ad88a8485f37bbaffa5fc7c2618079a458ab (diff)
downloadhdf5-0d94627836643e7ea3a6a874b20505613041dc19.zip
hdf5-0d94627836643e7ea3a6a874b20505613041dc19.tar.gz
hdf5-0d94627836643e7ea3a6a874b20505613041dc19.tar.bz2
Rename loglib_ / LOGLIB_ to hlog_ / HLOG_, remove the syslog-based
implementation, rename hlog_log() to hlog(), hlog_vlog() to vhlog(), et cetera. Rename hlog_lazy() to hlog_fast(). Define some log sinks and use them in the page buffer and in VFD SWMR.
Diffstat (limited to 'src')
-rw-r--r--src/H5Fvfd_swmr.c40
-rw-r--r--src/H5PB.c33
-rw-r--r--src/Makefile.am3
-rw-r--r--src/hlog.c286
-rw-r--r--src/hlog.h190
5 files changed, 260 insertions, 292 deletions
diff --git a/src/H5Fvfd_swmr.c b/src/H5Fvfd_swmr.c
index b105883..471bbe3 100644
--- a/src/H5Fvfd_swmr.c
+++ b/src/H5Fvfd_swmr.c
@@ -48,7 +48,7 @@
#include "H5Pprivate.h" /* Property lists */
#include "H5SMprivate.h" /* Shared Object Header Messages */
#include "H5Tprivate.h" /* Datatypes */
-
+#include "hlog.h"
/****************/
/* Local Macros */
@@ -86,22 +86,10 @@ unsigned int vfd_swmr_api_entries_g = 0;/* Times the library was entered
* on the 0->1 and 1->0
* transitions.
*/
-static const bool ldbg_enabled = false;
-
-static void
-ldbgf(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
-
- if (!ldbg_enabled)
- return;
-
- (void)vprintf(fmt, ap);
-
- va_end(ap);
-}
+HLOG_SINK_DECL(swmr);
+HLOG_SINK_SHORT_DEFN(swmr, all);
+HLOG_SINK_SHORT_DEFN(eot, swmr);
+HLOG_SINK_SHORT_DEFN(shadow_defrees, swmr);
/*
* The head of the end of tick queue (EOT queue) for files opened in either
@@ -362,6 +350,7 @@ H5F_vfd_swmr_close_or_flush(H5F_t *f, hbool_t closing)
TAILQ_REMOVE(&f->shared->shadow_defrees, curr, link);
H5FL_FREE(shadow_defree_t, curr);
}
+ hlog_fast(shadow_defrees, "Emptied deferred shadow frees.");
assert(TAILQ_EMPTY(&f->shared->shadow_defrees));
} else { /* For file flush */
@@ -392,7 +381,7 @@ shadow_range_defer_free(H5F_shared_t *shared, uint64_t offset, uint32_t length)
shadow_defree->tick_num = shared->tick_num;
if (TAILQ_EMPTY(&shared->shadow_defrees))
- ldbgf("Adding to the old images list.\n");
+ hlog_fast(shadow_defrees, "Adding first deferred shadow free.");
TAILQ_INSERT_HEAD(&shared->shadow_defrees, shadow_defree, link);
return 0;
@@ -454,6 +443,7 @@ H5F_update_vfd_swmr_metadata_file(H5F_t *f, uint32_t num_entries,
haddr_t md_addr; /* Address in the metadata file */
unsigned i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
+ bool visited_any_defree = false;
FUNC_ENTER_NOAPI(FAIL)
@@ -564,6 +554,8 @@ H5F_update_vfd_swmr_metadata_file(H5F_t *f, uint32_t num_entries,
TAILQ_FOREACH_REVERSE_SAFE(shadow_defree, &f->shared->shadow_defrees,
shadow_defree_queue, link, prev) {
+ visited_any_defree = true;
+
/* max_lag is at least 3 */
if ( ( f->shared->tick_num > f->shared->vfd_swmr_config.max_lag ) &&
( shadow_defree->tick_num <=
@@ -592,8 +584,8 @@ H5F_update_vfd_swmr_metadata_file(H5F_t *f, uint32_t num_entries,
}
}
- if (TAILQ_EMPTY(&f->shared->shadow_defrees))
- ldbgf("Emptied the old images list.\n");
+ if (visited_any_defree && TAILQ_EMPTY(&f->shared->shadow_defrees))
+ hlog_fast(shadow_defrees, "Removed last deferred shadow free.");
done:
@@ -1112,11 +1104,11 @@ H5F_vfd_swmr_reader_end_of_tick(H5F_t *f)
HDassert(f->shared->vfd_swmr);
HDassert(!f->shared->vfd_swmr_writer);
HDassert(f->shared->lf);
-#if 0 /* JRM */
- HDfprintf(stderr, "--- reader EOT entering ---\n");
- HDfprintf(stderr, "--- reader EOT init index used / len = %d / %d ---\n",
+
+ hlog_fast(eot, "--- reader EOT entering ---");
+ hlog_fast(eot, "--- reader EOT init index used / len = %d / %d ---",
f->shared->mdf_idx_entries_used, f->shared->mdf_idx_len);
-#endif /* JRM */
+
/* 1) Direct the VFD SWMR reader VFD to load the current header
* from the metadata file, and report the current tick.
*
diff --git a/src/H5PB.c b/src/H5PB.c
index b1772a4..5b306f0 100644
--- a/src/H5PB.c
+++ b/src/H5PB.c
@@ -45,6 +45,8 @@
#include "H5PBpkg.h" /* File access */
+#include "hlog.h"
+
/****************/
/* Local Macros */
/****************/
@@ -97,8 +99,6 @@ static herr_t H5PB__write_meta(H5F_shared_t *, H5FD_mem_t, haddr_t,
static herr_t H5PB__write_raw(H5F_shared_t *, H5FD_mem_t, haddr_t,
size_t, const void *);
-static void ldbgf(const char *, ...) H5_ATTR_FORMAT(printf, 1, 2);
-
/*********************/
/* Package Variables */
/*********************/
@@ -123,22 +123,10 @@ H5FL_DEFINE_STATIC(H5PB_t);
/* Declare a free list to manage the H5PB_entry_t struct */
H5FL_DEFINE_STATIC(H5PB_entry_t);
-static const bool ldbg_enabled = false;
-
-static void
-ldbgf(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
-
- if (!ldbg_enabled)
- return;
-
- (void)vprintf(fmt, ap);
-
- va_end(ap);
-}
+HLOG_SINK_DECL(pagebuffer);
+HLOG_SINK_SHORT_DEFN(pagebuffer, all);
+HLOG_SINK_SHORT_DEFN(pbflush, pagebuffer);
+HLOG_SINK_SHORT_DEFN(pbflush_entry, pbflush);
/*-------------------------------------------------------------------------
@@ -811,14 +799,14 @@ H5PB_flush(H5F_shared_t *shared)
flush_ptr = entry_ptr;
entry_ptr = entry_ptr->ht_next;
- ldbgf("%s: visiting %zu-byte page %" PRIu64 "\n",
+ hlog_fast(pbflush, "%s: visiting %zu-byte page %" PRIu64,
__func__, flush_ptr->size, flush_ptr->page);
if ( flush_ptr->is_dirty ) {
if (flush_ptr->delay_write_until != 0) {
- ldbgf("%s: delaying %zu-byte page %" PRIu64
- " until %" PRIu64 " (now %" PRIu64 ")\n",
+ hlog_fast(pbflush, "%s: delaying %zu-byte page %" PRIu64
+ " until %" PRIu64 " (now %" PRIu64 ")",
__func__, flush_ptr->size, flush_ptr->page,
flush_ptr->delay_write_until,
shared->tick_num);
@@ -2467,7 +2455,8 @@ H5PB__flush_entry(H5F_shared_t *shared, H5PB_t *pb_ptr, H5PB_entry_t *entry_ptr)
HDassert((pb_ptr->vfd_swmr_writer) || (!(entry_ptr->is_mpmde)));
HDassert(0 == entry_ptr->delay_write_until);
- ldbgf("%s: flushing %zu-byte page %" PRIu64 " @ %" PRIuHADDR "\n",
+ hlog_fast(pbflush_entry,
+ "%s: flushing %zu-byte page %" PRIu64 " @ %" PRIuHADDR,
__func__, entry_ptr->size, entry_ptr->page, entry_ptr->addr);
/* Retrieve the 'eoa' for the file */
diff --git a/src/Makefile.am b/src/Makefile.am
index 7d430dd..01662fe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -129,7 +129,8 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5system.c H5timer.c H5trace.c \
H5VLpassthru.c \
H5VM.c H5WB.c H5Z.c \
H5Zdeflate.c H5Zfletcher32.c H5Znbit.c H5Zshuffle.c \
- H5Zscaleoffset.c H5Zszip.c H5Ztrans.c
+ H5Zscaleoffset.c H5Zszip.c H5Ztrans.c \
+ hlog.c
# Only compile parallel sources if necessary
if BUILD_PARALLEL_CONDITIONAL
diff --git a/src/hlog.c b/src/hlog.c
index d3ff0ee..9598f9e 100644
--- a/src/hlog.c
+++ b/src/hlog.c
@@ -12,6 +12,8 @@
#include <err.h>
#include <errno.h>
#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h> /* for uintmax_t */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -20,67 +22,100 @@
#include <sys/param.h>
#include <sys/cdefs.h>
-#include "hlog/hlog.h"
+#include "hlog.h"
+#include "H5time_private.h"
-#ifndef lint
-__RCSID("$Id: log.c 4702 2007-06-22 07:01:28Z dyoung $");
-#endif
+TAILQ_HEAD(, hlog_sink) hlog_sinks = TAILQ_HEAD_INITIALIZER(hlog_sinks);
-static enum loglib_mode loglib_mode = LOGLIB_M_STDERR;
-TAILQ_HEAD(, loglib_sink) loglib_sinks = TAILQ_HEAD_INITIALIZER(loglib_sinks);
+HLOG_SINK_TOP_DEFN(all);
-LOGLIB_SINK_TOP_DEFN(all);
+static struct timespec timestamp_zero;
-LOGLIB_SINK_SHORT_DEFN(arithmetic, all);
-LOGLIB_SINK_SHORT_DEFN(mem, all);
+void hlog_init(void) __constructor;
+static void hlog_init_timestamps(void);
-LOGLIB_SINK_MEDIUM_DEFN(sys, all, LOG_NOTICE);
-LOGLIB_SINK_MEDIUM_DEFN(notice, all, LOG_NOTICE);
-LOGLIB_SINK_MEDIUM_DEFN(err, all, LOG_ERR);
-LOGLIB_SINK_MEDIUM_DEFN(warn, all, LOG_WARNING);
+void
+hlog_init(void)
+{
+ const char *settings0;
+ char *item, *settings;
+
+ if ((settings0 = getenv("HLOG")) == NULL)
+ return;
+
+ if ((settings = strdup(settings0)) == NULL) {
+ warn("%s: cannot duplicate settings string", __func__);
+ return;
+ }
+
+ while ((item = strsep(&settings, ",")) != NULL) {
+ hlog_sink_state_t state;
+ char key[64 + 1], val[4 + 1]; // + 1 for the terminating NUL
+ int nconverted;
+
+ nconverted = sscanf(item, " %64[0-9a-z_] = %4s ", key, val);
+ if (nconverted != 2) {
+ warnx("%s: malformed HLOG item \"%s\"", __func__, item);
+ continue;
+ }
+
+ if (strcmp(val, "on") == 0 || strcmp(val, "yes") == 0)
+ state = HLOG_SINK_S_ON;
+ else if (strcmp(val, "off") == 0 || strcmp(val, "no") == 0)
+ state = HLOG_SINK_S_OFF;
+ else if (strcmp(val, "pass") == 0)
+ state = HLOG_SINK_S_PASS;
+ else {
+ warnx("%s: bad HLOG value \"%s\" in item \"%s\"", __func__,
+ val, item);
+ continue;
+ }
+
+ if (hlog_set_state(key, state, true) == -1) {
+ warn("%s: could not set state for HLOG item \"%s\"", __func__,
+ item);
+ }
+ }
+
+ free(settings);
+}
-int
-loglib_start(enum loglib_mode mode, int facility)
+
+static void
+hlog_init_timestamps(void)
{
- loglib_mode = mode;
+ static bool initialized = false;
- if (mode == LOGLIB_M_STDERR)
- return 0;
- else if (mode != LOGLIB_M_SYSLOG)
- return -1;
+ if (initialized)
+ return;
- openlog(getprogname(), 0, facility);
- (void)setlogmask(LOG_UPTO(LOG_DEBUG));
- return 0;
+ if (clock_gettime(CLOCK_MONOTONIC, &timestamp_zero) == -1)
+ err(EXIT_FAILURE, "%s: clock_gettime", __func__);
+
+ initialized = true;
}
static void
-loglib_print_time(void)
+hlog_print_time(void)
{
- time_t t;
- struct tm *tm;
- char buf[80];
-
- t = time(NULL);
- tm = gmtime(&t);
- if (strftime(buf, sizeof(buf),"%Y%m%d%H%M%S ", tm) == 0) {
- warnx("%s: strftime failed", __func__);
- return;
- }
- (void)fprintf(stderr, "%s", buf);
+ struct timespec elapsed, now;
+
+ hlog_init_timestamps();
+
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
+ err(EXIT_FAILURE, "%s: clock_gettime", __func__);
+
+ timespecsub(&now, &timestamp_zero, &elapsed);
+
+ fprintf(stderr, "%ju.%.9ld ", (uintmax_t)elapsed.tv_sec, elapsed.tv_nsec);
}
void
-loglib_vlog(int priority, const char *fmt, va_list ap)
+vhlog(const char *fmt, va_list ap)
{
- if (loglib_mode == LOGLIB_M_SYSLOG) {
- vsyslog(priority, fmt, ap);
- return;
- } else {
- loglib_print_time();
- (void)vfprintf(stderr, fmt, ap);
- (void)fputc('\n', stderr);
- }
+ hlog_print_time();
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fputc('\n', stderr);
}
static char *
@@ -96,8 +131,7 @@ message_extend_stderr(const char *fmt0)
fmtlen = strlen(fmt0) + strlen(m) + sizeof(sep);
if ((fmt = malloc(fmtlen)) == NULL) {
- syslog(LOG_ERR, "%s: malloc failed: %s", __func__,
- strerror(errno));
+ err(EXIT_FAILURE, "%s: malloc failed", __func__);
return NULL;
}
@@ -110,127 +144,100 @@ message_extend_stderr(const char *fmt0)
}
static char *
-message_extend_syslogd(const char *fmt0)
-{
- static const char minterp[] = ": %m";
- char *fmt;
- size_t fmtlen;
-
- fmtlen = sizeof(minterp) + strlen(fmt0);
-
- if ((fmt = malloc(fmtlen)) == NULL) {
- syslog(LOG_ERR, "%s: malloc failed: %s", __func__,
- strerror(errno));
- return NULL;
- }
-
- /* Note well the safe strcpy, strcat usage. Thank you. */
- strcpy(fmt, fmt0);
- strcat(fmt, minterp);
-
- return fmt;
-}
-
-static char *
message_extend(const char *fmt0)
{
- switch (loglib_mode) {
- case LOGLIB_M_SYSLOG:
- return message_extend_syslogd(fmt0);
- default:
- return message_extend_stderr(fmt0);
- }
+ return message_extend_stderr(fmt0);
}
void
-loglib_verr(int status, const char *fmt0, va_list ap)
+vhlog_err(int status, const char *fmt0, va_list ap)
{
char *fmt;
if ((fmt = message_extend(fmt0)) == NULL)
exit(status);
- loglib_vlog(LOG_ERR, fmt, ap);
+ vhlog(fmt, ap);
free(fmt);
exit(status);
}
void
-loglib_verrx(int status, const char *fmt, va_list ap)
+vhlog_errx(int status, const char *fmt, va_list ap)
{
- loglib_vlog(LOG_ERR, fmt, ap);
+ vhlog(fmt, ap);
exit(status);
}
void
-loglib_vwarn(const char *fmt0, va_list ap)
+vhlog_warn(const char *fmt0, va_list ap)
{
char *fmt;
if ((fmt = message_extend(fmt0)) == NULL)
return;
- loglib_vlog(LOG_WARNING, fmt, ap);
+ vhlog(fmt, ap);
free(fmt);
}
void
-loglib_vwarnx(const char *fmt, va_list ap)
+vhlog_warnx(const char *fmt, va_list ap)
{
- loglib_vlog(LOG_WARNING, fmt, ap);
+ vhlog(fmt, ap);
}
void
-loglib_err(int status, const char *fmt, ...)
+hlog_err(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- loglib_verr(status, fmt, ap);
+ vhlog_err(status, fmt, ap);
va_end(ap);
}
void
-loglib_errx(int status, const char *fmt, ...)
+hlog_errx(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- loglib_verrx(status, fmt, ap);
+ vhlog_errx(status, fmt, ap);
va_end(ap);
}
void
-loglib_warn(const char *fmt, ...)
+hlog_warn(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- loglib_vwarn(fmt, ap);
+ vhlog_warn(fmt, ap);
va_end(ap);
}
void
-loglib_warnx(const char *fmt, ...)
+hlog_warnx(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- loglib_vwarnx(fmt, ap);
+ vhlog_warnx(fmt, ap);
va_end(ap);
}
-struct loglib_sink *
-loglib_sink_find_active(struct loglib_sink *ls0)
+struct hlog_sink *
+hlog_sink_find_active(struct hlog_sink *ls0)
{
- struct loglib_sink *ls;
+ struct hlog_sink *ls;
- LOGLIB_SINK_FOREACH(ls, ls0) {
+ HLOG_SINK_FOREACH(ls, ls0) {
switch (ls->ls_state) {
- case LOGLIB_SINK_S_PASS:
+ case HLOG_SINK_S_PASS:
continue;
- case LOGLIB_SINK_S_OFF:
+ case HLOG_SINK_S_OFF:
return NULL;
- case LOGLIB_SINK_S_ON:
+ case HLOG_SINK_S_ON:
default:
return ls;
}
@@ -239,127 +246,106 @@ loglib_sink_find_active(struct loglib_sink *ls0)
}
void
-loglib_always_log(struct loglib_sink *ls, const char *fmt, ...)
+hlog_always(struct hlog_sink *ls __unused, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- loglib_vlog(ls->ls_priority, fmt, ap);
+ vhlog(fmt, ap);
va_end(ap);
}
void
-loglib_log(struct loglib_sink *ls0, const char *fmt, ...)
+hlog_impl(struct hlog_sink *ls0, const char *fmt, ...)
{
- struct loglib_sink *ls;
+ struct hlog_sink *ls;
va_list ap;
- if ((ls = loglib_sink_find_active(ls0)) == NULL)
+ if ((ls = hlog_sink_find_active(ls0)) == NULL)
return;
va_start(ap, fmt);
- loglib_vlog(ls->ls_priority, fmt, ap);
+ vhlog(fmt, ap);
va_end(ap);
}
-struct loglib_sink *
-loglib_sink_lookup(const char *name)
+struct hlog_sink *
+hlog_sink_lookup(const char *name)
{
- struct loglib_sink *ls;
- TAILQ_FOREACH(ls, &loglib_sinks, ls_next) {
+ struct hlog_sink *ls;
+ TAILQ_FOREACH(ls, &hlog_sinks, ls_next) {
if (strcmp(ls->ls_name, name) == 0)
return ls;
}
return NULL;
}
-static struct loglib_sink *
-loglib_sink_create(const char *name)
+static struct hlog_sink *
+hlog_sink_create(const char *name)
{
- struct loglib_sink *ls;
- static struct nmalloc_pool *np;
-
- if (np == NULL && (np = nmalloc_pool_create(__func__)) == NULL)
- return NULL;
+ struct hlog_sink *ls;
- if ((ls = nzmalloc(np, sizeof(*ls))) == NULL)
+ if ((ls = calloc(1, sizeof(*ls))) == NULL)
return NULL;
else if ((ls->ls_name0 = strdup(name)) == NULL) {
- nfree(ls);
+ free(ls);
return NULL;
}
ls->ls_name = ls->ls_name0;
- ls->ls_rendezvous = 1;
+ ls->ls_rendezvous = true;
return ls;
}
static void
-loglib_sink_destroy(struct loglib_sink *ls)
+hlog_sink_destroy(struct hlog_sink *ls)
{
/*LINTED*/
if (ls->ls_name0 != NULL)
free(ls->ls_name0);
- nfree(ls);
+ free(ls);
}
int
-loglib_set_state(const char *name, enum loglib_sink_state state, int rendezvous)
+hlog_set_state(const char *name, enum hlog_sink_state state, bool rendezvous)
{
- struct loglib_sink *ls;
+ struct hlog_sink *ls;
errno = 0;
switch (state) {
- case LOGLIB_SINK_S_PASS:
- case LOGLIB_SINK_S_OFF:
- case LOGLIB_SINK_S_ON:
+ case HLOG_SINK_S_PASS:
+ case HLOG_SINK_S_OFF:
+ case HLOG_SINK_S_ON:
break;
default:
errno = EINVAL;
return -1;
}
- if ((ls = loglib_sink_lookup(name)) == NULL && !rendezvous) {
+ if ((ls = hlog_sink_lookup(name)) == NULL && !rendezvous) {
errno = ESRCH;
return -1;
} else if (ls == NULL) {
- if ((ls = loglib_sink_create(name)) == NULL)
+ if ((ls = hlog_sink_create(name)) == NULL)
return -1;
- TAILQ_INSERT_TAIL(&loglib_sinks, ls, ls_next);
+ TAILQ_INSERT_TAIL(&hlog_sinks, ls, ls_next);
}
ls->ls_state = state;
return 0;
}
void
-loglib_sink_register(struct loglib_sink *ls_arg)
+hlog_sink_register(struct hlog_sink *ls_arg)
{
- struct loglib_sink *ls;
- if ((ls = loglib_sink_lookup(ls_arg->ls_name)) == NULL ||
+ struct hlog_sink *ls;
+ if ((ls = hlog_sink_lookup(ls_arg->ls_name)) == NULL ||
ls->ls_rendezvous) {
- TAILQ_INSERT_TAIL(&loglib_sinks, ls_arg, ls_next);
+ TAILQ_INSERT_TAIL(&hlog_sinks, ls_arg, ls_next);
if (ls == NULL)
return;
warnx("%s: rendezvous with log-sink '%s'", __func__,
ls->ls_name);
ls_arg->ls_state = ls->ls_state;
- TAILQ_REMOVE(&loglib_sinks, ls, ls_next);
- loglib_sink_destroy(ls);
+ TAILQ_REMOVE(&hlog_sinks, ls, ls_next);
+ hlog_sink_destroy(ls);
} else
warnx("%s: duplicate log-sink, '%s'", __func__, ls->ls_name);
}
-
-/*ARGSUSED*/
-int
-log_printer(void *arg __unused, const char *fmt, ...)
-{
- va_list ap;
- struct loglib_sink *ls;
- if ((ls = loglib_sink_find_active(&log_notice)) == NULL) {
- errno = EAGAIN;
- return -1;
- }
-
- va_start(ap, fmt);
- loglib_vlog(ls->ls_priority, fmt, ap);
- va_end(ap);
- return 0;
-}
diff --git a/src/hlog.h b/src/hlog.h
index fcf6e80..2a8e567 100644
--- a/src/hlog.h
+++ b/src/hlog.h
@@ -9,123 +9,123 @@
*
* See COPYING at the top of the HDF5 distribution for license terms.
*/
-#ifndef _LOGLIB_H
-#define _LOGLIB_H
+#ifndef _HLOG_H
+#define _HLOG_H
#include <stdarg.h>
#include <syslog.h>
#include <sys/cdefs.h>
-#include <sys/queue.h>
-#include "misc/misc.h"
+#include "bsdqueue.h"
-enum loglib_mode {LOGLIB_M_SYSLOG = 0, LOGLIB_M_STDERR};
+#ifndef __unused
+#define __unused __attribute__((unused))
+#endif
-enum loglib_sink_state {
- LOGLIB_SINK_S_PASS = 0
- , LOGLIB_SINK_S_OFF = 1
- , LOGLIB_SINK_S_ON = 2
+#ifndef __constructor
+#define __constructor __attribute__((constructor))
+#endif
+
+#ifndef __noreturn
+#define __noreturn __attribute__((__noreturn__))
+#endif
+
+#ifndef __printflike
+#define __printflike(_fmt, _args) \
+ __attribute__((__format__(__printf__,_fmt,_args)))
+#endif
+
+enum hlog_sink_state {
+ HLOG_SINK_S_PASS = 0
+ , HLOG_SINK_S_OFF = 1
+ , HLOG_SINK_S_ON = 2
};
-struct loglib_sink {
+typedef enum hlog_sink_state hlog_sink_state_t;
+
+struct hlog_sink {
const char *ls_name;
char *ls_name0;
- struct loglib_sink *ls_parent;
- enum loglib_sink_state ls_state;
- int ls_priority;
- int ls_rendezvous;
- TAILQ_ENTRY(loglib_sink) ls_next;
+ struct hlog_sink *ls_parent;
+ enum hlog_sink_state ls_state;
+ bool ls_rendezvous;
+ TAILQ_ENTRY(hlog_sink) ls_next;
};
-#define LOGLIB_CONSTRUCTOR(__sym) \
-void loglib_constructor_##__sym(void) __attribute__((constructor)); \
+#define HLOG_CONSTRUCTOR(__sym) \
+void hlog_constructor_##__sym(void) __constructor; \
void \
-loglib_constructor_##__sym(void) \
+hlog_constructor_##__sym(void) \
{ \
- loglib_sink_register(&__sym); \
+ hlog_sink_register(&__sym); \
} \
-void loglib_constructor_##__sym(void) __attribute__((constructor))
+void hlog_undefined_##__sym(void) __constructor
-#define LOGLIB_SINK_FOREACH(__le, __le0) \
+#define HLOG_SINK_FOREACH(__le, __le0) \
for ((__le) = (__le0); (__le) != NULL; (__le) = (__le)->ls_parent)
-#define LOGLIB_SINK_DECL1(__sym) extern struct loglib_sink __sym
+#define HLOG_SINK_DECL1(__sym) extern struct hlog_sink __sym
-#define LOGLIB_SINK_DECL(__name) LOGLIB_SINK_DECL1(log_##__name)
+#define HLOG_SINK_DECL(__name) HLOG_SINK_DECL1(log_##__name)
-#define LOGLIB_SINK_DEFN(__sym, __name, __parent, __state, __priority) \
- struct loglib_sink __sym = { \
+#define HLOG_SINK_DEFN(__sym, __name, __parent, __state) \
+ struct hlog_sink __sym = { \
.ls_name = __name \
, .ls_parent = (__parent) \
, .ls_state = (__state) \
- , .ls_priority = (__priority) \
}; \
- LOGLIB_CONSTRUCTOR(__sym)
-
-#define LOGLIB_SINK_MEDIUM_DEFN(__name, __parent, __priority) \
- LOGLIB_SINK_DEFN(log_##__name, #__name, &log_##__parent, \
- LOGLIB_SINK_S_PASS, (__priority))
-
-#define LOGLIB_SINK_SHORT_DEFN(__name, __parent) \
- LOGLIB_SINK_MEDIUM_DEFN(__name, __parent, LOG_INFO)
-
-#define LOGLIB_SINK_TOP_DEFN(__name) \
- LOGLIB_SINK_DEFN(log_##__name, #__name, NULL, LOGLIB_SINK_S_ON, \
- LOG_INFO)
-
-#define LOGLIB_F_ALL (0xffffffff)
-
-LOGLIB_SINK_DECL(all);
-LOGLIB_SINK_DECL(arithmetic);
-LOGLIB_SINK_DECL(mem);
-LOGLIB_SINK_DECL(sys);
-LOGLIB_SINK_DECL(notice);
-LOGLIB_SINK_DECL(err);
-LOGLIB_SINK_DECL(warn);
-
-#define LOGLIB_LOG loglib_log
-
-#define LOGLIB_LAZY(__ls0, ...) \
- do { \
- struct loglib_sink *__ls; \
- if ((__ls = loglib_sink_find_active((__ls0))) != NULL) \
- loglib_always_log((__ls), __VA_ARGS__); \
- } while (/*CONSTCOND*/0)
-
-struct loglib_sink *loglib_sink_find_active(struct loglib_sink *);
-extern void loglib_sink_register(struct loglib_sink *);
-extern struct loglib_sink *loglib_sink_lookup(const char *);
-extern int loglib_set_state(const char *, enum loglib_sink_state, int);
-extern int loglib_start(enum loglib_mode, int);
-
-void loglib_vlog(int, const char *, va_list)
- __attribute__((__format__(__printf__,2,0)));
-
-void loglib_vwarn(const char *, va_list)
- __attribute__((__format__(__printf__,1,0)));
-void loglib_vwarnx(const char *, va_list)
- __attribute__((__format__(__printf__,1,0)));
-void loglib_verr(int, const char *, va_list)
- __attribute__((__format__(__printf__,2,0))) __attribute__((__noreturn__));
-void loglib_verrx(int, const char *, va_list)
- __attribute__((__format__(__printf__,2,0))) __attribute__((__noreturn__));
-
-void loglib_warnx(const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
-void loglib_warn(const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
-
-void loglib_err(int, const char *, ...)
- __attribute__((__format__(__printf__,2,3))) __attribute__((__noreturn__));
-void loglib_errx(int, const char *, ...)
- __attribute__((__format__(__printf__,2,3))) __attribute__((__noreturn__));
-
-void loglib_always_log(struct loglib_sink *, const char *, ...)
- __attribute__((__format__(__printf__,2,3)));
-
-void loglib_log(struct loglib_sink *, const char *, ...)
- __attribute__((__format__(__printf__,2,3)));
-
-int log_printer(void *, const char *, ...);
-
-#endif /* _LOGLIB_H */
+ HLOG_CONSTRUCTOR(__sym)
+
+#define HLOG_SINK_MEDIUM_DEFN(__name, __parent) \
+ HLOG_SINK_DEFN(log_##__name, #__name, &log_##__parent, \
+ HLOG_SINK_S_PASS)
+
+#define HLOG_SINK_SHORT_DEFN(__name, __parent) \
+ HLOG_SINK_MEDIUM_DEFN(__name, __parent)
+
+#define HLOG_SINK_TOP_DEFN(__name) \
+ HLOG_SINK_DEFN(log_##__name, #__name, NULL, HLOG_SINK_S_OFF)
+
+HLOG_SINK_DECL(all);
+HLOG_SINK_DECL(arithmetic);
+HLOG_SINK_DECL(mem);
+HLOG_SINK_DECL(sys);
+HLOG_SINK_DECL(notice);
+HLOG_SINK_DECL(err);
+HLOG_SINK_DECL(warn);
+
+#define hlog(_name, _fmt, ...) \
+ hlog_impl(&log_##_name, _fmt, __VA_ARGS__)
+
+#define hlog_fast(_name, ...) \
+ do { \
+ struct hlog_sink *_ls; \
+ if ((_ls = hlog_sink_find_active((&log_##_name))) != NULL) \
+ hlog_always((_ls), __VA_ARGS__); \
+ } while (/*CONSTCOND*/0)
+
+struct hlog_sink *hlog_sink_find_active(struct hlog_sink *);
+void hlog_sink_register(struct hlog_sink *);
+struct hlog_sink *hlog_sink_lookup(const char *);
+int hlog_set_state(const char *, enum hlog_sink_state, bool);
+
+void vhlog(const char *, va_list) __printflike(1,0);
+
+void vhlog_warn(const char *, va_list) __printflike(1,0);
+void vhlog_warnx(const char *, va_list) __printflike(1,0);
+void vhlog_err(int, const char *, va_list) __printflike(2,0) __noreturn;
+void vhlog_errx(int, const char *, va_list) __printflike(2,0) __noreturn;
+
+void hlog_warnx(const char *, ...) __printflike(1,2);
+void hlog_warn(const char *, ...) __printflike(1,2);
+
+void hlog_err(int, const char *, ...) __printflike(2,3) __noreturn;
+void hlog_errx(int, const char *, ...) __printflike(2,3) __noreturn;
+
+void hlog_always(struct hlog_sink *, const char *, ...)
+ __printflike(2,3);
+
+void hlog_impl(struct hlog_sink *, const char *, ...)
+ __printflike(2,3);
+
+#endif /* _HLOG_H */