#include <log_file.h>
#include <sort_vector.h>
+#include <dlog-internal.h>
#include "logutil_doc.h"
* @{
*/
-#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);
}
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);
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},
}
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':
}
}
- 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) {
* @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.
*
* 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;
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);
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: {