Example #1
0
void flux_handle_destroy (flux_t *h)
{
    if (h && --h->usecount == 0) {
        zhash_destroy (&h->aux);
        if ((h->flags & FLUX_O_CLONE)) {
            flux_handle_destroy (h->parent); // decr usecount
        }
        else {
            if (h->ops->impl_destroy)
                h->ops->impl_destroy (h->impl);
            tagpool_destroy (h->tagpool);
            if (h->dso)
                dlclose (h->dso);
            msglist_destroy (h->queue);
            if (h->pollfd >= 0)
                (void)close (h->pollfd);
        }
        free (h);
    }
}
Example #2
0
flux_t *flux_handle_create (void *impl, const struct flux_handle_ops *ops, int flags)
{
    flux_t *h = malloc (sizeof (*h));
    if (!h)
        goto nomem;
    memset (h, 0, sizeof (*h));
    h->usecount = 1;
    h->flags = flags;
    h->ops = ops;
    h->impl = impl;
    if (!(h->tagpool = tagpool_create ()))
        goto nomem;
    tagpool_set_grow_cb (h->tagpool, tagpool_grow_notify, h);
    if (!(h->queue = msglist_create ((msglist_free_f)flux_msg_destroy)))
        goto nomem;
    h->pollfd = -1;
    return h;
nomem:
    flux_handle_destroy (h);
    errno = ENOMEM;
    return NULL;
}
Example #3
0
void flux_close (flux_t h)
{
    int saved_errno = errno;
    flux_handle_destroy (&h);
    errno = saved_errno;
}
Example #4
0
flux_t *flux_open (const char *uri, int flags)
{
    char *default_uri = NULL;
    char *path = NULL;
    char *scheme = NULL;
    void *dso = NULL;
    connector_init_f *connector_init = NULL;
    const char *s;
    flux_t *h = NULL;

    if (!uri)
        uri = getenv ("FLUX_URI");
    if (!uri) {
        if (asprintf (&default_uri, "local://%s",
                      flux_conf_get ("rundir", 0)) < 0)
            goto done;
        uri = default_uri;
    }
    if (!(scheme = strdup (uri))) {
        errno = ENOMEM;
        goto done;
    }
    path = strstr (scheme, "://");
    if (path) {
        *path = '\0';
        path = strtrim (path + 3, " \t");
    }
    if (!(connector_init = find_connector (scheme, &dso)))
        goto done;
    if (getenv ("FLUX_HANDLE_TRACE"))
        flags |= FLUX_O_TRACE;
    if (getenv ("FLUX_HANDLE_MATCHDEBUG"))
        flags |= FLUX_O_MATCHDEBUG;
    if (!(h = connector_init (path, flags))) {
        dlclose (dso);
        goto done;
    }
    h->dso = dso;
#if HAVE_CALIPER
    profiling_context_init(&h->prof);
#endif
    if ((s = getenv ("FLUX_HANDLE_USERID"))) {
        uint32_t userid = strtoul (s, NULL, 10);
        if (flux_opt_set (h, FLUX_OPT_TESTING_USERID, &userid,
                                                      sizeof (userid)) < 0) {
            flux_handle_destroy (h);
            h = NULL;
            goto done;
        }
    }
    if ((s = getenv ("FLUX_HANDLE_ROLEMASK"))) {
        uint32_t rolemask = strtoul (s, NULL, 0);
        if (flux_opt_set (h, FLUX_OPT_TESTING_ROLEMASK, &rolemask,
                                                    sizeof (rolemask)) < 0) {
            flux_handle_destroy (h);
            h = NULL;
            goto done;
        }
    }
done:
    free (scheme);
    free (default_uri);
    return h;
}