}
lookup = g_tree_lookup(proc_tree, key);
- if (lookup) {
- if (STC_DEBUG_LOG)
- STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] "
- "cmdline[\033[0;34m%s\033[0;m] name[%s]", lookup->status[PROC_STATUS_TGID],
- lookup->status[PROC_STATUS_PID], lookup->status[PROC_STATUS_PPID],
- lookup->cmdline, lookup->status[PROC_STATUS_NAME]);
+ if (lookup)
return;
- }
proc_key_s *proc_key = MALLOC0(proc_key_s, 1);
if (proc_key == NULL) {
memcpy(proc_key, key, sizeof(proc_key_s));
memcpy(proc_value, value, sizeof(proc_value_s));
- if (STC_DEBUG_LOG)
- STC_LOGD("cmdline [%s] pid[%s] ppid[%s]", value->cmdline,
- value->status[PROC_STATUS_PID], value->status[PROC_STATUS_PPID]);
-
g_tree_insert(proc_tree, proc_key, proc_value);
/*
g_strlcpy(value.status[i], status[i], sizeof(value.status[i]));
g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
- if (STC_DEBUG_LOG) {
+ if (STC_DEBUG_LOG)
STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
"cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
- STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
- status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
- status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
- }
__proc_tree_add(&key, &value);
}
sizeof(value.status[i]));
g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
- if (STC_DEBUG_LOG) {
+ if (STC_DEBUG_LOG)
STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
"cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
- STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
- status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
- status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
- }
__proc_tree_add(&key, &value);
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glib.h>
+
+#include "helper-inotify.h"
+#include "stc-manager-util.h"
+
+typedef struct {
+ GIOChannel *channel;
+ uint watch;
+ int wd;
+
+ inotify_event_cb cb;
+} stc_inotify_s;
+
+static GHashTable *g_inotify_hash;
+
+static void __inotify_destroy(gpointer user_data)
+{
+ int fd;
+ stc_inotify_s *inotify = user_data;
+
+ if (!inotify->channel)
+ return;
+
+ if (inotify->watch > 0)
+ g_source_remove(inotify->watch);
+
+ if (inotify->wd >= 0) {
+ fd = g_io_channel_unix_get_fd(inotify->channel);
+ inotify_rm_watch(fd, inotify->wd);
+ }
+
+ g_io_channel_unref(inotify->channel);
+}
+
+static gboolean __inotify_data(GIOChannel *channel,
+ GIOCondition cond, gpointer user_data)
+{
+ stc_inotify_s *inotify = user_data;
+ char buf[256];
+ char *next_event = buf;
+ gsize bytes_read;
+ GIOStatus status;
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+ inotify->watch = 0;
+ return false;
+ }
+
+ status = g_io_channel_read_chars(channel, buf,
+ sizeof(buf), &bytes_read, NULL);
+ if (status != G_IO_STATUS_NORMAL) {
+ if (status == G_IO_STATUS_AGAIN)
+ return true;
+ else {
+ STC_LOGE("Failed to read from inotify channel");
+ inotify->watch = 0;
+ return false;
+ }
+ }
+
+ while (bytes_read > 0) {
+ struct inotify_event *event = next_event;
+ gchar *ident = NULL;
+ gsize len = 0;
+
+ len = sizeof(*event) + event->len;
+ if (bytes_read < len)
+ break;
+
+ if (event->len)
+ ident = next_event + sizeof(*event);
+
+ next_event += len;
+ bytes_read -= len;
+
+ (inotify->cb)(event, ident);
+ }
+
+ return true;
+}
+
+int inotify_register(const char *path, inotify_event_cb cb)
+{
+ int fd;
+ stc_inotify_s *inotify;
+
+ if (!cb)
+ return -EINVAL;
+
+ inotify = g_hash_table_lookup(g_inotify_hash, path);
+ if (inotify) {
+ inotify->cb = cb;
+ return 0;
+ }
+
+ inotify = g_try_new0(stc_inotify_s, 1);
+ if (!inotify)
+ return -ENOMEM;
+
+ fd = inotify_init();
+ if (fd < 0) {
+ FREE(inotify);
+ return -EIO;
+ }
+
+ inotify->wd = inotify_add_watch(fd, path, IN_MODIFY);
+ if (inotify->wd < 0) {
+ STC_LOGE("Failed to create watch [%s]", path);
+ FREE(inotify);
+ close(fd);
+ return -EIO;
+ }
+
+ inotify->channel = g_io_channel_unix_new(fd);
+ if (!inotify->channel) {
+ STC_LOGE("Failed to create channel");
+ inotify_rm_watch(fd, inotify->wd);
+ FREE(inotify);
+ close(fd);
+ return -EIO;
+ }
+
+ g_io_channel_set_close_on_unref(inotify->channel, TRUE);
+ g_io_channel_set_encoding(inotify->channel, NULL, NULL);
+ g_io_channel_set_buffered(inotify->channel, FALSE);
+
+ inotify->watch = g_io_add_watch(inotify->channel,
+ G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
+ __inotify_data, inotify);
+
+ inotify->cb = cb;
+
+ g_hash_table_insert(g_inotify_hash, g_strdup(path), inotify);
+ return 0;
+}
+
+void inotify_deregister(const char *path)
+{
+ stc_inotify_s *inotify;
+
+ inotify = g_hash_table_lookup(g_inotify_hash, path);
+ if (!inotify)
+ return;
+
+ g_hash_table_remove(g_inotify_hash, path);
+}
+
+int inotify_initialize(void)
+{
+ g_inotify_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, __inotify_destroy);
+
+ return 0;
+}
+
+void inotify_deinitialize(void)
+{
+ g_hash_table_destroy(g_inotify_hash);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_HELPER_INOTIFY_H__
+#define __STC_HELPER_INOTIFY_H__
+
+#include <sys/inotify.h>
+
+struct inotify_event;
+typedef void (* inotify_event_cb) (struct inotify_event *event, const char *ident);
+
+int inotify_register(const char *path, inotify_event_cb cb);
+void inotify_deregister(const char *path);
+
+int inotify_initialize(void);
+void inotify_deinitialize(void);
+
+#endif /*__STC_HELPER_INOTIFY_H__*/
else
path_to_net_cgroup_dir = FOREGROUND_CGROUP_NETWORK; //LCOV_EXCL_LINE
- if (access(child_buf, F_OK)) {
- if (STC_DEBUG_LOG)
- STC_LOGD("%s of %s is not existed", child_buf, app_id); //LCOV_EXCL_LINE
+ if (access(child_buf, F_OK))
return cgroup_write_pid(path_to_net_cgroup_dir, app_id, pid);
- }
return cgroup_write_pidtree(path_to_net_cgroup_dir, app_id, pid); //LCOV_EXCL_LINE
}
prepare_netlink_msg(req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
add_string_attr(req, counter->name, NFACCT_NAME);
- if (STC_DEBUG_LOG)
- STC_LOGD("counter name %s", counter->name); //LCOV_EXCL_LINE
-
/* padding */
add_uint64_attr(req, 0, NFACCT_PKTS);
add_uint64_attr(req, 0, NFACCT_BYTES);
return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
}
- if (STC_DEBUG_LOG)
- STC_LOGD("send remove request for %s", counter->name); //LCOV_EXCL_LINE
-
prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
add_string_attr(req, counter->name, NFACCT_NAME);
.data_limit_reached = FALSE,
};
- if (STC_DEBUG_LOG)
- STC_LOGD("cnt_name %s", cnt_name); //LCOV_EXCL_LINE
-
if (!recreate_counter_by_name(cnt_name, &counter)) {
STC_LOGE("Can't parse counter name %s", cnt_name); //LCOV_EXCL_LINE
return; //LCOV_EXCL_LINE
ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
lookup = __application_lookup(g_system->apps, &app_key);
- if (lookup) {
- if (STC_DEBUG_LOG)
- STC_LOGD("app_key already present"); //LCOV_EXCL_LINE
+ if (lookup)
return STC_ERROR_NONE; //LCOV_EXCL_LINE
- }
key = MALLOC0(stc_app_key_s, 1);
if (!key) {
}
proc_lookup = __process_lookup(app_lookup->processes, &proc_key);
- if (proc_lookup) {
- if (STC_DEBUG_LOG)
- STC_LOGD("proc_key already present"); //LCOV_EXCL_LINE
+ if (proc_lookup)
return STC_ERROR_NONE; //LCOV_EXCL_LINE
- }
key = MALLOC0(stc_process_key_s, 1);
if (!key) {
#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"
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)
{
stc_plugin_exception_deinit();
stc_plugin_procfs_deinit();
+ inotify_deregister(INFO_STORAGE_DIR);
+ inotify_deinitialize();
+
STC_LOGI("stc manager deinitialized");
FREE(g_stc);
__STC_LOG_FUNC_EXIT__;
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());