#include "log.h"
#include "common.h"
-#define PERMANENT_DIR "/tmp/permanent"
-#define VIP_DIR "/tmp/vip"
#define BUFF_MAX 255
#define APP_ATTR_PATH "/proc/%d/attr/current"
-/**
- * Opens "/proc/$pid/oom_score_adj" file for w/r;
- * Return: FILE pointer or NULL
- */
-FILE *open_proc_oom_score_adj_file(int pid, const char *mode)
-{
- char buf[32];
- FILE *fp;
-
- snprintf(buf, sizeof(buf), "/proc/%d/oom_score_adj", pid);
- fp = fopen(buf, mode);
- return fp;
-}
-
int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
{
int fd, ret;
return 0;
}
-int is_vip(int pid)
-{
- if (pid < 1)
- return -1;
-
- char buf[PATH_MAX];
-
- snprintf(buf, PATH_MAX, "%s/%d", VIP_DIR, pid);
-
- if (access(buf, R_OK) == 0)
- return 1;
- else
- return 0;
-}
-
int is_app(pid_t pid)
{
char attr[64];
thaw_processes_on_path(frz_name);
}
-void print_time(const char *prefix)
-{
- struct timeval tv;
- struct tm tm;
- struct tm *ret;
- gettimeofday(&tv, NULL);
- ret = localtime_r(&(tv.tv_sec), &tm);
- if (ret)
- _D("'%s' %d:%02d:%02d %06ld",
- prefix, tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec);
-}
-
int get_privilege(pid_t pid, char *name, size_t len)
{
char path[PATH_MAX];
return do_copy_internal(src, dst, 0644, true);
}
-
-#if 0
-int print_open_files(const char *mount_point)
-{
- DIR *dp;
- struct dirent entry;
- struct dirent *dentry;
-
- DIR *dp_child;
- struct dirent entry_child;
- struct dirent *dentry_child;
-
- int pid = -1, fd;
- int ret;
- char buf[PATH_MAX];
- char buf2[PATH_MAX];
-
- char cmdline[PATH_MAX];
- char check_path[PATH_MAX];
-
- int len = strlen(mount_point);
-
- dp = opendir("/proc");
- if (!dp) {
- _E("FAIL: open /proc");
- return -1;
- }
-
- while (1) {
- ret = readdir_r(dp, &entry, &dentry);
- if (ret != 0 || dentry == NULL)
- break;
-
- if (!isdigit(dentry->d_name[0]))
- continue;
-
- pid = atoi(dentry->d_name);
- snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
-
- fd = open(buf, O_RDONLY);
- if (fd < 0)
- continue;
- ret = read(fd, cmdline, PATH_MAX);
- close(fd);
-
- if (ret < 0 || ret >= PATH_MAX)
- continue;
- cmdline[ret] = '\0';
-
- snprintf(buf, PATH_MAX, "/proc/%d/fd", pid);
- dp_child = opendir(buf);
- if (!dp_child)
- continue;
- while (1) {
- ret = readdir_r(dp_child, &entry_child, &dentry_child);
- if (ret != 0 || dentry_child == NULL)
- break;
-
- snprintf(check_path, PATH_MAX, "%s/%s", buf, dentry_child->d_name);
-
- if (readlink(check_path, buf2, PATH_MAX) < 0)
- continue;
-
- if (strncmp(buf2, mount_point, len) == 0)
- _D("Process %s : Opened files - %s", cmdline, buf2);
- }
- closedir(dp_child);
- }
-
- closedir(dp);
- return 0;
-}
-
-int get_exec_pid(const char *execpath)
-{
- DIR *dp;
- struct dirent entry;
- struct dirent *dentry;
- int pid = -1, fd;
- int ret;
- int len;
- char buf[PATH_MAX];
- char buf2[PATH_MAX];
-
- dp = opendir("/proc");
- if (!dp) {
- _E("FAIL: open /proc");
- return -1;
- }
-
- len = strlen(execpath) + 1;
- while (1) {
- ret = readdir_r(dp, &entry, &dentry);
- if (ret != 0 || dentry == NULL)
- break;
-
- if (!isdigit(dentry->d_name[0]))
- continue;
-
- pid = atoi(dentry->d_name);
-
- snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
- fd = open(buf, O_RDONLY);
- if (fd < 0)
- continue;
- ret = read(fd, buf2, PATH_MAX);
- close(fd);
-
- if (ret < 0 || ret >= PATH_MAX)
- continue;
-
- buf2[ret] = '\0';
-
- if (!strncmp(buf2, execpath, len)) {
- closedir(dp);
- return pid;
- }
- }
-
- errno = ESRCH;
- closedir(dp);
- return -1;
-}
-
-static int get_num_thawed_processes(const char *path)
-{
- char *fuser_cmd = NULL;
- FILE *fuser_fp;
- char *line = NULL;
- size_t len = 0;
- int num_processes = 0;
- int ret;
-
- ret = asprintf(&fuser_cmd, "fuser -m %s | grep -o '[0-9]*'", path);
- if (ret < 0)
- return -1;
-
- fuser_fp = popen(fuser_cmd, "r");
- free(fuser_cmd);
- if (fuser_fp == NULL)
- return -1;
-
- while (getline(&line, &len, fuser_fp) != -1) {
- char *stat_cmd = NULL;
- FILE *stat_fp;
- int pid;
- char comm[128];
- char state = 0;
- int str_len;
- int ret;
-
- str_len = strlen(line);
- if (str_len > 0)
- // To remove '\n'
- *(line+str_len-1) = 0;
-
- ret = asprintf(&stat_cmd, "cat /proc/%s/stat", line);
- if (ret < 0) {
- num_processes++;
- continue;
- }
-
- stat_fp = popen(stat_cmd, "r");
- free(stat_cmd);
- if (stat_fp == NULL) {
- num_processes++;
- continue;
- }
-
- fscanf(stat_fp, "%d %128s %c", &pid, comm, &state);
- pclose(stat_fp);
-
- // if thawed
- if (state != 'D') num_processes++;
- }
-
- free(line);
- pclose(fuser_fp);
-
- return num_processes;
-}
-#endif
-