Disallow adapter sinks (kmsg, syslog) from printing 23/288623/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 20 Feb 2023 13:05:07 +0000 (14:05 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 20 Feb 2023 14:24:17 +0000 (15:24 +0100)
Change-Id: I211d7d7afa4b0d0698985ae9e56352eac1ee3fe2
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlog/log.c
src/log-redirect-stdout/lib.c
src/logctl/logctl.c
src/logsend/logsend.c

index 8204480..8bf4024 100644 (file)
@@ -374,10 +374,11 @@ static void __dlog_fatal_assert(int prio)
  * @param[in] log_id The target buffer ID
  * @param[in] prio The log's priority
  * @param[in] tag The log's tag
+ * @param[in] only_core Whether non-core buffers are rejected
  * @return DLOG_ERROR_NONE on success, else an error code.
  * @retval DLOG_ERROR_INVALID_PARAMETER Invalid parameter
  */
-static int dlog_check_validity(log_id_t log_id, int prio, const char *tag)
+static int dlog_check_validity(log_id_t log_id, int prio, const char *tag, bool only_core)
 {
        (void) prio;
        if (!tag)
@@ -386,6 +387,15 @@ static int dlog_check_validity(log_id_t log_id, int prio, const char *tag)
        if (!is_buffer_valid(log_id))
                return DLOG_ERROR_INVALID_PARAMETER;
 
+       /* The interface here is a bit confused. `__dlog_print` is nominally
+        * for platform logging and is not necessarily supposed to use the
+        * APPS buffer (which is a core buffer, but not a platform buffer),
+        * yet the internal interface (dlog-internal.h) exposes macros for
+        * platform programs to log into APPS. The design is probably too
+        * ossified to change at this point though. */
+       if (only_core && !is_core_buffer(log_id))
+               return DLOG_ERROR_INVALID_PARAMETER;
+
        return DLOG_ERROR_NONE;
 }
 
@@ -486,7 +496,7 @@ static int __write_to_log_critical_section(log_id_t log_id, int prio, const char
 
 static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap, bool check_should_log, bool secure_log)
 {
-       int ret = dlog_check_validity(log_id, prio, tag);
+       int ret = dlog_check_validity(log_id, prio, tag, check_should_log);
        if (ret < 0)
                return ret;
 
index e32f7b5..6aa6729 100644 (file)
@@ -23,6 +23,7 @@
 #include <tizen.h>
 #include <dlog-redirect-stdout.h>
 
+#include <buffer_traits.h>
 #include <logcommon.h>
 #include <zero_copy_backend.h>
 
 
 EXPORT_API int dlog_connect_fd(int buffer, int fileno, const char *tag, int prio)
 {
-       if (buffer <= LOG_ID_INVALID || buffer >= LOG_ID_MAX)
+       if (!is_buffer_valid(buffer))
+               return -EINVAL;
+
+       if (!is_core_buffer(buffer))
                return -EINVAL;
 
        if (fileno < 0)
index 4b101ed..a38d39f 100644 (file)
@@ -747,16 +747,19 @@ int handle_dump(const struct parsed_params *params, const char *config_path, str
 
        printf("\nLogging buffer status:\n");
        for (int i = 0; i < LOG_ID_MAX; ++i) {
-               bool stdout_enabled;
-               ret = (is_pipe ? get_stdout_one_pipe : get_stdout_one_nonpipe)(i, conf, &stdout_enabled);
                printf("* %s (regular): %s\n"
                        , log_name_by_id((log_id_t)i)
                        , is_buffer_enabled((log_id_t) i, conf) ? "ENABLED" : "DISABLED"
                );
-               printf("* %s (stdout): %s\n"
-                       , log_name_by_id((log_id_t)i)
-                       , ret != 0 ? "UNKNOWN" : stdout_enabled ? "ENABLED" : "DISABLED"
-               );
+
+               if (is_core_buffer(i)) {
+                       bool stdout_enabled;
+                       ret = (is_pipe ? get_stdout_one_pipe : get_stdout_one_nonpipe)(i, conf, &stdout_enabled);
+                       printf("* %s (stdout): %s\n"
+                               , log_name_by_id((log_id_t)i)
+                               , ret != 0 ? "UNKNOWN" : stdout_enabled ? "ENABLED" : "DISABLED"
+                       );
+               }
        }
 
        __log_limiter_destroy(limiter_data);
index f97b289..97225fb 100644 (file)
@@ -131,7 +131,7 @@ void print_help(const char *progname)
        printf("Usage: %s [-p priority] [-b buffer] [-t tag] [-c number] [-s] [-d time] [-f freq] [message]\n"
               "\t-p priority \tone of {Debug, Info, Warning, Error, Verbose, Fatal}\n"
               "\t            \tfirst letter is enough; defaults to Info\n"
-              "\t-b buffer   \tone of {main, system, radio, apps, kmsg, syslog}\n"
+              "\t-b buffer   \tone of {main, system, radio, apps}\n"
               "\t            \tdefaults to apps\n"
               "\t-t tag      \ta short identification string for identification and filtering purposes\n"
               "\t            \tcan be anything, defaults to DLOG_SEND\n"