Add zero-copy backend support to log-redirect-stdout 06/280606/1 submit/tizen/20220902.191720
authorMateusz Majewski <m.majewski2@samsung.com>
Thu, 1 Sep 2022 06:34:57 +0000 (08:34 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Thu, 1 Sep 2022 06:34:57 +0000 (08:34 +0200)
Change-Id: I7e54084e89a1f0dfe0b94fc497d71e50492cb3e9

src/log-redirect-stdout/internal.c

index 6c4cb66..f0b4bb3 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/logger.h>
 #include <logconfig.h>
 #include <logpipe.h>
+#include <zero_copy_backend.h>
 
 #include <stdint.h>
 
@@ -94,9 +95,30 @@ static int setup_single_android_logger(log_id_t buffer, const char *tag, log_pri
        return 0;
 }
 
+static int apply_zero_copy_ioctl(int fd, const char *tag, log_priority prio)
+{
+       int r = ioctl(fd, ZLOGGER_IOCTL_COMMAND_SET_DEFAULT_PRIORITY, (uint32_t)prio);
+       if (r < 0)
+               return -errno;
+
+       r = ioctl(fd, ZLOGGER_IOCTL_COMMAND_SET_DEFAULT_TAG, tag);
+       if (r < 0)
+               return -errno;
+
+       return 0;
+}
+
 static int setup_single_zero_copy(log_id_t buffer, const char *tag, log_priority prio, struct log_config *config, int *fd)
 {
-       return -ENOTSUP;
+       *fd = open(ZERO_COPY_DEVICE_NAME, O_WRONLY);
+       if (*fd < 0)
+               return -errno;
+
+       int r = apply_zero_copy_ioctl(*fd, tag, prio);
+       if (r < 0)
+               return r;
+
+       return 0;
 }
 
 int setup_single_unstructed(log_id_t buffer, const char *tag, log_priority prio, int *fd)