flux_t flux_open (const char *uri, int flags) { char *path = NULL; char *scheme = NULL; void *dso = NULL; connector_init_f *connector_init = NULL; flux_t h = NULL; if (!uri) uri = getenv ("FLUX_URI"); if (!uri) { errno = EINVAL; goto done; } if (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 (!(h = connector_init (path, flags))) { dlclose (dso); goto done; } h->dso = dso; #if HAVE_CALIPER profiling_context_init(&h->prof); #endif done: if (scheme) free (scheme); return h; }
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; }