Exemple #1
0
/*!
 * add a child
 * @return pointer to struct server_child_data on success, NULL on error
 */
afp_child_t *server_child_add(server_child_t *children, pid_t pid, int ipc_fd)
{
    afp_child_t *child = NULL;

    pthread_mutex_lock(&children->servch_lock);

    /* it's possible that the child could have already died before the
     * pthread_sigmask. we need to check for this. */
    if (kill(pid, 0) < 0) {
        LOG(log_error, logtype_default, "server_child_add: no such process pid [%d]", pid);
        goto exit;
    }

    /* if we already have an entry. just return. */
    if ((child = server_child_resolve(children, pid)))
        goto exit;

    if ((child = calloc(1, sizeof(afp_child_t))) == NULL)
        goto exit;

    child->afpch_pid = pid;
    child->afpch_ipc_fd = ipc_fd;
    child->afpch_logintime = time(NULL);

    hash_child(children->servch_table, child);
    children->servch_count++;

exit:
    pthread_mutex_unlock(&children->servch_lock);
    return child;
}
Exemple #2
0
/*!
 * add a child
 * @return pointer to struct server_child_data on success, NULL on error
 */
afp_child_t *server_child_add(server_child *children, int forkid, pid_t pid, int ipc_fd)
{
    server_child_fork *fork;
    afp_child_t *child = NULL;
    sigset_t sig, oldsig;

    /* we need to prevent deletions from occuring before we get a
     * chance to add the child in. */
    sigemptyset(&sig);
    sigaddset(&sig, SIGCHLD);
    pthread_sigmask(SIG_BLOCK, &sig, &oldsig);

    /* it's possible that the child could have already died before the
     * pthread_sigmask. we need to check for this. */
    if (kill(pid, 0) < 0) {
        LOG(log_error, logtype_default, "server_child_add: no such process pid [%d]", pid);
        goto exit;
    }

    fork = (server_child_fork *) children->fork + forkid;

    /* if we already have an entry. just return. */
    if ((child = resolve_child(fork->table, pid)))
        goto exit;

    if ((child = calloc(1, sizeof(afp_child_t))) == NULL)
        goto exit;

    child->pid = pid;
    child->valid = 0;
    child->killed = 0;
    child->ipc_fd = ipc_fd;

    hash_child(fork->table, child);
    children->count++;

exit:
    pthread_sigmask(SIG_SETMASK, &oldsig, NULL);
    return child;
}