* @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)
#pragma once
#include <logconfig.h>
+#include <logprint.h>
+#include <ptrs_list.h>
#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);
/**
* @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;
}
* @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) {
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;
}
#pragma once
#include <logconfig.h>
+#include <logprint.h>
+#include <ptrs_list.h>
#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);
}
}
-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);
assert(file_input_names);
assert(action);
assert(dump);
- assert(tag_cnt);
+ assert(filters);
int silence = 0;
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)
}
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;
}
{
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;
__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;
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)))
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);