wlan.sh:script
wpa_supp.sh:script
stc-manager:sys
+stc-iptables:sys
dlogutil:sys
wifi-loader:sys
wrt-loader:sys
typedef struct {
GMainLoop *main_loop;
+ guint timer;
+ gboolean keep_alive;
+ gboolean ondemand_mode;
gpointer statistics_obj;
gpointer restriction_obj;
stc_s *stc_get_manager(void);
void stc_stop_manager(void);
int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
+void stc_set_keep_alive(gboolean keep_alive);
#endif /* __STC_MANAGER__ */
mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
cp resources/dbus/stc-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/stc-manager.conf
+mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services/
+cp resources/dbus/net.stc-manager.service %{buildroot}%{_datadir}/dbus-1/system-services/net.stc-manager.service
+
%files
%manifest %{name}.manifest
%license LICENSE
#DBus DAC
%attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/*
+%attr(644,root,root) %{_datadir}/dbus-1/system-services/*
%if %{?enable_database} == YES
%config(noreplace) %attr(660, root, root) %{database_full_path}
--- /dev/null
+[D-BUS Service]
+Name=net.stc
+Exec=/bin/false
+User=root
+SystemdService=stc-manager.service
After=dbus.socket
[Service]
-Type=forking
+Type=dbus
+BusName=net.stc
SmackProcessLabel=System
ExecStart=/usr/bin/stc-manager
-Restart=always
[Install]
WantedBy=multi-user.target
{
__STC_LOG_FUNC_ENTER__;
+ stc_set_keep_alive(TRUE);
+
stc_plugin_firewall_lock();
STC_DBUS_REPLY_ERROR_NONE(invocation);
{
__STC_LOG_FUNC_ENTER__;
+ stc_set_keep_alive(TRUE);
+
stc_plugin_firewall_unlock();
STC_DBUS_REPLY_ERROR_NONE(invocation);
GVariant *return_parameters = NULL;
int state = 0;
+ stc_set_keep_alive(TRUE);
+
stc_plugin_firewall_get_lock(&state);
return_parameters = g_variant_new("(i)", state);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
if (chain == NULL) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
if (chain == NULL) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
if (chain == NULL) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
GVariantBuilder *builder = NULL;
GVariant *return_parameters = NULL;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
stc_plugin_firewall_get_all_chain(builder);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
if (chain == NULL ||
target >= STC_FW_CHAIN_TARGET_MAX) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
if (chain == NULL) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
ret = stc_plugin_firewall_add_rule(parameters);
if (ret != STC_ERROR_NONE) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
ret = stc_plugin_firewall_remove_rule(parameters);
if (ret != STC_ERROR_NONE) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
__STC_LOG_FUNC_ENTER__;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
ret = stc_plugin_firewall_update_rule(parameters);
if (ret != STC_ERROR_NONE) {
STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
GVariantBuilder *builder = NULL;
GVariant *return_parameters = NULL;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
stc_plugin_firewall_get_all_rule(builder);
__STC_LOG_FUNC_ENTER__;
GVariant *return_parameters = NULL;
+ stc_set_keep_alive(TRUE);
+
STC_LOGI("stc manager stop");
return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
char *err_str = NULL;
char cmd[STC_CMD_SIZE] = { 0, };
+ stc_set_keep_alive(TRUE);
+
if (option == NULL) {
STC_MANAGER_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
char *err_str = NULL;
char cmd[STC_CMD_SIZE] = { 0, };
+ stc_set_keep_alive(TRUE);
+
if (option == NULL) {
STC_MANAGER_DBUS_REPLY_ERROR(invocation,
STC_ERROR_INVALID_PARAMETER);
return NULL; //LCOV_EXCL_LINE
}
+ g_stc->ondemand_mode = TRUE;
+
stc_plugin_appstatus_init();
stc_plugin_exception_init();
stc_plugin_procfs_init();
stc_plugin_tether_init();
- stc_plugin_pcap_init();
- stc_plugin_monitor_init();
+ if (stc_plugin_pcap_init() == STC_ERROR_NONE)
+ g_stc->ondemand_mode = FALSE;
+ if (stc_plugin_monitor_init() == STC_ERROR_NONE)
+ g_stc->ondemand_mode = FALSE;
stc_plugin_firewall_init();
stc_plugin_procfs_load_pid();
return stc;
}
+static gboolean __stc_timer_expired(gpointer data)
+{
+ if (g_stc->keep_alive) {
+ g_stc->keep_alive = FALSE;
+ return TRUE;
+ }
+
+ g_main_loop_quit(g_stc->main_loop);
+
+ return FALSE;
+}
+
API stc_s *stc_get_manager(void)
{
return g_stc;
return STC_ERROR_FAIL;
}
+void stc_set_keep_alive(gboolean keep_alive)
+{
+ g_stc->keep_alive = keep_alive;
+}
+
gint32 main(gint32 argc, gchar *argv[])
{
GMainLoop *main_loop = NULL;
- gint32 ret = -1;
STC_LOGI("Smart Traffic Control Manager");
setenv("GCOV_PREFIX", "/tmp/daemon", 1);
#endif
+/*
if (daemon(0, 0) != 0)
STC_LOGE("Can't start daemon"); //LCOV_EXCL_LINE
+*/
/* Initialize required subsystems */
#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
#endif
- /* Crate the GLIB main loop */
- main_loop = g_main_loop_new(NULL, FALSE);
-
g_stc = __stc_manager_init();
if (!g_stc)
goto fail;
+ /* Crate the GLIB main loop */
+ main_loop = g_main_loop_new(NULL, FALSE);
g_stc->main_loop = main_loop;
+ if (g_stc->ondemand_mode) {
+ g_stc->timer = g_timeout_add_seconds(10, __stc_timer_expired, NULL);
+ g_stc->keep_alive = FALSE;
+ }
+
/* Run the main loop */
g_main_loop_run(main_loop);
- ret = 0;
-
fail:
__stc_manager_deinit();
if (main_loop)
g_main_loop_unref(main_loop);
- return ret;
+ return 0;
}
stc_pcap_s pcap;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
memset(&pcap, 0, sizeof(stc_pcap_s));
g_variant_get(parameters, "a{sv}", &iter);
stc_pcap_s pcap;
int ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
memset(&pcap, 0, sizeof(stc_pcap_s));
g_variant_get(parameters, "a{sv}", &iter);
GVariantBuilder *builder = NULL;
GVariant *return_parameters = NULL;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
stc_plugin_pcap_get_all_loop(builder);
GVariantBuilder *builder = NULL;
GVariant *return_parameters = NULL;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
stc_plugin_pcap_find_all_devs(builder);
table_restrictions_info rule;
stc_error_e ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
memset(&rule, 0, sizeof(table_restrictions_info));
__initialize_rstn_rule(&rule);
table_restrictions_info rule;
stc_error_e ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
memset(&rule, 0, sizeof(table_restrictions_info));
__initialize_rstn_rule(&rule);
GVariantIter *iter_row = NULL;
stc_error_e ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
g_variant_get(parameters, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
table_restrictions_info rule;
GVariantIter *iter_row = NULL;
stc_error_e ret = STC_ERROR_NONE;
+ stc_set_keep_alive(TRUE);
+
g_variant_get(parameters, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
table_restrictions_info rule;
GVariant *return_parameters = NULL;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
ret = table_restrictions_per_app(app_id,
GVariant *return_parameters = NULL;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
ret = table_restrictions_foreach(__table_restrictions_foreach_app_cb,
stc_rstn_type_e type = STC_RSTN_TYPE_UNKNOWN;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
ret = table_restrictions_get_restriction_type(app_id, iftype, &type);
if (ret < STC_ERROR_NONE) {
STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
GVariant *return_parameters = NULL;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
/* Total statistics since epoch */
rule.from = epoch;
rule.to = cur_time;
{
__STC_LOG_FUNC_ENTER__;
+ stc_set_keep_alive(TRUE);
+
STC_LOGI("stc statistics initialized");
stc_statistics_complete_init(object, invocation);
GVariant *return_parameters = NULL;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
/* Total statistics since epoch */
rule.from = epoch;
rule.to = cur_time;
GVariant *return_parameters = NULL;
stc_error_e ret;
+ stc_set_keep_alive(TRUE);
+
if (reset_rule != NULL) {
DEBUG_GDBUS_VARIANT("Selection rule: ", reset_rule);
GVariantIter *iter = NULL;