test_libredirect_multi_SOURCES = \
tests/test_libredirect_multi.c
+usrlibexeclibdlog_PROGRAMS += test_config_redirect
+test_config_redirect_CFLAGS = \
+ $(AM_CFLAGS) \
+ -fPIE
+
+test_config_redirect_LDFLAGS = \
+ $(AM_LDFLAGS) \
+ -pie
+
+test_config_redirect_DEPENDENCIES = \
+ libdlog_redirect_stdout.la
+
+test_config_redirect_LDADD = \
+ libdlog_redirect_stdout.la
+
+test_config_redirect_SOURCES = \
+ tests/test_config_redirect.c
+
check_PROGRAMS = \
src/tests/test_fastlz_pos \
configs/dlog-pipe.conf.qos \
configs/dlog-logger.conf.qos \
configs/dlog-pipe.conf.autodetect \
- configs/dlog-logger.conf.autodetect
+ configs/dlog-logger.conf.autodetect \
+ configs/dlog-logger.conf.stdout_enable.1 \
+ configs/dlog-logger.conf.stdout_enable.2 \
+ configs/dlog-logger.conf.stdout_enable.3 \
+ configs/dlog-pipe.conf.stdout_enable.1 \
+ configs/dlog-pipe.conf.stdout_enable.2 \
+ configs/dlog-pipe.conf.stdout_enable.3
unitdir = $(prefix)/lib/systemd/system
nodist_unit_DATA = units/dlog_logger.service \
--- /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
+debugmode=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=1000
+util_sorting_buffer_size=8192
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=0
+stdout_enable_radio=0
+stdout_enable_system=0
+stdout_enable_apps=0
--- /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
+debugmode=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=1000
+util_sorting_buffer_size=8192
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=1
+stdout_enable_radio=1
+stdout_enable_system=0
+stdout_enable_apps=0
--- /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
+debugmode=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=1000
+util_sorting_buffer_size=8192
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=0
+stdout_enable_radio=0
+stdout_enable_system=1
+stdout_enable_apps=1
--- /dev/null
+# Lines starting with # are comments and are ignored.
+# Empty lines are also ignored.
+# Every other line is a config value and has to be in key=value format
+
+backend=pipe
+
+##### Settings used by the logging library
+
+# Platform logging. Whether logging happens at all.
+plog=1
+
+# Debugmode - whether write platform debug log or not
+debugmode=1
+
+# Limiter - whether it's enabled and the rules (check the documentation for how to create rules).
+limiter=1
+limiter|*|*=allow
+
+##### Settings used by the logging daemon
+
+# 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
+
+main_conn_sock_owner=log
+apps_conn_sock_owner=log
+system_conn_sock_owner=log
+radio_conn_sock_owner=log
+kmsg_conn_sock_owner=log
+syslog_conn_sock_owner=log
+
+main_ctl_sock_owner=log
+apps_ctl_sock_owner=log
+system_ctl_sock_owner=log
+radio_ctl_sock_owner=log
+kmsg_ctl_sock_owner=log
+syslog_ctl_sock_owner=log
+
+main_conn_sock_group=log
+apps_conn_sock_group=log
+system_conn_sock_group=log
+radio_conn_sock_group=log
+kmsg_conn_sock_group=log
+syslog_conn_sock_group=log
+
+main_ctl_sock_group=log
+apps_ctl_sock_group=log
+system_ctl_sock_group=log
+radio_ctl_sock_group=log
+kmsg_ctl_sock_group=log
+syslog_ctl_sock_group=log
+
+main_size=1048576
+apps_size=1048576
+system_size=1048576
+radio_size=1048576
+kmsg_size=1048576
+syslog_size=1048576
+
+util_sorting_time_window=5000
+util_sorting_buffer_size=32000
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=0
+stdout_enable_radio=0
+stdout_enable_system=0
+stdout_enable_apps=0
--- /dev/null
+# Lines starting with # are comments and are ignored.
+# Empty lines are also ignored.
+# Every other line is a config value and has to be in key=value format
+
+backend=pipe
+
+##### Settings used by the logging library
+
+# Platform logging. Whether logging happens at all.
+plog=1
+
+# Debugmode - whether write platform debug log or not
+debugmode=1
+
+# Limiter - whether it's enabled and the rules (check the documentation for how to create rules).
+limiter=1
+limiter|*|*=allow
+
+##### Settings used by the logging daemon
+
+# 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
+
+main_conn_sock_owner=log
+apps_conn_sock_owner=log
+system_conn_sock_owner=log
+radio_conn_sock_owner=log
+kmsg_conn_sock_owner=log
+syslog_conn_sock_owner=log
+
+main_ctl_sock_owner=log
+apps_ctl_sock_owner=log
+system_ctl_sock_owner=log
+radio_ctl_sock_owner=log
+kmsg_ctl_sock_owner=log
+syslog_ctl_sock_owner=log
+
+main_conn_sock_group=log
+apps_conn_sock_group=log
+system_conn_sock_group=log
+radio_conn_sock_group=log
+kmsg_conn_sock_group=log
+syslog_conn_sock_group=log
+
+main_ctl_sock_group=log
+apps_ctl_sock_group=log
+system_ctl_sock_group=log
+radio_ctl_sock_group=log
+kmsg_ctl_sock_group=log
+syslog_ctl_sock_group=log
+
+main_size=1048576
+apps_size=1048576
+system_size=1048576
+radio_size=1048576
+kmsg_size=1048576
+syslog_size=1048576
+
+util_sorting_time_window=5000
+util_sorting_buffer_size=32000
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=1
+stdout_enable_radio=1
+stdout_enable_system=0
+stdout_enable_apps=0
--- /dev/null
+# Lines starting with # are comments and are ignored.
+# Empty lines are also ignored.
+# Every other line is a config value and has to be in key=value format
+
+backend=pipe
+
+##### Settings used by the logging library
+
+# Platform logging. Whether logging happens at all.
+plog=1
+
+# Debugmode - whether write platform debug log or not
+debugmode=1
+
+# Limiter - whether it's enabled and the rules (check the documentation for how to create rules).
+limiter=1
+limiter|*|*=allow
+
+##### Settings used by the logging daemon
+
+# 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
+
+main_conn_sock_owner=log
+apps_conn_sock_owner=log
+system_conn_sock_owner=log
+radio_conn_sock_owner=log
+kmsg_conn_sock_owner=log
+syslog_conn_sock_owner=log
+
+main_ctl_sock_owner=log
+apps_ctl_sock_owner=log
+system_ctl_sock_owner=log
+radio_ctl_sock_owner=log
+kmsg_ctl_sock_owner=log
+syslog_ctl_sock_owner=log
+
+main_conn_sock_group=log
+apps_conn_sock_group=log
+system_conn_sock_group=log
+radio_conn_sock_group=log
+kmsg_conn_sock_group=log
+syslog_conn_sock_group=log
+
+main_ctl_sock_group=log
+apps_ctl_sock_group=log
+system_ctl_sock_group=log
+radio_ctl_sock_group=log
+kmsg_ctl_sock_group=log
+syslog_ctl_sock_group=log
+
+main_size=1048576
+apps_size=1048576
+system_size=1048576
+radio_size=1048576
+kmsg_size=1048576
+syslog_size=1048576
+
+util_sorting_time_window=5000
+util_sorting_buffer_size=32000
+dynamic_config_path=/tmp/dlog-filters/
+
+stdout_enable_main=0
+stdout_enable_radio=0
+stdout_enable_system=1
+stdout_enable_apps=1
\ No newline at end of file
%{_libexecdir}/libdlog/test_libredirect
%{_libexecdir}/libdlog/test_libredirect_multi
%{_libexecdir}/libdlog/test_filters
+%{_libexecdir}/libdlog/test_config_redirect
%{_datadir}/dlog-pipe.conf.test
%{_datadir}/dlog-logger.conf.test
%{_datadir}/dlog-logger.conf.alias
%{_datadir}/dlog-logger.conf.qos
%{_datadir}/dlog-pipe.conf.autodetect
%{_datadir}/dlog-logger.conf.autodetect
+%{_datadir}/dlog-logger.conf.stdout_enable.1
+%{_datadir}/dlog-logger.conf.stdout_enable.2
+%{_datadir}/dlog-logger.conf.stdout_enable.3
+%{_datadir}/dlog-pipe.conf.stdout_enable.1
+%{_datadir}/dlog-pipe.conf.stdout_enable.2
+%{_datadir}/dlog-pipe.conf.stdout_enable.3
%{_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 <dlog-redirect-stdout.h>
#include <logcommon.h>
+#include <logconfig.h>
#include "internal.h"
+static bool config_allows_redirection(log_id_t buffer)
+{
+ struct log_config conf = {};
+ if (log_config_read(&conf) < 0)
+ return false;
+
+ char key[MAX_CONF_KEY_LEN];
+ snprintf(key, sizeof key, "stdout_enable_%s", log_name_by_id(buffer));
+
+ bool ret = log_config_get_boolean(&conf, key, true);
+ log_config_free(&conf);
+ return ret;
+}
+
EXPORT_API int dlog_connect_fd(int buffer, int fileno, const char *tag, int prio)
{
if (buffer <= LOG_ID_INVALID || buffer >= LOG_ID_MAX)
else if (fileno == STDERR_FILENO)
setenv(DLOG_ENV_STDERR_LINE_BUFFERED, "1", 1);
+ if (!config_allows_redirection((log_id_t)buffer))
+ return -EOPNOTSUPP;
+
return 0;
}
LOG_DETAILS="testing if the timestamps are correct"
test_verifytime && ok || fail
+DLOG_PREV_PATH=$DLOG_CONFIG_PATH
+
+LOG_DETAILS="testing if config has control over redirecting to stdout (1/3)"
+DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.1"
+
+test_config_redirect 1 1 1 1 && ok || fail
+
+LOG_DETAILS="testing if config has control over redirecting to stdout (2/3)"
+DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.2"
+test_config_redirect 0 0 1 1 && ok || fail
+
+LOG_DETAILS="testing if config has control over redirecting to stdout (3/3)"
+DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.stdout_enable.3"
+test_config_redirect 1 1 0 0 && ok || fail
+
+DLOG_CONFIG_PATH=$DLOG_PREV_PATH
+
if [ "$quick" -ne 1 ]; then
PREAUTODETECT_CONFIG_PATH=$DLOG_CONFIG_PATH
DLOG_CONFIG_PATH="@datadir@/dlog-$type.conf.autodetect"
--- /dev/null
+/* DLOG
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <dlog-redirect-stdout.h>
+#include <dlog.h>
+
+int main(int argc, char** argv)
+{
+ int log_count = argc - 1;
+ bool* expected_results = (bool*)malloc(sizeof(bool) * (log_count));
+
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "1") == 0) {
+ expected_results[i - 1] = true;
+ } else if (strcmp(argv[i], "0") == 0) {
+ expected_results[i - 1] = false;
+ } else {
+ free(expected_results);
+ return EXIT_FAILURE;
+ }
+ }
+
+ for (int i = 0; i < log_count; i++) {
+ int result = dlog_connect_fd(i, STDOUT_FILENO, "tag", DLOG_INFO);
+ bool is_eopnotsupp = (result == -EOPNOTSUPP);
+ if (is_eopnotsupp != expected_results[i]) {
+ free(expected_results);
+ return EXIT_FAILURE;
+ }
+ }
+
+ free(expected_results);
+ return EXIT_SUCCESS;
+}
\ No newline at end of file