return true;
}
+static void __attribute__((constructor(101))) __install_pipe_handler(void)
+{
+ /* We mask SIGPIPE signal because most applications do not install their
+ * own SIGPIPE handler. Default behaviour in SIGPIPE case is to abort the
+ * process. SIGPIPE occurs when e.g. dlog daemon closes read pipe endpoint.
+ *
+ * We do this in the library constructor (at maximum priority) and not
+ * during regular (lazy) initialisation so as to prevent overwriting the
+ * program's actual signal handler, if it has one.
+ *
+ * In theory this is not required for the Android logger backend; however,
+ * this early we don't yet know the backend and also it is good to behave
+ * consistently in this regard anyway.
+ *
+ * We don't revert this in a destructor because Unix signals are bonkers
+ * and we have no way to do this cleanly. Most libdlog users don't use
+ * runtime linking so this would mostly done at program exit either way. */
+ signal(SIGPIPE, SIG_IGN);
+}
+
static bool first = true;
static bool initialize()
{
close(pipe_fd[i]);
wait_pipe_ms = DEFAULT_WAIT_PIPE_MS;
- signal(SIGPIPE, SIG_DFL);
}
/**
*/
void __dlog_init_pipe(const struct log_config *conf)
{
- int i;
-
- /*
- * We mask SIGPIPE signal because most applications do not install their
- * own SIGPIPE handler. Default behaviour in SIGPIPE case is to abort the
- * process. SIGPIPE occurs when e.g. dlog daemon closes read pipe endpoint
- */
- signal(SIGPIPE, SIG_IGN);
-
- for (i = 0; i < LOG_ID_MAX; ++i) {
+ for (int i = 0; i < LOG_ID_MAX; ++i) {
char conf_key[MAX_CONF_KEY_LEN];
snprintf(conf_key, sizeof(conf_key), "%s_write_sock", log_name_by_id(i));
const char * conf_val = log_config_get(conf, conf_key);