Пример #1
0
/**
 * Adds a PID.
 *
 * @param pid       [in] The PID to be added.
 * @retval 0        Success.
 * @retval ENOMEM   Out-of-memory.
 */
int
cps_add(
    pid_t pid)
{
    int    error;

    if (cps_contains(pid)) {
        error = 0;
    }
    else {
        pid_t *elt = malloc(sizeof(pid_t));

        if (elt == NULL) {
            error = ENOMEM;
        }
        else {
            *elt = pid;

            if (tsearch(elt, &root, compare) == NULL) {
                error = ENOMEM;
            }
            else {
                ++count;
                error = 0;
            }

            if (error)
                free(elt);
        } /* "elt" allocated */
    } /* "pid" doesn't exist */

    return error;
}
Пример #2
0
int *is_alive_6_svc(
        unsigned *id,
        struct svc_req *rqstp)
{
    static int alive;
    SVCXPRT * const xprt = rqstp->rq_xprt;
    int error = 0;

    alive = cps_contains((pid_t) *id);

    if (ulogIsDebug()) {
        udebug("LDM %u is %s", *id, alive ? "alive" : "dead");
    }

    if (!svc_sendreply(xprt, (xdrproc_t) xdr_bool, (caddr_t) &alive)) {
        svcerr_systemerr(xprt);

        error = 1;
    }

    if (!svc_freeargs(xprt, xdr_u_int, (caddr_t)id)) {
        uerror("Couldn't free arguments");

        error = 1;
    }

    svc_destroy(xprt);
    exit(error);

    /*NOTREACHED*/

    return NULL ;
}
Пример #3
0
/*
 * @return 0      if successful.
 * @return ENOMEM if out-of-memory.
 */
int
cps_add(
    pid_t pid)
{
    int    error;

    if (cps_contains(pid)) {
        error = 0;
    }
    else {
        pid_t *elt;

        elt = (pid_t*)malloc(sizeof(pid_t));

        if (elt == NULL) {
            error = ENOMEM;
        }
        else {
            *elt = pid;

            if (tsearch(elt, &root, compare) == NULL) {
                error = ENOMEM;
            }
            else {
                ++count;
                error = 0;
            }
        }
    }

    return error;
}