From 15af46f1287673a3bdb9d34be47da459a4c75cc7 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Thu, 11 Jun 2020 20:34:55 +0530 Subject: [PATCH] Add callback in monitor plugin to stop stc-manager Change-Id: I88c9d9275620ee1ee32ee62e853e88c46c535a3f Signed-off-by: Nishant Chaprana --- include/stc-manager-plugin-monitor.h | 2 +- packaging/stc-manager.spec | 2 +- plugin/monitor/include/stc-plugin-monitor.h | 6 ++++-- plugin/monitor/stc-plugin-monitor.c | 11 ++++++++++- src/stc-manager-plugin-monitor.c | 4 ++-- src/stc-manager.c | 18 +++++++++++++++++- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/stc-manager-plugin-monitor.h b/include/stc-manager-plugin-monitor.h index 3830608..76a65bd 100755 --- a/include/stc-manager-plugin-monitor.h +++ b/include/stc-manager-plugin-monitor.h @@ -21,7 +21,7 @@ #include "stc-plugin-monitor.h" -int stc_plugin_monitor_init(void); +int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb); int stc_plugin_monitor_deinit(void); int stc_plugin_monitor_add_app(uint32_t classid, diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index a418017..f8690c2 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -1,6 +1,6 @@ Name: stc-manager Summary: STC(Smart Traffic Control) manager -Version: 0.1.0 +Version: 0.1.1 Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/plugin/monitor/include/stc-plugin-monitor.h b/plugin/monitor/include/stc-plugin-monitor.h index 35509c8..0cc8c42 100755 --- a/plugin/monitor/include/stc-plugin-monitor.h +++ b/plugin/monitor/include/stc-plugin-monitor.h @@ -38,8 +38,10 @@ #define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction" #endif +typedef void (*stc_manager_stop_cb)(void); + typedef struct { - int (*initialize_plugin) (void); + int (*initialize_plugin) (stc_manager_stop_cb stop_cb); int (*deinitialize_plugin) (void); int (*add_application) (uint32_t classid, @@ -68,7 +70,7 @@ typedef struct { int (*check_excn_by_cmdline) (char *cmdline); } stc_plugin_monitor_s; -stc_error_e stc_plugin_monitor_initialize(void); +stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb); stc_error_e stc_plugin_monitor_deinitialize(void); GHashTable *stc_monitor_get_system_apps(void); diff --git a/plugin/monitor/stc-plugin-monitor.c b/plugin/monitor/stc-plugin-monitor.c index 1f08dc3..ab06816 100755 --- a/plugin/monitor/stc-plugin-monitor.c +++ b/plugin/monitor/stc-plugin-monitor.c @@ -32,6 +32,7 @@ #include "stc-manager-plugin-exception.h" static stc_system_s *g_system = NULL; +static stc_manager_stop_cb g_stop_cb = NULL; static int __vconf_get_int(const char *key, int *value) { @@ -101,6 +102,7 @@ static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system) STC_LOGE("failed to open socket"); __free_system(system); g_system = NULL; + g_stop_cb(); return STC_ERROR_FAIL; } @@ -337,7 +339,7 @@ static void __fill_exceptions_list(void) stc_plugin_fill_exception_list(); } -stc_error_e stc_plugin_monitor_initialize(void) +stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb) { __STC_LOG_FUNC_ENTER__; @@ -347,6 +349,11 @@ stc_error_e stc_plugin_monitor_initialize(void) ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY, "stc_system_s malloc fail!"); + ret_value_msg_if(stop_cb == NULL, STC_ERROR_INVALID_PARAMETER, + "stop_cb callback is NULL"); + + g_stop_cb = stop_cb; + /* initializing current classid */ init_current_classid(); @@ -362,6 +369,7 @@ stc_error_e stc_plugin_monitor_initialize(void) if (system->contr_sock < 0) { STC_LOGE("failed to open socket"); __free_system(system); + g_stop_cb(); return STC_ERROR_FAIL; } @@ -417,6 +425,7 @@ stc_error_e stc_plugin_monitor_deinitialize(void) __free_system(g_system); g_system = NULL; + g_stop_cb = NULL; return STC_ERROR_NONE; } diff --git a/src/stc-manager-plugin-monitor.c b/src/stc-manager-plugin-monitor.c index 209b1a1..efdf759 100755 --- a/src/stc-manager-plugin-monitor.c +++ b/src/stc-manager-plugin-monitor.c @@ -24,7 +24,7 @@ static void *handle_plugin; static stc_plugin_monitor_s *stc_plugin; //LCOV_EXCL_START -API int stc_plugin_monitor_init(void) +API int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb) { __STC_LOG_FUNC_ENTER__; @@ -43,7 +43,7 @@ API int stc_plugin_monitor_init(void) return STC_ERROR_UNINITIALIZED; } - stc_plugin->initialize_plugin(); + stc_plugin->initialize_plugin(stop_cb); stc_plugin_enabled = TRUE; __STC_LOG_FUNC_EXIT__; diff --git a/src/stc-manager.c b/src/stc-manager.c index a376e7f..0011c97 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -38,6 +38,7 @@ #define BUF_SIZE_FOR_ERR 100 static stc_s *g_stc = NULL; +static gboolean g_is_fail_exit = FALSE; static gboolean __validate_ident(const char *ident) { @@ -100,6 +101,15 @@ static void __stc_manager_deinit(void) __STC_LOG_FUNC_EXIT__; } +void __stc_manager_stop_with_fail(void) +{ + STC_LOGI("plugin needs stc-manager to exit"); + + g_is_fail_exit = TRUE; + + stc_stop_manager(); +} + static stc_s *__stc_manager_init(void) { __STC_LOG_FUNC_ENTER__; @@ -134,7 +144,7 @@ static stc_s *__stc_manager_init(void) stc_plugin_tether_init(); if (stc_plugin_pcap_init() == STC_ERROR_NONE) g_stc->ondemand_mode = FALSE; - if (stc_plugin_monitor_init() == STC_ERROR_NONE) + if (stc_plugin_monitor_init(__stc_manager_stop_with_fail) == STC_ERROR_NONE) g_stc->ondemand_mode = FALSE; stc_plugin_firewall_init(); @@ -265,6 +275,9 @@ gint32 main(gint32 argc, gchar *argv[]) if (!g_stc) goto fail; + if (g_is_fail_exit == TRUE) + goto fail; + /* Crate the GLIB main loop */ main_loop = g_main_loop_new(NULL, FALSE); g_stc->main_loop = main_loop; @@ -283,5 +296,8 @@ fail: if (main_loop) g_main_loop_unref(main_loop); + if (g_is_fail_exit == TRUE) + exit(-1); + return 0; } -- 2.7.4