src_tests_fd_info_neg_CFLAGS = $(check_CFLAGS)
src_tests_fd_info_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_timestamp,--wrap=log_should_print_line
-src_tests_fdi_logger_pos_SOURCES = src/tests/fdi_logger_pos.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
+src_tests_fdi_logger_pos_SOURCES = src/tests/fdi_logger_pos.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
src_tests_fdi_logger_pos_CFLAGS = $(check_CFLAGS)
src_tests_fdi_logger_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=dlogutil_filter_options_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
-src_tests_fdi_logger_neg_SOURCES = src/tests/fdi_logger_neg.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
+src_tests_fdi_logger_neg_SOURCES = src/tests/fdi_logger_neg.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c src/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.c
src_tests_fdi_logger_neg_CFLAGS = $(check_CFLAGS)
src_tests_fdi_logger_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=dlogutil_filter_options_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
int logger_open_buffer_from_config(int buf_id, const struct log_config *conf, int open_flags, int *fd);
int logger_open_buffer_from_config_get_path(int buf_id, const struct log_config *conf, int open_flags, int *fd, char *actual_path, size_t path_size);
+int logger_ioctl(int fd, int ioctl_id);
+int logger_get_log_len(int fd);
+
#ifdef __cplusplus
}
#endif
#define UNLIMITED_LOG_LEN -1
-static int logger_ioctl(int fd, int ioctl_id)
-{
- assert(fd >= 0);
-
- int ret = ioctl(fd, ioctl_id);
- if (ret < 0)
- return -errno;
- return ret;
-}
-
static int logger_get_capacity(struct fd_info *fdi, unsigned int *capacity)
{
assert(fdi);
}
/**
- * @brief Get buffer filled size
- * @details Sends a get log len ioctl to given fd
- * @param[in] fd File descriptor of the buffer
- * @return -errno on failure, else >= 0 length in bytes
- * @remarks ANDROID LOGGER version
- */
-static int logger_get_log_len(int fd)
-{
- /* WARNING! This value REQUIRES `CAP_SYSLOG` to be correct!
- *
- * The driver returns the total amount of logs in the buffer
- * from this syscall, but poll() and read() will NOT return
- * all of those unless we have `CAP_SYSLOG` or `euid` matches.
- *
- * This means that the code will know there are more logs and
- * wait for them, but will never receive them, causing what
- * looks like a hang until more valid logs appear to fill in
- * the gap. This usually takes a long time and is not what
- * we want, at any rate.
- *
- * A full workaround (given that a kernel fix would be nearly
- * impossible to properly distribute) would be to perform an
- * additional read() call after the first one, on following
- * conditions:
- * - CAP_SYSLOG is not present
- * - epoll marked our FD ready the previous iteration
- * - epoll marked our FD unready the current iteration
- * - we are a dumping instance
- * - we are using Android Logger backend.
- * That would solve the issue with the minimal amount of syscalls.
- * However, it would be a horrible idea to do so because it would
- * turn our code into an abomination, and terror would consume
- * those who dwell upon the earth.
- *
- * Alternatively, the loop could receive special handling for
- * dumping Android Logger instances since technically they don't
- * even need to poll (just read a log after each extraction to
- * replace the hole). It's not very elegant either but would
- * also offer a decent performance bonus so if mana permits it
- * might be worth doing regardless.
- *
- * In the meantime, using [lib]dlogutil without CAP_SYSLOG is
- * unsupported and people should just be told to get the cap if
- * they want to use it (it took us four years to discover that
- * this is an actual condition so presumably nowadays the cap is
- * a dime a dozen and comparatively easy to obtain). */
-
- return logger_ioctl(fd, LOGGER_GET_LOG_LEN);
-}
-
-/**
* @brief Clear the buffer
* @details Sends a clear ioctl to given fd
* @param[in] fdi File descriptor info
{
return logger_open_buffer_from_config_get_path(buf_id, conf, open_flags, fd, NULL, 0U);
}
+
+int logger_ioctl(int fd, int ioctl_id)
+{
+ assert(fd >= 0);
+
+ int ret = ioctl(fd, ioctl_id);
+ if (ret < 0)
+ return -errno;
+ return ret;
+}
+
+/**
+ * @brief Get buffer filled size
+ * @details Sends a get log len ioctl to given fd
+ * @param[in] fd File descriptor of the buffer
+ * @return -errno on failure, else >= 0 length in bytes
+ */
+int logger_get_log_len(int fd)
+{
+ /* WARNING! This value REQUIRES `CAP_SYSLOG` to be correct!
+ *
+ * The driver returns the total amount of logs in the buffer
+ * from this syscall, but poll() and read() will NOT return
+ * all of those unless we have `CAP_SYSLOG` or `euid` matches.
+ *
+ * This is problematic in [lib]dlogutil. For example, the
+ * monitor and dump modes use the number of logs to recognize
+ * how much logs to print (dump) or skip (monitor).
+ * This means that the code will know there are more logs and
+ * wait for them, but will never receive them, causing what
+ * looks like a hang until more valid logs appear to fill in
+ * the gap. This usually takes a long time and is not what
+ * we want, at any rate.
+ *
+ * A full workaround (given that a kernel fix would be nearly
+ * impossible to properly distribute) would be to perform an
+ * additional read() call after the first one, on following
+ * conditions:
+ * - CAP_SYSLOG is not present
+ * - epoll marked our FD ready the previous iteration
+ * - epoll marked our FD unready the current iteration
+ * - we are a dumping or monitoring instance
+ * - we are using Android Logger backend.
+ * That would solve the issue with the minimal amount of syscalls.
+ * However, it would be a horrible idea to do so because it would
+ * turn our code into an abomination, and terror would consume
+ * those who dwell upon the earth.
+ *
+ * Therefore, using [lib]dlogutil without CAP_SYSLOG is
+ * unsupported and people should just be told to get the cap if
+ * they want to use it (it took us four years to discover that
+ * this is an actual condition so presumably nowadays the cap is
+ * a dime a dozen and comparatively easy to obtain). */
+
+ return logger_ioctl(fd, LOGGER_GET_LOG_LEN);
+}