Example #1
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 #2
0
uint32_t service_query(const char *name) {
	return (uint32_t)env_getint(g.names, name);
}