+static
+void _lttng_ust_fd_ctor(void)
+ __attribute__((constructor));
+static
+void _lttng_ust_fd_ctor(void)
+{
+ lttng_ust_common_ctor();
+
+ /*
+ * Initialize the function pointers to the original libc symbols in the
+ * constructor since close() has to stay async-signal-safe and as such,
+ * we can't call dlsym() in the override functions.
+ */
+ (void) _lttng_ust_fd_init_plibc_close();
+ (void) _lttng_ust_fd_init_plibc_fclose();
+}
+
+/*
+ * Override the libc close() symbol with our own, allowing applications to
+ * close arbitrary file descriptors. If the fd is owned by lttng-ust, return
+ * -1, errno=EBADF instead of closing it.
+ *
+ * If dlsym failed to find the original libc close() symbol, return -1,
+ * errno=ENOSYS.
+ *
+ * There is a short window before the library constructor has executed where
+ * this wrapper could call dlsym() and thus not be async-signal-safe.
+ */