tools: hal-compatibility-checker: Add stdout/stderr redirection to dlog 03/306603/3
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 23 Feb 2024 02:40:05 +0000 (11:40 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 6 Mar 2024 01:11:05 +0000 (10:11 +0900)
Options, --redirect-all, --redirect-stdout, --redirect-stderr, can now
recognize special symbol "dlog" as a parameter, which redirects output
to dlog SYSTEM buffer with log tag HAL_COMPATIBILITY_CHECKER.

Change-Id: I80425f5643709d0b0b16f8aaaa98b2a3021d263a
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
packaging/hal-api-common.spec
tools/hal-compatibility-checker/CMakeLists.txt
tools/hal-compatibility-checker/main.c

index 37f76eb8c7c5fb3920c4e219cad6ed9974ef6416..e44678d8e774d9583de2ff53e2175e538f302a0b 100644 (file)
@@ -25,6 +25,7 @@ Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(dlog-redirect-stdout)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: pkgconfig(libxml-2.0)
index c3b6c137463c42e90f252af5a3bb0edc2a38f446..5b7d63fcb9ad2df65232838b91776b163c4d9a56 100644 (file)
@@ -3,7 +3,10 @@ PROJECT(hal-compatibility-checker C)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/halcc/include)
 
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED dlog-redirect-stdout)
+
 ADD_EXECUTABLE(${PROJECT_NAME} main.c)
 SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES INSTALL_RPATH ${LIBDIR}/hal)
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE libhalcc)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE libhalcc ${REQUIRED_PKGS_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
index 1bf188a18ba1e865ae0abb662fcd18ad3c68c3c1..329355b0068fba626a38001f7a6cbee8864fcabb 100644 (file)
@@ -23,7 +23,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <getopt.h>
+#include <string.h>
 
+#include <dlog/dlog-redirect-stdout.h>
 #include <hal-common.h>
 #include <halcc/hal-compatibility-checker.h>
 
@@ -33,6 +35,8 @@
 #define HCC_BUF_MAX            (256)
 #define BOLD(STR)      "\e[1m"STR"\e[m"
 
+#define LOG_TAG_HAL_COMPATIBILITY_CHECKER     "HAL_COMPATIBILITY_CHECKER"
+
 enum {
        OPT_START = 0,
        OPT_HELP = OPT_START,
@@ -121,9 +125,20 @@ static bool result_exist(const char *dir)
 
 static int redirect_output(const char *file, int stdfd)
 {
-       int fd = open(file, O_WRONLY | O_APPEND | O_CREAT, 0644);
+       int fd = -1;
        int newfd;
 
+       assert(file);
+
+       /* recognize special symbol "dlog" */
+       if (strncmp(file, "dlog", sizeof("dlog")) == 0)
+               return dlog_connect_fd(2 /* LOG_ID_SYSTEM */,
+                       stdfd,
+                       LOG_TAG_HAL_COMPATIBILITY_CHECKER,
+                       stdfd == STDERR_FILENO ? 6 /* DLOG_ERROR */ : 4 /* DLOG_INFO */);
+
+       fd = open(file, O_WRONLY | O_APPEND | O_CREAT, 0644);
+
        if (fd == -1) {
                printf("hal-compatibility-checker: Failed to redirect output: %m\n");
                return -1;
@@ -155,14 +170,14 @@ static void show_help(void)
                "\t\tskip compatibility check if there exists a result of compatibility.\n"
                "\t\tif DIRECTORY is given, locate a result based on the given DIRECTORY.\n"
                "\n"
-               "\t--redirect-all=FILE\n"
-               "\t\tredirect stdout/stderr to FILE.\n"
+               "\t--redirect-all=FILE|dlog\n"
+               "\t\tredirect stdout/stderr to FILE or dlog with tag "LOG_TAG_HAL_COMPATIBILITY_CHECKER".\n"
                "\n"
-               "\t--redirect-stdout=FILE\n"
-               "\t\tredirect stdout to FILE.\n"
+               "\t--redirect-stdout=FILE|dlog\n"
+               "\t\tredirect stdout to FILE or dlog with tag "LOG_TAG_HAL_COMPATIBILITY_CHECKER".\n"
                "\n"
-               "\t--redirect-stderr=FILE\n"
-               "\t\tredirect stderr to FILE.\n"
+               "\t--redirect-stderr=FILE|dlog\n"
+               "\t\tredirect stderr to FILE or dlog with tag "LOG_TAG_HAL_COMPATIBILITY_CHECKER".\n"
                , default_platform_manifest_dir()
          );
 }