On Thu, Jul 31, 2008 at 01:09:38PM +0100, Andy Whitcroft wrote:
> Add support for requesting a specific library set for preload. This adds
> the --library-path option. If this option points to a directory containing
> a libhugetlbfs library it is used, else it is assumed to be a library
> prefix and both the 32 bit and 64 bit library directories are added
> (where available). By default the specific libraries installed with the
> version of hugectl are used.
>
> Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
> ---
> Makefile | 9 ++++++-
> hugectl.c | 76
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 84 insertions(+), 1 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 59fdb47..0cd7bf7 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -109,6 +109,13 @@ BINDIR = $(PREFIX)/share/libhugetlbfs
> EXEDIR = $(PREFIX)/bin
> DOCDIR = $(PREFIX)/share/doc/libhugetlbfs
>
> +ifdef LIB32
> +LIBPATHS += -DLIB32='"$(LIB32)"' -DLIBDIR32='"$(LIBDIR32)"'
> +endif
> +ifdef LIB64
> +LIBPATHS += -DLIB64='"$(LIB64)"' -DLIBDIR64='"$(LIBDIR64)"'
> +endif
> +
> EXTRA_DIST = \
> README \
> HOWTO \
> @@ -236,7 +243,7 @@ obj64/%.s: %.c
>
> $(OBJS): hugectl.c
> @$(VECHO) CPP $@
> - $(CC) $(CFLAGS) -o $@ -c $<
> + $(CC) $(CFLAGS) $(LIBPATHS) -o $@ -c $<
Bah, this has changed in mainline, this part becoming redundant but not
removed. This patch needs updating. Will update, retest correctly and
repost.
> $(INSTALL_BIN:%=$(BIN_OBJ_DIR)/%): $(BIN_OBJ_DIR)/%: %.c
> @$(VECHO) CC $@
> diff --git a/hugectl.c b/hugectl.c
> index e24d69f..26f0389 100644
> --- a/hugectl.c
> +++ b/hugectl.c
> @@ -31,6 +31,7 @@
> #include <stdio.h>
> #include <errno.h>
> #include <string.h>
> +#include <limits.h>
>
> #define _GNU_SOURCE /* for getopt_long */
> #include <unistd.h>
> @@ -68,6 +69,16 @@ void print_usage()
> OPTION("--no-preload", "Disable preloading the libhugetlbfs library");
>
> OPTION("--dry-run", "describe what would be done without doing it");
> +
> + OPTION("--library-path <path>", "Select a library prefix");
> + CONT("(Default: "
> +#ifdef LIBDIR32
> + LIBDIR32 ":"
> +#endif
> +#ifdef LIBDIR32
> + LIBDIR32 ":"
> +#endif
> + ")");
> }
>
> int opt_dry_run = 0;
> @@ -105,6 +116,8 @@ void setup_environment(char *var, char *val)
>
> #define LONG_DRY_RUN (LONG_BASE | 'd')
>
> +#define LONG_LIBRARY (LONG_BASE | 'l')
> +
> /*
> * Mapping selectors, one bit per remappable/backable area as requested
> * by the user. These are also used as returns from getopts where they
> @@ -148,6 +161,60 @@ void setup_mappings(int which)
> setup_environment("HUGETLB_MORECORE", "yes");
> }
>
> +void library_path(char *path)
> +{
> + char val[NAME_MAX] = "";
> + char *env;
> +
> + env = getenv("LD_LIBRARY_PATH");
> +
> + /*
> + * Select which libraries we wish to use. If the path is NULL
> + * use the libraries included with hugectl. If the path is valid
> + * and points to a directory including a libhugetlbfs.so use it
> + * directly. Else path is assumed to be a prefix to the 32/64 bit
> + * directories both of which are added, where available.
> + */
> + if (path) {
> + snprintf(val, sizeof(val), "%s/libhugetlbfs.so", path);
> + if (access(val, F_OK) == 0) {
> + /* $PATH */
> + snprintf(val, sizeof(val), "%s:%s",
> + path, env ? env : "");
> +
> + } else {
> + /* [$PATH/LIB32:][$PATH/LIB64:]$LD_LIBRARY_PATH */
> + snprintf(val, sizeof(val), ""
> +#ifdef LIBDIR32
> + "%s/" LIB32 ":"
> +#endif
> +#ifdef LIBDIR64
> + "%s/" LIB64 ":"
> +#endif
> + "%s",
> +#ifdef LIBDIR32
> + path,
> +#endif
> +#ifdef LIBDIR64
> + path,
> +#endif
> + env ? env : "");
> + }
> +
> + } else {
> + /* [LIBDIR32:][LIBDIR64:]$LD_LIBRARY_PATH */
> + snprintf(val, sizeof(val), ""
> +#ifdef LIBDIR32
> + LIBDIR32 ":"
> +#endif
> +#ifdef LIBDIR64
> + LIBDIR64 ":"
> +#endif
> + "%s", env ? env : "");
> + }
> + setup_environment("LD_LIBRARY_PATH", val);
> +}
> +
> void ldpreload(int which)
> {
> if (which == MAP_HEAP) {
> @@ -162,6 +229,7 @@ int main(int argc, char** argv)
> {
> int opt_mappings = 0;
> int opt_preload = 1;
> + char *opt_library = NULL;
>
> char opts[] = "+h";
> int ret = 0, index = 0;
> @@ -169,6 +237,8 @@ int main(int argc, char** argv)
> {"help", no_argument, NULL, 'h'},
> {"no-preload", no_argument, NULL, LONG_NO_PRELOAD},
> {"dry-run", no_argument, NULL, LONG_DRY_RUN},
> + {"library-path",
> + required_argument, NULL, LONG_LIBRARY},
>
> {"disable", no_argument, NULL, MAP_BASE|MAP_DISABLE},
> {"text", no_argument, NULL, MAP_BASE|MAP_TEXT},
> @@ -205,6 +275,10 @@ int main(int argc, char** argv)
> opt_dry_run = 1;
> break;
>
> + case LONG_LIBRARY:
> + opt_library = optarg;
> + break;
> +
> default:
> WARNING("unparsed option %08x\n", ret);
> ret = -1;
> @@ -219,6 +293,8 @@ int main(int argc, char** argv)
> exit(EXIT_FAILURE);
> }
>
> + library_path(opt_library);
> +
> if (opt_mappings)
> setup_mappings(opt_mappings);
>
> --
> 1.5.6.GIT
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Libhugetlbfs-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel