*/
#include <signal.h>
+#include <errno.h>
+#include <sys/wait.h>
#include "stc-manager.h"
#include "stc-emulator.h"
#include "stc-manager-gdbus.h"
#include "helper-cgroup.h"
#include "helper-nfacct-rule.h"
#include "helper-iptables.h"
+#include "helper-inotify.h"
#include "stc-monitor.h"
-#include "stc-manager-plugin.h"
-#include "stc-app-lifecycle.h"
+#include "stc-firewall.h"
+#include "stc-manager-plugin-appstatus.h"
+#include "stc-manager-plugin-exception.h"
+#include "stc-manager-plugin-procfs.h"
+
+#define BUF_SIZE_FOR_ERR 100
static stc_s *g_stc = NULL;
-/*
static gboolean __validate_ident(const char *ident)
{
unsigned int i;
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)
{
iptables_flush_chains();
iptables_deinit();
+
stc_manager_gdbus_deinit((gpointer)g_stc);
- stc_app_lifecycle_monitor_deinit();
- stc_manager_plugin_deinit();
+
+ stc_firewall_deinit();
+
+ stc_plugin_appstatus_deinit();
+ stc_plugin_exception_deinit();
+ stc_plugin_procfs_deinit();
+
+ inotify_deregister(INFO_STORAGE_DIR);
+ inotify_deinitialize();
STC_LOGI("stc manager deinitialized");
FREE(g_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());
- stc_manager_plugin_init();
+
+ stc_plugin_appstatus_init();
+ stc_plugin_exception_init();
+ stc_plugin_procfs_init();
+
+ stc_firewall_init();
err = stc_monitor_init();
if (err != STC_ERROR_NONE)
goto handle_error;
- stc_app_lifecycle_monitor_init();
+ stc_plugin_procfs_load_pid();
stc_manager_gdbus_init((gpointer)stc);
STC_LOGI("stc manager initialized");
g_main_loop_quit(g_stc->main_loop);
}
+int stc_commit_iptables(char *cmd, int *err_num, char **err_str)
+{
+ pid_t pid = 0;
+ int status = 0;
+ int ret = 0;
+ char err_buf[BUF_SIZE_FOR_ERR] = { 0, };
+ gchar **args = NULL;
+
+ if (cmd == NULL) {
+ STC_LOGE("Invalid arguments");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ args = g_strsplit_set(cmd, " ", -1);
+
+ errno = 0;
+ pid = fork();
+
+ if (pid == 0) {
+ errno = 0;
+ if (execv(args[0], args) == -1) {
+ STC_LOGE("Failed to execute [%s]", *err_str);
+ g_strfreev(args);
+ exit(-1);
+ }
+ } else if (pid > 0) {
+ if (waitpid(pid, &status, 0) == -1)
+ STC_LOGD("wait pid [%u] status [%d] ", pid, status);
+
+ if (WIFEXITED(status)) {
+ ret = WEXITSTATUS(status);
+ STC_LOGD("exited, status [%d]", status);
+ } else if (WIFSIGNALED(status)) {
+ STC_LOGD("killed by signal [%d]", WTERMSIG(status));
+ } else if (WIFSTOPPED(status)) {
+ STC_LOGD("stopped by signal [%d]", WSTOPSIG(status));
+ } else if (WIFCONTINUED(status)) {
+ STC_LOGD("continued");
+ }
+
+ *err_num = ret;
+ *err_str = strerror_r(ret, err_buf, BUF_SIZE_FOR_ERR);
+ STC_LOGD("return err_num [%d] err_str [%s]", *err_num, *err_str);
+
+ g_strfreev(args);
+ if (ret == 0)
+ return STC_ERROR_NONE;
+ else
+ return STC_ERROR_FAIL;
+ }
+
+ *err_num = errno;
+ *err_str = strerror_r(errno, err_buf, BUF_SIZE_FOR_ERR);
+ STC_LOGD("Failed to fork [%d:%s]", *err_num, *err_str);
+
+ g_strfreev(args);
+ return STC_ERROR_FAIL;
+}
+
gint32 main(gint32 argc, gchar *argv[])
{
GMainLoop *main_loop = NULL;