-I$(srcdir)/external/sd-daemon \
-I$(srcdir)/external/fastlz \
-I$(srcdir)/external/miniz \
+ -I$(srcdir)/src/logger \
+ -I$(srcdir)/src/libdlogutil \
$(DEBUG_CFLAGS) \
-Wall \
-Werror \
configs/dlog-logger.conf.qos \
configs/dlog-pipe.conf.plog \
configs/dlog-logger.conf.plog \
+ configs/dlog-pipe.conf.compress \
+ configs/dlog-logger.conf.compress \
configs/dlog-pipe.conf.autodetect \
configs/dlog-logger.conf.autodetect \
configs/dlog-logger.conf.stdout_enable.1 \
--- /dev/null
+##### Settings used by the logging library
+backend=logger
+main=/dev/log_main
+apps=/dev/log_apps:/dev/log_events:
+system=/dev/log_system:
+radio=/dev/log_radio:
+
+main_size=1048576
+apps_size=1048576
+system_size=1048576
+radio_size=1048576
+
+plog=1
+limiter_apply_to_all_buffers=1
+limiter=1
+limiter|*|*=allow
+kmsg=:
+syslog=:
+
+kmsg_conn_sock=/var/lib/dlog-tests/kmsg.conn
+syslog_conn_sock=/var/lib/dlog-tests/syslog.conn
+
+kmsg_ctl_sock=/var/lib/dlog-tests/kmsg.ctl
+syslog_ctl_sock=/var/lib/dlog-tests/syslog.ctl
+
+kmsg_conn_sock_rights=0222
+syslog_conn_sock_rights=0222
+
+kmsg_ctl_sock_rights=0222
+syslog_ctl_sock_rights=0222
+
+kmsg_size=1048576
+syslog_size=1048576
+
+util_sorting_time_window=5000
+util_sorting_buffer_size=32000
+dynamic_config_path=/tmp/dlog-filters/
+
+main_conn_sock=/var/lib/dlog-tests/main.conn
+
+main_ctl_sock=/var/lib/dlog-tests/main.ctl
+main_ctl_sock_rights=0222
+main_ctl_sock_owner=log
+main_ctl_sock_group=log
+
+dlog_logger_conf_compress=dlogutil -b main -r 160000 -m xyz123
\ No newline at end of file
--- /dev/null
+##### Settings used by the logging library
+backend=pipe
+main=/dev/log_main
+apps=/dev/log_apps:/dev/log_events:
+system=/dev/log_system:
+radio=/dev/log_radio:
+
+main_size=1048576
+apps_size=1048576
+system_size=1048576
+radio_size=1048576
+
+plog=1
+limiter_apply_to_all_buffers=1
+limiter=1
+limiter|*|*=allow
+
+# Sockets that all programs connect to to receive a logging pipe.
+main_conn_sock=/var/lib/dlog-tests/main.conn
+apps_conn_sock=/var/lib/dlog-tests/apps.conn
+system_conn_sock=/var/lib/dlog-tests/system.conn
+radio_conn_sock=/var/lib/dlog-tests/radio.conn
+kmsg_conn_sock=/var/lib/dlog-tests/kmsg.conn
+syslog_conn_sock=/var/lib/dlog-tests/syslog.conn
+
+# Sockets that administrative programs connect to to manipulate the daemon.
+main_ctl_sock=/var/lib/dlog-tests/main.ctl
+apps_ctl_sock=/var/lib/dlog-tests/apps.ctl
+system_ctl_sock=/var/lib/dlog-tests/system.ctl
+radio_ctl_sock=/var/lib/dlog-tests/radio.ctl
+kmsg_ctl_sock=/var/lib/dlog-tests/kmsg.ctl
+syslog_ctl_sock=/var/lib/dlog-tests/syslog.ctl
+
+# Permissions for the relevant sockets.
+main_conn_sock_rights=0222
+apps_conn_sock_rights=0222
+system_conn_sock_rights=0222
+radio_conn_sock_rights=0222
+kmsg_conn_sock_rights=0222
+syslog_conn_sock_rights=0222
+
+main_ctl_sock_rights=0222
+apps_ctl_sock_rights=0222
+system_ctl_sock_rights=0222
+radio_ctl_sock_rights=0222
+kmsg_ctl_sock_rights=0222
+syslog_ctl_sock_rights=0222
+
+kmsg_size=1048576
+syslog_size=1048576
+
+util_sorting_time_window=5000
+util_sorting_buffer_size=32000
+dynamic_config_path=/tmp/dlog-filters/
+
+main_conn_sock=/var/lib/dlog-tests/main.conn
+main_ctl_sock=/var/lib/dlog-tests/main.ctl
+main_ctl_sock_rights=0222
+main_ctl_sock_owner=log
+main_ctl_sock_group=log
+
+dlog_logger_conf_compress=dlogutil -b main -r 160000 -m xyz123
\ No newline at end of file
/* the following can be OR'd with REPLY,
* but are exclusive with each other */
- DLOG_REQ_PIPE = 1 << 1,
- DLOG_REQ_CLEAR = 2 << 1,
- DLOG_REQ_HANDLE_LOGUTIL = 3 << 1,
- DLOG_REQ_GET_CAPACITY = 4 << 1,
- DLOG_REQ_GET_USAGE = 5 << 1,
- DLOG_REQ_STDOUT = 6 << 1,
- DLOG_REQ_GLOBAL_ENABLE_DISABLE_STDOUT = 7 << 1,
- DLOG_REQ_GET_STDOUT = 8 << 1,
- DLOG_REQ_HANDLE_COMPRESSED_LOGUTIL = 9 << 1,
+ DLOG_REQ_PIPE = 1 << 1,
+ DLOG_REQ_CLEAR = 2 << 1,
+ DLOG_REQ_HANDLE_LOGUTIL = 3 << 1,
+ DLOG_REQ_GET_CAPACITY = 4 << 1,
+ DLOG_REQ_GET_USAGE = 5 << 1,
+ DLOG_REQ_STDOUT = 6 << 1,
+ DLOG_REQ_GLOBAL_ENABLE_DISABLE_STDOUT = 7 << 1,
+ DLOG_REQ_GET_STDOUT = 8 << 1,
+ DLOG_REQ_HANDLE_COMPRESSED_LOGUTIL = 9 << 1,
+ DLOG_REQ_CHANGE_COMPRESSION_SIZE = 10 << 1,
};
enum {
%{_datadir}/dlog-pipe.conf.stdout_enable.1
%{_datadir}/dlog-pipe.conf.stdout_enable.2
%{_datadir}/dlog-pipe.conf.stdout_enable.3
+%{_datadir}/dlog-logger.conf.compress
+%{_datadir}/dlog-pipe.conf.compress
%{_sysconfdir}/dlog.conf.d/99-dlog-logger.disable-platform-logging-for-testsuite.conf
%dir %attr(755,log,log) /var/lib/dlog-tests
%dir %attr(755,log,log) /usr/share/dlog-filters.conf.test
#include <logconfig.h>
#include <loglimiter.h>
+#include "log_compressed_storage.h"
+#include "fdi_pipe.h"
+#include "fdi_pipe_internal.h"
#include "logctl.h"
+#include "logpipe.h"
int get_is_pipe(struct log_config *conf, bool *out)
{
bool use_global_action = true; // if neither tag, pid nor priority is specified
+ /* skips a part of the help message */
+ bool show_dynamic_conf_msg = true;
+
#define SET_ACTION(x) do { \
if (params->action != x && params->action != ACTION_NONE) \
goto failure; \
{"pid" , required_argument, NULL, 2},
{"enable-stdout", no_argument, NULL, 3},
{"disable-stdout", no_argument, NULL, 4},
+ {"compression-resize", required_argument, NULL, 5},
+ {"compression-name", required_argument, NULL, 6},
{0}
};
SET_ACTION(ACTION_STDOUT);
params->plog_enable = false;
break;
- case 'b': {
+ case 5: {
+ const int capacity = atoi(optarg);
+ if (capacity <= 0)
+ goto failure;
+ params->capacity = capacity;
+ SET_ACTION(ACTION_RESIZE);
+ show_dynamic_conf_msg = false;
+ break;
+ } case 6: {
+ params->storage_name = optarg;
+ SET_ACTION(ACTION_RESIZE);
+ show_dynamic_conf_msg = false;
+ break;
+ } case 'b': {
const int buf_id = sink_id_by_name(optarg);
if (buf_id == LOG_ID_INVALID)
goto failure;
"\tbufname: main system radio apps (default: all of them)\n"
"\t-b/--buffer bufname: pick given buffer for plog control\n"
"\t--enable/--disable: control platform logging for chosen buffers\n"
- "\t--enable-stdout/--disable-stdout: control stdout redirection for chosen buffers\n\n"
- "NOTE: to use dlogctl, dynamic dlog config has to be enabled!\n"
+ "\t--enable-stdout/--disable-stdout: control stdout redirection for chosen buffers\n"
+ "\t--compression-name: resizes given named compression buffer. Must be used with --compression-resize\n"
+ "\t--compression-resize: sets compression buffer to given size, in bytes.\n"
+ "\n"
+ , argv[0]
+ , __LOG_LIMITER_LIMIT_MAX
+ , argv[0]
+ );
+
+ if (show_dynamic_conf_msg) {
+ printf("NOTE: to use dlogctl, dynamic dlog config has to be enabled!\n"
"Define the %s config entry to a *DIRECTORY* path.\n"
"ALSO: filters won't work for the APPS buffer (whence most spam comes)\n"
"unless you set `limiter_apply_to_all_buffers` in the config to 1!\n"
"The filters are also currently per process; this may change in the future.\n\n"
- , argv[0]
- , __LOG_LIMITER_LIMIT_MAX
- , argv[0]
, DYNAMIC_CONFIG_CONF_KEY
- );
+ );
+ }
return false;
}
return 0;
}
+int handle_resize(const struct parsed_params *params, const char *config_path, struct log_config *conf)
+{
+ assert(params);
+ assert(conf);
+ (void)config_path;
+
+ const unsigned int capacity = params->capacity;
+ int request = DLOG_REQ_CHANGE_COMPRESSION_SIZE;
+
+ char conf_key[MAX_CONF_KEY_LEN];
+ snprintf(conf_key, sizeof(conf_key), "main_ctl_sock");
+ strtok(conf_key, "\n");
+
+ const char *sock_path = log_config_get(conf, conf_key);
+ if (!sock_path) {
+ fprintf(stderr, "Couldn't get sock path\n");
+ return -ENOENT;
+ }
+
+ __attribute__((cleanup(close_fd))) int sock_fd = connect_sock(sock_path);
+ if (sock_fd < 0) {
+ fprintf(stderr, "Couldn't connect to the sock\n");
+ return sock_fd;
+ }
+
+ size_t data_size = sizeof(unsigned int) + strlen(params->storage_name) + 1;
+ if (data_size > MAX_LOGGER_REQUEST_LEN) {
+ fprintf(stderr, "Request data is too big\n");
+ return -ENOMEM;
+ }
+
+ __attribute__((cleanup(free_ptr))) char *data = malloc(data_size);
+ memcpy(data, &capacity, sizeof(unsigned int));
+ memcpy(data + sizeof(unsigned int), params->storage_name, strlen(params->storage_name) + 1);
+
+ return send_dlog_request(sock_fd, request, (void *)data, data_size);
+}
+
int get_stdout_one_pipe(log_id_t id, struct log_config *conf, bool *out_enabled)
{
assert(conf);
[ACTION_PLOG] = handle_plog,
[ACTION_CLEAR] = handle_clear,
[ACTION_STDOUT] = handle_stdout,
+ [ACTION_RESIZE] = handle_resize,
};
exit_code = handles[params.action](¶ms, full_inotify_path, &conf);
ACTION_SET_PID,
ACTION_PLOG,
ACTION_STDOUT,
+ ACTION_RESIZE,
} action;
const char *tag;
char prio;
const char *value;
bool plog_enable;
int plog_buffers_bitset;
+ unsigned int capacity;
+ const char *storage_name;
};
struct keys_values {
int handle_set(const struct parsed_params *params, const char *config_path, struct log_config *conf);
int handle_plog(const struct parsed_params *params, const char *config_path, struct log_config *conf);
int handle_clear(const struct parsed_params *params, const char *config_path, struct log_config *conf);
+int handle_resize(const struct parsed_params *params, const char *config_path, struct log_config *conf);
#include "log_buffer.h"
+#include "log_compressed_storage.h"
#include "logger_internal.h"
#include "subreader_dlogutil.h"
#include "reader_memory.h"
return send_dlog_reply(wr->fd_entity.fd, DLOG_REQ_GET_STDOUT, DLOG_REQ_RESULT_OK, &(char){ wr->buf_ptr->accept_stdout }, sizeof(char));
}
+bool cmp_names(void *element, void *userdata)
+{
+ return strcmp(log_compressed_storage_get_name((log_compressed_storage *) element), (char *) userdata) == 0;
+}
+
+static int service_writer_handle_req_compression_resize(struct logger *server, struct writer *wr, struct dlog_control_msg *msg)
+{
+ assert(server);
+ assert(wr);
+ assert(wr->buf_ptr);
+ assert(msg);
+ assert(msg->request == DLOG_REQ_CHANGE_COMPRESSION_SIZE);
+
+ if (msg->length <= sizeof(struct dlog_control_msg) ||
+ msg->length > sizeof(struct dlog_control_msg) + MAX_LOGGER_REQUEST_LEN)
+ return -EINVAL;
+
+ if (msg->data[msg->length - sizeof(struct dlog_control_msg)] != 0)
+ return -EINVAL;
+
+ __attribute__((cleanup(free_ptr))) char *storage_name = NULL;
+ __attribute__((cleanup(free_ptr))) char *data = calloc(1, msg->length);
+ if (data == NULL)
+ return -ENOMEM;
+ memcpy(data, msg->data, msg->length);
+
+ unsigned int capacity = *(unsigned int *)data;
+ if (capacity == 0)
+ return -EINVAL;
+
+ size_t storage_name_len = msg->length - sizeof(unsigned int);
+ storage_name = calloc(1, storage_name_len);
+ if (storage_name == NULL)
+ return -ENOMEM;
+ memcpy(storage_name, (data + sizeof(unsigned int)), storage_name_len);
+
+ log_compressed_storage *storage = list_find_if(server->compressed_memories, storage_name, cmp_names);
+ if (storage == NULL)
+ return -ENOENT;
+
+ log_compressed_storage_resize(storage, capacity);
+ return 0;
+}
+
/**
* @brief Service control request
* @details Handle a clear-buffer or util request in respect to msg request type
case DLOG_REQ_GET_USAGE: ret = service_writer_handle_req_get_usage (server, wr, msg); break;
case DLOG_REQ_GLOBAL_ENABLE_DISABLE_STDOUT: ret = service_writer_handle_req_global_enable_disable_stdout(server, wr, msg); break;
case DLOG_REQ_GET_STDOUT: ret = service_writer_handle_req_get_stdout (server, wr, msg); break;
+ case DLOG_REQ_CHANGE_COMPRESSION_SIZE: ret = service_writer_handle_req_compression_resize (server, wr, msg); break;
default: ret = -EINVAL;
}
done
fi
+if [ "$type" = "pipe" ]; then
+ kill $LOGGER > /dev/null
+ sleep 1
+
+ PRERESIZE_CONFIG_PATH="$DLOG_CONFIG_PATH"
+ DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.compress"
+
+ RUNTIME_FILTERS_DIR="/tmp/dlog-filters/"
+ mkdir -m 777 -p "$RUNTIME_FILTERS_DIR"
+
+ dlog_logger -t 0 &
+ LOGGER=$!
+ sleep 1
+
+ dlogsend -b main -c 9999 resizetestblalbl &
+ sleep 4
+ LOG_DETAILS="testing if compression-resize works (1/3)"
+ [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
+
+ dlogctl --compression-name xyz123 --compression-resize 1
+ sleep 5
+ LOG_DETAILS="testing if compression-resize works (2/3)"
+ [ "$(dlogutil -d -m xyz123 | wc -l)" -eq 0 ] && ok || fail
+
+ dlogctl --compression-name xyz123 --compression-resize 200000
+ dlogsend -b main -c 9999 resizetestblalbl &
+ sleep 4
+ LOG_DETAILS="testing if compression-resize works (3/3)"
+ [ "$(dlogutil -d -m xyz123 | wc -l)" -ge 1 ] && ok || fail
+
+ dlogutil -c
+ kill $LOGGER > /dev/null
+ DLOG_CONFIG_PATH=$PRERESIZE_CONFIG_PATH
+ rm -rf $RUNTIME_FILTERS_DIR
+fi
+
# show results, clean up and return an exit code
echo "$OKS / $TOTAL tests passed"