Ejemplo n.º 1
0
/* Route string will not include the endpoints.
 */
static void ping_cb (flux_t h, flux_msg_handler_t *w,
                     const flux_msg_t *msg, void *arg)
{
    module_t *p = arg;
    const char *json_str;
    JSON o = NULL;
    char *route = NULL;
    char *route_plus_uuid = NULL;
    int rc = -1;

    if (flux_request_decode (msg, NULL, &json_str) < 0)
        goto done;
    if (!(o = Jfromstr (json_str))) {
        errno = EPROTO;
        goto done;
    }
    if (!(route = flux_msg_get_route_string (msg)))
        goto done;
    route_plus_uuid = xasprintf ("%s!%.5s", route, module_get_uuid (p));
    Jadd_str (o, "route", route_plus_uuid);
    rc = 0;
done:
    if (flux_respond (h, msg, rc < 0 ? errno : 0,
                                rc < 0 ? NULL : Jtostr (o)) < 0)
        FLUX_LOG_ERROR (h);
    Jput (o);
    if (route_plus_uuid)
        free (route_plus_uuid);
    if (route)
        free (route);
}
Ejemplo n.º 2
0
static void ping_request_cb (flux_t *h, flux_msg_handler_t *mh,
                             const flux_msg_t *msg, void *arg)
{
    const char *json_str;
    char *route_str = NULL;
    char *full_route_str = NULL;
    char *resp_str = NULL;
    uint32_t rank, userid, rolemask;

    if (flux_request_decode (msg, NULL, &json_str) < 0)
        goto error;
    if (flux_msg_get_rolemask (msg, &rolemask) < 0)
        goto error;
    if (flux_msg_get_userid (msg, &userid) < 0)
        goto error;
    if (!(route_str = flux_msg_get_route_string (msg)))
        goto error;
    if (flux_get_rank (h, &rank) < 0)
        goto error;
    if (asprintf (&full_route_str, "%s!%u", route_str, rank) < 0) {
        errno = ENOMEM;
        goto error;
    }
    if (!(resp_str = make_json_response_payload (json_str, full_route_str,
                                                 userid, rolemask))) {
        goto error;
    }
    if (flux_respond (h, msg, resp_str) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    free (route_str);
    free (full_route_str);
    free (resp_str);
    return;
error:
    if (flux_respond_error (h, msg, errno, NULL) < 0)
        flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
    free (route_str);
    free (full_route_str);
    free (resp_str);
}