[Fix] Fetch proper app_id for creation of cgroup.
[platform/core/connectivity/stc-manager.git] / src / stc-manager.c
index cfee380..d6e8521 100755 (executable)
 #include "table-restrictions.h"
 #include "helper-cgroup.h"
 #include "helper-nfacct-rule.h"
+#include "helper-inotify.h"
 #include "stc-monitor.h"
 #include "stc-manager-plugin.h"
 #include "stc-app-lifecycle.h"
 
 static stc_s *g_stc = NULL;
 
+static gboolean __validate_ident(const char *ident)
+{
+       unsigned int i;
+
+       if (!ident)
+               return FALSE;
+
+       for (i = 0; i < strlen(ident); ++i)
+               if (!g_ascii_isprint(ident[i]))
+                       return FALSE;
+
+       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 (event->mask & IN_MODIFY) {
+               if (!g_strcmp0(ident, INFO_CONFIG)) {
+                       int debug = 0;
+                       debug = stc_util_get_config_int(INFO_DEBUGLOG);
+                       stc_util_set_debuglog(debug);
+               }
+       }
+}
+
 static void __stc_manager_deinit(void)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -46,6 +80,9 @@ static void __stc_manager_deinit(void)
        stc_app_lifecycle_monitor_deinit();
        stc_manager_plugin_deinit();
 
+       inotify_deregister(INFO_STORAGE_DIR);
+       inotify_deinitialize();
+
        STC_LOGI("stc manager deinitialized");
        FREE(g_stc);
        __STC_LOG_FUNC_EXIT__;
@@ -64,6 +101,11 @@ static stc_s *__stc_manager_init(void)
        }
        g_stc = stc;
 
+       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());