Separate monitoring function plugin
[platform/core/connectivity/stc-manager.git] / src / helper / helper-cgroup.c
index 8c258a5..1d5ba2b 100755 (executable)
@@ -34,7 +34,7 @@ static int cgroup_create(const char *cgroup_full_path)
 {
        if (mkdir(cgroup_full_path,
                  S_IRUSR | S_IWUSR | S_IRGRP) < 0)
-               return -errno;
+               return -errno; //LCOV_EXCL_LINE
 
        return 0;
 }
@@ -49,8 +49,8 @@ stc_error_e cgroup_write_pid_fullpath(const char *cgroup_full_path,
        int ret;
 
        if (pid <= 0) {
-               STC_LOGE("try to write empty pid to %s", cgroup_full_path);
-               return STC_ERROR_NO_DATA;
+               STC_LOGE("try to write empty pid to %s", cgroup_full_path); //LCOV_EXCL_LINE
+               return STC_ERROR_NO_DATA; //LCOV_EXCL_LINE
        }
 
        ret = cgroup_write_node_uint32(cgroup_full_path, CGROUP_FILE_NAME,
@@ -69,13 +69,14 @@ stc_error_e cgroup_write_pid(const char *cgroup_subsystem,
        return cgroup_write_pid_fullpath(buf, pid);
 }
 
+//LCOV_EXCL_START
 stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
                                 const char *cgroup_name, const int pid)
 {
        char buf[MAX_PATH_LENGTH];
 
        /*/proc/%d/task/%d/children */
-       char child_buf[21 + MAX_DEC_SIZE(int) + MAX_DEC_SIZE(int)];
+       char child_buf[21 + MAX_DEC_SIZE(int) + MAX_DEC_SIZE(int) + 1];
        char pidbuf[MAX_DEC_SIZE(int)];
        stc_error_e ret;
 
@@ -110,6 +111,7 @@ stc_error_e cgroup_write_pidtree(const char *cgroup_subsystem,
        fclose(f);
        return STC_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int cgroup_write_node_uint32(const char *cgroup_name,
                             const char *file_name, uint32_t value)
@@ -117,8 +119,8 @@ int cgroup_write_node_uint32(const char *cgroup_name,
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
 
-       if (STC_DEBUG_LOG)
-               STC_LOGD("cgroup_buf %s, value %d\n", buf, value);
+       if (STC_STAT_LOG)
+               STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE
 
        return fwrite_uint(buf, value);
 }
@@ -129,8 +131,8 @@ int cgroup_write_node_str(const char *cgroup_name,
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
 
-       if (STC_DEBUG_LOG)
-               STC_LOGD("cgroup_buf %s, string %s\n", buf, string);
+       if (STC_STAT_LOG)
+               STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE
 
        return fwrite_str(buf, string);
 }
@@ -143,8 +145,8 @@ int cgroup_read_node_uint32(const char *cgroup_name,
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
        ret = fread_uint(buf, value);
 
-       if (STC_DEBUG_LOG)
-               STC_LOGD("cgroup_buf %s, value %d\n", buf, *value);
+       if (STC_STAT_LOG)
+               STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE
 
        return ret;
 }
@@ -173,12 +175,12 @@ int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
 
                if (parentdir && !strncmp(parentdir, DEFAULT_CGROUP,
                                          sizeof(DEFAULT_CGROUP))) {
-                       ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs",
+                       ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs", //LCOV_EXCL_LINE
                                    MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME,
                                    "mode=755");
                        if (ret < 0) {
-                               STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name);
-                               return STC_ERROR_FAIL;
+                               STC_LOGE("Fail to RW mount cgroup directory. Can't make %s cgroup", cgroup_name); //LCOV_EXCL_LINE
+                               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
                        }
                        cgroup_remount = true;
                }
@@ -189,11 +191,11 @@ int cgroup_make_subdir(const char *parentdir, const char *cgroup_name,
                                 cgroup_name, errno);
 
                if (cgroup_remount) {
-                       ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs",
+                       ret = mount("tmpfs", DEFAULT_CGROUP, "tmpfs",  //LCOV_EXCL_LINE
                                    MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME|MS_RDONLY,
                                    "mode=755");
                        if (ret < 0)
-                               STC_LOGD("Fail to RO mount");
+                               STC_LOGD("Fail to RO mount"); //LCOV_EXCL_LINE
                }
        }
 
@@ -220,7 +222,7 @@ int cgroup_set_release_agent(const char *cgroup_subsys,
        return cgroup_write_node_str(buf, NOTIFY_ON_RELEASE, "1");
 }
 
-void cgroup_init(void)
+API void cgroup_init(void)
 {
        /* create stc cgroup directory */
        cgroup_make_subdir(CGROUP_NETWORK, STC_CGROUP_NAME, NULL);
@@ -229,10 +231,11 @@ void cgroup_init(void)
        cgroup_make_subdir(STC_CGROUP_NETWORK, STC_BACKGROUND_CGROUP_NAME,
                           NULL);
 
-       cgroup_write_node_uint32(BACKGROUND_CGROUP_NETWORK,
-               CLASSID_FILE_NAME, STC_BACKGROUND_APP_CLASSID);
-
        /* create foreground cgroup directory */
        cgroup_make_subdir(STC_CGROUP_NETWORK, STC_FOREGROUND_CGROUP_NAME,
                           NULL);
+
+       /* create tethering cgroup directory */
+       cgroup_make_subdir(STC_CGROUP_NETWORK, STC_TETHERING_CGROUP_NAME,
+                          NULL);
 }