#include "ioloop.h"
#include "fd-close-on-exec.h"
#include "fd-set-nonblock.h"
+#include "write-full.h"
#include "lib-signals.h"
+#include <stdio.h>
#include <signal.h>
#include <unistd.h>
}
}
+void lib_signals_syscall_error(const char *prefix)
+{
+ /* @UNSAFE: We're in a signal handler. It's very limited what is
+ allowed in here. Especially strerror() isn't at least officially
+ allowed. */
+ char errno_buf[MAX_INT_STRLEN], *errno_str;
+ errno_str = dec2str_buf(errno_buf, errno);
+
+ size_t prefix_len = strlen(prefix);
+ size_t errno_str_len = strlen(errno_str);
+ char buf[prefix_len + errno_str_len + 1];
+
+ memcpy(buf, prefix, prefix_len);
+ memcpy(buf + prefix_len, errno_str, errno_str_len);
+ buf[prefix_len + errno_str_len] = '\n';
+ if (write_full(STDERR_FILENO, buf, prefix_len + errno_str_len + 1) < 0) {
+ /* can't really do anything */
+ }
+}
+
void lib_signals_init(void)
{
int i;
the delayed signals to work when using multiple I/O loops. */
void lib_signals_reset_ioloop(void);
+/* Log a syscall error inside a (non-delayed) signal handler where i_error() is
+ unsafe. errno number will be appended to the prefix. */
+void lib_signals_syscall_error(const char *prefix);
+
void lib_signals_init(void);
void lib_signals_deinit(void);