summaryrefslogtreecommitdiff
path: root/sysdep/unix/log.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-01-23 19:46:26 +0100
committerMaria Matejka <mq@ucw.cz>2023-01-23 19:46:26 +0100
commit758aabd96c0f09709183dff4261ffbfdd72ae870 (patch)
tree75d17bb906331213d5107a6be6446f58f0251541 /sysdep/unix/log.c
parent4821612c94f9e935a6e841f6bcace9465dd2ad78 (diff)
parent7fb23041a52d01754c53ba963e2282e524813364 (diff)
Merge commit '7fb23041a52d01754c53ba963e2282e524813364' into thread-next
Diffstat (limited to 'sysdep/unix/log.c')
-rw-r--r--sysdep/unix/log.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 185231e8..d09481bc 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -32,6 +32,7 @@
#include "lib/lists.h"
#include "sysdep/unix/unix.h"
+static int dbg_fd = -1;
static FILE *dbgf;
static list *current_log_list;
static char *current_syslog_name; /* NULL -> syslog closed */
@@ -341,6 +342,21 @@ debug(const char *msg, ...)
va_end(args);
}
+/**
+ * debug_safe - async-safe write to debug output
+ * @msg: a string message
+ *
+ * This function prints the message @msg to the debugging output in a
+ * way that is async safe and can be used in signal handlers. No newline
+ * character is appended.
+ */
+void
+debug_safe(const char *msg)
+{
+ if (dbg_fd >= 0)
+ write(dbg_fd, msg, strlen(msg));
+}
+
static list *
default_log_list(int initial, const char **syslog_name)
{
@@ -441,8 +457,10 @@ log_init_debug(char *f)
{
clock_gettime(CLOCK_MONOTONIC, &dbg_time_start);
+ dbg_fd = -1;
if (dbgf && dbgf != stderr)
fclose(dbgf);
+
if (!f)
dbgf = NULL;
else if (!*f)
@@ -453,6 +471,10 @@ log_init_debug(char *f)
fprintf(stderr, "bird: Unable to open debug file %s: %s\n", f, strerror(errno));
exit(1);
}
+
if (dbgf)
+ {
setvbuf(dbgf, NULL, _IONBF, 0);
+ dbg_fd = fileno(dbgf);
+ }
}