vold/ProcessKiller.c
void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded)
{
    DIR*    dir;
    struct dirent* de;

    LOG_ERROR("KillProcessesWithOpenFiles %s", mountPoint);
    dir = opendir("/proc");
    if (!dir) return;

    while ((de = readdir(dir)) != 0)
    {
        boolean killed = false;
        // does the name look like a process ID?
        int pid = get_pid(de->d_name);
        if (pid == -1) continue;

        if (CheckFileDescriptorSymLinks(pid, mountPoint)    // check for open files
                || CheckFileMaps(pid, mountPoint)           // check for mmap()
                || CheckSymLink(pid, mountPoint, "cwd", "working directory")    // check working directory
                || CheckSymLink(pid, mountPoint, "root", "chroot")              // check for chroot()
                || CheckSymLink(pid, mountPoint, "exe", "executable path")      // check executable path
            ) 
        {
            int i;
            boolean hit = false;

            for (i = 0; i < num_excluded; i++) {
                if (pid == excluded[i]) {
                    LOG_ERROR("I just need a little more TIME captain!");
                    hit = true;
                    break;
                }
            }

            if (!hit) {
                LOG_ERROR("Killing process %d", pid);
                kill(pid, (sigkill ? SIGKILL : SIGTERM));
            }
        }
    }

    closedir(dir);
}
// hunt down and kill processes that have files open on the given mount point
hunt down and kill processes that have files open on the given mount point
hunt down and kill processes that have files open on the given mount point
void KillProcessesWithOpenFiles(const char* mountPoint, boolean sigkill, int *excluded, int num_excluded)
{
    DIR*    dir;
    struct dirent* de;
    LOG_ERROR("KillProcessesWithOpenFiles %s", mountPoint);
    dir = opendir("/proc");
    if (!dir) return;
    while ((de = readdir(dir)) != 0)
    {
        boolean killed = false;
        int pid = get_pid(de->d_name);
        if (pid == -1) continue;
        if (CheckFileDescriptorSymLinks(pid, mountPoint)    
                || CheckFileMaps(pid, mountPoint)           
                || CheckSymLink(pid, mountPoint, "cwd", "working directory")    
                || CheckSymLink(pid, mountPoint, "root", "chroot")              
                || CheckSymLink(pid, mountPoint, "exe", "executable path")      
            ) 
        {
            int i;
            boolean hit = false;
            for (i = 0; i < num_excluded; i++) {
                if (pid == excluded[i]) {
                    LOG_ERROR("I just need a little more TIME captain!");
                    hit = true;
                    break;
                }
            }
            if (!hit) {
                LOG_ERROR("Killing process %d", pid);
                kill(pid, (sigkill ? SIGKILL : SIGTERM));
            }
        }
    }
    closedir(dir);
}
void KillProcessesWithOpenFiles ( const char * mountPoint , boolean sigkill , int * excluded , int num_excluded ) { DIR * dir ; struct dirent * de ; LOG_ERROR ( " " , mountPoint ) ; dir = opendir ( " " ) ; if ( ! dir ) return ; while ( ( de = readdir ( dir ) ) != 0 ) { boolean killed = false ; int pid = get_pid ( de -> d_name ) ; if ( pid == -1 ) continue ; if ( CheckFileDescriptorSymLinks ( pid , mountPoint ) || CheckFileMaps ( pid , mountPoint ) || CheckSymLink ( pid , mountPoint , " " , " " ) || CheckSymLink ( pid , mountPoint , " " , " " ) || CheckSymLink ( pid , mountPoint , " " , " " ) ) { int i ; boolean hit = false ; for ( i = 0 ; i < num_excluded ; i ++ ) { if ( pid == excluded [ i ] ) { LOG_ERROR ( " " ) ; hit = true ; break ; } } if ( ! hit ) { LOG_ERROR ( " " , pid ) ; kill ( pid , ( sigkill ? SIGKILL : SIGTERM ) ) ; } } } closedir ( dir ) ; }
hunt down and kill processes that have files open on the given mount point
hunt down and kill processes that have files open on the given mount point
// does the name look like a process ID? // check for open files // check for mmap() // check working directory // check for chroot() // check executable path