From ee1a23c25bc3f3c62b5b24d9e9a85e27c91c893d Mon Sep 17 00:00:00 2001 From: Jiyong Date: Wed, 24 Apr 2024 11:26:23 +0900 Subject: [PATCH] Remove unnecessary socket activation code Change-Id: I6343c90e712ea4356c9d9c57ac9a022fe50e9641 --- src/media_controller_ipc.c | 78 ++++------------------------------- svc/daemon/media_controller_main.c | 46 ++++++++++----------- svc/include/media_controller_socket.h | 3 +- svc/media_controller_svc.c | 20 +-------- 4 files changed, 31 insertions(+), 116 deletions(-) diff --git a/src/media_controller_ipc.c b/src/media_controller_ipc.c index c27f314..dc0c2c4 100644 --- a/src/media_controller_ipc.c +++ b/src/media_controller_ipc.c @@ -314,22 +314,6 @@ int _mc_ipc_send_reply(GDBusConnection *connection, const char *dbus_name, const return __dbus_send_message(connection, dbus_name, interface_name, signal_name, message, request_id); } -/* This checks if service daemon is running */ -static int __make_service_connection(mc_priv_type_e priv_type) -{ - int ret = MEDIA_CONTROLLER_ERROR_NONE; - char *app_id = NULL; - - ret = _mc_util_get_own_name(&app_id); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Failed to _mc_util_get_own_name[%d]", ret); - - ret = _mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, priv_type, app_id); - - g_free(app_id); - - return ret; -} - int _mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_type, const char *request_msg) { int ret = MEDIA_CONTROLLER_ERROR_NONE; @@ -397,71 +381,23 @@ int _mc_ipc_send_message_to_server(mc_msg_type_e msg_type, mc_priv_type_e priv_t return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; } - mc_debug("RECEIVE OK [%d]", recv_msg); + mc_debug("RECEIVE RESULT OK [%d]", recv_msg); close(sockfd); return recv_msg; } -#ifdef _ON_DEMAND_SOCKET_ACTIVATION -static int __activate_service(void) -{ - int ret = MEDIA_CONTROLLER_ERROR_NONE; - int sockfd = -1; - struct sockaddr_un serv_addr; - - /* Create Socket */ - ret = mc_ipc_create_client_socket(MC_TIMEOUT_SEC_5, &sockfd); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "socket is not created properly"); - - /* Set socket activation address, the path is already created by system */ - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sun_family = AF_UNIX; - MC_SAFE_STRLCPY(serv_addr.sun_path, MC_SOCK_ACTIVATION_PATH, sizeof(serv_addr.sun_path)); - - /* Connecting to the media controller service for activation */ - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { - mc_stderror("connect error"); - close(sockfd); - return MEDIA_CONTROLLER_ERROR_INVALID_OPERATION; - } - - close(sockfd); - - return MEDIA_CONTROLLER_ERROR_NONE; -} - -static int __launch_service(mc_priv_type_e priv_type) +int _mc_ipc_service_connect(mc_priv_type_e priv_type) { int ret = MEDIA_CONTROLLER_ERROR_NONE; - unsigned int retry_count = 0; + char *app_id = NULL; - ret = _mc_ipc_send_message_to_server(MC_MSG_SERVICE_LAUNCH, priv_type, "launch"); - mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_NONE, ret, "service is already running!"); - mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED, ret, "Permission deny!"); + ret = _mc_util_get_own_name(&app_id); + mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Failed to _mc_util_get_own_name[%d]", ret); - ret = __activate_service(); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Fail to __activate_service"); + ret = _mc_ipc_send_message_to_server(MC_MSG_SERVER_CONNECTION, priv_type, app_id); - while (retry_count++ < MAX_WAIT_COUNT) { - usleep(10000); - mc_error("[No-Error] retry_count [%d]", retry_count); - ret = _mc_ipc_send_message_to_server(MC_MSG_SERVICE_LAUNCH, priv_type, "launch"); - mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_NONE, ret, "service is running!"); - mc_retvm_if(ret == MEDIA_CONTROLLER_ERROR_PERMISSION_DENIED, ret, "Permission deny!"); - } + g_free(app_id); return ret; } -#endif - -int _mc_ipc_service_connect(mc_priv_type_e priv_type) -{ -#ifdef _ON_DEMAND_SOCKET_ACTIVATION - int ret = MEDIA_CONTROLLER_ERROR_NONE; - ret = __launch_service(priv_type); - mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "Fail to __launch_service"); -#endif - - return __make_service_connection(priv_type); -} diff --git a/svc/daemon/media_controller_main.c b/svc/daemon/media_controller_main.c index 84d0b60..5da9d79 100644 --- a/svc/daemon/media_controller_main.c +++ b/svc/daemon/media_controller_main.c @@ -14,9 +14,7 @@ * limitations under the License. */ -#ifdef _ON_DEMAND_SOCKET_ACTIVATION #include -#endif #include "media_controller_private.h" #include "media_controller_socket.h" @@ -69,16 +67,15 @@ static void __mc_main_create_timer(void) g_mc_timer_id = g_timeout_add_seconds(MC_MAIN_TIMEOUT_SEC_60, __mc_main_check_connection, NULL); } +#endif -static int __mc_main_create_socket_activation(void) +static int __mc_main_listen_socket(void) { - int fd = -1; int listen_fds; listen_fds = sd_listen_fds(0); if (listen_fds == 1) { - fd = SD_LISTEN_FDS_START; - return fd; + return SD_LISTEN_FDS_START; } else if (listen_fds > 1) { mc_error("Too many file descriptors received."); return -1; @@ -87,42 +84,40 @@ static int __mc_main_create_socket_activation(void) return -1; } } -#endif int main(int argc, char **argv) { GThread *svc_thread = NULL; -#ifdef _ON_DEMAND_SOCKET_ACTIVATION int fd = -1; - int client_fd = -1; - struct sockaddr_in client_addr; - int client_addr_size = 0; -#endif mc_debug_fenter(); - /* Init main loop */ g_mc_mainloop = g_main_loop_new(NULL, FALSE); + fd = __mc_main_listen_socket(); + if (fd < 0) { + mc_error("Failed to listen socket"); + if (mc_ipc_create_server_socket(&fd) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Failed to create socket"); + return -1; + } + } + if (mc_cynara_initialize() != MEDIA_CONTROLLER_ERROR_NONE) { mc_error("Failed to initialize cynara"); + close(fd); return -1; } -#ifdef _ON_DEMAND_SOCKET_ACTIVATION - fd = __mc_main_create_socket_activation(); - if (fd < 0) { - mc_error("Failed to socket creation"); - } else { - client_addr_size = sizeof(client_addr); - client_fd = accept(fd, (struct sockaddr*)&client_addr, (socklen_t *)&client_addr_size); - if (client_fd == -1) - mc_error("accept failed"); + if (mc_cynara_enable_credentials_passing(fd) != MEDIA_CONTROLLER_ERROR_NONE) { + mc_error("Failed to append socket options"); + mc_cynara_finish(); + close(fd); + return -1; } -#endif /* Create media controller service thread */ - svc_thread = g_thread_new("mc_svc_thread", (GThreadFunc)mc_svc_thread, NULL); + svc_thread = g_thread_new("mc_svc_thread", (GThreadFunc)mc_svc_thread, GINT_TO_POINTER(fd)); #ifdef _ON_DEMAND_SOCKET_ACTIVATION /* Create Timer */ @@ -145,6 +140,9 @@ int main(int argc, char **argv) #endif mc_cynara_finish(); + /* close socket */ + close(fd); + mc_debug("*** Media Controller Daemon is stopped ***"); return 0; diff --git a/svc/include/media_controller_socket.h b/svc/include/media_controller_socket.h index d7db351..6cca973 100755 --- a/svc/include/media_controller_socket.h +++ b/svc/include/media_controller_socket.h @@ -28,8 +28,7 @@ extern "C" { #define MC_TIMEOUT_SEC_5 5 /* Response from daemon time out */ #define MAX_MSG_SIZE 10 * 1024 /* Maximum of message to daemon */ -#define MC_SOCK_ACTIVATION_PATH "/run/.mediacontroller.sock" /* tzplatform_mkpath(TZ_SYS_RUN, ".media_controller.sock") */ -#define MC_IPC_PATH "/run/.mediacontroller-comm.sock" /* tzplatform_mkpath(TZ_SYS_RUN, ".media_controller-comm.sock") */ +#define MC_IPC_PATH "/run/.mediacontroller.sock" /* tzplatform_mkpath(TZ_SYS_RUN, ".media_controller.sock") */ typedef enum { MC_MSG_DB_UPDATE, /**< Media Controller DB Update */ diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c index 3d0047f..6ff7576 100644 --- a/svc/media_controller_svc.c +++ b/svc/media_controller_svc.c @@ -696,7 +696,7 @@ static void __destroy_recv_msg_queue(gpointer data) gpointer mc_svc_thread(gpointer data) { - int sockfd = -1; + int sockfd = GPOINTER_TO_INT(data); int ret = MEDIA_CONTROLLER_ERROR_NONE; GSource *source = NULL; GIOChannel *channel = NULL; @@ -734,24 +734,9 @@ gpointer mc_svc_thread(gpointer data) return NULL; } - /* Create TCP Socket*/ - ret = mc_ipc_create_server_socket(&sockfd); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("Failed to create socket"); - return NULL; - } - - ret = mc_cynara_enable_credentials_passing(sockfd); - if (ret != MEDIA_CONTROLLER_ERROR_NONE) { - mc_error("Failed to append socket options"); - close(sockfd); - return NULL; - } - /* Register app_dead signal handler */ if (aul_listen_app_dead_signal(__mc_service_app_dead_handler, NULL) != AUL_R_OK) { mc_error("Failed to register app_dead signal"); - close(sockfd); return NULL; } @@ -802,9 +787,6 @@ gpointer mc_svc_thread(gpointer data) g_io_channel_unref(channel); g_source_destroy(source); - /* close socket */ - close(sockfd); - g_main_loop_unref(g_mc_svc_mainloop); return NULL; -- 2.7.4