From 82c9dec122d013dd4c09cf009b5ac35623ebc34e Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Tue, 13 Apr 2021 16:23:30 +0200 Subject: [PATCH] Update Android Logger stdout tag setting Kernel-side development changed the expected data format; conform. Change-Id: I107b55b195cb9247fcccec7e7d48e646eeb09af8 Signed-off-by: Michal Bloch --- include/dlog_ioctl.h | 11 +++++++++++ src/log-redirect-stdout/internal.c | 16 ++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/dlog_ioctl.h b/include/dlog_ioctl.h index 7ba5e79..1e42787 100644 --- a/include/dlog_ioctl.h +++ b/include/dlog_ioctl.h @@ -2,6 +2,7 @@ #define _DLOG_IOCTL_H_ #include +#include // These are taken from the kernel: ./drivers/staging/android/logger.h #define __LOGGERIO 0xAE @@ -14,4 +15,14 @@ #define LOGGER_SET_TAG _IO(__LOGGERIO, 7) /* set flow mode tag */ #define LOGGER_SET_PRIO _IO(__LOGGERIO, 8) /* set flow mode prio */ +/** + * struct logger_set_tag + * @len: Length of a NULL-terminated tag including '\0' + * @msg: Pointer to a user buffer containing the tag + */ +struct logger_set_tag { + uint64_t len; + uint64_t ptr; +}; + #endif diff --git a/src/log-redirect-stdout/internal.c b/src/log-redirect-stdout/internal.c index b41a413..86b33cb 100644 --- a/src/log-redirect-stdout/internal.c +++ b/src/log-redirect-stdout/internal.c @@ -27,6 +27,8 @@ #include #include +#include + static int setup_single_pipe(log_id_t buffer, const char *tag, log_priority prio, struct log_config *config, int *fd) { /* We don't really have a way to get the PID correctly in @@ -64,16 +66,10 @@ static int setup_single_pipe(log_id_t buffer, const char *tag, log_priority prio static int apply_android_logger_ioctl(int fd, const char *tag, log_priority prio) { - struct { - int len; - char tag[128]; // soft limit on length based on dlogutil output format - } tag_info; - - strncpy(tag_info.tag, tag, sizeof tag_info.tag); - tag_info.tag[sizeof tag_info.tag - 1] = '\0'; - tag_info.len = strlen(tag_info.tag) + 1; - - int r = ioctl(fd, LOGGER_SET_TAG, &tag_info); + int r = ioctl(fd, LOGGER_SET_TAG, & (struct logger_set_tag) { + .len = strlen(tag) + 1, + .ptr = (uintptr_t) tag + }); if (r < 0) return -errno; -- 2.7.4