[Add] tether plugin
[platform/core/connectivity/stc-manager.git] / src / stc-manager.c
old mode 100755 (executable)
new mode 100644 (file)
index 00854ea..58f6531
@@ -18,7 +18,6 @@
 #include <errno.h>
 #include <sys/wait.h>
 #include "stc-manager.h"
-#include "stc-emulator.h"
 #include "stc-manager-gdbus.h"
 #include "stc-db.h"
 #include "counter.h"
 #include "helper-cgroup.h"
 #include "helper-nfacct-rule.h"
 #include "helper-iptables.h"
+#include "helper-inotify.h"
 #include "stc-monitor.h"
 #include "stc-firewall.h"
 #include "stc-manager-plugin-appstatus.h"
 #include "stc-manager-plugin-exception.h"
 #include "stc-manager-plugin-procfs.h"
+#include "stc-manager-plugin-tether.h"
 
 #define BUF_SIZE_FOR_ERR 100
 
 static stc_s *g_stc = NULL;
 
-/*
 static gboolean __validate_ident(const char *ident)
 {
        unsigned int i;
@@ -50,7 +50,22 @@ static gboolean __validate_ident(const char *ident)
 
        return TRUE;
 }
-*/
+
+static void __stc_inotify_handler(struct inotify_event *event, const char *ident)
+{
+       if (!ident)
+               return;
+
+       if (!__validate_ident(ident)) {
+               STC_LOGE("Invalid ident [%s]", ident);
+               return;
+       }
+
+       if (!g_strcmp0(ident, INFO_CONFIG)) {
+               int debug = stc_util_get_config_int(INFO_DEBUGLOG);
+               stc_util_set_debuglog(debug);
+       }
+}
 
 static void __stc_manager_deinit(void)
 {
@@ -75,6 +90,10 @@ static void __stc_manager_deinit(void)
        stc_plugin_appstatus_deinit();
        stc_plugin_exception_deinit();
        stc_plugin_procfs_deinit();
+       stc_plugin_tether_deinit();
+
+       inotify_deregister(INFO_STORAGE_DIR);
+       inotify_deinitialize();
 
        STC_LOGI("stc manager deinitialized");
        FREE(g_stc);
@@ -96,6 +115,9 @@ static stc_s *__stc_manager_init(void)
 
        stc_util_initialize_config();
 
+       inotify_initialize();
+       inotify_register(INFO_STORAGE_DIR, __stc_inotify_handler);
+
        cgroup_set_release_agent(NET_CLS_SUBSYS, NET_RELEASE_AGENT);
 
        EXEC(STC_ERROR_NONE, stc_db_initialize());
@@ -103,6 +125,7 @@ static stc_s *__stc_manager_init(void)
        stc_plugin_appstatus_init();
        stc_plugin_exception_init();
        stc_plugin_procfs_init();
+       stc_plugin_tether_init();
 
        stc_firewall_init();
 
@@ -155,7 +178,7 @@ int stc_commit_iptables(char *cmd, int *err_num, char **err_str)
        if (pid == 0) {
                errno = 0;
                if (execv(args[0], args) == -1) {
-                       STC_LOGE("Failed to execute [%s]", err_str);
+                       STC_LOGE("Failed to execute [%s]", *err_str);
                        g_strfreev(args);
                        exit(-1);
                }
@@ -215,13 +238,11 @@ gint32 main(gint32 argc, gchar *argv[])
        /* Crate the GLIB main loop */
        main_loop = g_main_loop_new(NULL, FALSE);
 
-       stc_emulator_check_environment();
-       if (stc_emulator_is_emulated() == FALSE) {
-               g_stc = __stc_manager_init();
-               if (!g_stc)
-                       goto fail;
-               g_stc->main_loop = main_loop;
-       }
+       g_stc = __stc_manager_init();
+       if (!g_stc)
+               goto fail;
+
+       g_stc->main_loop = main_loop;
 
        /* Run the main loop */
        g_main_loop_run(main_loop);
@@ -229,8 +250,7 @@ gint32 main(gint32 argc, gchar *argv[])
        ret = 0;
 
 fail:
-       if (stc_emulator_is_emulated() == FALSE)
-               __stc_manager_deinit();
+       __stc_manager_deinit();
 
        if (main_loop)
                g_main_loop_unref(main_loop);