From: Youngjae Cho Date: Fri, 23 Feb 2024 02:40:05 +0000 (+0900) Subject: tools: hal-compatibility-checker: Add stdout/stderr redirection to dlog X-Git-Tag: accepted/tizen/unified/20240319.140945~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db2a006e71352d62f1718da5884651f1bc4a02fa;p=platform%2Fhal%2Fapi%2Fcommon.git tools: hal-compatibility-checker: Add stdout/stderr redirection to dlog 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 --- diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 37f76eb..e44678d 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -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) diff --git a/tools/hal-compatibility-checker/CMakeLists.txt b/tools/hal-compatibility-checker/CMakeLists.txt index c3b6c13..5b7d63f 100644 --- a/tools/hal-compatibility-checker/CMakeLists.txt +++ b/tools/hal-compatibility-checker/CMakeLists.txt @@ -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/) diff --git a/tools/hal-compatibility-checker/main.c b/tools/hal-compatibility-checker/main.c index 1bf188a..329355b 100644 --- a/tools/hal-compatibility-checker/main.c +++ b/tools/hal-compatibility-checker/main.c @@ -23,7 +23,9 @@ #include #include #include +#include +#include #include #include @@ -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() ); }