library integration : remove backend dependent macro 07/87907/9
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 12 Sep 2016 05:54:54 +0000 (14:54 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 22 Sep 2016 04:29:48 +0000 (13:29 +0900)
- To use dlog with all backends by building only one time, backend dependent macro should be removed
- Instead, we will find backend information in the conf file

Change-Id: Ie3d918deac3d3179a33a8c7d5a8e00360e271b5d
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
Makefile.am
configure.ac
include/dlog_ioctl.h
include/logconfig.h
include/queued_entry.h
src/logctrl/logctrl.c
src/logctrl/logctrl_doc.h
src/loginit/loginit.c
src/shared/dlog_ioctl.c [deleted file]
src/shared/logconfig.c
src/shared/queued_entry.c

index 16e77a7..3871c01 100755 (executable)
@@ -56,7 +56,6 @@ dlogutil_LDFLAGS = \
 
 dlogutil_SOURCES = \
        src/logutil/logutil.c \
-       src/shared/dlog_ioctl.c \
        src/shared/logcommon.c \
        src/shared/logprint.c \
        src/shared/queued_entry.c \
@@ -80,7 +79,6 @@ dlog_logger_LDFLAGS = \
 
 dlog_logger_SOURCES = \
        src/logger/logger.c \
-       src/shared/dlog_ioctl.c \
        src/shared/logcommon.c \
        src/shared/logconfig.c \
        src/shared/logprint.c \
index d59834f..4622fe5 100755 (executable)
@@ -21,7 +21,6 @@ AC_ARG_ENABLE(pipe, AS_HELP_STRING([--enable-pipe], [enable pipe (log to pipe fd
        [with_pipe=yes],
        with_pipe=no)
 if test "x$with_pipe" = "xyes"; then
-       AC_DEFINE(DLOG_BACKEND_PIPE, 1, [Define if pipe backend is selected])
        __dlog_backends_selected=$(($__dlog_backends_selected + 1))
 fi
 AM_CONDITIONAL(WITH_PIPE, [test "x$with_pipe" = "xyes"])
@@ -31,7 +30,6 @@ AC_ARG_ENABLE(kmsg, AS_HELP_STRING([--enable-kmsg], [enable kmsg (requires kmsg
        [with_kmsg=yes],
        with_kmsg=no)
 if test "x$with_kmsg" = "xyes"; then
-       AC_DEFINE(DLOG_BACKEND_KMSG, 1, [Define if kmsg backend is selected])
        __dlog_backends_selected=$(($__dlog_backends_selected + 1))
 fi
 AM_CONDITIONAL(WITH_KMSG, [test "x$with_kmsg" = "xyes"])
@@ -41,7 +39,6 @@ AC_ARG_ENABLE(android_logger, AS_HELP_STRING([--enable-android-logger], [enable
        [with_android_logger=yes],
        with_android_logger=no)
 if test "x$with_android_logger" = "xyes"; then
-       AC_DEFINE(DLOG_BACKEND_LOGGER, 1, [Define if (legacy) android logger backend is selected])
        __dlog_backends_selected=$(($__dlog_backends_selected + 1))
 fi
 AM_CONDITIONAL(WITH_ANDROID_LOGGER, [test "x$with_android_logger" = "xyes"])
index 3ebd009..e9c9743 100644 (file)
@@ -48,9 +48,4 @@ struct kmsg_cmd_buffer_add {
 #define LOGGER_GET_NEXT_ENTRY_LEN      _IO(__LOGGERIO, 3) /* next entry len */
 #define LOGGER_FLUSH_LOG               _IO(__LOGGERIO, 4) /* flush log */
 
-
-void clear_log(int fd);
-void get_log_size(int fd, uint32_t *size);
-void get_log_read_size_max(int fd, uint32_t *size);
-
 #endif
index 305ab06..1186fd1 100755 (executable)
 #define MAX_CONF_VAL_LEN   256
 #define MAX_CONF_ENTRY_LEN (MAX_CONF_KEY_LEN + MAX_CONF_VAL_LEN + 2) // +2 for the delimiter and newline
 
-typedef enum {
-       CONFIG_TYPE_KMSG,
-       CONFIG_TYPE_COMMON,
-       CONFIG_TYPE_MAX
-} config_type;
+#ifndef TZ_SYS_ETC
+#define TZ_SYS_ETC     "/opt/etc"
+#endif
+
+#define DEFAULT_CONFIG_PATH    TZ_SYS_ETC"/dlog.conf"
+#define KMSG_CONFIG_PATH       "/run/dlog.conf"
 
 struct log_conf_entry;
 
@@ -35,8 +36,6 @@ struct log_config {
        struct log_conf_entry *last;
 };
 
-const char *get_config_filename(config_type type);
-
 int log_config_set(struct log_config* config, const char* key, const char* value);
 const char* log_config_get(struct log_config* config, const char* key);
 int log_config_read(struct log_config* config);
index 4afc9b5..a4569f4 100644 (file)
@@ -52,7 +52,6 @@ int parse_kmsg_message(char * buffer, int prime, int buffer_size);
 struct queued_entry_t* new_queued_entry(uint32_t log_read_size_max);
 void free_queued_entry(struct queued_entry_t* entry);
 void free_queued_entry_list(struct queued_entry_t *queue);
-int read_queued_entry_from_dev(int fd, struct queued_entry_t *entry, uint32_t log_read_size_max);
 int cmp(struct queued_entry_t* a, struct queued_entry_t* b);
 struct queued_entry_t* pop_queued_entry(struct queued_entry_t** queue);
 void enqueue(struct queued_entry_t** queue, struct queued_entry_t* entry);
index eb79118..176fe5a 100644 (file)
@@ -51,11 +51,13 @@ int validate(struct options o)
 
 int main(int argc, char ** argv)
 {
-       struct log_config conf;
+       struct log_config conf_etc, conf_run;
+       struct log_config *conf;
        char key[MAX_CONF_KEY_LEN];
        char val[MAX_CONF_VAL_LEN];
        struct options opt = {0, 0, 0, 0, 0, 0};
-       const char *filename = getenv("DLOG_CONFIG_PATH") ? : get_config_filename(CONFIG_TYPE_COMMON);
+       const char *filename = getenv("DLOG_CONFIG_PATH") ? : DEFAULT_CONFIG_PATH;
+       const char *backend = NULL;
 
        if (argc == 1) {
                print_help(argv[0]);
@@ -97,30 +99,49 @@ int main(int argc, char ** argv)
                return 1;
        }
 
-       if (opt.help) {
-               print_extended_help();
+       conf_etc.begin = conf_etc.last = NULL;
+       conf_run.begin = conf_run.last = NULL;
+       if (!log_config_read_file(&conf_etc, filename)) {
+               printf("Error: cannot open the config file!\n");
                return 1;
        }
+       backend = log_config_get(&conf_etc, "backend");
 
-       if (!log_config_read(&conf)) {
-               printf("Error: cannot open the config file!\n");
+       if (opt.help) {
+               print_extended_help(backend);
                return 1;
        }
 
-       if (opt.print_all)
-               log_config_print_out(&conf);
+       conf = &conf_etc;
+       if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1)) {
+               if (!log_config_read_file(&conf_run, KMSG_CONFIG_PATH)) {
+                       printf("Error: cannot open the config file!\n");
+                       return 1;
+               }
+
+               /* 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);
+               log_config_print_out(&conf_run);
+       }
        else if (opt.should_get) {
-               if (!log_config_print_key(&conf, key))
+               if (!log_config_print_key(conf, key))
                        goto err_entry;
        } else if (opt.should_clear) {
-               if (!log_config_remove(&conf, key))
+               if (!log_config_remove(conf, key))
                        goto err_entry;
-               if (!log_config_write(&conf, filename))
+               if (!log_config_write(conf, filename))
                        goto err_save;
        } else if (opt.should_set) {
-               if (!log_config_set(&conf, key, val))
-                       log_config_push(&conf, key, val);
-               if (!log_config_write(&conf, filename))
+               if (!log_config_set(conf, key, val))
+                       log_config_push(conf, key, val);
+               if (!log_config_write(conf, filename))
                        goto err_save;
        } else {
                printf("Error: invalid options\n");
index 2f70705..a152faa 100644 (file)
@@ -11,7 +11,7 @@ void print_help()
        );
 }
 
-void print_extended_help()
+void print_extended_help(const char *backend)
 {
        printf("Important entries:\n"
                "\tplog: enable platform logging, ie. whether any logging happens at all. Values are 0 or 1.\n"
@@ -48,16 +48,10 @@ void print_extended_help()
                "\tkeys are of the format dlog_logger_conf_#\n"
                "\twhere # are consecutive integers from 0.\n"
                "\tValues are the same as when calling dlogutil (including \"dlogutil\" at start), for example\n"
-               "\t\tdlogutil -b system -r 5120 -n 1 -f /var/log/dlog/system.raw *:I\n\n"
-#ifndef DLOG_BACKEND_PIPE
-               "Buffer device names:\n"
-               "\tkeys are simply buffer names, for example main;\n"
-               "\tvalues are paths to the devices.\n"
-               "\tNote: these values are read-only!\n"
-               "\tChanging them does nothing and can potentially break things.\n\n"
-#endif
-#ifdef DLOG_BACKEND_PIPE
-               "DLogUtil sorting:\n"
+               "\t\tdlogutil -b system -r 5120 -n 1 -f /var/log/dlog/system.raw *:I\n\n");
+
+       if (!strncmp(backend, "pipe", sizeof("pipe") + 1))
+               printf("DLogUtil sorting:\n"
                "\tkey is util_sorting_time_window;\n"
                "\tvalue is an integer representing the size\n"
                "\tof the sorting window in milliseconds. This\n"
@@ -68,7 +62,11 @@ void print_extended_help()
                "\tCTL sockets are for administrative purposes, WRITE are for programs making logs.\n"
                "\tFor PATH, values signify the path to the appropriate socket.\n"
                "\tFor RIGHTS, the value is file permissions in octal (for example 0664).\n"
-               "\tFor GROUP and OWNER the values are group/owner of the file (for example root).\n\n"
-#endif
-       );
+               "\tFor GROUP and OWNER the values are group/owner of the file (for example root).\n\n");
+       else
+               printf("Buffer device names:\n"
+               "\tkeys are simply buffer names, for example main;\n"
+               "\tvalues are paths to the devices.\n"
+               "\tNote: these values are read-only!\n"
+               "\tChanging them does nothing and can potentially break things.\n\n");
 }
index 37594d3..6631323 100755 (executable)
@@ -127,7 +127,7 @@ int main()
                log_config_push(&conf_out, log_name_by_id(i), val);
        }
 
-       log_config_write(&conf_out, get_config_filename(CONFIG_TYPE_KMSG));
+       log_config_write(&conf_out, KMSG_CONFIG_PATH);
 
        return 0;
 
diff --git a/src/shared/dlog_ioctl.c b/src/shared/dlog_ioctl.c
deleted file mode 100644 (file)
index 11251b7..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * DLOG
- * Copyright (c) 2005-2008, The Android Open Source Project
- * Copyright (c) 2012-2015 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 <sys/ioctl.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <dlog_ioctl.h>
-#include <logcommon.h>
-
-#if DLOG_BACKEND_KMSG
-
-/**
- * @brief Get buffer size
- * @details Sends a getsize ioctl to given fd and stores the result
- * @param[in] fd File descriptor of the buffer
- * @param[out] size Pointer to a variable in which to store the size
- * @remarks KMSG version
- */
-void get_log_size(int fd, uint32_t *size)
-{
-       int ret = ioctl(fd, KMSG_CMD_GET_BUF_SIZE, size);
-       if (ret < 0) {
-               _E("ioctl KMSG_CMD_GET_BUF_SIZE failed (%d)", errno);
-               exit(EXIT_FAILURE);
-       }
-}
-
-/**
- * @brief Get max read size
- * @details Sends an ioctl to given fd and stores the result
- * @param[in] fd File descriptor of the buffer
- * @param[out] size Pointer to a variable in which to store the returned value
- * @remarks KMSG version
- */
-void get_log_read_size_max(int fd, uint32_t *size)
-{
-       int ret = ioctl(fd, KMSG_CMD_GET_READ_SIZE_MAX, size);
-       if (ret < 0) {
-               _E("ioctl KMSG_CMD_GET_READ_SIZE_MAX failed (%d)", errno);
-               exit(EXIT_FAILURE);
-       }
-}
-
-#else
-
-/**
- * @brief Get buffer size
- * @details Sends a getsize ioctl to given fd and stores the result
- * @param[in] fd File descriptor of the buffer
- * @param[out] size Pointer to a variable in which to store the size
- * @remarks ANDROID_LOGGER version
- */
-void get_log_size(int fd, uint32_t *size)
-{
-       *size = ioctl(fd, LOGGER_GET_LOG_BUF_SIZE);
-       if (size < 0) {
-               _E("ioctl LOGGER_GET_LOG_BUF_SIZE failed (%d)", errno);
-               exit(EXIT_FAILURE);
-       }
-}
-
-
-/**
- * @brief Get max read size
- * @details This function retrieves the maximum log entry size
- * @param[in] fd File descriptor of the buffer
- * @param[out] size Pointer to a variable in which to store the returned value
- * @remarks ANDROID LOGGER version
- */
-void get_log_read_size_max(int fd, uint32_t *size)
-{
-       *size = LOGGER_ENTRY_MAX_LEN;
-}
-
-#endif
index ce48611..339c8a2 100644 (file)
@@ -3,29 +3,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#ifndef TZ_SYS_ETC
-#define TZ_SYS_ETC "/opt/etc"
-#endif
-
-/**
- * @brief Get config path by type
- * @details Returns the path to the given type of configfer with the given name
- * @param[in] type The type of the config: CONFIG_TYPE_COMMON or CONFIG_TYPE_KMSG
- * @return Path to given config type, or NULL if invalid type given.
- * @see log_config_read_file
- */
-const char * get_config_filename(config_type type)
-{
-       switch (type) {
-       case CONFIG_TYPE_COMMON:
-               return TZ_SYS_ETC "/dlog.conf";
-       case CONFIG_TYPE_KMSG:
-               return "/run/dlog.conf";
-       default:
-               return NULL;
-       }
-}
-
 /**
  * @brief A singular config entry list element.
  */
@@ -99,8 +76,8 @@ int log_config_set(struct log_config* c, const char* key, const char* value)
  */
 int log_config_read(struct log_config* config)
 {
-       int ret = 0;
        char const * override;
+       char const * backend;
 
        if (!config)
                return 0;
@@ -110,12 +87,17 @@ int log_config_read(struct log_config* config)
        override = getenv("DLOG_CONFIG_PATH");
        if (override)
                return log_config_read_file(config, override);
-#ifdef DLOG_BACKEND_KMSG
-       ret |= log_config_read_file(config, get_config_filename(CONFIG_TYPE_KMSG)); // fixme: ugly
-#endif
-       ret |= log_config_read_file(config, get_config_filename(CONFIG_TYPE_COMMON));
+       if (!log_config_read_file(config, DEFAULT_CONFIG_PATH))
+               return 0;
+
+       backend = log_config_get(config, "backend");
+       if (!backend)
+               return 0;
+
+       if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1))
+               log_config_read_file(config, KMSG_CONFIG_PATH);
 
-       return ret;
+       return 1;
 }
 
 /**
@@ -126,7 +108,6 @@ int log_config_read(struct log_config* config)
  * @param[in] filename The filename of the config file
  * @return 1 on success, 0 on failure
  * @see log_config_read
- * @see get_config_filename
  */
 int log_config_read_file(struct log_config* config, const char* filename)
 {
index b724571..5d06d11 100644 (file)
@@ -228,56 +228,6 @@ void free_queued_entry_list(struct queued_entry_t *queue)
 }
 
 /**
- * @brief Read queued entry
- * @details Reads an entry from the device
- * @param[in] fd FD of the device
- * @param[out] entry The entry to read to
- * @param[in] log_read_size_max Max log read size
- * @return 0 on success, error code on failure
- * @retval RQER_PARSE Parsing failure
- * @retval RQER_EINTR Interrupted
- * @retval RQER_EAGAIN Try again
- * @retval RQER_PIPE KMSG device has wrapped around
- */
-int read_queued_entry_from_dev(int fd, struct queued_entry_t *entry, uint32_t log_read_size_max)
-{
-       int ret = read(fd, entry->buf, LOGGER_ENTRY_MAX_LEN);
-
-       if (ret < 0) {
-               int err = errno;
-               free_queued_entry(entry);
-               switch (err) {
-               case EINTR:
-                       return RQER_EINTR;
-               case EAGAIN:
-                       return RQER_EAGAIN;
-#if DLOG_BACKEND_KMSG
-               case EPIPE:
-                       return RQER_EPIPE;
-#endif
-               default:
-                       _E("read: %d", errno);
-                       exit(EXIT_FAILURE);
-               }
-       } else if (!ret) {
-               _E("read: Unexpected EOF!\n");
-               exit(EXIT_FAILURE);
-       }
-
-       entry->buf[ret] = '\0';
-
-#if DLOG_BACKEND_KMSG
-       if (!parse_kmsg_message(entry->buf, 0, ret)) {
-               _D("parsing log failed\n");
-               free_queued_entry(entry);
-               return RQER_PARSE;
-       }
-#endif
-
-       return RQER_SUCCESS;
-}
-
-/**
  * @brief Pop queued entry
  * @details Pops queued entry
  * @param[in/out] queue The pointer to the list (ie. its head)