From 4b1a3eac53ef3549cee802057c9c5e3ce9167bf9 Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Wed, 15 Feb 2023 16:45:19 +0100 Subject: [PATCH] Extract buffer trait functions from logcommon Change-Id: If920b77c08d79b3d704ff2aba5cbf48a40845485 Signed-off-by: Michal Bloch --- Makefile.am | 42 ++++++++++++++++--------- include/buffer_traits.h | 63 ++++++++++++++++++++++++++++++++++++++ include/logcommon.h | 17 ---------- src/libdlog/log.c | 2 +- src/libdlog/log_pipe.c | 1 + src/libdlogutil/fdi_pipe.c | 2 +- src/libdlogutil/lib.c | 2 +- src/log-redirect-stdout/internal.c | 1 + src/log-redirect-stdout/main.c | 3 +- src/logctl/logctl.c | 2 +- src/logger/logger.c | 1 + src/logger/reader_logger.c | 2 ++ src/logsend/logsend.c | 2 +- src/shared/backend_androidlogger.c | 1 + src/shared/buffer_traits.c | 62 +++++++++++++++++++++++++++++++++++++ src/shared/logcommon.c | 50 ------------------------------ src/shared/util_parser.c | 2 ++ src/tests/libdlog_pipe.c | 2 +- src/tests/test_common_wrap.c | 1 + 19 files changed, 170 insertions(+), 88 deletions(-) create mode 100644 include/buffer_traits.h create mode 100644 src/shared/buffer_traits.c diff --git a/Makefile.am b/Makefile.am index c4dcf14..b934695 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,7 @@ lib_LTLIBRARIES = libdlog.la libdlog_la_SOURCES = \ src/libdlog/log.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/connect_pipe.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ @@ -72,6 +73,7 @@ libdlogutil_la_SOURCES = \ src/libdlogutil/fdi_logger.c \ src/libdlogutil/fdi_zero_copy.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logprint.c \ src/shared/parsers.c \ @@ -100,6 +102,7 @@ dlogutil_LDADD = \ dlogutil_SOURCES = \ src/logutil/logutil.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ src/shared/logprint.c \ @@ -155,6 +158,7 @@ dlog_logger_SOURCES = \ src/logger/socket.c \ src/logger/writer.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/ptrs_list.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ @@ -199,6 +203,7 @@ dlogsend_LDADD = \ libdlog.la dlogsend_SOURCES = \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/logsend/logsend.c @@ -213,6 +218,7 @@ dlogctl_LDFLAGS = \ -pie dlogctl_SOURCES = \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ src/shared/parsers.c \ @@ -268,6 +274,7 @@ libdlog_redirect_stdout_la_SOURCES = \ src/log-redirect-stdout/lib.c \ src/log-redirect-stdout/internal.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/connect_pipe.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ @@ -286,6 +293,7 @@ dlog_redirect_stdout_LDADD = \ libdlog_redirect_stdout.la dlog_redirect_stdout_SOURCES = \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/log-redirect-stdout/main.c @@ -557,15 +565,15 @@ src_tests_test_ptrs_list_neg_SOURCES = src/tests/test_ptrs_list_neg.c src/shared src_tests_test_ptrs_list_neg_CFLAGS = $(check_CFLAGS) src_tests_test_ptrs_list_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=free,--wrap=calloc -src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c +src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c src_tests_test_common_CFLAGS = $(check_CFLAGS) src_tests_test_common_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl -src_tests_test_common_neg_SOURCES = src/tests/test_common_neg.c src/shared/logcommon.c +src_tests_test_common_neg_SOURCES = src/tests/test_common_neg.c src/shared/logcommon.c src/shared/buffer_traits.c src_tests_test_common_neg_CFLAGS = $(check_CFLAGS) src_tests_test_common_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl -src_tests_test_common_pos_SOURCES = src/tests/test_common_pos.c src/shared/logcommon.c +src_tests_test_common_pos_SOURCES = src/tests/test_common_pos.c src/shared/logcommon.c src/shared/buffer_traits.c src_tests_test_common_pos_CFLAGS = $(check_CFLAGS) src_tests_test_common_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl @@ -609,23 +617,23 @@ src_tests_fd_info_neg_SOURCES = src/tests/fd_info_neg.c \ 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/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.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/buffer_traits.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=log_filter_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/shared/backend_androidlogger.c src/shared/logconfig.c src/shared/parsers.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/buffer_traits.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=log_filter_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc -src_tests_fdi_pipe_pos_SOURCES = src/tests/fdi_pipe_pos.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/queued_entry_timestamp.c +src_tests_fdi_pipe_pos_SOURCES = src/tests/fdi_pipe_pos.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/queued_entry_timestamp.c src_tests_fdi_pipe_pos_CFLAGS = $(check_CFLAGS) src_tests_fdi_pipe_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=connect_sock,--wrap=close,--wrap=malloc,--wrap=free,--wrap=send_dlog_request,--wrap=recv_dlog_reply,--wrap=read,--wrap=recv_pipe -src_tests_fdi_pipe_neg_SOURCES = src/tests/fdi_pipe_neg.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/queued_entry_timestamp.c +src_tests_fdi_pipe_neg_SOURCES = src/tests/fdi_pipe_neg.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/queued_entry_timestamp.c src_tests_fdi_pipe_neg_CFLAGS = $(check_CFLAGS) src_tests_fdi_pipe_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=connect_sock,--wrap=close,--wrap=malloc,--wrap=free,--wrap=send_dlog_request,--wrap=recv_dlog_reply,--wrap=read,--wrap=recv_pipe -src_tests_libdlog_pipe_SOURCES = src/tests/libdlog_pipe.c src/libdlog/log_pipe.c src/shared/connect_pipe.c src/shared/logcommon.c src/shared/logconfig.c src/shared/queued_entry.c src/shared/translate_syslog.c src/shared/parsers.c +src_tests_libdlog_pipe_SOURCES = src/tests/libdlog_pipe.c src/libdlog/log_pipe.c src/shared/connect_pipe.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/queued_entry.c src/shared/translate_syslog.c src/shared/parsers.c src_tests_libdlog_pipe_CFLAGS = $(check_CFLAGS) -pthread src_tests_libdlog_pipe_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=syslog_critical_failure,--wrap=connect,--wrap=write,--wrap=recv_pipe,--wrap=dup2,--wrap=socket,--wrap=close -lm @@ -645,15 +653,15 @@ src_tests_libdlog_android_monotonic_neg_SOURCES = src/tests/libdlog_android_neg. src_tests_libdlog_android_monotonic_neg_CFLAGS = $(check_CFLAGS) -DUSE_ANDROID_MONOTONIC src_tests_libdlog_android_monotonic_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config,--wrap=close,--wrap=writev,--wrap=clock_gettime -src_tests_libdlog_base_pos_SOURCES = src/tests/libdlog_base_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c +src_tests_libdlog_base_pos_SOURCES = src/tests/libdlog_base_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src_tests_libdlog_base_pos_CFLAGS = $(check_CFLAGS) -pthread src_tests_libdlog_base_pos_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read,--wrap=snprintf -src_tests_libdlog_base_neg_SOURCES = src/tests/libdlog_base_neg.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c +src_tests_libdlog_base_neg_SOURCES = src/tests/libdlog_base_neg.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src_tests_libdlog_base_neg_CFLAGS = $(check_CFLAGS) -pthread src_tests_libdlog_base_neg_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read,--wrap=snprintf -src_tests_libdlog_prio_filter_pos_SOURCES = src/tests/libdlog_prio_filter_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c +src_tests_libdlog_prio_filter_pos_SOURCES = src/tests/libdlog_prio_filter_pos.c src/libdlog/log.c src/shared/hash.c src/libdlog/deduplicate.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src_tests_libdlog_prio_filter_pos_CFLAGS = $(check_CFLAGS) -pthread src_tests_libdlog_prio_filter_pos_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_read @@ -675,7 +683,7 @@ src_tests_queued_entry_monotonic_pos_SOURCES = src/tests/queued_entry_pos.c src/ src_tests_queued_entry_monotonic_pos_CFLAGS = $(check_CFLAGS) -DUSE_ANDROID_MONOTONIC src_tests_queued_entry_monotonic_pos_LDFLAGS = $(AM_LDFLAGS) -src_tests_logctl_SOURCES = src/tests/logctl.c src/logctl/logctl.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c +src_tests_logctl_SOURCES = src/tests/logctl.c src/logctl/logctl.c src/shared/logcommon.c src/shared/logconfig.c src/shared/parsers.c src/shared/buffer_traits.c src_tests_logctl_CFLAGS = $(check_CFLAGS) src_tests_logctl_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=calloc,--wrap=asprintf,--wrap=open,--wrap=open64,--wrap=fdopen,--wrap=fdopen64,--wrap=mkstemp,--wrap=mkstemp64,--wrap=fchmod,--wrap=rename @@ -683,7 +691,7 @@ src_tests_config_SOURCES = src/tests/config.c src/shared/logconfig.c src/shared/ src_tests_config_CFLAGS = $(check_CFLAGS) src_tests_config_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=openat64,--wrap=openat,--wrap=scandirat,--wrap=scandirat64,--wrap=fdopen,--wrap=fdopen64,--wrap=open,--wrap=open64,--wrap=calloc -src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c +src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logconfig.c src/shared/buffer_traits.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c src_tests_logprint_CFLAGS = $(check_CFLAGS) src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add @@ -703,6 +711,7 @@ src_tests_logutil_pos_SOURCES = src/tests/logutil_pos.c \ src/libdlogutil/fdi_logger.c \ src/libdlogutil/fdi_zero_copy.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logprint.c \ src/shared/parsers.c \ @@ -722,6 +731,7 @@ src_tests_logutil_neg_SOURCES = src/tests/logutil_neg.c \ src/libdlogutil/fdi_logger.c \ src/libdlogutil/fdi_zero_copy.c \ src/shared/backend_androidlogger.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logprint.c \ src/shared/parsers.c \ @@ -786,6 +796,7 @@ src_tests_critical_log_SOURCES = src/tests/critical_log.c \ src/shared/hash.c \ src/libdlog/dynamic_config.c \ src/shared/ptrs_list.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ src/shared/parsers.c @@ -795,6 +806,7 @@ src_tests_critical_log_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=execv,--wrap src_tests_pid_limiter_SOURCES = src/tests/pid_limiter.c \ src/shared/hash.c \ src/shared/loglimiter.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/shared/logconfig.c \ src/shared/parsers.c \ @@ -816,6 +828,7 @@ src_tests_libdlogutil_neg_SOURCES = src/tests/libdlogutil_neg.c \ src/shared/logprint.c \ src/shared/ptrs_list.c \ src/libdlogutil/logretrieve.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/libdlogutil/fd_info.c \ src/libdlogutil/sort_vector.c \ @@ -838,6 +851,7 @@ src_tests_libdlogutil_pos_SOURCES = src/tests/libdlogutil_pos.c \ src/shared/logprint.c \ src/shared/ptrs_list.c \ src/libdlogutil/logretrieve.c \ + src/shared/buffer_traits.c \ src/shared/logcommon.c \ src/libdlogutil/fd_info.c \ src/libdlogutil/sort_vector.c \ @@ -861,7 +875,7 @@ src_tests_metrics_LDADD = libdlogutil.la src_tests_metrics_CFLAGS = $(check_CFLAGS) src_tests_metrics_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=dlogutil_entry_get_tag,--wrap=dlogutil_entry_get_pid,--wrap=dlogutil_entry_get_priority,--wrap=free,--wrap=calloc,--wrap=strdup -src_tests_deduplicate_test_SOURCES = src/tests/deduplicate_test.c src/libdlog/log.c src/libdlog/deduplicate.c src/shared/hash.c src/shared/logcommon.c src/shared/loglimiter.c src/libdlog/dynamic_config.c src/shared/logconfig.c src/shared/parsers.c src/shared/ptrs_list.c +src_tests_deduplicate_test_SOURCES = src/tests/deduplicate_test.c src/libdlog/log.c src/libdlog/deduplicate.c src/shared/hash.c src/shared/buffer_traits.c src/shared/logcommon.c src/shared/loglimiter.c src/libdlog/dynamic_config.c src/shared/logconfig.c src/shared/parsers.c src/shared/ptrs_list.c src_tests_deduplicate_test_CFLAGS = $(check_CFLAGS) -pthread src_tests_deduplicate_test_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=clock_gettime,--wrap=log_config_read,--wrap=deduplicate_warn diff --git a/include/buffer_traits.h b/include/buffer_traits.h new file mode 100644 index 0000000..c7fe8f7 --- /dev/null +++ b/include/buffer_traits.h @@ -0,0 +1,63 @@ +/* MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ + +#pragma once + +#include +#include + +/** + * @brief Get buffer ID by name + * @details Returns the ID of the buffer with the given name + * @param[in] name The name of the buffer whose ID we seek + * @return If such buffer exists, its ID. + * Else, LOG_ID_INVALID. + * @see log_name_by_id + */ +log_id_t log_id_by_name(const char *name); + +/** + * @brief Get buffer name by ID + * @details Returns the name of the buffer with the given ID + * @param[in] id The ID of the buffer whose name we seek + * @return If such buffer exists, its name. + * Else, empty string. + * @see log_id_by_name + */ +char * log_name_by_id(log_id_t id); + +/** + * @brief Is core buffer + * @details Returns whether given buffer is one of the original four buffers + * @param[in] id The ID of the buffer + * @return boolean + */ +bool is_core_buffer(log_id_t id); + +/** + * @brief Is buffer valid + * @details Returns whether given buffer ID represents an actual buffer + * @param[in] id The ID of the buffer + * @return boolean + */ +bool is_buffer_valid(log_id_t id); + diff --git a/include/logcommon.h b/include/logcommon.h index 2105222..e1067ef 100644 --- a/include/logcommon.h +++ b/include/logcommon.h @@ -107,23 +107,6 @@ static inline void close_fd(const int *fd) close(*fd); } -static inline bool is_core_buffer(log_id_t buf_id) -{ - static bool const is_core [LOG_ID_MAX] = { - [LOG_ID_MAIN ] = true, - [LOG_ID_RADIO ] = true, - [LOG_ID_SYSTEM] = true, - [LOG_ID_APPS ] = true, - }; - - if (buf_id < 0 || buf_id >= (log_id_t) NELEMS(is_core)) - return false; - return is_core [buf_id]; -} - -char * log_name_by_id(log_id_t id); -log_id_t log_id_by_name(const char *name); - log_priority filter_char_to_pri(int c); char filter_pri_to_char(log_priority pri); diff --git a/src/libdlog/log.c b/src/libdlog/log.c index dbb7ecc..3d88744 100644 --- a/src/libdlog/log.c +++ b/src/libdlog/log.c @@ -35,10 +35,10 @@ #include // DLog +#include #include "deduplicate.h" #include #include -#include #include "logconfig.h" #include "loglimiter.h" diff --git a/src/libdlog/log_pipe.c b/src/libdlog/log_pipe.c index a7692e4..9b3e893 100644 --- a/src/libdlog/log_pipe.c +++ b/src/libdlog/log_pipe.c @@ -31,6 +31,7 @@ #include // DLog +#include #include #include #include diff --git a/src/libdlogutil/fdi_pipe.c b/src/libdlogutil/fdi_pipe.c index b753c19..e4eee7b 100644 --- a/src/libdlogutil/fdi_pipe.c +++ b/src/libdlogutil/fdi_pipe.c @@ -24,8 +24,8 @@ #include #include +#include #include -#include #include #include "fd_info.h" diff --git a/src/libdlogutil/lib.c b/src/libdlogutil/lib.c index 8c263c2..04492ed 100644 --- a/src/libdlogutil/lib.c +++ b/src/libdlogutil/lib.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include "logretrieve.h" diff --git a/src/log-redirect-stdout/internal.c b/src/log-redirect-stdout/internal.c index f064bac..04fbe73 100644 --- a/src/log-redirect-stdout/internal.c +++ b/src/log-redirect-stdout/internal.c @@ -23,6 +23,7 @@ #include "internal.h" #include +#include #include #include #include diff --git a/src/log-redirect-stdout/main.c b/src/log-redirect-stdout/main.c index 197ac3d..d791e51 100644 --- a/src/log-redirect-stdout/main.c +++ b/src/log-redirect-stdout/main.c @@ -23,8 +23,9 @@ #include #include -#include +#include #include +#include /* Tag length is limited by maximum request size. */ #define MAX_TAG_LENGTH (MAX_LOGGER_REQUEST_LEN - sizeof(struct dlog_control_msg) - sizeof(struct dlog_control_msg_stdout)) diff --git a/src/logctl/logctl.c b/src/logctl/logctl.c index c07ec6f..903d4e6 100644 --- a/src/logctl/logctl.c +++ b/src/logctl/logctl.c @@ -13,8 +13,8 @@ #include // DLog +#include #include -#include #include #include diff --git a/src/logger/logger.c b/src/logger/logger.c index c7d12e5..d82e2bb 100644 --- a/src/logger/logger.c +++ b/src/logger/logger.c @@ -24,6 +24,7 @@ #include "subreader_metrics.h" #include "subreader_memory.h" +#include #include #include #include diff --git a/src/logger/reader_logger.c b/src/logger/reader_logger.c index a4ea684..a090b33 100644 --- a/src/logger/reader_logger.c +++ b/src/logger/reader_logger.c @@ -2,6 +2,8 @@ #include "reader_common.h" #include "logger_internal.h" +#include + static void free_reader_logger(struct reader_common *_reader) { struct reader_logger *const reader = (struct reader_logger *) _reader; diff --git a/src/logsend/logsend.c b/src/logsend/logsend.c index cc47a8b..f97b289 100644 --- a/src/logsend/logsend.c +++ b/src/logsend/logsend.c @@ -3,8 +3,8 @@ #include #include +#include #include -#include #include struct parsed_params { diff --git a/src/shared/backend_androidlogger.c b/src/shared/backend_androidlogger.c index 7b5b871..1eba03d 100644 --- a/src/shared/backend_androidlogger.c +++ b/src/shared/backend_androidlogger.c @@ -32,6 +32,7 @@ // DLog #include +#include #include #include #include diff --git a/src/shared/buffer_traits.c b/src/shared/buffer_traits.c new file mode 100644 index 0000000..a9dfebc --- /dev/null +++ b/src/shared/buffer_traits.c @@ -0,0 +1,62 @@ +/* MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ + +#include + +static const struct { + log_id_t id; + char * name; + bool core; +} buffer_traits[LOG_ID_MAX] = { + [LOG_ID_MAIN ] = { .name = "main" , .core = true, }, + [LOG_ID_RADIO ] = { .name = "radio" , .core = true, }, + [LOG_ID_SYSTEM] = { .name = "system", .core = true, }, + [LOG_ID_APPS ] = { .name = "apps" , .core = true, }, + [LOG_ID_KMSG ] = { .name = "kmsg" , .core = false, }, + [LOG_ID_SYSLOG] = { .name = "syslog", .core = false, }, +}; + +bool is_buffer_valid(log_id_t id) +{ + return id > LOG_ID_INVALID + && id < LOG_ID_MAX; +} + +bool is_core_buffer(log_id_t id) +{ + return is_buffer_valid(id) && buffer_traits[id].core; +} + +char *log_name_by_id(log_id_t id) +{ + return is_buffer_valid(id) ? buffer_traits[id].name : ""; +} + +log_id_t log_id_by_name(const char *name) +{ + for (log_id_t i = 0; i < LOG_ID_MAX; ++i) + if (!strcmp(name, buffer_traits[i].name)) + return i; + + return LOG_ID_INVALID; +} + diff --git a/src/shared/logcommon.c b/src/shared/logcommon.c index df5a277..a5c720e 100644 --- a/src/shared/logcommon.c +++ b/src/shared/logcommon.c @@ -43,18 +43,6 @@ #define MAX_PREFIX_SIZE 32 -static struct { - log_id_t id; - char * name; -} logid_map[LOG_ID_MAX] = { - { .id = LOG_ID_MAIN, .name = "main" }, - { .id = LOG_ID_RADIO, .name = "radio" }, - { .id = LOG_ID_SYSTEM, .name = "system" }, - { .id = LOG_ID_APPS, .name = "apps" }, - { .id = LOG_ID_KMSG, .name = "kmsg" }, - { .id = LOG_ID_SYSLOG, .name = "syslog" }, -}; - // message header structure to send and receive pipe file descriptor // contains header data required for building message // to send it using sendmsg(2) and receive using recvmsg(2) @@ -168,44 +156,6 @@ static int parse_pipe_msg_control(struct msghdr *msg_hdr) } /** - * @brief Get buffer ID by name - * @details Returns the ID of the buffer with the given name - * @param[in] name The name of the buffer whose ID we seek - * @return If such buffer exists, its ID. - * Else, LOG_ID_INVALID. - * @see log_name_by_id - */ -log_id_t log_id_by_name(const char *name) -{ - log_id_t i; - - for (i = 0; i < LOG_ID_MAX; ++i) - if (!strcmp(name, logid_map[i].name)) - return logid_map[i].id; - - return LOG_ID_INVALID; -} - -/** - * @brief Get buffer name by ID - * @details Returns the name of the buffer with the given ID - * @param[in] id The ID of the buffer whose name we seek - * @return If such buffer exists, its name. - * Else, empty string. - * @see log_id_by_name - */ -char * log_name_by_id(log_id_t id) -{ - log_id_t i; - - for (i = 0; i < LOG_ID_MAX; ++i) - if (id == logid_map[i].id) - return logid_map[i].name; - - return ""; -} - -/** * @brief Log crtical failure * @details Writes the given message to syslog with a critical failure note * @param[in] message The message to write to syslog diff --git a/src/shared/util_parser.c b/src/shared/util_parser.c index 78ba0e0..1c13560 100644 --- a/src/shared/util_parser.c +++ b/src/shared/util_parser.c @@ -1,4 +1,6 @@ #include + +#include #include #include diff --git a/src/tests/libdlog_pipe.c b/src/tests/libdlog_pipe.c index 974d361..dd5623c 100644 --- a/src/tests/libdlog_pipe.c +++ b/src/tests/libdlog_pipe.c @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono, int32_t pid, int32_t tid) = NULL; diff --git a/src/tests/test_common_wrap.c b/src/tests/test_common_wrap.c index d877c5b..9631513 100644 --- a/src/tests/test_common_wrap.c +++ b/src/tests/test_common_wrap.c @@ -28,6 +28,7 @@ // DLog #include +#include #include #include #include -- 2.7.4