From 29550842ae3e10b7842f2dd40c804b4fbbf13e22 Mon Sep 17 00:00:00 2001 From: Rafal Pietruch Date: Thu, 16 Feb 2017 16:50:02 +0100 Subject: [PATCH] [4.0] kmsg-backend removed Change-Id: I9d98e6fdbecfc6fdea7459667d5ae506b3772982 --- Makefile.am | 19 +----- configs/dlog.conf.kmsg | 24 -------- include/dlog_ioctl.h | 36 ----------- include/logconfig.h | 1 - include/queued_entry.h | 2 +- packaging/01-dlog.rules | 1 - packaging/dlog.spec | 42 ------------- packaging/dloginit.service | 20 ------- src/libdlog/log.c | 3 - src/libdlog/log_kmsg.c | 113 ----------------------------------- src/logctrl/logctrl.c | 12 ---- src/logctrl/logctrl_doc.h | 2 +- src/logger/logger.c | 29 ++++----- src/loginit/loginit.c | 146 --------------------------------------------- src/logutil/logutil.c | 46 ++------------ src/shared/logconfig.c | 3 - src/shared/queued_entry.c | 80 ++++--------------------- src/tests/kmsg_parser.c | 15 +---- 18 files changed, 31 insertions(+), 563 deletions(-) delete mode 100644 configs/dlog.conf.kmsg delete mode 100644 packaging/dloginit.service delete mode 100644 src/libdlog/log_kmsg.c delete mode 100644 src/loginit/loginit.c diff --git a/Makefile.am b/Makefile.am index 59a4653..4017010 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,8 +23,7 @@ libdlog_la_SOURCES = \ src/shared/queued_entry.c \ src/libdlog/loglimiter.c \ src/libdlog/log_pipe.c \ - src/libdlog/log_android.c \ - src/libdlog/log_kmsg.c + src/libdlog/log_android.c libdlog_la_LIBADD = -lpthread \ $(CAPI_BASE_COMMON_LIBS) @@ -69,22 +68,6 @@ dlog_logger_SOURCES = \ src/shared/queued_entry.c \ src/shared/log_file.c -sbin_PROGRAMS = dloginit -dloginit_CFLAGS = \ - $(AM_CFLAGS) \ - $(LIBUDEV_CFLAGS) \ - -fPIE - -dloginit_LDFLAGS = \ - $(AM_LDFLAGS) \ - $(LIBUDEV_LIBS) \ - -pie - -dloginit_SOURCES = \ - src/loginit/loginit.c \ - src/shared/logconfig.c \ - src/shared/logcommon.c - bin_PROGRAMS += dlogctrl dlogctrl_CFLAGS = \ $(AM_CFLAGS) \ diff --git a/configs/dlog.conf.kmsg b/configs/dlog.conf.kmsg deleted file mode 100644 index 108c985..0000000 --- a/configs/dlog.conf.kmsg +++ /dev/null @@ -1,24 +0,0 @@ -backend=kmsg -plog=1 -debugmode=1 -limiter=0 -limiter|*|*=allow -main_size=1048576 -apps_size=1048576 -system_size=1048576 -radio_size=1048576 -kmsg_size=1048576 -kmsg_ctl_sock=/run/dlog/kmsg.ctl -kmsg_write_sock=/run/dlog/kmsg.wr -kmsg_ctl_sock_rights=0222 -kmsg_write_sock_rights=0222 -kmsg_ctl_sock_owner=log -kmsg_write_sock_owner=log -kmsg_ctl_sock_group=log -kmsg_write_sock_group=log -dlog_logger_conf_0=dlogutil -b system -r 2048 -n 1 -f /var/log/dlog/system -v recv_realtime *:I -dlog_logger_conf_1=dlogutil -b main -r 512 -n 1 -f /var/log/dlog/main -v recv_realtime *:W -dlog_logger_conf_2=dlogutil -b radio -r 256 -n 1 -f /var/log/dlog/radio -v recv_realtime -dlog_logger_conf_3=dlogutil -b apps -r 1024 -n 1 -f /var/log/dlog/apps -v recv_realtime -dlog_logger_conf_4=dlogutil -b kmsg -r 1024 -n 1 -f /var/log/dlog/kernel -v rwtime -util_sorting_buffer_size=8192 diff --git a/include/dlog_ioctl.h b/include/dlog_ioctl.h index e9c9743..3bb7db2 100644 --- a/include/dlog_ioctl.h +++ b/include/dlog_ioctl.h @@ -2,46 +2,10 @@ #define _DLOG_IOCTL_H_ #include -#include #define LOGGER_ENTRY_MAX_LEN (4*1024) #define LOGGER_ENTRY_MAX_PAYLOAD (LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry)) - -struct kmsg_cmd_buffer_add { - size_t size; - unsigned short mode; - int minor; -} __attribute__((packed)); - -#define KMSG_IOCTL_MAGIC 0xBB - -/* - * A ioctl interface for kmsg device. - * - * KMSG_CMD_BUFFER_ADD: Creates additional kmsg device based on its size - * and mode. Minor of created device is put. - * KMSG_CMD_BUFFER_DEL: Removes additional kmsg device based on its minor - */ -#define KMSG_CMD_BUFFER_ADD _IOWR(KMSG_IOCTL_MAGIC, 0x00, struct kmsg_cmd_buffer_add) -#define KMSG_CMD_BUFFER_DEL _IOW(KMSG_IOCTL_MAGIC, 0x01, int) - -/* - * A ioctl interface for kmsg* devices. - * - * KMSG_CMD_GET_BUF_SIZE: Retrieve cyclic log buffer size associated with - * device. - * KMSG_CMD_GET_READ_SIZE_MAX: Retrieve max size of data read by kmsg read - * operation. - * KMSG_CMD_CLEAR: Clears cyclic log buffer. After that operation - * there is no data to read from buffer unless - * logs are written. - */ -#define KMSG_CMD_GET_BUF_SIZE _IOR(KMSG_IOCTL_MAGIC, 0x80, uint32_t) -#define KMSG_CMD_GET_READ_SIZE_MAX _IOR(KMSG_IOCTL_MAGIC, 0x81, uint32_t) -#define KMSG_CMD_CLEAR _IO(KMSG_IOCTL_MAGIC, 0x82) - - #define __LOGGERIO 0xAE #define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */ #define LOGGER_GET_LOG_LEN _IO(__LOGGERIO, 2) /* used log len */ diff --git a/include/logconfig.h b/include/logconfig.h index 1186fd1..eb6ad72 100644 --- a/include/logconfig.h +++ b/include/logconfig.h @@ -27,7 +27,6 @@ #endif #define DEFAULT_CONFIG_PATH TZ_SYS_ETC"/dlog.conf" -#define KMSG_CONFIG_PATH "/run/dlog.conf" struct log_conf_entry; diff --git a/include/queued_entry.h b/include/queued_entry.h index 8304b11..f5a935a 100644 --- a/include/queued_entry.h +++ b/include/queued_entry.h @@ -47,7 +47,7 @@ struct android_logger_entry { }; void create_pipe_message(void * buf, int prio, char const * tag, char const * msg); -int parse_kmsg_message(char * buffer, int prime, int buffer_size); +int parse_kmsg_message(char * buffer, int buffer_size); void parse_androidlogger_message(struct android_logger_entry * const ale, struct logger_entry * const le, const int dgram_size); void add_recv_timestamp(struct logger_entry * const le); diff --git a/packaging/01-dlog.rules b/packaging/01-dlog.rules index ae5c884..c643690 100644 --- a/packaging/01-dlog.rules +++ b/packaging/01-dlog.rules @@ -1,4 +1,3 @@ -KERNEL=="kmsg[0-9]*", MODE="0662", OWNER="log", GROUP="log", SECLABEL{smack}="*" KERNEL=="log_system", MODE="0662", OWNER="log", GROUP="log", SECLABEL{smack}="*" KERNEL=="log_radio", MODE="0662", OWNER="log", GROUP="log", SECLABEL{smack}="*" KERNEL=="log_main", MODE="0662", OWNER="log", GROUP="log", SECLABEL{smack}="*" diff --git a/packaging/dlog.spec b/packaging/dlog.spec index 08a84dc..cac31d7 100644 --- a/packaging/dlog.spec +++ b/packaging/dlog.spec @@ -7,11 +7,9 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source101: packaging/dlogutil.manifest Source102: packaging/libdlog.manifest -Source103: packaging/dlogbackend-kmsg.manifest Source104: packaging/dlogbackend-logger.manifest Source301: packaging/dlog_logger.service Source302: packaging/dlog_logger.path -Source401: packaging/dloginit.service Source501: packaging/01-dlog.rules %define upgrade_file_path /usr/share/upgrade @@ -48,20 +46,10 @@ Requires: lib%{name} = %{?epoch:%{epoch}:}%{version}-%{release} %description -n libdlog-devel dlog API library -%package -n dlogbackend-kmsg -Summary: kmsg backend selection for dlog -Requires: lib%{name} = %{?epoch:%{epoch}:}%{version}-%{release} -Requires(post): coreutils -Conflicts: dlogbackend-logger - -%description -n dlogbackend-kmsg -Change dlog backend to kmsg backend. Require kernel support (multiple kmsg) - %package -n dlogbackend-logger Summary: Android-logger backend selection for dlog Requires: lib%{name} = %{?epoch:%{epoch}:}%{version}-%{release} Requires(post): coreutils -Conflicts: dlogbackend-kmsg %description -n dlogbackend-logger Change dlog backend to logger backend. Require kernel support (Android-logger) @@ -91,7 +79,6 @@ Documentation for dlog cp %{SOURCE101} . cp %{SOURCE102} . -cp %{SOURCE103} . cp %{SOURCE104} . %autogen --disable-static %configure --disable-static \ @@ -115,7 +102,6 @@ cp -r documentation/* %{buildroot}/usr/share/doc/dlog mkdir -p %{buildroot}%{TZ_SYS_ETC} install -m 0644 configs/dlog.conf.pipe %{buildroot}%{TZ_SYS_ETC}/dlog.conf.pipe -install -m 0644 configs/dlog.conf.kmsg %{buildroot}%{TZ_SYS_ETC}/dlog.conf.kmsg install -m 0644 configs/dlog.conf.logger %{buildroot}%{TZ_SYS_ETC}/dlog.conf.logger mkdir -p %{buildroot}%{_unitdir}/basic.target.wants/ @@ -124,10 +110,6 @@ install -m 0644 %SOURCE301 %{buildroot}%{_unitdir} install -m 0644 %SOURCE302 %{buildroot}%{_unitdir}/dlog_logger.path ln -s ../dlog_logger.service %{buildroot}%{_unitdir}/basic.target.wants/dlog_logger.service -mkdir -p %{buildroot}%{_unitdir}/sysinit.target.wants/ -install -m 0644 %SOURCE401 %{buildroot}%{_unitdir} -ln -s ../dloginit.service %{buildroot}%{_unitdir}/sysinit.target.wants/dloginit.service - mkdir -p %{buildroot}%{_udevrulesdir} install -m 0644 %SOURCE501 %{buildroot}%{_udevrulesdir}/01-dlog.rules @@ -141,7 +123,6 @@ mkdir -p %{buildroot}/var/log/dlog install -D scripts/210.dlog_upgrade.sh %{buildroot}%{upgrade_file_path}/scripts/210.dlog_upgrade.sh mkdir -p %{buildroot}%{upgrade_file_path}/data install -m 0644 configs/dlog.conf.pipe %{buildroot}%{upgrade_file_path}/data/dlog.conf.pipe -install -m 0644 configs/dlog.conf.kmsg %{buildroot}%{upgrade_file_path}/data/dlog.conf.kmsg install -m 0644 configs/dlog.conf.logger %{buildroot}%{upgrade_file_path}/data/dlog.conf.logger %post @@ -164,20 +145,6 @@ ln %{upgrade_file_path}/data/dlog.conf.pipe %{upgrade_file_path}/data/dlog.conf rm %{TZ_SYS_ETC}/dlog.conf rm %{upgrade_file_path}/data/dlog.conf -%pre -n dlogbackend-kmsg -rm %{TZ_SYS_ETC}/dlog.conf -rm %{upgrade_file_path}/data/dlog.conf - -%post -n dlogbackend-kmsg -ln -s %{TZ_SYS_ETC}/dlog.conf.kmsg %{TZ_SYS_ETC}/dlog.conf -ln %{upgrade_file_path}/data/dlog.conf.kmsg %{upgrade_file_path}/data/dlog.conf - -%postun -n dlogbackend-kmsg -rm %{TZ_SYS_ETC}/dlog.conf -ln -s %{TZ_SYS_ETC}/dlog.conf.pipe %{TZ_SYS_ETC}/dlog.conf -rm %{upgrade_file_path}/data/dlog.conf -ln %{upgrade_file_path}/data/dlog.conf.pipe %{upgrade_file_path}/data/dlog.conf - %pre -n dlogbackend-logger rm %{TZ_SYS_ETC}/dlog.conf rm %{upgrade_file_path}/data/dlog.conf @@ -222,15 +189,6 @@ ln %{upgrade_file_path}/data/dlog.conf.pipe %{upgrade_file_path}/data/dlog.conf %{_libdir}/pkgconfig/dlog.pc %{_libdir}/libdlog.so -%files -n dlogbackend-kmsg -%manifest dlogbackend-kmsg.manifest -%attr(664,log,log) %{TZ_SYS_ETC}/dlog.conf.kmsg -%attr(700,log,log) %{_sbindir}/dloginit -%attr(-,log,log) %{_unitdir}/dloginit.service -%{_unitdir}/sysinit.target.wants/dloginit.service -# For upgrade -%{upgrade_file_path}/data/dlog.conf.kmsg - %files -n dlogbackend-logger %manifest dlogbackend-logger.manifest %attr(664,log,log) %{TZ_SYS_ETC}/dlog.conf.logger diff --git a/packaging/dloginit.service b/packaging/dloginit.service deleted file mode 100644 index 3c3d9dd..0000000 --- a/packaging/dloginit.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -Description=Dlog kmsg devices initializer -DefaultDependencies=no -# -# We need to delay dloginit initialization until after all filesystems are mounted -# (local-fs.target) for dloginit to be able to read administrator-provided -# configuration in /opt/etc/dlog.conf correctly. -# -After=systemd-udevd-control.socket systemd-udevd-kernel.socket local-fs.target -Before=basic.target - -[Service] -Type=oneshot -RemainAfterExit=yes -SmackProcessLabel=System -ExecStart=/usr/sbin/dloginit -RemainAfterExit=yes - -[Install] -WantedBy=sysinit.target diff --git a/src/libdlog/log.c b/src/libdlog/log.c index b21eba7..4a3cdda 100644 --- a/src/libdlog/log.c +++ b/src/libdlog/log.c @@ -41,7 +41,6 @@ int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg); pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; extern void __dlog_init_pipe(); -extern void __dlog_init_kmsg(); extern void __dlog_init_android(); static int limiter; @@ -134,8 +133,6 @@ static void __configure(void) if (!strncmp(conf_value, "pipe", sizeof("pipe") + 1)) __dlog_init_pipe(); - else if (!strncmp(conf_value, "kmsg", sizeof("kmsg") + 1)) - __dlog_init_kmsg(); else if (!strncmp(conf_value, "logger", sizeof("logger") + 1)) __dlog_init_android(); else diff --git a/src/libdlog/log_kmsg.c b/src/libdlog/log_kmsg.c deleted file mode 100644 index 66bca55..0000000 --- a/src/libdlog/log_kmsg.c +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include - -#include -#include - -extern int __write_to_log_null(log_id_t, log_priority, const char *tag, const char *msg); -extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg); - -static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 }; - -/** - * @brief Write to log - * @details Writes a log - * @param[in] log_id ID of the buffer to log to. Belongs to (LOG_ID_INVALID, LOG_ID_MAX) non-inclusive - * @param[in] prio Priority of the message. - * @param[in] tag The message tag, identifies the sender. - * @param[in] msg The contents of the message. - * @return Number of bytes written, or negative errno - */ -static int __write_to_log_kmsg(log_id_t log_id, log_priority prio, const char *tag, const char *msg) -{ - ssize_t ret; - int log_fd; - ssize_t prefix_len; - char buf[LOG_ATOMIC_SIZE]; - const char *msg_ptr = msg; - - if (log_id > LOG_ID_INVALID && log_id < LOG_ID_MAX) - log_fd = log_fds[log_id]; - else - return DLOG_ERROR_INVALID_PARAMETER; - - if (prio < DLOG_VERBOSE || prio >= DLOG_PRIO_MAX) - return DLOG_ERROR_INVALID_PARAMETER; - - if (!tag) - tag = ""; - - if (!msg) - return DLOG_ERROR_INVALID_PARAMETER; - - ret = 0; - prefix_len = strlen(tag) + 3; - while (1) { - int last_msg_len = snprintf(buf, LOG_ATOMIC_SIZE, "%s;%d;%s", tag, prio, msg_ptr); - int written_len = write(log_fd, buf, - last_msg_len < LOG_ATOMIC_SIZE - 1 ? last_msg_len : LOG_ATOMIC_SIZE - 1); - - if (written_len < 0) - return -errno; - - ret += (written_len - prefix_len); - msg_ptr += (written_len - prefix_len); - - if (*(msg_ptr) == '\0') - break; - } - - return ret; -} - -/** - * @brief Initialize the backend - * @details Prepares the backend for proper and fruitful work - */ -void __dlog_init_kmsg() -{ - struct log_config conf; - log_id_t buf_id; - - if (log_config_read(&conf) < 0) { - write_to_log = __write_to_log_null; - return; - } - - for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id) { - const char * const buffer_name = log_config_get(&conf, log_name_by_id(buf_id)); - - if (!buffer_name) { - char err_message[MAX_CONF_VAL_LEN + 64]; - snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, log_name_by_id(buf_id)); - syslog_critical_failure(err_message); - goto failure; - } - - log_fds[buf_id] = open(buffer_name, O_WRONLY); - } - - if (log_fds[LOG_ID_MAIN] < 0) { - syslog_critical_failure("COULD NOT OPEN MAIN LOG"); - goto failure; - } - - for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id) - if ((buf_id != LOG_ID_MAIN) && (log_fds[buf_id] < 0)) - log_fds[buf_id] = log_fds[LOG_ID_MAIN]; - - write_to_log = __write_to_log_kmsg; - goto cleanup; - -failure: - for (buf_id = 0; buf_id < LOG_ID_MAX; buf_id++) { - if (log_fds[buf_id] >= 0) - close(log_fds[buf_id]); - } - write_to_log = __write_to_log_null; - -cleanup: - log_config_free(&conf); - return; -} - diff --git a/src/logctrl/logctrl.c b/src/logctrl/logctrl.c index 1f52c7c..251c7bb 100644 --- a/src/logctrl/logctrl.c +++ b/src/logctrl/logctrl.c @@ -126,18 +126,6 @@ int main(int argc, char ** argv) } conf = &conf_etc; - if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1)) { - if (log_config_read_file(&conf_run, KMSG_CONFIG_PATH) < 0) { - printf("Error: cannot open the config file!\n"); - goto cleanup; - } - - /* keys existing only in the conf_run will be stored in the /run */ - if (!log_config_get(&conf_etc, key) && log_config_get(&conf_run, key)) { - conf = &conf_run; - filename = KMSG_CONFIG_PATH; - } - } if (opt.print_all) { log_config_print_out(&conf_etc); diff --git a/src/logctrl/logctrl_doc.h b/src/logctrl/logctrl_doc.h index 8ef5ddc..a2e8ed1 100644 --- a/src/logctrl/logctrl_doc.h +++ b/src/logctrl/logctrl_doc.h @@ -24,7 +24,7 @@ limiter | 0 or 1 | Enable log limiting. See limiter rules for details. limiter\|\\|\ | "allow", "deny" or integers | A series of entries to control limiting of apps with given TAG and PRIORITY. "allow" and values < 0 mean no filtering, "deny" or values > 10000 mean no logging allowed, and values between 0 and 10000 mean this many logs per minute are allowed. util_sorting_time_window | >= 0 | Sorting time window (in ms) for dlogutil. dlogutil can achieve logs out of order so it waits a bit to make sure unsorted logs have had time to arrive and get sorted. dlog_logger_conf_# | dlogutil invocations | The keys should be consecutive numbers from 0. The logger daemon will behave as if dlogutil was invoked for each of these. -\ | path | Specifies the path to given buffer. Only for android-logger and kmsg backends. Do not change because these are usually hardcoded in the kernel. +\ | path | Specifies the path to given buffer. Only for android-logger backend. Do not change because these are usually hardcoded in the kernel. \_{ctl,write}_sock | path | Pipe backend only. Specifies a path to the control/write socket for given buffer. \_{ctl,write}_sock_owner | username | Pipe backend only. Specifies the owner of the control/write socket for given buffer. \_{ctl,write}_sock_group | path | Pipe only. Specifies the group of the control/write socket for given buffer. diff --git a/src/logger/logger.c b/src/logger/logger.c index 6b0e2b9..9fdda96 100644 --- a/src/logger/logger.c +++ b/src/logger/logger.c @@ -102,8 +102,7 @@ enum { enum reader_type { READER_BUFFER = 0, - READER_LOGGER, - READER_KMSG // additional /dev/kmsg## devices + READER_LOGGER }; enum entity_type { @@ -938,15 +937,10 @@ static int service_reader_file(struct logger * server, struct reader* reader) else { buffer[r] = '\0'; struct logger_entry * const entry = (struct logger_entry *) buffer; - if (reader->type != READER_LOGGER) - r = parse_kmsg_message(buffer, 0, r); - else - parse_androidlogger_message((struct android_logger_entry *) buffer, entry, r); - + parse_androidlogger_message((struct android_logger_entry *) buffer, entry, r); add_recv_timestamp(entry); - if (r) - write_with_rotation((struct logger_entry *) buffer, &reader->file); + write_with_rotation((struct logger_entry *) buffer, &reader->file); } } @@ -976,7 +970,6 @@ static int service_reader(struct logger* server, struct reader* reader) return print_out_logs(reader, buffer); } case READER_LOGGER: - case READER_KMSG: return service_reader_file(server, reader); default: return -1; @@ -996,7 +989,6 @@ static void add_reader(struct logger * server, struct reader * reader) reader->current = server->buffers[reader->buf_id]->head; LIST_ADD(server->buffers[reader->buf_id]->readers, reader); break; - case READER_KMSG: case READER_LOGGER: LIST_ADD(server->extra_readers, reader); break; @@ -1095,11 +1087,8 @@ static int parse_command_line(const char* cmdl, struct writer* wr, struct reader if (!strcmp(conf_val, "pipe") || (optarg && !strcmp(optarg, "kmsg"))) { reader->type = READER_BUFFER; reader->buf_id = log_id_by_name(optarg); - } else { - if (!strcmp(conf_val, "logger")) - reader->type = READER_LOGGER; - else - reader->type = READER_KMSG; + } else if (!strcmp(conf_val, "logger")) { + reader->type = READER_LOGGER; conf_val = log_config_get(&conf, optarg); if (!conf_val) { @@ -1111,6 +1100,9 @@ static int parse_command_line(const char* cmdl, struct writer* wr, struct reader retval = -errno; goto cleanup; } + } else { + retval = -EINVAL; + goto cleanup; } break; case 'r': @@ -1145,8 +1137,7 @@ static int parse_command_line(const char* cmdl, struct writer* wr, struct reader } if (reader->type != READER_BUFFER && - reader->type != READER_LOGGER && - reader->type != READER_KMSG) { + reader->type != READER_LOGGER) { retval = -EINVAL; goto cleanup; } @@ -1475,7 +1466,7 @@ static int service_writer_kmsg(struct logger* server, struct writer* wr, struct return -EBADF; wr->buffer[r] = '\0'; - parse_kmsg_message(wr->buffer, 1, r); + parse_kmsg_message(wr->buffer, r); struct logger_entry * entry = (struct logger_entry*)wr->buffer; add_recv_timestamp(entry); buffer_append(server, entry, server->buffers[LOG_ID_KMSG], server->buffers[LOG_ID_KMSG]->readers); diff --git a/src/loginit/loginit.c b/src/loginit/loginit.c deleted file mode 100644 index d1bee5b..0000000 --- a/src/loginit/loginit.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2005-2008, The Android Open Source Project - * Copyright (c) 2009-2015, Samsung Electronics Co., Ltd. All rights reserved. - * - * 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 -#include -#include -#include - -#include -#include - -#define DEV_KMSG "/dev/kmsg" -#define BACKUP_SIZE 1048576 - -int g_minors[LOG_ID_MAX] = {-1, -1, -1, -1, -1}; -int g_sizes[LOG_ID_MAX] = {-1, -1, -1, -1, -1}; - -/** - * @brief Create KMSG edvices - * @details Spawns the KMSG devices for logging to be possible - * @param[in] fd The /dev/kmsg file descriptor - * @param[in] conf The configuration - * @return 0 on success, nonzero on failure - */ -static int create_kmsg_devs(int fd, struct log_config *conf) -{ - int i; - struct kmsg_cmd_buffer_add cmd = { - .mode = 0662, - }; - - for (i = 0; i < LOG_ID_MAX; i++) { - char key[MAX_CONF_KEY_LEN]; - const char *size_str; - char *size_str_end; - - snprintf(key, MAX_CONF_KEY_LEN, "%s_size", log_name_by_id(i)); - size_str = log_config_get(conf, key); - errno = 0; - - if (!size_str) { - cmd.size = BACKUP_SIZE; - } else { - cmd.size = strtol(size_str, &size_str_end, 10); - if (errno || (cmd.size <= 0) || (*size_str_end != '\0')) - cmd.size = BACKUP_SIZE; - } - - g_sizes[i] = cmd.size; - - if (0 > ioctl(fd, KMSG_CMD_BUFFER_ADD, &cmd)) { - _E("ioctl KMSG_CMD_BUFFER_ADD failed. (%d)\n", errno); - return -1; - } - g_minors[i] = cmd.minor; - } - return 0; -} - -/** - * @brief Remove KMSG devices - * @details Removes KMSG devices - * @param[in] fd The /dev/kmsg file descriptor - */ -static void remove_kmsg_devs(int fd) -{ - int i; - - for (i = 0; i < LOG_ID_MAX; i++) { - if (g_minors[i] < 0) - continue; - if (0 > ioctl(fd, KMSG_CMD_BUFFER_DEL, &g_minors[i])) - _E("ioctl KMSG_CMD_BUFFER_DEL failed. (%d)\n", errno); - } -} - -int main() -{ - int kmsg_fd, i; - struct log_config conf_in; - struct log_config conf_out; - - if (log_config_read(&conf_in) < 0) - return EXIT_FAILURE; - - memset(&conf_out, 0, sizeof(struct log_config)); - - kmsg_fd = open(DEV_KMSG, O_RDWR); - if (kmsg_fd < 0) { - _E("Unable to open kmsg device. %d\n", errno); - exit(EXIT_FAILURE); - } - - if (0 > create_kmsg_devs(kmsg_fd, &conf_in)) - goto error; - - log_config_free(&conf_in); - - for (i = 0; i < LOG_ID_MAX; ++i) { - char key[MAX_CONF_KEY_LEN]; - char val[MAX_CONF_VAL_LEN]; - - snprintf(key, MAX_CONF_KEY_LEN, "%s_size", log_name_by_id(i)); - snprintf(val, MAX_CONF_VAL_LEN, "%d", g_sizes[i]); - log_config_push(&conf_out, key, val); - - snprintf(val, MAX_CONF_VAL_LEN, "%s%d", DEV_KMSG, g_minors[i]); - log_config_push(&conf_out, log_name_by_id(i), val); - } - - return (0 > log_config_write(&conf_out, KMSG_CONFIG_PATH)) ? EXIT_FAILURE : EXIT_SUCCESS; - -error: - remove_kmsg_devs(kmsg_fd); - exit(EXIT_FAILURE); -} - -/** - @defgroup CLI_DLOGINIT dloginit usage - @ingroup DLOG_COMMAND_LINE_UTILITIES - @brief KMSG buffer creator - @details dloginit provides a way to create buffers in the KMSG backend. It works in three simple steps: - - 1) read requested size values from the config - - 2) create buffers - - 3) write final size values and buffer paths back to the config - -It accepts no parameters. To read more about the config, see dlogctrl documentation. -*/ - diff --git a/src/logutil/logutil.c b/src/logutil/logutil.c index da76fd0..4752bd3 100644 --- a/src/logutil/logutil.c +++ b/src/logutil/logutil.c @@ -81,7 +81,6 @@ static struct sorting_vector { typedef enum { PIPE, BINARY_FILE, - KMSG, ANDROID_LOGGER } fd_type; @@ -189,20 +188,6 @@ static int do_clear_pipe(int sock_fd) return ret; } - -/** - * @brief Clear the buffer - * @details Sends a clear ioctl to given fd - * @param[in] fd File descriptor of the buffer - * @remarks KMSG version - */ -void clear_log_kmsg(int fd) -{ - int ret = ioctl(fd, KMSG_CMD_CLEAR); - if (ret < 0) - printf("ioctl KMSG_CMD_CLEAR failed (%d)", errno); -} - /** * @brief Clear the buffer * @details Sends a clear ioctl to given fd @@ -406,8 +391,6 @@ static void handle_pipe(struct fd_info **data_fds, int fd_count, int dump) r = read(fdi->fd, fdi->buff + fdi->index, RECEIVE_BUFFER_SIZE - fdi->index); if (r < 0) { - if (fdi->type == KMSG && errno == EPIPE) - continue; if (errno != EAGAIN) return; else { @@ -430,14 +413,6 @@ static void handle_pipe(struct fd_info **data_fds, int fd_count, int dump) e = (struct logger_entry *)fdi->buff; switch (fdi->type) { - case KMSG: - if (!parse_kmsg_message(fdi->buff, 0, r)) { - fdi->index = 0; - continue; - } - fdi->index = e->len; - add_recv_timestamp(e); - break; case ANDROID_LOGGER: { parse_androidlogger_message((struct android_logger_entry *) fdi->buff, e, r); add_recv_timestamp(e); @@ -563,10 +538,9 @@ void filter_buffer_names(char ** names, int * cnt) * @param[in] conf The configuration * @param[in] argc Argument count * @param[in] argv Argument values - * @param[in] kmsg Whether the device is kmsg * @return FD wrapper structure to read from */ -struct fd_info * process_buffer_nonpipe(char * buffer_name, int clear, struct log_config * conf, int argc, char ** argv, int kmsg) +struct fd_info * process_buffer_nonpipe(char * buffer_name, int clear, struct log_config * conf, int argc, char ** argv) { char const * dev_path; dev_path = log_config_get(conf, buffer_name); @@ -578,24 +552,16 @@ struct fd_info * process_buffer_nonpipe(char * buffer_name, int clear, struct lo return NULL; if (clear) { - if (kmsg) - clear_log_kmsg(fd); - else - clear_log_logger(fd); + clear_log_logger(fd); goto cleanup; } - /* CLEAR does not actually physically clear the buffer; read() calls would still read existing data - Instead, the SEEK_DATA call is made to return the spot after the cleared area. */ - if (kmsg) - lseek(fd, 0, SEEK_DATA); - struct fd_info * fdi = malloc(sizeof(struct fd_info)); if (!fdi) goto cleanup; fdi->fd = fd; fdi->do_sorting = 1; - fdi->type = kmsg ? KMSG : ANDROID_LOGGER; + fdi->type = ANDROID_LOGGER; fdi->index = 0; return fdi; @@ -890,11 +856,11 @@ int main(int argc, char ** argv) for (i = 0; i < buffer_cnt; ++i) { struct fd_info * fdi; - if (!strncmp(conf_value, "pipe", sizeof("pipe") + 1) || - !strncmp(buffer_names[i], "kmsg", sizeof("kmsg") + 1)) + if (!strncmp(conf_value, "pipe", sizeof("pipe") + 1) + || !strncmp(buffer_names[i], "kmsg", sizeof("kmsg") + 1)) fdi = process_buffer_pipe(buffer_names[i], should_clear, &conf, argc, argv); else - fdi = process_buffer_nonpipe(buffer_names[i], should_clear, &conf, argc, argv, !strcmp(conf_value, "kmsg")); + fdi = process_buffer_nonpipe(buffer_names[i], should_clear, &conf, argc, argv); if (fdi) { fdi_ptrs[fdi_cnt++] = fdi; if (buffer_cnt == 1 || tag_cnt == 1) diff --git a/src/shared/logconfig.c b/src/shared/logconfig.c index b907421..3c12aa7 100644 --- a/src/shared/logconfig.c +++ b/src/shared/logconfig.c @@ -101,9 +101,6 @@ int log_config_read(struct log_config* config) return -ENOENT; } - if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1)) - log_config_read_file(config, KMSG_CONFIG_PATH); - return 0; } diff --git a/src/shared/queued_entry.c b/src/shared/queued_entry.c index 2b8652c..79717e9 100644 --- a/src/shared/queued_entry.c +++ b/src/shared/queued_entry.c @@ -68,43 +68,19 @@ void create_pipe_message(void * buf, int prio, char const * tag, char const * ms } /** - * @brief Parse a KMSG dictionary value - * @details Parses one of the extra values a KMSG message can have - * @param[in] buf The string to parse - * @param[out] val The value inside - * @return The first char after the parsed value in the string - */ -static char* parse_dict_val(char *buf, char **val) -{ - char *cptr; - - *val = strchr(buf, '='); - if (*val == NULL) - return NULL; - (*val)++; - cptr = strchr(*val, '\n'); - if (cptr) { - *cptr = '\0'; - cptr++; - } - return cptr; -} - -/** * @brief Parse KMSG message * @details Parses a raw KMSG message into the internal format * @param[in,out] buffer The buffer which contains the message and will contain the entry afterwards - * @param[in] prime Whether this is the primary /dev/kmsg or an extra numbered device /dev/kmsg## * @param[in] buffer_size The size of the input buffer * @return 1 on success, 0 on failure. */ -int parse_kmsg_message(char * buffer, int prime, int buffer_size) +int parse_kmsg_message(char * buffer, int buffer_size) { static char buffer_temp[LOG_MAX_SIZE]; struct logger_entry le; unsigned long long timestamp; char * tag_begin, * pri_begin, * msg_begin; - char *cptr, *cptr2; + char *cptr; int prio; int i; int is_new_format = 0; @@ -138,33 +114,13 @@ int parse_kmsg_message(char * buffer, int prime, int buffer_size) le.sec = timestamp / (1000*1000); le.nsec = 1000 * (timestamp % (1000 * 1000)); - if (!prime) { - tag_begin = strchr(cptr+1, ';'); - if (tag_begin == NULL) - return 0; - tag_begin++; - - pri_begin = strchr(tag_begin, ';'); - if (pri_begin == NULL) - return 0; - - *pri_begin = '\0'; - pri_begin++; - - msg_begin = strchr(pri_begin, ';'); - if (msg_begin == NULL) - return 0; - *msg_begin = '\0'; - msg_begin++; - } else { - msg_begin = strchr(cptr+1, ';'); - if (msg_begin == NULL) - return 0; - ++msg_begin; + msg_begin = strchr(cptr+1, ';'); + if (msg_begin == NULL) + return 0; + ++msg_begin; - tag_begin = "DEVKMSG"; - pri_begin = "6"; - } + tag_begin = "DEVKMSG"; + pri_begin = "6"; if (!is_new_format) { cptr = strchr(msg_begin, '\n'); @@ -178,24 +134,8 @@ int parse_kmsg_message(char * buffer, int prime, int buffer_size) cptr++; } - if (prime) { - le.pid = 0; - le.tid = 0; - } else { - cptr = parse_dict_val(cptr+1, &cptr2); - if (cptr == NULL) { - le.pid = -1; - le.tid = -1; - } else { - le.pid = strtol(cptr2, NULL, 10); - - cptr = parse_dict_val(cptr, &cptr2); - if (cptr == NULL) - le.tid = -1; - else - le.tid = strtol(cptr2, NULL, 10); - } - } + le.pid = 0; + le.tid = 0; prio = strtol(pri_begin, NULL, 10); diff --git a/src/tests/kmsg_parser.c b/src/tests/kmsg_parser.c index 3935c3e..8ec9697 100644 --- a/src/tests/kmsg_parser.c +++ b/src/tests/kmsg_parser.c @@ -5,36 +5,25 @@ #define TAG "SOME_TAG" #define MESSAGE1 "Some message." -#define MESSAGE2 "Some other message.\nWith newline." #define STRING1 "1,234,56789,-;" MESSAGE1 "\n _SOME_IRRELEVANT_TAG=BLA\n" -#define STRING2 "1,234,56789,-;" TAG ";4;" MESSAGE2 "\0\n _PID=1234\n _TID=5678\n\0" int main() { char message_prime[1024] = STRING1; - char message_added[1024] = STRING2; - parse_kmsg_message(message_prime, 1, sizeof(STRING1)-1); - parse_kmsg_message(message_added, 0, sizeof(STRING2)-1); + parse_kmsg_message(message_prime, sizeof(STRING1)-1); struct logger_entry * entry_prime = (struct logger_entry *) message_prime; - struct logger_entry * entry_added = (struct logger_entry *) message_added; - log_entry le_prime, le_added; + log_entry le_prime; log_process_log_buffer(entry_prime, &le_prime); - log_process_log_buffer(entry_added, &le_added); assert(le_prime.pid == 0); assert(le_prime.tid == 0); - assert(le_added.pid == 1234); - assert(le_added.tid == 5678); assert(!strcmp(le_prime.tag, "DEVKMSG")); - assert(!strcmp(le_added.tag, TAG)); assert(!strcmp(le_prime.message, MESSAGE1)); - assert(!strcmp(le_added.message, MESSAGE2)); - assert(le_added.priority == 4); return 0; } -- 2.7.4