From: Michal Bloch Date: Wed, 7 Feb 2018 19:06:18 +0000 (+0100) Subject: util: handle filters correctly X-Git-Tag: accepted/tizen/unified/20180315.061335~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=440a7ca1f4065a7bc39c569661ece2ef5e0e7d12;p=platform%2Fcore%2Fsystem%2Fdlog.git util: handle filters correctly * for pipe-backend, do not create a filter locally as the daemon already does that. * do not disable sorting based on filter count as it is orthogonal to sorting (it is possible for many processes to share a tag). Change-Id: I21932344861b3c8d418e39c569ace62e8cb454c0 Signed-off-by: Michal Bloch --- diff --git a/src/logutil/fdi_logger.c b/src/logutil/fdi_logger.c index 2232328..f840057 100644 --- a/src/logutil/fdi_logger.c +++ b/src/logutil/fdi_logger.c @@ -47,12 +47,16 @@ static void clear_log_logger(int fd) * @param[in] buffer_name The name of the buffer * @param[in] clear Whether to clear the buffer * @param[in] conf The configuration - * @param[in] argc Argument count - * @param[in] argv Argument values + * @param[in] dump Whether dumping or not + * @param[in] filters List of filters + * @param[in] format Log processing format * @return FD wrapper structure to read from */ -struct fd_info *process_buffer_nonpipe(const char *buffer_name, int clear, struct log_config *conf) +struct fd_info *process_buffer_nonpipe(const char *buffer_name, int clear, struct log_config *conf, list_head filters, log_format *format) { + for (list_head iter = filters; iter; list_next(&iter)) + log_add_filter_string(format, (const char *)list_at(iter)); + char const *dev_path; dev_path = log_config_get(conf, buffer_name); if (!dev_path) diff --git a/src/logutil/fdi_logger.h b/src/logutil/fdi_logger.h index 320a7b5..af80cd3 100644 --- a/src/logutil/fdi_logger.h +++ b/src/logutil/fdi_logger.h @@ -1,7 +1,9 @@ #pragma once #include +#include +#include #include "fd_info.h" -struct fd_info *process_buffer_nonpipe(const char *buffer_name, int clear, struct log_config *conf); +struct fd_info *process_buffer_nonpipe(const char *buffer_name, int clear, struct log_config *conf, list_head filters, log_format *format); diff --git a/src/logutil/fdi_pipe.c b/src/logutil/fdi_pipe.c index 92f4c1d..b7e709e 100644 --- a/src/logutil/fdi_pipe.c +++ b/src/logutil/fdi_pipe.c @@ -29,24 +29,34 @@ static int do_clear_pipe(int sock_fd) /** * @brief Send a logger request * @details Send a logging request to the daemon - * @param[in] argc Argument count - * @param[in] argv Argument values + * @param[in] filters Log filters to use + * @param[in] dump Whether dumping or not * @param[in] sock_fd Socket file descriptor * @return 0 on success, -errno on failure */ -static int send_logger_request(int argc, char **argv, int sock_fd) +static int send_logger_request(list_head filters, int dump, int sock_fd) { + assert(filters); + assert(sock_fd >= 0); + char request_string[MAX_LOGGER_REQUEST_LEN] = "dlogutil"; int len = strlen(request_string); - for (int i = 1; i < argc; i++) { - int arglen = strnlen(argv[i], MAX_LOGGER_REQUEST_LEN); + if (dump) { + static const char dump_str[] = " -d"; + strncat(request_string, dump_str, sizeof request_string - len); + len += sizeof dump_str - 1; + } + + for (list_head iter = filters; iter; list_next(&iter)) { + const char *filter = (const char *)list_at(iter); + int arglen = strnlen(filter, MAX_LOGGER_REQUEST_LEN); int needed = arglen + 1 /* space */ + 1 /* null byte */; if (len + needed > sizeof(request_string)) - return 0; + return -E2BIG; strncat(request_string, " ", 1); - strncat(request_string, argv[i], arglen + 1); + strncat(request_string, filter, arglen + 1); len += needed; } @@ -62,22 +72,22 @@ static int send_logger_request(int argc, char **argv, int sock_fd) * @param[in] buffer_name The name of the buffer * @param[in] clear Whether to clear the buffer * @param[in] conf The configuration - * @param[in] argc Argument count - * @param[in] argv Argument values + * @param[in] dump Whether dumping or not + * @param[in] filters List of filters + * @param[in] format Log processing format * @return FD wrapper structure of a pipe if we are to read from one, else NULL */ -struct fd_info *process_buffer_pipe(const char *buffer_name, int clear, struct log_config *conf, int argc, char **argv) +struct fd_info *process_buffer_pipe(const char *buffer_name, int clear, struct log_config *conf, int dump, list_head filters, log_format *format) { char conf_key[MAX_CONF_KEY_LEN]; - int argc_processed = 0; - char * argv_processed[argc]; char const * sock_path; int sock_fd = -1; int pipe_fd; - int i; struct fd_info *ret = NULL; + log_add_filter_string(format, "*:V"); // use the widest possible filter to let everything through as data are already filtered daemonside + snprintf(conf_key, sizeof(conf_key), "%s_ctl_sock", buffer_name); sock_path = log_config_get(conf, conf_key); if (!sock_path) { @@ -96,18 +106,7 @@ struct fd_info *process_buffer_pipe(const char *buffer_name, int clear, struct l goto cleanup; } - for (i = 0; i < argc; ++i) { - if ((!strcmp("-b", argv[i])) - || !strcmp("--dumpfile", argv[i]) - || !strcmp("-f", argv[i]) - || !strcmp("-r", argv[i]) - || !strcmp("-n", argv[i])) - ++i; - else - argv_processed[argc_processed++] = argv[i]; - } - - if (send_logger_request(argc_processed, argv_processed, sock_fd) < 0) { + if (send_logger_request(filters, dump, sock_fd) < 0) { printf("Error: could not send request to logger daemon\n"); goto cleanup; } diff --git a/src/logutil/fdi_pipe.h b/src/logutil/fdi_pipe.h index 1e96ee8..d6896e6 100644 --- a/src/logutil/fdi_pipe.h +++ b/src/logutil/fdi_pipe.h @@ -1,7 +1,9 @@ #pragma once #include +#include +#include #include "fd_info.h" -struct fd_info *process_buffer_pipe(const char *buffer_name, int clear, struct log_config *conf, int argc, char **argv); +struct fd_info *process_buffer_pipe(const char *buffer_name, int clear, struct log_config *conf, int dump, list_head filters, log_format *format); diff --git a/src/logutil/logutil.c b/src/logutil/logutil.c index 3377966..d17696f 100755 --- a/src/logutil/logutil.c +++ b/src/logutil/logutil.c @@ -235,7 +235,7 @@ static void handle_pipe(struct fd_info **data_fds, int fd_count, int dump, struc } } -int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_vector *logs, int *enabled_buffers, list_head *file_input_names, action_e *action, int *dump, int *tag_cnt) +int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_vector *logs, int *enabled_buffers, list_head *file_input_names, action_e *action, int *dump, list_head *filters) { assert(argv); assert(logs); @@ -244,7 +244,7 @@ int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_ve assert(file_input_names); assert(action); assert(dump); - assert(tag_cnt); + assert(filters); int silence = 0; @@ -301,7 +301,7 @@ int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_ve break; case 's': silence = 1; - log_add_filter_string(l_file->format, "*:s"); + list_add(filters, "*:s"); break; case 'r': if (sscanf(optarg, "%zu", &l_file->rotate_size_kbytes) != 1) @@ -328,14 +328,10 @@ int parse_options(int argc, char **argv, struct log_file *l_file, struct sort_ve } if (optind < argc) - while (optind < argc) { - log_add_filter_string(l_file->format, argv[optind]); - if (argv[optind][0] != '*') - ++*tag_cnt; - optind++; - } + while (optind < argc) + list_add(filters, argv[optind++]); else if (!silence) - log_add_filter_string(l_file->format, "*:D"); + list_add(filters, "*:D"); return 0; } @@ -359,6 +355,7 @@ int main(int argc, char **argv) { int enabled_buffers = 0; // bitset __attribute__ ((cleanup(list_clear))) list_head file_input_names = NULL; + __attribute__ ((cleanup(list_clear))) list_head filters = NULL; const char * conf_value; __attribute__ ((cleanup(log_config_free))) struct log_config conf = {.begin = NULL, .last = NULL}; action_e action = ACTION_PRINT; @@ -366,7 +363,6 @@ int main(int argc, char **argv) __attribute__ ((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = NULL; int fdi_cnt = 0; int i; - int tag_cnt = 0; __attribute__ ((cleanup(logfile_free))) struct log_file l_file; __attribute__ ((cleanup(sort_vector_free))) struct sort_vector logs; int r; @@ -384,7 +380,7 @@ int main(int argc, char **argv) else sort_vector_apply_config(&logs, &conf); - if (parse_options(argc, argv, &l_file, &logs, &enabled_buffers, &file_input_names, &action, &dump, &tag_cnt) < 0) + if (parse_options(argc, argv, &l_file, &logs, &enabled_buffers, &file_input_names, &action, &dump, &filters) < 0) return 1; if (!validate_buffer_set(&enabled_buffers, list_count(file_input_names))) @@ -423,12 +419,12 @@ int main(int argc, char **argv) if (!strcmp(conf_value, "pipe") || !strcmp(bufname, "syslog") || !strcmp(bufname, "kmsg")) - fdi = process_buffer_pipe(bufname, action == ACTION_CLEAR, &conf, argc, argv); + fdi = process_buffer_pipe(bufname, action == ACTION_CLEAR, &conf, dump, filters, l_file.format); else - fdi = process_buffer_nonpipe(bufname, action == ACTION_CLEAR, &conf); + fdi = process_buffer_nonpipe(bufname, action == ACTION_CLEAR, &conf, filters, l_file.format); if (fdi) { fdi_ptrs[fdi_cnt++] = fdi; - if (bit_count(enabled_buffers) == 1 || tag_cnt == 1 || !IS_VECTOR_SIZE_SORTABLE(logs.size)) + if (bit_count(enabled_buffers) == 1 || !IS_VECTOR_SIZE_SORTABLE(logs.size)) fdi->do_sorting = 0; } else { printf("Unable to access buffer \"%s\"\n", bufname);