From: Youngjae Cho Date: Thu, 20 Jun 2024 03:47:56 +0000 (+0900) Subject: halcc: Fix error log to dlog instead of stdout X-Git-Tag: accepted/tizen/unified/20240625.163203~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d3613e962f1f0ec7e9e0879473b8dc7acfa73fa4;p=platform%2Fhal%2Fapi%2Fcommon.git halcc: Fix error log to dlog instead of stdout It was printf() because it should work before dlog daemon start up. However, it can be written to dlog even without dlog daemon. Therefore replace printf() with dlog function. And by this, it becomes unnecessary for tool hal-compatibility-checker that redirecting outputs. Thus removed related options and operations. Change-Id: I0e3a81f666b22b6f9ae909c81f7d62ea7431cc47 Signed-off-by: Youngjae Cho --- diff --git a/src/hal-api-compatibility-checker-object.c b/src/hal-api-compatibility-checker-object.c index b0318fe..918a230 100644 --- a/src/hal-api-compatibility-checker-object.c +++ b/src/hal-api-compatibility-checker-object.c @@ -59,7 +59,7 @@ static void hashtable_foreach(GHashTable *table, halcc_iter_cb cb, void *user_da void *data; if (!table || !cb) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -83,12 +83,12 @@ static GHashTable* hashtable_hal_new(void) static int hashtable_hal_insert(GHashTable *hal_table, halcc_hal *hal) { if (!hal_table || !hal || !hal->name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } if (g_hash_table_lookup_extended(hal_table, hal->name, NULL, NULL)) { - printf("Failed to insert hal, duplicate: hal name=%s", hal->name); + _E("Failed to insert hal, duplicate: hal name=%s", hal->name); return -EALREADY; } @@ -100,7 +100,7 @@ static int hashtable_hal_insert(GHashTable *hal_table, halcc_hal *hal) static halcc_hal* hashtable_hal_lookup(GHashTable *hal_table, const char *name) { if (!hal_table || !name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return NULL; } @@ -110,7 +110,7 @@ static halcc_hal* hashtable_hal_lookup(GHashTable *hal_table, const char *name) static void hashtable_hal_remove(GHashTable *hal_table, const char *name) { if (!hal_table || !name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -171,7 +171,7 @@ static halcc_interface* hashtable_interface_lookup(GHashTable *interface_table, halcc_interface key; if (!interface_table || !name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return NULL; } @@ -190,7 +190,7 @@ static void hashtable_interface_remove(GHashTable *interface_table, halcc_interface key; if (!interface_table || !name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -207,13 +207,13 @@ int halcc_manifest_new(halcc_manifest **manifest) halcc_manifest *m; if (!manifest) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } m = calloc(1, sizeof(halcc_manifest)); if (!m) { - printf("Failed to allocate halcc_manifest\n"); + _E("Failed to allocate halcc_manifest\n"); return -ENOMEM; } @@ -231,7 +231,7 @@ int halcc_manifest_new(halcc_manifest **manifest) void halcc_manifest_free(halcc_manifest *manifest) { if (!manifest) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -243,12 +243,12 @@ void halcc_manifest_free(halcc_manifest *manifest) int halcc_manifest_set_platform_version(halcc_manifest *manifest, int major, int minor) { if (!manifest) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } if (major < 0 || minor < 0) { - printf("Invalid parameter of version, major=%d, minor=%d\n", major, minor); + _E("Invalid parameter of version, major=%d, minor=%d\n", major, minor); return -EINVAL; } @@ -261,7 +261,7 @@ int halcc_manifest_set_platform_version(halcc_manifest *manifest, int major, int int halcc_manifest_get_platform_version(halcc_manifest *manifest, int *major, int *minor) { if (!manifest || !major || !minor) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -274,14 +274,14 @@ int halcc_manifest_get_platform_version(halcc_manifest *manifest, int *major, in int halcc_manifest_add_hal(halcc_manifest *manifest, halcc_hal *hal) { if (!manifest || !hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } assert(manifest->hals); if (!hal->name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -294,7 +294,7 @@ int halcc_manifest_find_hal(halcc_manifest *manifest, halcc_hal *h; if (!manifest || !hal_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -311,7 +311,7 @@ int halcc_manifest_find_hal(halcc_manifest *manifest, void halcc_manifest_remove_hal(halcc_manifest *manifest, const char *hal_name) { if (!manifest || !hal_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -322,7 +322,7 @@ void halcc_manifest_foreach_hal(halcc_manifest *manifest, halcc_iter_cb cb, void *user_data) { if (!manifest || !manifest->hals || !cb) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -334,13 +334,13 @@ int halcc_hal_new(halcc_hal **hal) halcc_hal *h; if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } h = calloc(1, sizeof(halcc_hal)); if (!h) { - printf("Failed to allocate halcc_hal\n"); + _E("Failed to allocate halcc_hal\n"); return -ENOMEM; } @@ -355,7 +355,7 @@ int halcc_hal_new(halcc_hal **hal) void halcc_hal_free(halcc_hal *hal) { if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -369,7 +369,7 @@ int halcc_hal_set_name(halcc_hal *hal, const char *hal_name) char *n; if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -381,7 +381,7 @@ int halcc_hal_set_name(halcc_hal *hal, const char *hal_name) n = strndup(hal_name, HALCC_NAME_MAX); if (!n) { - printf("Failed to allocate hal_name\n"); + _E("Failed to allocate hal_name\n"); return -ENOMEM; } @@ -393,7 +393,7 @@ int halcc_hal_set_name(halcc_hal *hal, const char *hal_name) int halcc_hal_get_name(halcc_hal *hal, const char **hal_name) { if (!hal || !hal_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -407,7 +407,7 @@ int halcc_hal_add_version(halcc_hal *hal, int major, int minor) int i; if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -461,7 +461,7 @@ int halcc_hal_get_version_list(halcc_hal *hal, int version_list[][2], int halcc_hal_set_transport(halcc_hal *hal, halcc_transport_e transport) { if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -473,7 +473,7 @@ int halcc_hal_set_transport(halcc_hal *hal, halcc_transport_e transport) int halcc_hal_get_transport(halcc_hal *hal, halcc_transport_e *transport) { if (!hal || !transport) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -488,7 +488,7 @@ int halcc_hal_get_transport(halcc_hal *hal, halcc_transport_e *transport) int halcc_hal_add_interface(halcc_hal *hal, halcc_interface *interface) { if (!hal || !interface) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -499,7 +499,7 @@ void halcc_hal_remove_interface(halcc_hal *hal, const char *interface_name, const char *instance_id) { if (!hal || !interface_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -509,7 +509,7 @@ void halcc_hal_remove_interface(halcc_hal *hal, void halcc_hal_foreach_interface(halcc_hal *hal, halcc_iter_cb cb, void *user_data) { if (!hal || !hal->interfaces || !cb) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -519,7 +519,7 @@ void halcc_hal_foreach_interface(halcc_hal *hal, halcc_iter_cb cb, void *user_da bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor) { if (!hal) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return false; } @@ -541,13 +541,13 @@ int halcc_interface_new(halcc_interface **interface) halcc_interface *iface; if (!interface) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } iface = calloc(1, sizeof(halcc_interface)); if (!iface) { - printf("Failed to allocate halcc_interface\n"); + _E("Failed to allocate halcc_interface\n"); return -ENOMEM; } @@ -559,7 +559,7 @@ int halcc_interface_new(halcc_interface **interface) void halcc_interface_free(halcc_interface *interface) { if (!interface) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return; } @@ -573,13 +573,13 @@ int halcc_interface_set_name(halcc_interface *interface, const char *interface_n char *n; if (!interface || !interface_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } n = strndup(interface_name, HALCC_NAME_MAX); if (!n) { - printf("Failed to allocate interface_name\n"); + _E("Failed to allocate interface_name\n"); return -ENOMEM; } @@ -591,7 +591,7 @@ int halcc_interface_set_name(halcc_interface *interface, const char *interface_n int halcc_interface_get_name(halcc_interface *interface, const char **interface_name) { if (!interface || !interface_name) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } @@ -605,13 +605,13 @@ int halcc_interface_set_instance_id(halcc_interface *interface, const char *inst char *id = NULL; if (!interface || !instance_id) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } id = strndup(instance_id, HALCC_NAME_MAX); if (!id) { - printf("Failed to allocate instance_id\n"); + _E("Failed to allocate instance_id\n"); return -ENOMEM; } @@ -623,7 +623,7 @@ int halcc_interface_set_instance_id(halcc_interface *interface, const char *inst int halcc_interface_get_instance_id(halcc_interface *interface, const char **instance_id) { if (!interface || !instance_id) { - printf("Invalid parameter\n"); + _E("Invalid parameter\n"); return -EINVAL; } diff --git a/src/hal-api-compatibility-checker-parser.c b/src/hal-api-compatibility-checker-parser.c index c4aa095..cf0e4b9 100644 --- a/src/hal-api-compatibility-checker-parser.c +++ b/src/hal-api-compatibility-checker-parser.c @@ -24,7 +24,7 @@ #include #include - +#include "common.h" #include "hal-api-compatibility-checker-object.h" #include "hal-api-compatibility-checker-parser.h" @@ -44,7 +44,7 @@ static int parse_interface(xmlNode *node, halcc_interface *interface) assert(interface); if (!xmlStrEqual(node->name, "interface")) { - printf("Invalid interface node, %s\n", node->name); + _E("Invalid interface node, %s\n", node->name); return -EINVAL; } @@ -81,7 +81,7 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) } if (!hal_name) { - printf("Invalid hal node, name is unspecified\n"); + _E("Invalid hal node, name is unspecified\n"); return -EINVAL; } @@ -89,7 +89,7 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) if (ret != 0) { ret = halcc_hal_new(&hal); if (ret != 0) { - printf("Failed to halcc_hal_new(), ret=%d\n", ret); + _E("Failed to halcc_hal_new(), ret=%d\n", ret); return ret; } @@ -97,7 +97,7 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) ret = halcc_manifest_add_hal(manifest, hal); if (ret != 0) { - printf("Failed to halcc_manifest_add_hal(), ret=%d\n", ret); + _E("Failed to halcc_manifest_add_hal(), ret=%d\n", ret); halcc_hal_free(hal); hal = NULL; return ret; @@ -112,13 +112,13 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) scanned = sscanf(version, "%d.%d", &major, &minor); if (scanned != 2) { - printf("Invalid version format %s\n", version); + _E("Invalid version format %s\n", version); continue; } ret = halcc_hal_add_version(hal, major, minor); if (ret != 0) - printf("Failed to halcc_hal_add_version(), ret=%d\n", ret); + _E("Failed to halcc_hal_add_version(), ret=%d\n", ret); } else if (xmlStrEqual(child->name, "transport")) { __xmlchar__ xmlChar *transport = xmlNodeGetContent(child); @@ -130,19 +130,19 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest) ret = -EINVAL; if (ret != 0) - printf("Failed to halcc_hal_set_transport(), %s, ret=%d\n", transport, ret); + _E("Failed to halcc_hal_set_transport(), %s, ret=%d\n", transport, ret); } else if (xmlStrEqual(child->name, "interface")) { halcc_interface *iface; ret = halcc_interface_new(&iface); if (ret != 0) { - printf("Failed to halcc_interface_new(), ret=%d\n", ret); + _E("Failed to halcc_interface_new(), ret=%d\n", ret); continue; } ret = parse_interface(child, iface); if (ret != 0) { - printf("Failed to parse_interface(), ret=%d\n", ret); + _E("Failed to parse_interface(), ret=%d\n", ret); halcc_interface_free(iface); continue; } @@ -171,7 +171,7 @@ static int parse_manifest(xmlNode *node, halcc_manifest *manifest) // version prop = xmlGetProp(node, "platform-version"); if (!prop) { - printf("Failed to xmlGetProp() \"platform-version\"\n"); + _E("Failed to xmlGetProp() \"platform-version\"\n"); return -EINVAL; } @@ -179,13 +179,13 @@ static int parse_manifest(xmlNode *node, halcc_manifest *manifest) xmlFree(prop); if (ret != 2) { - printf("Failed to scan platform-version, ret=%d\n", ret); + _E("Failed to scan platform-version, ret=%d\n", ret); return -EINVAL; } ret = halcc_manifest_set_platform_version(manifest, major, minor); if (ret != 0) { - printf("Failed to halcc_manifest_set_version(), ret=%d\n", ret); + _E("Failed to halcc_manifest_set_version(), ret=%d\n", ret); return -EINVAL; } @@ -206,12 +206,12 @@ static int parse_xml_doc(xmlDoc *doc, halcc_manifest *manifest) root = xmlDocGetRootElement(doc); if (!root) { - printf("Failed to get root element\n"); + _E("Failed to get root element\n"); return -EINVAL; } if (!xmlStrEqual(root->name, "hal-api")) { - printf("Invalid root node, %s\n", root->name); + _E("Invalid root node, %s\n", root->name); return -EINVAL; } @@ -230,13 +230,13 @@ int halcc_parse_fd(int fd, halcc_manifest *manifest) int ret = 0; if (!manifest) { - printf("Invalid manifest\n"); + _E("Invalid manifest\n"); return -EINVAL; } doc = xmlReadFd(fd, NULL, NULL, 0); if (!doc) { - printf("Failed to read doc %d\n", fd); + _E("Failed to read doc %d\n", fd); return -ENOENT; } @@ -253,13 +253,13 @@ int halcc_parse_path(const char *filepath, halcc_manifest *manifest) int ret = 0; if (!filepath || !manifest) { - printf("Invalid filepath or manifest\n"); + _E("Invalid filepath or manifest\n"); return -EINVAL; } doc = xmlReadFile(filepath, NULL, XML_PARSE_NOWARNING); if (!doc) { - printf("Failed to read doc %s\n", filepath); + _E("Failed to read doc %s\n", filepath); return -ENOENT; } @@ -297,13 +297,13 @@ int halcc_parse_directory(const char *directory, halcc_manifest *manifest) fd = openat(dfd, entry->d_name, O_RDONLY); if (fd < 0) { - printf("Failed to openat(), %m\n"); + _E("Failed to openat(), %m\n"); continue; } ret = halcc_parse_fd(fd, manifest); if (ret < 0) { - printf("Failed to parse xml, ret=%d\n", ret); + _E("Failed to parse xml, ret=%d\n", ret); close(fd); continue; } @@ -322,13 +322,13 @@ int halcc_parse_string(const char *string, int len, halcc_manifest *manifest) int ret = 0; if (!string || !manifest) { - printf("Invalid string or manifest\n"); + _E("Invalid string or manifest\n"); return -EINVAL; } doc = xmlReadMemory(string, len, NULL, NULL, 0); if (!doc) { - printf("Failed to read xml string\n"); + _E("Failed to read xml string\n"); return -ENOENT; } diff --git a/tools/hal-compatibility-checker/main.c b/tools/hal-compatibility-checker/main.c index 37f6967..679913c 100644 --- a/tools/hal-compatibility-checker/main.c +++ b/tools/hal-compatibility-checker/main.c @@ -26,7 +26,6 @@ #include #include -#include #include #define DEFAULT_PLATFORM_MANIFEST_DIR "/etc/hal" @@ -41,9 +40,6 @@ enum { OPT_START = 0, OPT_HELP = OPT_START, OPT_SKIP_IF_RESULT_EXIST, - OPT_REDIRECT_ALL, - OPT_REDIRECT_STDOUT, - OPT_REDIRECT_STDERR, OPT_RESET, OPT_END, }; @@ -55,15 +51,6 @@ static const struct option long_option[] = { [OPT_SKIP_IF_RESULT_EXIST] = { "skip-if-result-exist", optional_argument, NULL, 0 }, - [OPT_REDIRECT_ALL] - = { "redirect-all", required_argument, NULL, 0 }, - - [OPT_REDIRECT_STDOUT] - = { "redirect-stdout", required_argument, NULL, 0 }, - - [OPT_REDIRECT_STDERR] - = { "redirect-stderr", required_argument, NULL, 0 }, - [OPT_RESET] = { "reset", no_argument, NULL, 0 }, @@ -107,33 +94,6 @@ static bool result_exist(const char *dir) return false; } -static int redirect_output(const char *file, int stdfd) -{ - 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; - } - - newfd = dup2(fd, stdfd); - close(fd); - - return newfd; -} - static void show_help(void) { printf( @@ -150,15 +110,6 @@ 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|dlog\n" - "\t\tredirect stdout/stderr to FILE or dlog with tag "LOG_TAG_HAL_COMPATIBILITY_CHECKER".\n" - "\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|dlog\n" - "\t\tredirect stderr to FILE or dlog with tag "LOG_TAG_HAL_COMPATIBILITY_CHECKER".\n" - "\n" "\t--reset\n" "\t\tremove the existing result file.\n" ); @@ -173,8 +124,6 @@ int main(int argc, char *argv[]) bool reset_file = false; const char *skip_if_result_exist_dir = NULL; const char *platform_manifest_dir = NULL; - const char *outfile = NULL; - const char *errfile = NULL; for (;;) { opt = getopt_long(argc, argv, "h", long_option, &index); @@ -192,16 +141,6 @@ int main(int argc, char *argv[]) skip_if_result_exist = true; skip_if_result_exist_dir = optarg; break; - case OPT_REDIRECT_ALL: - outfile = optarg; - errfile = optarg; - break; - case OPT_REDIRECT_STDOUT: - outfile = optarg; - break; - case OPT_REDIRECT_STDERR: - errfile = optarg; - break; case OPT_RESET: reset_file = true; break; @@ -221,12 +160,6 @@ int main(int argc, char *argv[]) return 0; } - if (outfile) - redirect_output(outfile, STDOUT_FILENO); - - if (errfile) - redirect_output(errfile, STDERR_FILENO); - if (skip_if_result_exist && result_exist(skip_if_result_exist_dir)) { printf("hal-compatibility-checker: skip checking\n"); return 0;