From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 3/4] shared/shell: Add option to print to monitor
Date: Tue, 20 Nov 2018 15:58:20 +0200 [thread overview]
Message-ID: <20181120135821.18082-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20181120135821.18082-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds option -m/--monitor which send output to btmon using
libshared bt_log:
= bluetoothctl: power on
= bluetoothctl: Changing power on succeeded
---
src/shared/shell.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 241046440..89a2e82bc 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <errno.h>
+#include <syslog.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -45,6 +46,7 @@
#include "src/shared/util.h"
#include "src/shared/queue.h"
#include "src/shared/shell.h"
+#include "src/shared/log.h"
#define CMD_LENGTH 48
#define print_text(color, fmt, args...) \
@@ -70,6 +72,7 @@ static struct {
int argc;
char **argv;
bool mode;
+ bool monitor;
int timeout;
struct io *input;
@@ -521,6 +524,12 @@ void bt_shell_printf(const char *fmt, ...)
vprintf(fmt, args);
va_end(args);
+ if (data.monitor) {
+ va_start(args, fmt);
+ bt_log_vprintf(0xffff, data.name, LOG_INFO, fmt, args);
+ va_end(args);
+ }
+
if (save_input) {
if (!data.saved_prompt)
rl_restore_prompt();
@@ -613,6 +622,9 @@ static void rl_handler(char *input)
if (history_search(input, -1))
add_history(input);
+ if (data.monitor)
+ bt_log_printf(0xffff, data.name, LOG_INFO, "%s", input);
+
if (wordexp(input, &w, WRDE_NOCMD))
goto done;
@@ -988,6 +1000,7 @@ static const struct option main_options[] = {
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
{ "timeout", required_argument, 0, 't' },
+ { "monitor", no_argument, 0, 'm' },
};
static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
@@ -1003,7 +1016,8 @@ static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
for (i = 0; opt && opt->options[i].name; i++)
printf("\t--%s \t%s\n", opt->options[i].name, opt->help[i]);
- printf("\t--timeout \tTimeout in seconds for non-interactive mode\n"
+ printf("\t--monitor \tEnable monitor output\n"
+ "\t--timeout \tTimeout in seconds for non-interactive mode\n"
"\t--version \tDisplay version\n"
"\t--help \t\tDisplay help\n");
}
@@ -1022,9 +1036,9 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
if (opt) {
memcpy(options + offset, opt->options,
sizeof(struct option) * opt->optno);
- snprintf(optstr, sizeof(optstr), "+hvt:%s", opt->optstr);
+ snprintf(optstr, sizeof(optstr), "+mhvt:%s", opt->optstr);
} else
- snprintf(optstr, sizeof(optstr), "+hvt:");
+ snprintf(optstr, sizeof(optstr), "+mhvt:");
data.name = strrchr(argv[0], '/');
if (!data.name)
@@ -1047,6 +1061,13 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
case 't':
data.timeout = atoi(optarg);
break;
+ case 'm':
+ data.monitor = true;
+ if (bt_log_open() < 0) {
+ data.monitor = false;
+ printf("Unable to open logging channel\n");
+ }
+ break;
default:
if (index < 0) {
for (index = 0; options[index].val; index++) {
@@ -1131,6 +1152,9 @@ void bt_shell_cleanup(void)
data.envs = NULL;
}
+ if (data.monitor)
+ bt_log_close();
+
rl_cleanup();
data.init = false;
--
2.17.2
next prev parent reply other threads:[~2018-11-20 13:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-20 13:58 [PATCH v2 1/4] shared/log: Add common code to interface with logging channel Luiz Augusto von Dentz
2018-11-20 13:58 ` [PATCH v2 2/4] shared/tester: Make use of shared log Luiz Augusto von Dentz
2018-11-20 13:58 ` Luiz Augusto von Dentz [this message]
2018-11-20 13:58 ` [PATCH v2 4/4] log: Use shared log code Luiz Augusto von Dentz
2018-11-21 9:16 ` [PATCH v2 1/4] shared/log: Add common code to interface with logging channel Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181120135821.18082-3-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).