// hunt down and kill processes that have files open on the given mount point void Process::killProcessesWithOpenFiles(const char *path, int action) { DIR* dir; struct dirent* de; if (!(dir = opendir("/proc"))) { SLOGE("opendir failed (%s)", strerror(errno)); return; } LOGE("(%s) (%d)", path, action); while ((de = readdir(dir))) { int killed = 0; int pid = getPid(de->d_name); char name[PATH_MAX]; if (pid == -1) continue; getProcessName(pid, name, sizeof(name)); char openfile[PATH_MAX]; if (checkFileDescriptorSymLinks(pid, path, openfile, sizeof(openfile))) { LOGE("Process %s (%d) has open file %s", name, pid, openfile); killed = 1; } else if (checkFileMaps(pid, path, openfile, sizeof(openfile))) { LOGE("Process %s (%d) has open filemap for %s", name, pid, openfile); killed = 1; } else if (checkSymLink(pid, path, "cwd")) { LOGE("Process %s (%d) has cwd within %s", name, pid, path); killed = 1; } else if (checkSymLink(pid, path, "root")) { LOGE("Process %s (%d) has chroot within %s", name, pid, path); killed = 1; } else if (checkSymLink(pid, path, "exe")) { LOGE("Process %s (%d) has executable path within %s", name, pid, path); } else { // continue; } #if 1 if( (!strcmp("android.process.media", name) && (strcmp("/mnt/extsd", path)) ) || killed == 1) { if (action == 1) { LOGE("Sending SIGHUP to process %d", pid); kill(pid, SIGTERM); } else if (action == 2) { LOGE("Sending SIGKILL to process %d", pid); kill(pid, SIGKILL); } } #else if (action == 1) { SLOGE("Sending SIGHUP to process %d", pid); kill(pid, SIGTERM); } else if (action == 2) { SLOGE("Sending SIGKILL to process %d", pid); kill(pid, SIGKILL); } #endif } closedir(dir); }
// hunt down and kill processes that have files open on the given mount point void killProcessesWithOpenFiles(const char *path, int action) { DIR *dir; struct dirent *de; if (!(dir = opendir("/proc"))) { SLOGE("opendir failed (%s)", strerror(errno)); return; } while ((de = readdir(dir))) { int pid = getPid(de->d_name); char name[PATH_MAX]; if (pid == -1) continue; getProcessName(pid, name, sizeof(name)); char openfile[PATH_MAX]; if (checkfileDescriptorSymLinks (pid, path, openfile, sizeof(openfile))) { SLOGE("Process %s (%d) has open file %s", name, pid, openfile); } else if (checkfileMaps(pid, path, openfile, sizeof(openfile))) { SLOGE("Process %s (%d) has open filemap for %s", name, pid, openfile); } else if (checkSymLink(pid, path, "cwd")) { SLOGE("Process %s (%d) has cwd within %s", name, pid, path); } else if (checkSymLink(pid, path, "root")) { SLOGE("Process %s (%d) has chroot within %s", name, pid, path); } else if (checkSymLink(pid, path, "exe")) { SLOGE("Process %s (%d) has executable path within %s", name, pid, path); } else { continue; } if (action == 1) { SLOGW("Sending SIGHUP to process %d", pid); kill(pid, SIGTERM); } else if (action == 2) { SLOGE("Sending SIGKILL to process %d", pid); kill(pid, SIGKILL); } } closedir(dir); }