]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/cli-command.c
cli, log: Improve the set-log-target functionality
[pulseaudio] / src / pulsecore / cli-command.c
index 33f4d491de0be4985cb4675a105cf564527b7e85..e374694e07593a28423d01fcafa86967d8224317 100644 (file)
@@ -188,7 +188,7 @@ static const struct command commands[] = {
     { "kill-client",             pa_cli_command_kill_client,        "Kill a client (args: index)", 2},
     { "kill-sink-input",         pa_cli_command_kill_sink_input,    "Kill a sink input (args: index)", 2},
     { "kill-source-output",      pa_cli_command_kill_source_output, "Kill a source output (args: index)", 2},
-    { "set-log-target",          pa_cli_command_log_target,         "Change the log target (args: null,auto,syslog,stderr,file:PATH)", 2},
+    { "set-log-target",          pa_cli_command_log_target,         "Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH)", 2},
     { "set-log-level",           pa_cli_command_log_level,          "Change the log level (args: numeric level)", 2},
     { "set-log-meta",            pa_cli_command_log_meta,           "Show source code location in log messages (args: bool)", 2},
     { "set-log-time",            pa_cli_command_log_time,           "Show timestamps in log messages (args: bool)", 2},
@@ -1423,6 +1423,8 @@ static int pa_cli_command_suspend_sink(pa_core *c, pa_tokenizer *t, pa_strbuf *b
         return -1;
     }
 
+    pa_log_debug("%s of sink %s requested via CLI.", suspend ? "Suspending" : "Resuming", sink->name);
+
     if ((r = pa_sink_suspend(sink, suspend, PA_SUSPEND_USER)) < 0)
         pa_strbuf_printf(buf, "Failed to resume/suspend sink: %s\n", pa_strerror(r));
 
@@ -1459,6 +1461,8 @@ static int pa_cli_command_suspend_source(pa_core *c, pa_tokenizer *t, pa_strbuf
         return -1;
     }
 
+    pa_log_debug("%s of source %s requested via CLI.", suspend ? "Suspending" : "Resuming", source->name);
+
     if ((r = pa_source_suspend(source, suspend, PA_SUSPEND_USER)) < 0)
         pa_strbuf_printf(buf, "Failed to resume/suspend source: %s\n", pa_strerror(r));
 
@@ -1484,6 +1488,8 @@ static int pa_cli_command_suspend(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, p
         return -1;
     }
 
+    pa_log_debug("%s of all sinks and sources requested via CLI.", suspend ? "Suspending" : "Resuming");
+
     if ((r = pa_sink_suspend_all(c, suspend, PA_SUSPEND_USER)) < 0)
         pa_strbuf_printf(buf, "Failed to resume/suspend all sinks: %s\n", pa_strerror(r));
 
@@ -1495,6 +1501,7 @@ static int pa_cli_command_suspend(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, p
 
 static int pa_cli_command_log_target(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     const char *m;
+    pa_log_target *log_target = NULL;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -1502,34 +1509,30 @@ static int pa_cli_command_log_target(pa_core *c, pa_tokenizer *t, pa_strbuf *buf
     pa_assert(fail);
 
     if (!(m = pa_tokenizer_get(t, 1))) {
-        pa_strbuf_puts(buf, "You need to specify a log target (null,auto,syslog,stderr,file:PATH).\n");
-        return -1;
-    }
-
-    if (pa_streq(m, "null"))
-        pa_log_set_target(PA_LOG_NULL);
-    else if (pa_streq(m, "syslog"))
-        pa_log_set_target(PA_LOG_SYSLOG);
-    else if (pa_streq(m, "stderr") || pa_streq(m, "auto")) {
-        /* 'auto' is actually the effect with 'stderr' */
-        pa_log_set_target(PA_LOG_STDERR);
-    } else if (pa_startswith(m, "file:")) {
-        const char *file_path = m + 5;
-        int log_fd;
-
-        /* Open target file with user rights */
-        if ((log_fd = open(file_path, O_RDWR|O_TRUNC|O_CREAT, S_IRUSR | S_IWUSR)) >= 0) {
-            pa_log_set_target(PA_LOG_FD);
-            pa_log_set_fd(log_fd);
-        } else {
-            pa_strbuf_printf(buf, "Failed to open target file %s, error : %s\n", file_path, pa_cstrerror(errno));
+        pa_strbuf_puts(buf, "You need to specify a log target (null|auto|syslog|stderr|file:PATH|newfile:PATH).\n");
+        return -1;
+    }
+
+    /* 'auto' is actually the effect with 'stderr' */
+    if (pa_streq(m, "auto"))
+        log_target = pa_log_target_new(PA_LOG_STDERR, NULL);
+    else {
+        log_target = pa_log_parse_target(m);
+
+        if (!log_target) {
+            pa_strbuf_puts(buf, "Invalid log target.\n");
             return -1;
         }
-    } else {
-        pa_strbuf_puts(buf, "You need to specify a log target (null,auto,syslog,stderr,file:PATH).\n");
+    }
+
+    if (pa_log_set_target(log_target) < 0) {
+        pa_strbuf_puts(buf, "Failed to set log target.\n");
+        pa_log_target_free(log_target);
         return -1;
     }
 
+    pa_log_target_free(log_target);
+
     return 0;
 }
 
@@ -1559,7 +1562,7 @@ static int pa_cli_command_log_level(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
 
 static int pa_cli_command_log_meta(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     const char *m;
-    pa_bool_t b;
+    int b;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -1583,7 +1586,7 @@ static int pa_cli_command_log_meta(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
 
 static int pa_cli_command_log_time(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
     const char *m;
-    pa_bool_t b;
+    int b;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -1766,7 +1769,7 @@ static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
         return -1;
     }
 
-    pa_device_port_set_latency_offset(port, (pa_usec_t) offset);
+    pa_device_port_set_latency_offset(port, offset);
 
     return 0;
 }
@@ -1840,8 +1843,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
             nl = TRUE;
         }
 
-        if (card->active_profile)
-            pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
+        pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
     }
 
     nl = FALSE;
@@ -2057,11 +2059,21 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b
                             char *pathname;
 
                             pathname = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", p, filename);
-                            pa_xfree(p);
 
                             *ifstate = access(pathname, F_OK) == 0 ? IFSTATE_TRUE : IFSTATE_FALSE;
                             pa_log_debug("Checking for existence of '%s': %s", pathname, *ifstate == IFSTATE_TRUE ? "success" : "failure");
 
+                            if (PA_UNLIKELY(pa_run_from_build_tree())) {
+                                /* If run from the build tree, search in <path>/.libs as well */
+                                char *ltpathname = pa_sprintf_malloc("%s" PA_PATH_SEP ".libs" PA_PATH_SEP "%s", p, filename);
+
+                                *ifstate = access(ltpathname, F_OK) == 0 ? IFSTATE_TRUE : IFSTATE_FALSE;
+                                pa_log_debug("Checking for existence of '%s': %s", ltpathname, *ifstate == IFSTATE_TRUE ? "success" : "failure");
+
+                                pa_xfree(ltpathname);
+                            }
+
+                            pa_xfree(p);
                             pa_xfree(pathname);
 
                             if (*ifstate == IFSTATE_TRUE)