Example #1
0
flux_t *connector_init (const char *path, int flags)
{
    ctx_t *c = malloc (sizeof (*c));
    if (!c) {
        errno = ENOMEM;
        goto error;
    }
    memset (c, 0, sizeof (*c));
    c->magic = CTX_MAGIC;
    if (!(c->queue = msglist_create ((msglist_free_f)flux_msg_destroy)))
        goto error;
    if (!(c->h = flux_handle_create (c, &handle_ops, flags)))
        goto error;
    /* Fake out size, rank, tbon-arity attributes for testing.
     */
    if (flux_attr_fake (c->h, "rank", "0", FLUX_ATTRFLAG_IMMUTABLE) < 0
                || flux_attr_fake (c->h, "size", "1",
                                   FLUX_ATTRFLAG_IMMUTABLE) < 0
                || flux_attr_fake (c->h, "tbon-arity", "2",
                                   FLUX_ATTRFLAG_IMMUTABLE) < 0)
        goto error;
    return c->h;
error:
    if (c) {
        int saved_errno = errno;
        op_fini (c);
        errno = saved_errno;
    }
    return NULL;
}
Example #2
0
/* Path is interpreted as the directory containing the unix domain socket
 * and broker pid.
 */
flux_t connector_init (const char *path, int flags)
{
    ctx_t *c = NULL;
    struct sockaddr_un addr;
    char pidfile[PATH_MAX + 1];
    char sockfile[PATH_MAX + 1];
    int n, count;

    if (!path) {
        errno = EINVAL;
        goto error;
    }
    n = snprintf (sockfile, sizeof (sockfile), "%s/local", path);
    if (n >= sizeof (sockfile)) {
        errno = EINVAL;
        goto error;
    }
    n = snprintf (pidfile, sizeof (pidfile), "%s/broker.pid", path);
    if (n >= sizeof (pidfile)) {
        errno = EINVAL;
        goto error;
    }

    if (!(c = malloc (sizeof (*c)))) {
        errno = ENOMEM;
        goto error;
    }
    memset (c, 0, sizeof (*c));
    c->magic = CTX_MAGIC;

    c->fd = socket (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
    if (c->fd < 0)
        goto error;
    c->fd_nonblock = -1;
    for (count=0;;count++) {
        if (count >= env_getint("FLUX_RETRY_COUNT", 5) || !pidcheck (pidfile))
            goto error;
        memset (&addr, 0, sizeof (struct sockaddr_un));
        addr.sun_family = AF_UNIX;
        strncpy (addr.sun_path, sockfile, sizeof (addr.sun_path) - 1);
        if (connect (c->fd, (struct sockaddr *)&addr,
                     sizeof (struct sockaddr_un)) == 0)
            break;
        usleep (100*1000);
    }
    flux_msg_iobuf_init (&c->outbuf);
    flux_msg_iobuf_init (&c->inbuf);
    if (!(c->h = flux_handle_create (c, &handle_ops, flags)))
        goto error;
    return c->h;
error:
    if (c) {
        int saved_errno = errno;
        op_fini (c);
        errno = saved_errno;
    }
    return NULL;
}
Example #3
0
flux_t connector_init (const char *path, int flags)
{
    ctx_t *ctx;
    if (!path) {
        errno = EINVAL;
        return NULL;
    }
    ctx = xzmalloc (sizeof (*ctx));
    ctx->magic = MODHANDLE_MAGIC;
    ctx->uuid = xstrdup (path);
    ctx->uri = xasprintf ("inproc://%s", ctx->uuid);
    if (!(ctx->h = flux_handle_create (ctx, &handle_ops, flags))) {
        op_fini (ctx);
        return NULL;
    }
    return ctx->h;
}
Example #4
0
flux_t *connector_init (const char *path, int flags)
{
#if HAVE_CALIPER
    cali_id_t uuid   = cali_create_attribute ("flux.uuid",
                       CALI_TYPE_STRING,
                       CALI_ATTR_SKIP_EVENTS);
    size_t length = strlen(path);
    cali_push_snapshot ( CALI_SCOPE_PROCESS | CALI_SCOPE_THREAD,
                         1, &uuid, (const void **)&path, &length);
#endif

    ctx_t *ctx = NULL;
    if (!path) {
        errno = EINVAL;
        goto error;
    }
    if (!(ctx = malloc (sizeof (*ctx)))) {
        errno = ENOMEM;
        goto error;
    }
    memset (ctx, 0, sizeof (*ctx));
    ctx->magic = MODHANDLE_MAGIC;
    if (!(ctx->uuid = strdup (path))) {
        errno = ENOMEM;
        goto error;
    }
    if (asprintf (&ctx->uri, "inproc://%s", ctx->uuid) < 0) {
        errno = ENOMEM;
        goto error;
    }
    if (!(ctx->h = flux_handle_create (ctx, &handle_ops, flags)))
        goto error;
    return ctx->h;
error:
    if (ctx) {
        int saved_errno = errno;
        op_fini (ctx);
        errno = saved_errno;
    }
    return NULL;
}
Example #5
0
flux_t connector_init (const char *path, int flags)
{
    ctx_t *c = xzmalloc (sizeof (*c));
    c->magic = CTX_MAGIC;
    c->rank = 0;
    if (!(c->queue = msglist_create ((msglist_free_f)flux_msg_destroy)))
        goto error;
    c->h = flux_handle_create (c, &handle_ops, flags);
    /* Fake out flux_size() and flux_rank () for testing.
     */
    c->size = 1;
    flux_aux_set (c->h, "flux::size", &c->size, NULL);
    flux_aux_set (c->h, "flux::rank", &c->rank, NULL);
    return c->h;
error:
    if (c) {
        int saved_errno = errno;
        op_fini (c);
        errno = saved_errno;
    }
    return NULL;
}