Пример #1
0
void test_insmod_codec (void)
{
    int argc = 2;
    char *argv[] = { "foo", "bar", NULL };
    char *argz = NULL;
    size_t argz_len = 0;
    char *av[16];
    char *json_str;
    char *s;
    int rc;

    json_str = flux_insmod_json_encode ("/foo/bar", argc, argv);
    ok (json_str != NULL,
        "flux_insmod_json_encode works");

    rc = flux_insmod_json_decode (json_str, &s, &argz, &argz_len);
    argz_extract (argz, argz_len, av);
    ok (rc == 0 && s != NULL && !strcmp (s, "/foo/bar")
        && !strcmp (av[0], "foo") && !strcmp (av[1], "bar") && av[2] == NULL,
        "flux_insmod_json_decode works");

    if (argz)
        free (argz);
    free (s);
    free (json_str);
}
Пример #2
0
static void insmod_cb (flux_t *h, flux_msg_handler_t *w,
                       const flux_msg_t *msg, void *arg)
{
    struct sched_plugin_loader *sploader = arg;
    struct sched_plugin *plugin = sched_plugin_get (sploader);
    const sched_params_t *sp = sched_params_get (h);
    const char *json_str;
    char *path = NULL;
    char *argz = NULL;
    size_t argz_len = 0;
    int rc = -1;

    if (flux_request_decode (msg, NULL, &json_str) < 0)
        goto done;
    if (flux_insmod_json_decode (json_str, &path, &argz, &argz_len) < 0)
        goto done;
    if (plugin) {
        errno = EEXIST;
        goto done;
    }
    if (sched_plugin_load (sploader, path) < 0)
        goto done;

    if (sploader->plugin->process_args (sploader->h, argz, argz_len, sp) < 0) {
        goto done;
    }
    rc = 0;

done:
    if (flux_respond (h, msg, rc < 0 ? errno : 0, NULL) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    if (path)
        free (path);
    if (argz)
        free (argz);
}