#include "helper-nl.h"
#include "helper-nfacct-rule.h"
#include "helper-net-cls.h"
+#include "helper-cgroup.h"
#include "counter.h"
#include "table-statistics.h"
#include "table-counters.h"
return FALSE;
}
+#if 0
static void __apps_tree_printall(void)
{
g_tree_foreach(g_system->apps, __apps_tree_foreach_print, NULL);
}
+#endif
static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value,
gpointer data)
value.rst_state = info->rst_state;
value.restriction_id = info->restriction_id;
- if (value.rst_state != STC_RESTRICTION_EXCLUDED)
- value.classid = get_classid_by_app_id(info->app_id ?
- info->app_id :
- STC_ALL_APP, TRUE);
+ if (value.rst_state != STC_RESTRICTION_EXCLUDED && info->app_id)
+ value.classid = get_classid_by_app_id(info->app_id, TRUE);
else
value.classid = STC_UNKNOWN_CLASSID;
app_id);
}
-/* used only for (STC_ALL_APP/STC_BACKGROUND_APP_NAME) */
-static void __stc_monitor_add_application_by_app_id(const char *app_id)
-{
- stc_app_key_s app_key;
- stc_app_value_s app_value;
-
- if (app_id == NULL)
- return;
-
- memset(&app_key, 0, sizeof(stc_app_key_s));
- memset(&app_value, 0, sizeof(stc_app_value_s));
-
- app_key.pkg_id = g_strdup(app_id);
- app_key.app_id = g_strdup(app_id);
-
- app_value.type = STC_APP_TYPE_NONE;
- app_value.processes = NULL;
- app_value.counter.in_bytes = 0;
- app_value.counter.out_bytes = 0;
-
- stc_monitor_application_add(app_key, app_value);
-
- FREE(app_key.pkg_id);
- FREE(app_key.app_id);
-
- __apps_tree_printall();
-}
-
stc_error_e stc_monitor_init(void)
{
stc_system_s *system = MALLOC0(stc_system_s, 1);
ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY, "stc_system_s malloc fail!");
+ /* initializing cgroups */
+ cgroup_init();
+
/* creating monitored application tree */
system->apps = g_tree_new_full(__apps_tree_key_compare, NULL,
__apps_tree_key_free,
g_system = system;
- /* create entry for STC_ALL_APP */
- __stc_monitor_add_application_by_app_id(STC_ALL_APP);
-
- /* create entry for STC_BACKGROUND_APP_NAME */
- __stc_monitor_add_application_by_app_id(STC_BACKGROUND_APP_NAME);
-
- /* create background cgroup */
- g_system->background_pids = NULL;
- create_net_background_cgroup(g_system->background_pids);
-
/* creating restriction rules tree */
__update_contr_cb(NULL);
g_system->contr_timer_id = 0;
}
- /* free background pid list */
- g_slist_free(g_system->background_pids);
- g_system->background_pids = NULL;
-
/* destroy monitored application tree */
g_tree_destroy(g_system->apps);
g_system->apps = NULL;
/* add pid to application cgroup */
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
- /* add pid to background cgroup if gound state is background */
- if (proc_value.ground == STC_APP_STATE_BACKGROUND)
- add_pid_to_background_cgroup(proc_key.pid);
-
return ret;
}
ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
- /* remove pid from background cgroup */
- remove_pid_from_background_cgroup(pid);
-
g_tree_foreach(g_system->apps, __apps_tree_foreach_remove_pid,
&context);
if (proc_lookup->ground != ground)
proc_lookup->ground = ground;
- if (ground == STC_APP_STATE_BACKGROUND)
- add_pid_to_background_cgroup(proc_key.pid);
- else
+ if (ground == STC_APP_STATE_BACKGROUND) {
+ char *background_app_id = g_strconcat(app_key.app_id,
+ STC_BACKGROUND_APP_SUFFIX,
+ NULL);
+ place_pids_to_net_cgroup(proc_key.pid, background_app_id);
+ g_free(background_app_id);
+ } else {
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
+ }
return ret;
}
value.rst_state = info->rst_state;
value.restriction_id = info->restriction_id;
- if (value.rst_state != STC_RESTRICTION_EXCLUDED)
- value.classid = get_classid_by_app_id(info->app_id ?
- info->app_id :
- STC_ALL_APP, TRUE);
+ if (value.rst_state != STC_RESTRICTION_EXCLUDED && info->app_id)
+ value.classid = get_classid_by_app_id(info->app_id, TRUE);
else
value.classid = STC_UNKNOWN_CLASSID;