summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-05-03 11:59:31 -0400
committerNick Mathewson <nickm@torproject.org>2018-05-03 11:59:31 -0400
commited636de4cc71fb2936358da27f211fb6a255cd9d (patch)
treea67eddd76c29cd20ad73540c62bbdfcd24be87a5 /src/common
parentbe9f0e5f20e37d2176ce0663b71b532c44c10c28 (diff)
parent77b7eb2795208ad5c5f66a5626a89b14b03de6f2 (diff)
downloadtor-ed636de4cc71fb2936358da27f211fb6a255cd9d.tar.gz
tor-ed636de4cc71fb2936358da27f211fb6a255cd9d.zip
Merge remote-tracking branch 'github/ticket25951'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/log.c25
-rw-r--r--src/common/torlog.h2
2 files changed, 27 insertions, 0 deletions
diff --git a/src/common/log.c b/src/common/log.c
index 922e9dd38f..ebd50f62d3 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -170,6 +170,9 @@ typedef struct pending_log_message_t {
/** Log messages waiting to be replayed onto callback-based logs */
static smartlist_t *pending_cb_messages = NULL;
+/** Callback to invoke when pending_cb_messages becomes nonempty. */
+static pending_callback_callback pending_cb_cb = NULL;
+
/** Log messages waiting to be replayed once the logging system is initialized.
*/
static smartlist_t *pending_startup_messages = NULL;
@@ -538,6 +541,9 @@ logfile_deliver(logfile_t *lf, const char *buf, size_t msg_len,
smartlist_add(pending_cb_messages,
pending_log_message_new(severity,domain,NULL,msg_after_prefix));
*callbacks_deferred = 1;
+ if (smartlist_len(pending_cb_messages) == 1 && pending_cb_cb) {
+ pending_cb_cb();
+ }
}
} else {
lf->callback(severity, domain, msg_after_prefix);
@@ -825,6 +831,7 @@ logs_free_all(void)
logfiles = NULL;
messages = pending_cb_messages;
pending_cb_messages = NULL;
+ pending_cb_cb = NULL;
messages2 = pending_startup_messages;
pending_startup_messages = NULL;
UNLOCK_LOGS();
@@ -988,6 +995,24 @@ add_temp_log(int min_severity)
}
/**
+ * Register "cb" as the callback to call when there are new pending log
+ * callbacks to be flushed with flush_pending_log_callbacks().
+ *
+ * Note that this callback, if present, can be invoked from any thread.
+ *
+ * This callback must not log.
+ *
+ * It is intentional that this function contains the name "callback" twice: it
+ * sets a "callback" to be called on the condition that there is a "pending
+ * callback".
+ **/
+void
+logs_set_pending_callback_callback(pending_callback_callback cb)
+{
+ pending_cb_cb = cb;
+}
+
+/**
* Add a log handler to send messages in <b>severity</b>
* to the function <b>cb</b>.
*/
diff --git a/src/common/torlog.h b/src/common/torlog.h
index ac632ff521..de389883c0 100644
--- a/src/common/torlog.h
+++ b/src/common/torlog.h
@@ -154,6 +154,8 @@ int add_android_log(const log_severity_list_t *severity,
const char *android_identity_tag);
#endif // HAVE_ANDROID_LOG_H.
int add_callback_log(const log_severity_list_t *severity, log_callback cb);
+typedef void (*pending_callback_callback)(void);
+void logs_set_pending_callback_callback(pending_callback_callback cb);
void logs_set_domain_logging(int enabled);
int get_min_log_level(void);
void switch_logs_debug(void);