On Thu, 2008-07-24 at 17:44 +0100, Andy Whitcroft wrote:
> Add support for requesting a specific library set for preload.  This adds
> the --library option which takes an optional argument.  Without an argument
> it requests use of the specific libraries installed with the version
> of hugectl in use.  An argument is treated as a prefix to the library
> directories and the approprate 32/64 bit library directories are added.

Hmm, there is a use case that this patch doesn't cover (and it was the
first thing I thought of when I saw the patch title).  Say I have a
pre-built library in /home/aglitke (or some such path without lib/lib64
structure) that I want to use.  The patch (as it exists now) would not
let me point hugectl at this library.  Am I the only one who thinks this
might be useful?  I suppose one option is to make users wanting to do
this simply use LD_LIBRARY_PATH directly.


> 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 d69a365..6571672 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -101,6 +101,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 \
> @@ -228,7 +235,7 @@ obj64/%.s:        %.c
> 
>  $(OBJS):     hugectl.c
>       @$(VECHO) CPP $@
> -     $(CC) $(CFLAGS) -o $@ -c $<
> +     $(CC) $(CFLAGS) $(LIBPATHS) -o $@ -c $<
> 
>  $(INSTALL_OBJ):      $(OBJS)
>       @$(VECHO) CC $@
> diff --git a/hugectl.c b/hugectl.c
> index 755d3b6..81e76b2 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>
> @@ -66,6 +67,17 @@ void print_usage()
>       CONT("(malloc space)");
> 
>       OPTION("--no-preload", "Disable preloading the libhugetlbfs library");
> +
> +     OPTION("--library-use-path", "Use the system library path");
> +     OPTION("--library <path>", "Select a library prefix");
> +     CONT("(Default: "
> +#ifdef LIBDIR32
> +             LIBDIR32 ":"
> +#endif
> +#ifdef LIBDIR32
> +             LIBDIR32 ":"
> +#endif
> +             ")");
>  }
> 
>  int verbose_level = VERBOSITY_DEFAULT;
> @@ -97,6 +109,9 @@ void setup_environment(char *var, char *val)
> 
>  #define LONG_NO_PRELOAD      (LONG_BASE | 'p')
> 
> +#define LONG_NO_LIBRARY      (LONG_BASE | 'L')
> +#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
> @@ -140,6 +155,51 @@ void setup_mappings(int which)
>               setup_environment("HUGETLB_MORECORE", "yes");
>  }
> 
> +#define LIBRARY_DISABLE ((void *)-1)
> +
> +void library_path(char *path)
> +{
> +     char val[NAME_MAX] = "";
> +     char *env;
> +
> +     /*
> +      * Select which libraries we wish to use.  No argument implies
> +      * use the libraries included with this version of hugectl.
> +      * Else it is assumed to be a prefix to the 32/64 bit directories
> +      * both of which are added, where available.
> +      */
> +     env = getenv("LD_LIBRARY_PATH");
> +     if (!path) {
> +             /* [LIBDIR32:][LIBDIR64:]$LD_LIBRARY_PATH */
> +             snprintf(val, sizeof(val), ""
> +#ifdef LIBDIR32
> +                     LIBDIR32 ":"
> +#endif
> +#ifdef LIBDIR64
> +                     LIBDIR64 ":"
> +#endif
> +                     "%s", 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 : "");
> +     }
> +     setup_environment("LD_LIBRARY_PATH", val);
> +}
> +
>  void ldpreload(int which)
>  {
>       if (which == MAP_HEAP) {
> @@ -154,12 +214,16 @@ 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;
>       struct option long_opts[] = {
>               {"help",       no_argument, NULL, 'h'},
>               {"no-preload", no_argument, NULL, LONG_NO_PRELOAD},
> +             {"library-use-path",
> +                            no_argument, NULL, LONG_NO_LIBRARY},
> +             {"library",    required_argument, NULL, LONG_LIBRARY},
> 
>               {"disable",    no_argument, NULL, MAP_BASE|MAP_DISABLE},
>               {"text",       no_argument, NULL, MAP_BASE|MAP_TEXT},
> @@ -192,6 +256,15 @@ int main(int argc, char** argv)
>                       DEBUG("LD_PRELOAD disabled\n");
>                       break;
> 
> +             case LONG_NO_LIBRARY:
> +                     opt_library = LIBRARY_DISABLE;
> +                     DEBUG("using LD_LIBRARY_PATH to find library\n");
> +                     break;
> +
> +             case LONG_LIBRARY:
> +                     opt_library = optarg;
> +                     break;
> +
>               default:
>                       WARNING("unparsed option %08x\n", ret);
>                       ret = -1;
> @@ -206,6 +279,9 @@ int main(int argc, char** argv)
>               exit(EXIT_FAILURE);
>       }
> 
> +     if (opt_library != LIBRARY_DISABLE)
> +             library_path(opt_library);
> +
>       if (opt_mappings)
>               setup_mappings(opt_mappings);
> 
-- 
Adam Litke - (agl at us.ibm.com)
IBM Linux Technology Center


-------------------------------------------------------------------------
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
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to