示例#1
0
gboolean
mainloop_child_kill(pid_t pid)
{
    GListPtr iter;
    mainloop_child_t *child = NULL;

    for (iter = child_list; iter != NULL; iter = iter->next) {
        child = iter->data;
        if (pid == child->pid) {
            break;
        }
    }

    if (child == NULL) {
        return FALSE;
    }

    if (child_kill_helper(child) != 0) {
        /* failed to terminate child process */
        return FALSE;
    }

    /* It is impossible to block SIGKILL, this allows us to
     * call waitpid without WNOHANG here */
    if (child_waitpid(child, 0) == FALSE) {
        /* not much we can do if this occurs */
        return FALSE;
    }

    child_list = g_list_remove(child_list, child);
    child_free(child);
    return TRUE;
}
示例#2
0
int
mainloop_child_kill(pid_t pid)
{
    GListPtr iter;
    mainloop_child_t *child = NULL;
    mainloop_child_t *match = NULL;
    /* It is impossible to block SIGKILL, this allows us to
     * call waitpid without WNOHANG flag.*/
    int waitflags = 0, rc = 0;

    for (iter = child_list; iter != NULL && match == NULL; iter = iter->next) {
        child = iter->data;
        if (pid == child->pid) {
            match = child;
        }
    }

    if (match == NULL) {
        return FALSE;
    }

    rc = child_kill_helper(match);
    if(rc == -ESRCH) {
        /* Its gone, but hasn't shown up in waitpid() yet
         *
         * Wait until we get SIGCHLD and let child_death_dispatch()
         * clean it up as normal (so we get the correct return
         * code/status)
         *
         * The blocking alternative would be to call:
         *    child_waitpid(match, 0);
         */
        crm_trace("Waiting for child %d to be reaped by child_death_dispatch()", match->pid);
        return TRUE;

    } else if(rc != 0) {
        /* If KILL for some other reason set the WNOHANG flag since we
         * can't be certain what happened.
         */
        waitflags = WNOHANG;
    }

    if (child_waitpid(match, waitflags) == FALSE) {
        /* not much we can do if this occurs */
        return FALSE;
    }

    child_list = g_list_remove(child_list, match);
    child_free(match);
    return TRUE;
}
示例#3
0
static gboolean
child_timeout_callback(gpointer p)
{
    mainloop_child_t *child = p;
    int rc = 0;

    child->timerid = 0;
    if (child->timeout) {
        crm_crit("%s process (PID %d) will not die!", child->desc, (int)child->pid);
        return FALSE;
    }

    rc = child_kill_helper(child);
    if (rc == ESRCH) {
        /* Nothing left to do. pid doesn't exist */
        return FALSE;
    }

    child->timeout = TRUE;
    crm_warn("%s process (PID %d) timed out", child->desc, (int)child->pid);

    child->timerid = g_timeout_add(5000, child_timeout_callback, child);
    return FALSE;
}