From b471865aaaae33df9221decb6dcabcd7ab1d192d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 30 Mar 2023 04:08:14 +0000 Subject: [PATCH] Remove unnecessary log system If the execv() call fails, there used to be a feature that uses a socket to send the error message to the launchpad. This feature is no longer needed. The stderr file descriptor is redirected to dlog, so we can check error logs using dlog. Change-Id: I36ad6d690361bba01dce2df065e5caa8d22fab5b Signed-off-by: Hwankyu Jhun --- src/app-defined-loader/src/app-defined-loader.cc | 5 +- src/launchpad-loader/src/launchpad_loader.c | 8 +- src/launchpad-process-pool/launchpad.cc | 108 +++-------------------- src/lib/common/inc/launchpad_common.h | 1 - src/lib/common/src/launchpad_common.c | 61 ------------- 5 files changed, 18 insertions(+), 165 deletions(-) diff --git a/src/app-defined-loader/src/app-defined-loader.cc b/src/app-defined-loader/src/app-defined-loader.cc index 3e9f368..21f1c01 100644 --- a/src/app-defined-loader/src/app-defined-loader.cc +++ b/src/app-defined-loader/src/app-defined-loader.cc @@ -176,9 +176,10 @@ class AppDefinedLoader { unsetenv("AUL_LOADER_INIT"); unsetenv("AUL_HWACC"); if (execv(argv_[LOADER_ARG_PATH], argv_) < 0) { - _send_message_to_logger(argv_[LOADER_ARG_PATH], - "Failed to execute a file. error(%d:%s)", errno, + fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n", + argv_[LOADER_ARG_PATH], errno, strerror_r(errno, err_str, sizeof(err_str))); + exit(EXIT_FAILURE); } } } diff --git a/src/launchpad-loader/src/launchpad_loader.c b/src/launchpad-loader/src/launchpad_loader.c index b815e48..87f1d3c 100644 --- a/src/launchpad-loader/src/launchpad_loader.c +++ b/src/launchpad-loader/src/launchpad_loader.c @@ -382,14 +382,14 @@ do_exec: unsetenv("AUL_LOADER_INIT"); unsetenv("AUL_HWACC"); if (execv(argv[LOADER_ARG_PATH], argv) < 0) { - _send_message_to_logger(argv[LOADER_ARG_PATH], - "Failed to execute a file. error(%d:%s)", - errno, + fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n", + argv[LOADER_ARG_PATH], errno, strerror_r(errno, err_str, sizeof(err_str))); + exit(EXIT_FAILURE); } } - return -1; + return 0; } static Eina_Bool __process_fd_handler(void *data, Ecore_Fd_Handler *handler) diff --git a/src/launchpad-process-pool/launchpad.cc b/src/launchpad-process-pool/launchpad.cc index 70cf325..1a44270 100644 --- a/src/launchpad-process-pool/launchpad.cc +++ b/src/launchpad-process-pool/launchpad.cc @@ -72,7 +72,6 @@ #define CANDIDATE_NONE 0 #define HYDRA_NONE 0 #define PROCESS_POOL_LAUNCHPAD_SOCK ".launchpad-process-pool-sock" -#define LAUNCHPAD_LOGGER_SOCK ".launchpad-logger-sock" #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader" #define LOADER_INFO_PATH "/usr/share/aul" #define OPT_SHARE_PATH "/opt/share" @@ -309,7 +308,6 @@ static void __update_slot_state(candidate_process_context_t* cpc, launchpad::LoaderMethod method, bool force); static gboolean __launchpad_recovery_cb(gpointer data); -static gboolean __logger_recovery_cb(gpointer data); static gboolean __handle_queuing_slots(gpointer data) { candidate_process_context_t* cpc; @@ -868,14 +866,13 @@ static int __exec_loader_process(void* arg) { _setup_stdio(basename(argv[LOADER_ARG_PATH])); if (execv(argv[LOADER_ARG_PATH], argv) < 0) { - _send_message_to_logger(argv[LOADER_ARG_PATH], - "Failed to prepare candidate process. error(%d:%s)", - errno, strerror_r(errno, err_buf, sizeof(err_buf))); - } else { - _D("Succeeded to prepare candidate_process"); + fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n", + argv[LOADER_ARG_PATH], errno, + strerror_r(errno, err_buf, sizeof(err_buf))); + exit(EXIT_FAILURE); } - return -1; + return 0; } static gboolean __handle_deactivate_event(gpointer user_data) { @@ -1157,13 +1154,13 @@ static int __normal_fork_exec(int argc, char** argv, const char* app_path) { _close_all_fds(); - if (execv(argv[LOADER_ARG_PATH], argv) < 0) { /* Flawfinder: ignore */ - _send_message_to_logger(argv[LOADER_ARG_PATH], - "Failed to execute a file. error(%d:%s)", - errno, strerror_r(errno, err_buf, sizeof(err_buf))); - return -1; + if (execv(argv[LOADER_ARG_PATH], argv) < 0) { + fprintf(stderr, "Failed to execute a file. path: %s, errno: %d(%s)\n", + argv[LOADER_ARG_PATH], errno, + strerror_r(errno, err_buf, sizeof(err_buf))); + exit(EXIT_FAILURE); } - /* never reach*/ + return 0; } @@ -2884,66 +2881,6 @@ static int __add_default_slots(void) { return 0; } -static bool __handle_logger(int fd, io_condition_e cond, void* data) { - app_pkt_t* pkt; - struct ucred cr; - int clifd = -1; - - if (cond & (IO_ERR | IO_HUP | IO_NVAL)) { - _E("fd(%d), io_condition(%d)", fd, cond); - g_idle_add(__logger_recovery_cb, __logger_channel); - __logger_channel = nullptr; - return false; - } - - pkt = _accept_recv_pkt_raw(fd, &clifd, &cr); - if (!pkt) { - _E("Failed to receive the packet"); - return true; - } - - if (getuid() != cr.uid) { - _E("Invalid caller"); - goto end; - } - - if (pkt->len <= 0) { - _E("Invalid message"); - goto end; - } - - _E("[%d] %s", cr.pid, (const char*)pkt->data); - launchpad::Log::Print("[ERROR]", "pid(%7d) | message(%s)", - cr.pid, reinterpret_cast(pkt->data)); -end: - if (clifd != -1) - close(clifd); - - free(pkt); - - return true; -} - -static int __init_logger_fd(void) { - int fd; - - fd = _create_server_sock(LAUNCHPAD_LOGGER_SOCK); - if (fd < 0) { - _E("Failed to create logger socker"); - return -1; - } - - auto cond = IO_IN | IO_PRI | IO_ERR | IO_HUP | IO_NVAL; - __logger_channel = _io_channel_create(fd, static_cast(cond), - __handle_logger, nullptr); - if (!__logger_channel) { - close(fd); - return -1; - } - - return 0; -} - static void UpdateSlotStates(bool low_memory) { GList* iter = candidate_slot_list; while (iter) { @@ -2975,23 +2912,6 @@ static void HandleMemoryStatusChangedEvent(bool low_memory) { } } -static gboolean __logger_recovery_cb(gpointer data) { - auto channel = static_cast(data); - int ret; - - _io_channel_destroy(channel); - - ret = __init_logger_fd(); - if (ret < 0) { - _E("Failed to recover logger socket"); - return G_SOURCE_REMOVE; - } - - _E("[__RECOVERY__] Logger socket"); - - return G_SOURCE_REMOVE; -} - static gboolean __launchpad_recovery_cb(gpointer data) { auto channel = static_cast(data); int ret; @@ -3040,12 +2960,6 @@ static int __before_loop(int argc, char** argv) { return -1; } - ret = __init_logger_fd(); - if (ret != 0) { - _E("__init_logger_fd() failed"); - return -1; - } - ret = __init_label_monitor_fd(); if (ret != 0) _W("Failed to initialize label monitor"); diff --git a/src/lib/common/inc/launchpad_common.h b/src/lib/common/inc/launchpad_common.h index 000606a..2506fb8 100644 --- a/src/lib/common/inc/launchpad_common.h +++ b/src/lib/common/inc/launchpad_common.h @@ -110,7 +110,6 @@ typedef struct { void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd); -int _send_message_to_logger(const char *tag, const char *format, ...); int _send_cmd_to_amd(int cmd); int _create_server_sock(const char *name); app_pkt_t *_recv_pkt_raw(int fd); diff --git a/src/lib/common/src/launchpad_common.c b/src/lib/common/src/launchpad_common.c index f062423..9fab91e 100644 --- a/src/lib/common/src/launchpad_common.c +++ b/src/lib/common/src/launchpad_common.c @@ -1432,67 +1432,6 @@ int _prepare_id_file(void) return 0; } -static int __send_raw(int fd, int cmd, unsigned char *data, int datalen) -{ - app_pkt_t *pkt; - int ret; - - pkt = (app_pkt_t *)calloc(1, sizeof(app_pkt_t) + datalen); - if (!pkt) { - _E("Out of memory"); - return -ENOMEM; - } - - pkt->cmd = cmd; - pkt->len = datalen; - if (data) - memcpy(pkt->data, data, pkt->len); - - ret = _send_pkt_raw(fd, pkt); - if (ret < 0) { - free(pkt); - return -1; - } - - free(pkt); - - return 0; -} - -int _send_message_to_logger(const char *tag, const char *format, ...) -{ - char fmt[PATH_MAX - 256]; - char buf[PATH_MAX]; - va_list ap; - int ret; - int fd; - - va_start(ap, format); - ret = vsnprintf(fmt, sizeof(fmt), format, ap); - va_end(ap); - if (ret < 0 || ret >= sizeof(fmt)) { - _E("vsnprintf() is failed. result(%d)", ret); - return -1; - } - - snprintf(buf, sizeof(buf), "%s/daemons/%u/.launchpad-logger-sock", - SOCKET_PATH, getuid()); - fd = __create_client_socket(buf); - if (fd < 0) - return -1; - - snprintf(buf, sizeof(buf), "%s: %s", tag, fmt); - ret = __send_raw(fd, 0, (unsigned char *)buf, strlen(buf) + 1); - if (ret < 0) { - close(fd); - return -1; - } - - close(fd); - - return 0; -} - void _print_hwc_log(const char *format, ...) { char buf[1024]; -- 2.7.4