-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
broker/boot_pmi: add dlopen/singleton support
Problem: support dlopen()ing libpmi.so and for falling back to singleton operation was removed from the Flux libpmi.so, but the broker needs this capability. Re-add this capability, with significantly reduced complexity given that it need not be a faithful PMI-1 API interface.
- Loading branch information
Showing
6 changed files
with
563 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/************************************************************\ | ||
* Copyright 2014 Lawrence Livermore National Security, LLC | ||
* (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
* | ||
* This file is part of the Flux resource manager framework. | ||
* For details, see https://github.com/flux-framework. | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0 | ||
\************************************************************/ | ||
|
||
#if HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
#include <czmq.h> | ||
#include <argz.h> | ||
|
||
#include "liblist.h" | ||
|
||
static int liblist_append_from_environment (zlist_t *libs, const char *libname) | ||
{ | ||
const char *path; | ||
char *argz = NULL; | ||
size_t argz_len; | ||
int rc = -1; | ||
char *filename, *entry = NULL; | ||
|
||
if ((path = getenv ("LD_LIBRARY_PATH"))) { | ||
if (argz_create_sep (path, ':', &argz, &argz_len) != 0) | ||
goto done; | ||
while ((entry = argz_next (argz, argz_len, entry))) { | ||
if (asprintf (&filename, "%s/%s", entry, libname) < 0) | ||
goto done; | ||
if (access (filename, F_OK) < 0) { | ||
free (filename); | ||
continue; | ||
} | ||
if (zlist_append (libs, filename) < 0) { | ||
free (filename); | ||
goto done; | ||
} | ||
} | ||
} | ||
rc = 0; | ||
done: | ||
if (argz) | ||
free (argz); | ||
return rc; | ||
} | ||
|
||
static int split2 (char *s, int delim, char **w1, char **w2) | ||
{ | ||
char *p = strchr (s, delim); | ||
if (!p) | ||
return -1; | ||
*p++ = '\0'; | ||
*w1 = s; | ||
*w2 = p; | ||
return 0; | ||
} | ||
|
||
static void trim_end (char *s, int ch) | ||
{ | ||
int len = strlen (s); | ||
while (len > 0) { | ||
if (s[len - 1] != ch) | ||
break; | ||
s[--len] = '\0'; | ||
} | ||
} | ||
|
||
static int liblist_append_from_ldconfig (zlist_t *libs, const char *libname) | ||
{ | ||
FILE *f; | ||
const char *cmd = "ldconfig -p | sed -e 's/([^(]*)[\t ]*//'" \ | ||
" | awk -F\" => \" '{print $1 \":\" $2};'"; | ||
char line[1024]; | ||
int rc = -1; | ||
|
||
if (!(f = popen (cmd, "r"))) | ||
goto done; | ||
while (fgets (line, sizeof (line), f) != NULL) { | ||
char *name, *path, *cpy; | ||
if (split2 (line, ':', &name, &path) < 0) | ||
continue; | ||
while (isspace (*name)) | ||
name++; | ||
if (strcmp (name, libname) != 0) | ||
continue; | ||
trim_end (path, '\n'); | ||
if (!(cpy = strdup (path))) | ||
goto done; | ||
if (zlist_append (libs, cpy) < 0) { | ||
free (cpy); | ||
goto done; | ||
} | ||
} | ||
rc = 0; | ||
done: | ||
if (f) | ||
fclose (f); | ||
return rc; | ||
} | ||
|
||
void liblist_destroy (zlist_t *libs) | ||
{ | ||
char *entry; | ||
if (libs) { | ||
while ((entry = zlist_pop (libs))) | ||
free (entry); | ||
zlist_destroy (&libs); | ||
} | ||
} | ||
|
||
zlist_t *liblist_create (const char *libname) | ||
{ | ||
zlist_t *libs = NULL; | ||
|
||
if (!(libs = zlist_new ())) | ||
goto error; | ||
if (strchr (libname, '/')) { | ||
char *cpy = strdup (libname); | ||
if (!cpy) | ||
goto error; | ||
if (zlist_append (libs, cpy) < 0) { | ||
free (cpy); | ||
goto error; | ||
} | ||
} else { | ||
if (liblist_append_from_environment (libs, libname) < 0) | ||
goto error; | ||
if (liblist_append_from_ldconfig (libs, libname) < 0) | ||
goto error; | ||
} | ||
return libs; | ||
error: | ||
liblist_destroy (libs); | ||
return NULL; | ||
} | ||
|
||
/* | ||
* vi:tabstop=4 shiftwidth | ||
*/ |
Oops, something went wrong.