dlogutil: Kill yet another instance of dlogutil_mode_e clone 18/239218/4
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 22 Jul 2020 14:53:03 +0000 (16:53 +0200)
committerMichal Bloch <m.bloch@partner.samsung.com>
Thu, 23 Jul 2020 10:28:59 +0000 (10:28 +0000)
Change-Id: I097894366d7028b8a7481d90afbeee168f5a1828

src/logutil/logutil.c

index 63c8f0d..437e941 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <log_file.h>
 #include <sort_vector.h>
+#include <dlog-internal.h>
 
 #include "logutil_doc.h"
 
@@ -36,8 +37,6 @@
  * @{
  */
 
-#define MODE_CONTINUOUS 0
-
 // buffers to use by default, when nothing specified
 static const int default_buffers = (1 << LOG_ID_MAIN) | (1 << LOG_ID_SYSTEM) | (1 << LOG_ID_APPS);
 
@@ -53,7 +52,7 @@ static void show_version(const char *name)
 }
 
 static int parse_options(int argc, char **argv, struct log_file *l_file, int *enabled_buffers, action_e *action,
-       dlogutil_config_s *config, unsigned *mode, bool *monitor, dlogutil_sorting_order_e *sort_by)
+       dlogutil_config_s *config, dlogutil_mode_e *mode, unsigned int *dump_size, dlogutil_sorting_order_e *sort_by)
 {
        assert(argv);
        assert(l_file);
@@ -63,6 +62,9 @@ static int parse_options(int argc, char **argv, struct log_file *l_file, int *en
        assert(mode);
        assert(sort_by);
 
+       *mode = DLOGUTIL_MODE_CONTINUOUS;
+       *dump_size = DLOGUTIL_MAX_DUMP_SIZE;
+
        while (1) {
                static const struct option long_options[] = {
                        {"tid"    , required_argument, NULL,   0},
@@ -125,13 +127,14 @@ static int parse_options(int argc, char **argv, struct log_file *l_file, int *en
                        }
                        break;
                case 'd':
-                       *mode = DLOGUTIL_MAX_DUMP_SIZE;
+                       *mode = DLOGUTIL_MODE_DUMP;
                        break;
                case 'm':
-                       *monitor = true;
+                       *mode = DLOGUTIL_MODE_MONITOR;
                        break;
                case 't':
-                       if (sscanf(optarg, "%u", mode) != 1)
+                       *mode = DLOGUTIL_MODE_DUMP;
+                       if (sscanf(optarg, "%u", dump_size) != 1)
                                err_arg_nondigit = 1;
                        break;
                case 'c':
@@ -197,20 +200,6 @@ static int parse_options(int argc, char **argv, struct log_file *l_file, int *en
                }
        }
 
-       if (*monitor) {
-               switch (*mode) {
-               case MODE_CONTINUOUS:
-                       break;
-               case DLOGUTIL_MAX_DUMP_SIZE:
-                       *mode = MODE_CONTINUOUS; // monitor + dump = continuous
-                       *monitor = false;
-                       break;
-               default:
-                       ERR("Combining -m and -t not allowed\n");
-                       return -EINVAL;
-               }
-       }
-
        while (optind < argc) {
                int r = dlogutil_config_filter_filterspec(config, argv[optind++]);
                switch (r) {
@@ -303,7 +292,7 @@ static int for_each_buffer(int enabled_buffers, int (*func)(dlogutil_state_s *st
  * @retval 1 Silent failure
  * @retval <0 Failure as denoted by value: -errno
  */
-static int do_print(unsigned int mode, int enabled_buffers, bool monitor, dlogutil_sorting_order_e sort_by,
+static int do_print(dlogutil_mode_e mode, unsigned int dump_size, int enabled_buffers, dlogutil_sorting_order_e sort_by,
        dlogutil_config_s *config, struct log_file *l_file)
 {
        /* Optimisation for short-lived (i.e. dumping) instances.
@@ -319,7 +308,7 @@ static int do_print(unsigned int mode, int enabled_buffers, bool monitor, dlogut
         *
         * glibc has a feature where setting the TZ environmental var
         * will cache the timezone, achieving precisely what we want. */
-       if (mode != MODE_CONTINUOUS && !getenv("TZ"))
+       if (mode != DLOGUTIL_MODE_CONTINUOUS && !getenv("TZ"))
                putenv("TZ=:/etc/localtime");
 
        int r = l_file->path ? logfile_open(l_file) : 0;
@@ -375,12 +364,12 @@ static int do_print(unsigned int mode, int enabled_buffers, bool monitor, dlogut
                        dlogutil_config_buffer_add(config, i);
 
        dlogutil_state_s *state;
-       if (monitor)
+       if (mode == DLOGUTIL_MODE_MONITOR)
                r = dlogutil_config_mode_set_monitor(config);
-       else if (mode == MODE_CONTINUOUS)
+       else if (mode == DLOGUTIL_MODE_CONTINUOUS)
                r = dlogutil_config_mode_set_continuous(config);
        else
-               r = dlogutil_config_mode_set_dump(config, mode);
+               r = dlogutil_config_mode_set_dump(config, dump_size);
 
        if (!r)
                r = dlogutil_config_connect(config, &state);
@@ -428,17 +417,17 @@ int main(int argc, char **argv)
                ERR("Error while initialising: %m\n");
                return EXIT_FAILURE;
        }
-       unsigned mode = MODE_CONTINUOUS;
-       bool monitor = false;
+       dlogutil_mode_e mode;
+       unsigned int dump_size;
        dlogutil_sorting_order_e sort_by = DLOGUTIL_SORT_DEFAULT;
 
-       int r = parse_options(argc, argv, &l_file, &enabled_buffers, &action, config, &mode, &monitor, &sort_by);
+       int r = parse_options(argc, argv, &l_file, &enabled_buffers, &action, config, &mode, &dump_size, &sort_by);
        if (r)
                return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 
        switch (action) {
        case ACTION_PRINT: {
-               r = do_print(mode, enabled_buffers, monitor, sort_by, config, &l_file);
+               r = do_print(mode, dump_size, enabled_buffers, sort_by, config, &l_file);
                break;
        }
        case ACTION_GET_CAPACITY: {