#define NOTIFY_ON_RELEASE "notify_on_release"
#define CGROUP_FILE_NAME "cgroup.procs"
-#define MAX_PATH_LENGTH 512
-
-static int read_uint(FILE *handler, uint32_t *out)
-{
- return fscanf(handler, "%u", out);
-}
-
-static int write_uint(FILE *handler, uint32_t number)
-{
- _cleanup_free_ char *digit_buf = NULL;
- int ret;
-
- ret = asprintf(&digit_buf, "%u\n", number);
- ret_value_errno_msg_if(ret < 0, -ENOMEM, "asprintf failed\n");
-
- ret = fputs(digit_buf, handler);
- ret_value_errno_msg_if(ret == EOF, errno ? -errno : -EIO,
- "Fail to write file");
+#define CLASSID_FILE_NAME "net_cls.classid"
- return 0;
-}
+#define MAX_PATH_LENGTH 512
static bool cgroup_is_exists(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;
}
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,
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;
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)
{
char buf[MAX_PATH_LENGTH];
snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
- STC_LOGD("cgroup_buf %s, value %d\n", buf, value);
+
+ if (STC_DEBUG_LOG)
+ STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE
+
return fwrite_uint(buf, value);
}
{
char buf[MAX_PATH_LENGTH];
snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
- STC_LOGD("cgroup_buf %s, string %s\n", buf, string);
+
+ if (STC_DEBUG_LOG)
+ STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE
+
return fwrite_str(buf, string);
}
int ret;
snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
ret = fread_uint(buf, value);
- STC_LOGD("cgroup_buf %s, value %d\n", buf, *value);
+
+ if (STC_DEBUG_LOG)
+ STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE
+
return ret;
}
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;
}
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
}
}
return STC_ERROR_NONE;
}
-/* FIXME: tasks is not removed from tasks list */
-int cgroup_remove_pid(const char *cgroup_subsystem, const char *cgroup_name,
- const int pid)
-{
- char cgroup_tasks_file_path[MAX_PATH_LENGTH];
- FILE *handler = 0;
- guint i = 0;
- pid_t pid_for_read = 0;
- GArray *pids = NULL;
- guint pid_count = 0;;
-
- snprintf(cgroup_tasks_file_path, sizeof(cgroup_tasks_file_path),
- "%s/%s/tasks", cgroup_subsystem, cgroup_name);
-
- handler = fopen(cgroup_tasks_file_path, "r");
- if (!handler) {
- STC_LOGE("Read file open failed");
- return -1;
- }
-
- pids = g_array_new(FALSE, FALSE, sizeof(pid_t));
-
- while (read_uint(handler, (uint32_t *)&pid_for_read) >= 0) {
- if (pid_for_read != pid) {
- pids = g_array_append_val(pids, pid_for_read);
- ++pid_count;
- }
- }
-
- fclose(handler);
-
- handler = fopen(cgroup_tasks_file_path, "w");
- if (!handler) {
- STC_LOGE("Write file open failed");
- return -1;
- }
-
- for (i = 0; i < pid_count; i++)
- write_uint(handler, g_array_index(pids, pid_t, i));
-
- fclose(handler);
- g_array_free(pids, TRUE);
- return 0;
-}
-
int cgroup_set_release_agent(const char *cgroup_subsys,
const char *release_agent)
{
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);
}