コード例 #1
0
// 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\n", 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!\n");
                    hit = true;
                    break;
                }
            }

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

    closedir(dir);
}        
コード例 #2
0
// apply_patch_check(file, [sha1_1, ...])
Value* ApplyPatchCheckFn(const char* name, State* state,
                         int argc, Expr* argv[]) {
    int result = 0;
    if (argc < 1) {
        return ErrorAbort(state, "%s(): expected at least 1 arg, got %d",
                          name, argc);
    }

    char* filename;
    if (ReadArgs(state, argv, 1, &filename) < 0) {
        return NULL;
    }

    /*
     * Some of the symbolic links to shared libraries are created at runtime
     * based on hw being used as these are created at runtime sha1 would be
     * different compared to the one generated by updater-script. As we anyway
     * update the actual file the sym link points to, we can skip ahead sym links.
     */
    if (!CheckSymLink(filename)) {
        result = 0;
        goto ret;
    }

    int patchcount = argc-1;
    char** sha1s = ReadVarArgs(state, argc-1, argv+1);

    result = applypatch_check(filename, patchcount, sha1s);

    int i;
    for (i = 0; i < patchcount; ++i) {
        free(sha1s[i]);
    }
    free(sha1s);

ret:
    return StringValue(strdup(result == 0 ? "t" : ""));
}