Refactoring structures for monitoring and restrictions
[platform/core/connectivity/stc-manager.git] / src / helper / helper-net-cls.c
index 238b7de..f9d59e6 100644 (file)
@@ -72,17 +72,20 @@ static int __place_classid_to_cgroup(const char *cgroup, const char *subdir,
        return cgroup_write_node_uint32(buf, CLASSID_FILE_NAME, result_classid);
 }
 
-static uint32_t __get_classid_from_cgroup(const char *cgroup,
-                                         const char *subdir)
+static stc_error_e __get_classid_from_cgroup(const char *cgroup,
+                                         const char *subdir, uint32_t *classid)
 {
        char buf[MAX_PATH_LENGTH];
-       uint32_t classid = STC_UNKNOWN_CLASSID;
        snprintf(buf, sizeof(buf), "%s/%s", cgroup, subdir);
 
-       int ret = cgroup_read_node_uint32(buf, CLASSID_FILE_NAME, &classid);
-       if (ret < 0)
+       int ret = cgroup_read_node_uint32(buf, CLASSID_FILE_NAME, classid);
+       if (ret < 0) {
                STC_LOGE("Can't read classid from cgroup %s", buf); //LCOV_EXCL_LINE
-       return classid;
+               *classid = STC_UNKNOWN_CLASSID;
+               return STC_ERROR_NO_DATA;
+       }
+
+       return STC_ERROR_NONE;
 }
 
 stc_error_e init_current_classid(void)
@@ -102,10 +105,10 @@ stc_error_e init_current_classid(void)
        return STC_ERROR_NONE;
 }
 
-uint32_t get_classid_by_app_id(const char *app_id, int create)
+API uint32_t get_classid_by_app_id(const char *app_id, int create)
 {
-       int ret = 0;
        bool exists;
+       int ret = STC_ERROR_NONE;
        uint32_t classid = STC_UNKNOWN_CLASSID;
        const char *path_to_net_cgroup_dir = NULL;
 
@@ -144,8 +147,11 @@ uint32_t get_classid_by_app_id(const char *app_id, int create)
 
        /* just read */
        if (!create)
-               classid = __get_classid_from_cgroup(path_to_net_cgroup_dir, //LCOV_EXCL_LINE
-                                                   app_id);
+               ret = __get_classid_from_cgroup(path_to_net_cgroup_dir, //LCOV_EXCL_LINE
+                                                       app_id, &classid);
+
+       if (ret != STC_ERROR_NONE)
+               return STC_UNKNOWN_CLASSID;
 
        if (classid != STC_UNKNOWN_CLASSID)
                return classid;
@@ -156,8 +162,8 @@ uint32_t get_classid_by_app_id(const char *app_id, int create)
                goto handle_error;
 
        if (exists)
-               classid = __get_classid_from_cgroup(path_to_net_cgroup_dir,
-                                                   app_id);
+               ret = __get_classid_from_cgroup(path_to_net_cgroup_dir,
+                                                   app_id, &classid);
        else
                ret = __place_classid_to_cgroup(path_to_net_cgroup_dir,
                                                (char *)app_id, &classid, NULL);