From 14f6b3b3826e9558e6d53cc649a143252659120a Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 22 Dec 2014 15:23:06 +0900 Subject: [PATCH] Simplify the usage of filesystem logging Change-Id: I396668627e68bd5ddbdbdd887902cb0343519d61 --- ism/extras/efl_immodule/isf_imf_context.cpp | 5 +- ism/extras/efl_panel/isf_panel_efl.cpp | 82 +++++++-------------------- ism/modules/frontend/scim_socket_frontend.cpp | 14 +---- ism/src/scim.cpp | 73 ++++++------------------ ism/src/scim_helper.cpp | 66 ++++----------------- ism/src/scim_helper_launcher.cpp | 22 ++----- ism/src/scim_launcher.cpp | 13 +---- ism/src/scim_panel_agent.cpp | 49 ++++------------ ism/src/scim_socket.cpp | 40 +++---------- ism/src/scim_utility.cpp | 42 ++++++-------- ism/src/scim_utility.h | 6 +- 11 files changed, 100 insertions(+), 312 deletions(-) diff --git a/ism/extras/efl_immodule/isf_imf_context.cpp b/ism/extras/efl_immodule/isf_imf_context.cpp index 6655060..9dcbe56 100644 --- a/ism/extras/efl_immodule/isf_imf_context.cpp +++ b/ism/extras/efl_immodule/isf_imf_context.cpp @@ -2127,10 +2127,7 @@ isf_imf_context_filter_event (Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, _panel_client.prepare (ic->id); _panel_client.get_active_helper_option (&_active_helper_option); _panel_client.send (); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Changed keyboard mode from S/W to H/W (code: %x, name: %s)\n", - time (0), getpid (), __FILE__, __func__, key.code, ev->keyname); - isf_save_log (buf); + ISF_SAVE_LOG ("Changed keyboard mode from S/W to H/W (code: %x, name: %s)\n", key.code, ev->keyname); LOGD ("Hardware keyboard mode, active helper option: %d", _active_helper_option); } diff --git a/ism/extras/efl_panel/isf_panel_efl.cpp b/ism/extras/efl_panel/isf_panel_efl.cpp index c9a1f45..06f136a 100644 --- a/ism/extras/efl_panel/isf_panel_efl.cpp +++ b/ism/extras/efl_panel/isf_panel_efl.cpp @@ -1629,17 +1629,11 @@ static bool set_helper_ise (const String &uuid, const String &module_name, bool if (TOOLBAR_HELPER_MODE == mode && pre_uuid.length () > 0 && _soft_keyboard_launched) { _panel_agent->hide_helper (pre_uuid); _panel_agent->stop_helper (pre_uuid); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s stop helper (%s)\n", - time (0), getpid (), __FILE__, __func__, pre_uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG("stop helper : %s\n", pre_uuid.c_str ()); } if (launch_ise) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Start helper (%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Start helper (%s)\n", uuid.c_str ()); if (_panel_agent->start_helper (uuid)) _soft_keyboard_launched = true; @@ -1660,10 +1654,7 @@ static bool set_helper_ise (const String &uuid, const String &module_name, bool static bool set_active_ise (const String &uuid, bool launch_ise) { SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s set ISE (%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("set ISE (%s)\n", uuid.c_str ()); if (uuid.length () <= 0) return false; @@ -3658,10 +3649,7 @@ static bool initialize_panel_agent (const String &config, const String &display, { SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s, initializing panel agent\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("initializing panel agent\n"); _panel_agent = new PanelAgent (); @@ -3722,9 +3710,7 @@ static bool initialize_panel_agent (const String &config, const String &display, std::vector load_ise_list; _panel_agent->get_active_ise_list (load_ise_list); - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s, initializing panel agent succeeded\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("initializing panel agent succeeded\n"); return true; } @@ -3836,10 +3822,7 @@ static void slot_focus_in (void) if (_launch_ise_on_request && !_soft_keyboard_launched) { String uuid = _config->read (SCIM_CONFIG_DEFAULT_HELPER_ISE, String ("")); if (uuid.length () > 0 && (_options[get_ise_index (uuid)] & ISM_HELPER_PROCESS_KEYBOARD_KEYEVENT)) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Start helper (%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Start helper (%s)\n", uuid.c_str ()); if (_panel_agent->start_helper (uuid)) _soft_keyboard_launched = true; @@ -5109,10 +5092,7 @@ static void slot_close_connection (int fd) static void slot_exit (void) { std::cerr << __FUNCTION__ << "...\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("exit\n"); elm_exit (); } @@ -5301,10 +5281,7 @@ static void slot_start_default_ise (void) if (_launch_ise_on_request && !_soft_keyboard_launched) { String uuid = _config->read (SCIM_CONFIG_DEFAULT_HELPER_ISE, String ("")); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Start helper (%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Start helper (%s)\n", uuid.c_str ()); if (_panel_agent->start_helper (uuid)) _soft_keyboard_launched = true; @@ -5323,10 +5300,7 @@ static void slot_stop_default_ise (void) _panel_agent->hide_helper (uuid); _panel_agent->stop_helper (uuid); _soft_keyboard_launched = false; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s stop helper (%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("stop helper (%s)\n", uuid.c_str ()); } } } @@ -5349,7 +5323,6 @@ static Eina_Bool panel_agent_handler (void *data, Ecore_Fd_Handler *fd_handler) if (fd_handler == NULL) return ECORE_CALLBACK_RENEW; - char buf[256] = {0}; int fd = ecore_main_fd_handler_fd_get (fd_handler); for (unsigned int i = 0; i < _read_handler_list.size (); i++) { if (fd_handler == _read_handler_list [i]) { @@ -5357,9 +5330,7 @@ static Eina_Bool panel_agent_handler (void *data, Ecore_Fd_Handler *fd_handler) std::cerr << "_panel_agent->filter_event () is failed!!!\n"; ecore_main_fd_handler_del (fd_handler); - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s _panel_agent->filter_event (fd=%d) is failed!!!\n", - time (0), getpid (), __FILE__, __func__, fd); - isf_save_log (buf); + ISF_SAVE_LOG ("_panel_agent->filter_event (fd=%d) is failed!!!\n", fd); } return ECORE_CALLBACK_RENEW; } @@ -5368,9 +5339,7 @@ static Eina_Bool panel_agent_handler (void *data, Ecore_Fd_Handler *fd_handler) _panel_agent->filter_exception_event (fd); ecore_main_fd_handler_del (fd_handler); - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Received exception event (fd=%d)!!!\n", - time (0), getpid (), __FILE__, __func__, fd); - isf_save_log (buf); + ISF_SAVE_LOG ("Received exception event (fd=%d)!!!\n", fd); return ECORE_CALLBACK_RENEW; } @@ -5384,20 +5353,15 @@ static Eina_Bool panel_agent_handler (void *data, Ecore_Fd_Handler *fd_handler) */ static Eina_Bool helper_manager_input_handler (void *data, Ecore_Fd_Handler *fd_handler) { - char buf[256] = {0}; if (_panel_agent->has_helper_manager_pending_event ()) { if (!_panel_agent->filter_helper_manager_event ()) { std::cerr << "_panel_agent->filter_helper_manager_event () is failed!!!\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s _panel_agent->filter_helper_manager_event () is failed!!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("_panel_agent->filter_helper_manager_event () is failed!!!\n") elm_exit (); } } else { std::cerr << "_panel_agent->has_helper_manager_pending_event () is failed!!!\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s _panel_agent->has_helper_manager_pending_event () is failed!!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("_panel_agent->has_helper_manager_pending_event () is failed!!!\n"); } return ECORE_CALLBACK_RENEW; @@ -5411,10 +5375,7 @@ static Eina_Bool helper_manager_input_handler (void *data, Ecore_Fd_Handler *fd_ static void signalhandler (int sig) { std::cerr << __FUNCTION__ << " Signal=" << sig << "\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Signal=%d\n", - time (0), getpid (), __FILE__, __func__, sig); - isf_save_log (buf); + ISF_SAVE_LOG ("Signal=%d\n", sig); unregister_edbus_signal_handler (); elm_exit (); @@ -6260,6 +6221,7 @@ int main (int argc, char *argv []) ConfigModule *config_module = NULL; String config_name = String ("socket"); String display_name = String (); + char buf[256] = {0}; Ecore_Fd_Handler *panel_agent_read_handler = NULL; Ecore_Fd_Handler *helper_manager_handler = NULL; @@ -6270,10 +6232,7 @@ int main (int argc, char *argv []) perm_app_set_privilege ("isf", NULL, NULL); check_time ("\nStarting ISF Panel EFL...... "); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Starting ISF Panel EFL......\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Starting ISF Panel EFL......\n"); DebugOutput::disable_debug (SCIM_DEBUG_AllMask); DebugOutput::enable_debug (SCIM_DEBUG_MainMask); @@ -6404,13 +6363,12 @@ int main (int argc, char *argv []) snprintf (buf, sizeof (buf), "config_name=%s display_name=%s", config_name.c_str (), display_name.c_str ()); check_time (buf); + try { if (!initialize_panel_agent (config_name, display_name, should_resident)) { check_time ("Failed to initialize Panel Agent!"); std::cerr << "Failed to initialize Panel Agent!\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Failed to initialize Panel Agent!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Failed to initialize Panel Agent!\n"); ret = -1; goto cleanup; @@ -6634,9 +6592,7 @@ cleanup: } delete []new_argv; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s ret=%d\n", - time (0), getpid (), __FILE__, __func__, ret); - isf_save_log (buf); + ISF_SAVE_LOG ("ret=%d\n", ret); if (ret == 0) { std::cerr << "Successfully exited.\n"; return 0; diff --git a/ism/modules/frontend/scim_socket_frontend.cpp b/ism/modules/frontend/scim_socket_frontend.cpp index 68c867b..f359884 100644 --- a/ism/modules/frontend/scim_socket_frontend.cpp +++ b/ism/modules/frontend/scim_socket_frontend.cpp @@ -272,10 +272,7 @@ void SocketFrontEnd::run_helper (const Socket &client) m_send_trans.put_command (SCIM_TRANS_CMD_FAIL); return; } - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s uuid(%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("uuid(%s)\n", uuid.c_str ()); for (size_t i = 0; i < __helpers.size (); ++i) { if (__helpers [i].first.uuid == uuid && __helpers [i].second.length ()) { @@ -299,10 +296,7 @@ void SocketFrontEnd::run_helper (const Socket &client) 0}; SCIM_DEBUG_MAIN (2) << " Call scim-helper-launcher.\n"; - buf[0] = '\0'; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Exec scim_helper_launcher(%s)\n", - time (0), getpid (), getppid (), __FILE__, __func__, __helpers [i].second.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Exec scim_helper_launcher(%s)\n", __helpers [i].second.c_str ()); execv (SCIM_HELPER_LAUNCHER_PROGRAM, const_cast(argv)); exit (-1); @@ -313,9 +307,7 @@ void SocketFrontEnd::run_helper (const Socket &client) break; } else { - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Can't find and exec scim_helper_launcher uuid : %s\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Can't find and exec scim_helper_launcher uuid : %s\n", uuid.c_str ()); } } diff --git a/ism/src/scim.cpp b/ism/src/scim.cpp index cce81be..444bbf9 100644 --- a/ism/src/scim.cpp +++ b/ism/src/scim.cpp @@ -175,10 +175,7 @@ static void vconf_appservice_ready_changed (keynode_t *node, void *user_data) _appsvc_callback_regist = false; } - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s vconf_appservice_ready_changed val : %d)\n", - time (0), getpid (), __FILE__, __func__, node->value.i); - isf_save_log (buf); + ISF_SAVE_LOG ("vconf_appservice_ready_changed val : %d)\n", node->value.i); launch_helper (_ise_name, _ise_uuid); } @@ -192,10 +189,7 @@ static bool check_appservice_ready () int val = 0; ret = vconf_get_int (ISF_SYSTEM_APPSERVICE_READY_VCONF, &val); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s vconf returned : %d, val : %d)\n", - time (0), getpid (), __FILE__, __func__, ret, val); - isf_save_log (buf); + ISF_SAVE_LOG ("vconf returned : %d, val : %d)\n", ret, val); if (ret == 0) { if (val >= ISF_SYSTEM_APPSERVICE_READY_STATE) @@ -241,10 +235,7 @@ static void launch_helper (const char *name, const char *uuid) _ise_uuid, 0}; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Exec scim_helper_launcher(%s %s)\n", - time (0), getpid (), __FILE__, __func__, _ise_name, _ise_uuid); - isf_save_log (buf); + ISF_SAVE_LOG ("Exec scim_helper_launcher(%s %s)\n", _ise_name, _ise_uuid); execv (SCIM_HELPER_LAUNCHER_PROGRAM, const_cast(argv)); exit (-1); @@ -262,17 +253,11 @@ static Eina_Bool handler_client_data (void *data, int ev_type, void *ev) Ecore_Ipc_Event_Client_Data *e = (Ecore_Ipc_Event_Client_Data *)ev; if (!e) return ECORE_CALLBACK_RENEW; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s client %p sent [%i] [%i] [%i]\n", - time (0), getpid (), getppid (), __FILE__, __func__, e->client, e->major, e->minor, e->size); - isf_save_log (buf); + ISF_SAVE_LOG ("client %p sent [%i] [%i] [%i]\n", e->client, e->major, e->minor, e->size); const char *message = "Done"; if (ecore_ipc_client_send (e->client, 0, 0, 0, 0, 0, message, strlen (message)) == 0) { - buf[0] = '\0'; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s ecore_ipc_client_send FAILED!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ecore_ipc_client_send FAILED!!\n"); } char buffer[_POSIX_PATH_MAX + 1] = {0}; @@ -298,18 +283,12 @@ static Eina_Bool handler_client_data (void *data, int ev_type, void *ev) static void run_broker (int argc, char *argv []) { if (!ecore_init ()) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Failed to init ecore!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Failed to init ecore!!\n"); return; } if (!ecore_ipc_init ()) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Failed to init ecore_ipc!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Failed to init ecore_ipc!!\n"); ecore_shutdown (); return; } @@ -320,10 +299,7 @@ static void run_broker (int argc, char *argv []) server = ecore_ipc_server_add (ECORE_IPC_LOCAL_SYSTEM, "scim-helper-broker", 0, NULL); if (server == NULL) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s ecore_ipc_server_add returned NULL!!\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ecore_ipc_server_add returned NULL!!\n"); } ecore_main_loop_begin (); @@ -368,16 +344,11 @@ int main (int argc, char *argv []) int new_argc = 0; char *new_argv [80]; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Waiting for wm_ready\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid : %d Waiting for wm_ready\n", getppid ()); if (!check_wm_ready ()) { std::cerr << "[ISF-PANEL-EFL] WM ready timeout\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Window Manager ready timeout\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Window Manager ready timeout\n", getppid ()); } /* Display version info */ @@ -535,9 +506,7 @@ int main (int argc, char *argv []) new_argv [new_argc] = 0; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Starting SCIM......\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Starting SCIM......\n", getppid ()); /* Get the imengine module list which should be loaded. */ if (exclude_engine_list.size ()) { @@ -575,9 +544,7 @@ int main (int argc, char *argv []) /* Try to start a SocketFrontEnd daemon first. */ if (socket) { - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Now socket frontend......\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Now socket frontend......\n", getppid ()); /* If no Socket FrontEnd is running, then launch one. And set manual to false. */ @@ -614,9 +581,7 @@ int main (int argc, char *argv []) cerr << "Launching a process with " << def_frontend << " FrontEnd...\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Now default frontend......\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Now default frontend......\n", getppid ()); /* Launch the scim process. */ if (scim_launch (daemon, @@ -631,25 +596,19 @@ int main (int argc, char *argv []) gettime (clock_start, "ISM launch time"); - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Now checking panel process......\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Now checking panel process......\n", getppid ()); /* When finished launching scim-launcher, let's create panel process also, for the default display :0 */ try { if (!check_panel ("")) { cerr << "Launching Panel...\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s Launching panel process......%s\n", - time (0), getpid (), getppid (), __FILE__, __func__, def_config.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d Launching panel process......%s\n", getppid (), def_config.c_str ()); scim_launch_panel (true, "socket", "", NULL); } } catch (scim::Exception & e) { cerr << e.what () << "\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s %s\n", - time (0), getpid (), getppid (), __FILE__, __func__, e.what ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Fail to launch panel. error: %s\n", e.what ()); } run_broker (argc, argv); diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp index 474f581..fd9efff 100644 --- a/ism/src/scim_helper.cpp +++ b/ism/src/scim_helper.cpp @@ -228,12 +228,7 @@ HelperAgent::open_connection (const HelperInfo &info, } std::cerr << " Connected :" << i << "\n"; ISF_LOG (" Connected :%d\n", i); - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Connection to PanelAgent succeeded, %d\n", - time (0), getpid (), __FILE__, __func__, i); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Connection to PanelAgent succeeded, %d\n", i); /* Let's retry 10 times when failed */ int open_connection_retries = 0; @@ -246,12 +241,8 @@ HelperAgent::open_connection (const HelperInfo &info, m_impl->socket.close (); std::cerr << "scim_socket_open_connection () is failed!!!\n"; ISF_LOG ("scim_socket_open_connection () is failed!!!\n"); - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s scim_socket_open_connection failed, %d\n", - time (0), getpid (), __FILE__, __func__, timeout); - isf_save_log (buf); - } + ISF_SAVE_LOG ("scim_socket_open_connection failed, %d\n", timeout); + return -1; } @@ -268,12 +259,8 @@ HelperAgent::open_connection (const HelperInfo &info, } ISF_LOG ("scim_socket_open_connection () is successful.\n"); - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s scim_socket_open_connection successful\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("scim_socket_open_connection successful\n"); + m_impl->send.clear (); m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST); m_impl->send.put_data (magic); @@ -319,12 +306,8 @@ HelperAgent::open_connection (const HelperInfo &info, } } - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Trying connect() with Helper_Active\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Trying connect() with Helper_Active\n"); + /* connect to the panel agent as the active helper client */ if (!m_impl->socket_active.connect (address)) return -1; if (!scim_socket_open_connection (magic, @@ -333,12 +316,7 @@ HelperAgent::open_connection (const HelperInfo &info, m_impl->socket_active, timeout)) { m_impl->socket_active.close (); - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper_Active scim_socket_open_connection() failed %d\n", - time (0), getpid (), __FILE__, __func__, timeout); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Helper_Active scim_socket_open_connection() failed %d\n", timeout); return -1; } @@ -355,12 +333,7 @@ HelperAgent::open_connection (const HelperInfo &info, m_impl->send.put_data (info.option); if (!m_impl->send.write_to_socket (m_impl->socket_active, magic)) { - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper_Active write_to_socket() failed\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Helper_Active write_to_socket() failed\n"); m_impl->socket_active.close (); return -1; } @@ -454,12 +427,7 @@ HelperAgent::filter_event () while (m_impl->recv.get_command (cmd)) { switch (cmd) { case SCIM_TRANS_CMD_EXIT: - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper ISE received SCIM_TRANS_CMD_EXIT message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Helper ISE received SCIM_TRANS_CMD_EXIT message\n"); m_impl->signal_exit (this, ic, ic_uuid); break; case SCIM_TRANS_CMD_RELOAD_CONFIG: @@ -535,12 +503,7 @@ HelperAgent::filter_event () } case ISM_TRANS_CMD_SHOW_ISE_PANEL: { - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper ISE received ISM_TRANS_CMD_SHOW_ISE_PANEL message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Helper ISE received ISM_TRANS_CMD_SHOW_ISE_PANEL message\n"); char *data = NULL; size_t len; @@ -552,12 +515,7 @@ HelperAgent::filter_event () } case ISM_TRANS_CMD_HIDE_ISE_PANEL: { - { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper ISE received ISM_TRANS_CMD_HIDE_ISE_PANEL message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); - } + ISF_SAVE_LOG ("Helper ISE received ISM_TRANS_CMD_HIDE_ISE_PANEL message\n"); m_impl->signal_ise_hide (this, ic, ic_uuid); break; diff --git a/ism/src/scim_helper_launcher.cpp b/ism/src/scim_helper_launcher.cpp index fb11f9c..67a725f 100644 --- a/ism/src/scim_helper_launcher.cpp +++ b/ism/src/scim_helper_launcher.cpp @@ -143,20 +143,14 @@ int main (int argc, char *argv []) continue; } - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Invalid command line option: %d %s...\n", - time (0), getpid (), __FILE__, __func__, i, argv [i]); - isf_save_log (buf); + ISF_SAVE_LOG ("Invalid command line option: %d %s...\n", i, argv [i]); std::cerr << "Invalid command line option: " << argv [i] << "\n"; return -1; } SCIM_DEBUG_MAIN(1) << "scim-helper-launcher: " << config << " " << display << " " << helper << " " << uuid << "\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper ISE (%s %s) is launching...\n", - time (0), getpid (), __FILE__, __func__, helper.c_str (), uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Helper ISE (%s %s) is launching...\n", helper.c_str (), uuid.c_str ()); if (!helper.length () || !uuid.length ()) { std::cerr << "Module name or Helper UUID is missing.\n"; @@ -165,9 +159,7 @@ int main (int argc, char *argv []) int ret = ise_preexec (helper.c_str (), uuid.c_str ()); if (ret < 0) { - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s ise_preexec failed (%s, %d)\n", - time (0), getpid (), __FILE__, __func__, helper.c_str (), ret); - isf_save_log (buf); + ISF_SAVE_LOG ("ise_preexec failed (%s, %d)\n", helper.c_str (), ret); std::cerr << "ise_preexec failed(" << helper << ret << ")\n"; return -1; @@ -178,9 +170,7 @@ int main (int argc, char *argv []) HelperModule helper_module (helper); if (!helper_module.valid () || helper_module.number_of_helpers () == 0) { - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Unable to load helper module(%s)\n", - time (0), getpid (), __FILE__, __func__, helper.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Unable to load helper module(%s)\n", helper.c_str ()); std::cerr << "Unable to load helper module(" << helper << ")\n"; return -1; @@ -201,9 +191,7 @@ int main (int argc, char *argv []) if (!config_pointer.null ()) config_pointer.reset (); ConfigBase::set (0); - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Helper ISE (%s) is destroyed!!!\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("Helper ISE (%s) is destroyed!!!\n", uuid.c_str ()); } /* diff --git a/ism/src/scim_launcher.cpp b/ism/src/scim_launcher.cpp index 19aafd0..1144c42 100644 --- a/ism/src/scim_launcher.cpp +++ b/ism/src/scim_launcher.cpp @@ -95,10 +95,7 @@ int main (int argc, char *argv []) new_argv [new_argc ++] = argv [0]; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Start scim-launcher\n"); perm_app_set_privilege ("isf", NULL, NULL); @@ -278,15 +275,11 @@ int main (int argc, char *argv []) /* reset backend pointer, in order to destroy backend automatically. */ backend.reset (); - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s, now running frontend...\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("now running frontend...\n"); frontend_module->run (); } catch (const std::exception & err) { - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s, caught an exception! : %s\n", - time (0), getpid (), getppid (), __FILE__, __func__, err.what()); - isf_save_log (buf); + ISF_SAVE_LOG ("caught an exception! : %s\n", err.what()); std::cerr << err.what () << "\n"; return 1; diff --git a/ism/src/scim_panel_agent.cpp b/ism/src/scim_panel_agent.cpp index b5bd46f..f18e51f 100644 --- a/ism/src/scim_panel_agent.cpp +++ b/ism/src/scim_panel_agent.cpp @@ -1310,10 +1310,7 @@ public: bool start_helper (const String &uuid, int client, uint32 context) { SCIM_DEBUG_MAIN(1) << "PanelAgent::start_helper (" << uuid << ")\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s start ISE(%s)\n", - time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("start ISE(%s)\n", uuid.c_str ()); if (uuid.length () <= 0) return false; @@ -1336,7 +1333,7 @@ public: char buf[256] = {0}; snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s prepare to stop ISE(%s)\n", time (0), getpid (), __FILE__, __func__, uuid.c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("prepare to stop ISE(%s)\n", uuid.c_str ()); SCIM_DEBUG_MAIN(1) << "PanelAgent::stop_helper (" << uuid << ")\n"; if (uuid.length () <= 0) @@ -1359,9 +1356,7 @@ public: m_send_trans.put_command (SCIM_TRANS_CMD_EXIT); m_send_trans.write_to_socket (client_socket); SCIM_DEBUG_MAIN(1) << "Stop helper\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s send SCIM_TRANS_CMD_EXIT message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("send SCIM_TRANS_CMD_EXIT message\n"); } unlock (); @@ -1418,10 +1413,7 @@ public: m_send_trans.put_data (data, len); m_send_trans.write_to_socket (client_socket); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Send ISM_TRANS_CMD_SHOW_ISE_PANEL message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Send ISM_TRANS_CMD_SHOW_ISE_PANEL message\n"); return true; } @@ -1449,10 +1441,7 @@ public: m_send_trans.put_command (ISM_TRANS_CMD_HIDE_ISE_PANEL); m_send_trans.write_to_socket (client_socket); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Send ISM_TRANS_CMD_HIDE_ISE_PANEL message\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("Send ISM_TRANS_CMD_HIDE_ISE_PANEL message\n"); } } @@ -1804,10 +1793,7 @@ public: String initial_uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_INITIAL_ISE_UUID), String ("")); String default_uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), String ("")); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s prepare to show ISE %d [%s] [%s]\n", - time (0), getpid (), __FILE__, __func__, client_id, initial_uuid.c_str(), default_uuid.c_str()); - isf_save_log (buf); + ISF_SAVE_LOG ("prepare to show ISE %d [%s] [%s]\n", client_id, initial_uuid.c_str(), default_uuid.c_str()); char *data = NULL; size_t len; @@ -1862,10 +1848,7 @@ public: void hide_ise_panel (int client_id) { SCIM_DEBUG_MAIN(4) << "PanelAgent::hide_ise_panel ()\n"; - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s prepare to hide ISE, %d %d\n", - time (0), getpid (), __FILE__, __func__, client_id, m_show_request_client_id); - isf_save_log (buf); + ISF_SAVE_LOG ("prepare to hide ISE, %d %d\n", client_id, m_show_request_client_id); uint32 client; uint32 context; @@ -3780,35 +3763,25 @@ private: if (cmd == ISM_TRANS_CMD_GET_ACTIVE_ISE) get_active_ise (client_id); else if (cmd == ISM_TRANS_CMD_SET_ACTIVE_ISE_BY_UUID) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s checking sockfd privilege...\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("checking sockfd privilege...\n"); int ret = security_server_check_privilege_by_sockfd (client_id, "isf::manager", "w"); if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { SCIM_DEBUG_MAIN (2) <<"Security server api error. Access denied\n"; } else { SCIM_DEBUG_MAIN (2) <<"Security server api success\n"; } - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s setting active ise\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("setting active ise\n"); set_active_ise_by_uuid (client_id); } else if (cmd == ISM_TRANS_CMD_SET_INITIAL_ISE_BY_UUID) { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s checking sockfd privilege...\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("checking sockfd privilege...\n"); int ret = security_server_check_privilege_by_sockfd (client_id, "isf::manager", "w"); if (ret == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { SCIM_DEBUG_MAIN (2) <<"Security server api error. Access denied\n"; } else { SCIM_DEBUG_MAIN (2) <<"Security server api success\n"; } - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s setting initial ise\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("setting initial ise\n"); set_initial_ise_by_uuid (client_id); } else if (cmd == ISM_TRANS_CMD_GET_ISE_LIST) diff --git a/ism/src/scim_socket.cpp b/ism/src/scim_socket.cpp index 6210206..5f537cc 100644 --- a/ism/src/scim_socket.cpp +++ b/ism/src/scim_socket.cpp @@ -496,20 +496,14 @@ public: // Backup the current flag to restore after non-blocking connect() try int flags = fcntl (m_id, F_GETFL, 0); if (fcntl (m_id, F_SETFL, flags | O_NONBLOCK) == -1) { - char buf[256] = {0}; char buf_err[256]; m_err = errno; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s fcntl() failed, %d %s\n", - time (0), getpid (), getppid (), __FILE__, __func__, m_err, strerror_r (m_err, buf_err, sizeof (buf_err))); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid : %d fcntl() failed, %d %s\n", getppid (), m_err, strerror_r (m_err, buf_err, sizeof (buf_err))); } - char buf[256] = {0}; char proc_name[17] = {0}; /* the buffer provided shall at least be 16+1 bytes long */ if (-1 != prctl (PR_GET_NAME, proc_name, 0, 0, 0)) { - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s trying connect() to %s, %s\n", - time (0), getpid (), getppid (), __FILE__, __func__, addr.get_address ().c_str (), proc_name); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d trying connect() to %s, %s\n", getppid (), addr.get_address ().c_str (), proc_name); } if ((m_err = ::connect (m_id, data, len)) == 0) { @@ -518,9 +512,7 @@ public: } m_address = addr; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s connect() succeeded\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("connect() succeeded\n"); return true; } @@ -537,21 +529,15 @@ public: tval.tv_sec = nsec; tval.tv_usec = 0; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s EINPROGRESS, select() with timeout %d\n", - time (0), getpid (), __FILE__, __func__, nsec); - isf_save_log (buf); + ISF_SAVE_LOG ("EINPROGRESS, select() with timeout %d\n", nsec); if (select (m_id + 1, &rset, &wset, NULL, nsec ? &tval : NULL) == 0) { m_err = ETIMEDOUT; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s timeout in select()\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("timeout in select()\n"); } else { // We've got something, connection succeeded - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s finally connected\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("finally connected\n"); if (fcntl (m_id, F_SETFL, flags) == -1) { m_err = errno; @@ -562,9 +548,7 @@ public: } else { char buf_err[256]; m_err = errno; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s connect() failed with %d (%s)\n", - time (0), getpid (), __FILE__, __func__, m_err, strerror_r (m_err, buf_err, sizeof (buf_err))); - isf_save_log (buf); + ISF_SAVE_LOG ("connect() failed with %d (%s)\n", m_err, strerror_r (m_err, buf_err, sizeof (buf_err))); } if (fcntl (m_id, F_SETFL, flags) == -1) { m_err = errno; @@ -1540,10 +1524,7 @@ scim_socket_open_connection (uint32 &key, return true; } else { { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s read_from_socket() failed %d\n", - time (0), getpid (), __FILE__, __func__, timeout); - isf_save_log (buf); + ISF_SAVE_LOG ("read_from_socket() failed %d\n", timeout); } trans.clear (); trans.put_command (SCIM_TRANS_CMD_REPLY); @@ -1551,10 +1532,7 @@ scim_socket_open_connection (uint32 &key, trans.write_to_socket (socket); } } else { - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s write_to_socket() failed\n", - time (0), getpid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("write_to_socket() failed\n"); } return false; diff --git a/ism/src/scim_utility.cpp b/ism/src/scim_utility.cpp index e40d5f5..53da311 100644 --- a/ism/src/scim_utility.cpp +++ b/ism/src/scim_utility.cpp @@ -1191,10 +1191,7 @@ EAPI int scim_launch (bool daemon, child_pid = fork (); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s fork result : %d, user %s\n", - time (0), getpid (), getppid (), __FILE__, __func__, child_pid, scim_get_user_name ().c_str ()); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid: %d, fork result : %d, user %s\n", getppid (), child_pid, scim_get_user_name ().c_str ()); // Error fork. if (child_pid < 0) return -1; @@ -1274,10 +1271,7 @@ EAPI int scim_launch_panel (bool daemon, child_pid = fork (); - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s fork result : %d\n", - time (0), getpid (), getppid (), __FILE__, __func__, child_pid); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid : %d fork result : %d\n", getppid (), child_pid); // Error fork. if (child_pid < 0) return -1; @@ -1334,17 +1328,12 @@ scim_usleep (unsigned int usec) EAPI void scim_daemon () { #if HAVE_DAEMON - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s calling daemon()\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d calling daemon()\n", getppid ()); if (daemon (0, 0) == -1) std::cerr << "Error to make SCIM into a daemon!\n"; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s daemon() called\n", - time (0), getpid (), getppid (), __FILE__, __func__); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d daemon() called\n", getppid ()); return; #else @@ -1358,10 +1347,7 @@ EAPI void scim_daemon () _exit (0); } - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s fork result : %d\n", - time (0), getpid (), getppid (), __FILE__, __func__, id); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d fork result : %d\n", getppid (), id); id = fork (); if (id == -1) { @@ -1371,17 +1357,21 @@ EAPI void scim_daemon () _exit (0); } - char buf[256] = {0}; - snprintf (buf, sizeof (buf), "time:%ld pid:%d ppid:%d %s %s fork result : %d\n", - time (0), getpid (), getppid (), __FILE__, __func__, id); - isf_save_log (buf); + ISF_SAVE_LOG ("ppid:%d fork result : %d\n", getppid (), id); return; #endif } -EAPI void isf_save_log (const char *str) +EAPI void isf_save_log (const char *fmt, ...) { + char buf[1024] = {0}; + va_list ap; + + va_start (ap, fmt); + vsnprintf (buf, sizeof (buf), fmt, ap); + va_end (ap); + const int MAX_LOG_FILE_SIZE = 10 * 1024; /* 10KB */ static bool size_exceeded = false; @@ -1392,7 +1382,7 @@ EAPI void isf_save_log (const char *str) if (ret == 0 || (ret == -1 && errno == ENOENT)) { if (st.st_size < MAX_LOG_FILE_SIZE) { std::ofstream isf_log_file (strLogFile.c_str (), std::ios::app); - isf_log_file << str; + isf_log_file << buf; isf_log_file.flush (); } else { size_exceeded = true; @@ -1400,7 +1390,7 @@ EAPI void isf_save_log (const char *str) } } - LOGD ("%s", str); + LOGD ("%s", buf); } static struct timeval _t0 = {0, 0}; diff --git a/ism/src/scim_utility.h b/ism/src/scim_utility.h index cbdf3e5..b34371a 100644 --- a/ism/src/scim_utility.h +++ b/ism/src/scim_utility.h @@ -453,8 +453,12 @@ EAPI void scim_daemon (); * * @param str The string to be saved. */ -EAPI void isf_save_log (const char *str); +EAPI void isf_save_log (const char *fmt, ...); +#define ISF_SAVE_LOG(fmt, arg...) \ + do{ \ + isf_save_log ("time:%ld pid:%d %s %s " fmt, time (0), getpid (), __FILE__, __func__, ##arg); \ + }while(0); #ifdef ISF_PROF -- 2.7.4