]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
New audiod command: ll to change the log level at runtime.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 19 Oct 2021 20:19:25 +0000 (22:19 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 2 Jul 2022 19:29:17 +0000 (21:29 +0200)
The new public daemon_get_loglevel() is needed in the zero argument
case. Otherwise, the ll command handler parses the argument and calls
daemon_set_loglevel().

The lopsub stanza for the subcommand is stored in a separate file
which is currently only included by the lopsub suite for para_audiod,
but will be included as well by the server suite.

For similar reasons we implement the completer as a generic public
function, i9e_ll_completer(), although it only has one caller in
audioc.c. Another caller follows when the ll server command is added.

audioc.c
audiod_command.c
daemon.c
daemon.h
interactive.c
interactive.h
m4/lls/audiod_cmd.suite.m4
m4/lls/include/com_ll.m4 [new file with mode: 0644]

index af67063367044b675877173a1ed351bdd28f2dd1..f96922252ea91190bc647f77bd41506765e48149 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -107,6 +107,12 @@ static void help_completer(struct i9e_completion_info *ci,
        cr->matches = i9e_complete_commands(ci->word, audiod_completers);
 }
 
+static void ll_completer(struct i9e_completion_info *ci,
+               struct i9e_completion_result *cr)
+{
+       i9e_ll_completer(ci, cr);
+}
+
 static void version_completer(struct i9e_completion_info *ci,
                struct i9e_completion_result *cr)
 {
index bb54dfab87f7965a18f6cccbe6bc4077c147fa29..40f918569f389239b72d96b4968edde2b915334e 100644 (file)
@@ -240,6 +240,42 @@ static int com_help(int fd, struct lls_parse_result *lpr)
 }
 EXPORT_AUDIOD_CMD_HANDLER(help)
 
+static int com_ll(int fd, struct lls_parse_result *lpr)
+{
+       unsigned ll;
+       char *errctx;
+       const char *sev[] = {SEVERITIES};
+       const char *arg;
+       int ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx));
+
+       if (ret < 0) {
+               char *tmp = make_message("%s\n", errctx);
+               free(errctx);
+               client_write(fd, tmp);
+               free(tmp);
+               return ret;
+       }
+       if (lls_num_inputs(lpr) == 0) {
+               char *msg;
+               ll = daemon_get_loglevel();
+               msg = make_message("%s\n", sev[ll]);
+               ret = client_write(fd, msg);
+               free(msg);
+               return ret;
+       }
+       arg = lls_input(0, lpr);
+       for (ll = 0; ll < NUM_LOGLEVELS; ll++) {
+               if (!strcmp(arg, sev[ll]))
+                       break;
+       }
+       if (ll >= NUM_LOGLEVELS)
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
+       PARA_INFO_LOG("new log level: %s\n", sev[ll]);
+       daemon_set_loglevel(ll);
+       return 1;
+}
+EXPORT_AUDIOD_CMD_HANDLER(ll)
+
 static int com_tasks(int fd, __a_unused struct lls_parse_result *lpr)
 {
        int ret;
index f44848ac6077ce33141b12ea244e80d11723a052..1fff16beb39ee71a5244ad2b38f3855306270da7 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -152,7 +152,17 @@ void daemon_set_loglevel(int loglevel)
        assert(loglevel >= 0);
        assert(loglevel < NUM_LOGLEVELS);
        me->loglevel = loglevel;
+}
 
+/**
+ * Get the current log level of the daemon.
+ *
+ * \return Greater or equal than zero and less than NUM_LOGLEVELS. This
+ * function never fails.
+ */
+int daemon_get_loglevel(void)
+{
+       return me->loglevel;
 }
 
 /**
index 92b6ceaef3ced176371f0752b53dadea8d2f80b8..54879924954d0352d25cec928c1bcff9a6f9e58e 100644 (file)
--- a/daemon.h
+++ b/daemon.h
@@ -13,6 +13,7 @@ __malloc char *daemon_get_uptime_str(const struct timeval *current_time);
 void daemon_set_logfile(const char *logfile_name);
 void daemon_set_hooks(void (*pre_log_hook)(void), void (*post_log_hook)(void));
 void daemon_set_flag(unsigned flag);
+int daemon_get_loglevel(void);
 void daemon_set_loglevel(int loglevel);
 bool daemon_init_colors_or_die(int color_arg, int color_arg_auto,
                int color_arg_no, bool logfile_given);
index 8c4545b476e8f792ea7bba6f88b4e83fb952e540..209c5a36f70b194308a21d132c14541a46d51025 100644 (file)
@@ -805,3 +805,21 @@ create_matches:
        free(ci.word);
        return ret;
 }
+
+/**
+ * Complete on severity strings.
+ *
+ * \param ci See struct \ref i9e_completer.
+ * \param cr See struct \ref i9e_completer.
+ */
+void i9e_ll_completer(struct i9e_completion_info *ci,
+               struct i9e_completion_result *cr)
+{
+       char *sev[] = {SEVERITIES, NULL};
+
+       if (ci->word_num != 1) {
+               cr->matches = NULL;
+               return;
+       }
+       i9e_extract_completions(ci->word, sev, &cr->matches);
+}
index ddf02d76d2bc44a71133844fa0dddf4d9db03778..18c007b0b39172ca2443a86165119888213d4c32 100644 (file)
@@ -93,3 +93,5 @@ void i9e_complete_option(char **opts, struct i9e_completion_info *ci,
                struct i9e_completion_result *cr);
 int i9e_print_completions(struct i9e_completer *completers);
 int i9e_get_error(void);
+void i9e_ll_completer(struct i9e_completion_info *ci,
+               struct i9e_completion_result *cr);
index 80ae2e42be9773f0e619e1746b9bfdefbe02f2c4..bd2a23e2354dde09cc8090a08ccf6ad31d7ac9b9 100644 (file)
@@ -51,6 +51,8 @@ caption = list of audiod commands
                short_opt = o
                summary = One-shot mode: Stop grabbing if audio file changes
 
+m4_include(`com_ll.m4')
+
 [subcommand off]
        purpose = deactivate para_audiod
        [description]
diff --git a/m4/lls/include/com_ll.m4 b/m4/lls/include/com_ll.m4
new file mode 100644 (file)
index 0000000..d100dfa
--- /dev/null
@@ -0,0 +1,9 @@
+[subcommand ll]
+       purpose = Query or set the log level of the daemon
+       non-opts-name = [severity]
+       [description]
+               If no argument is given, the command prints the severity string (one
+               of the possible string arguments to --loglevel) which corresponds to
+               the current loglevel. Otherwise, if the given argument is a severity
+               string, the current log level is set accordingly.
+       [/description]