Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/rump_allserver Attempt to load all components even i...



details:   https://anonhg.NetBSD.org/src/rev/0275d50a1bdb
branches:  trunk
changeset: 326018:0275d50a1bdb
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Jan 16 00:31:39 2014 +0000

description:
Attempt to load all components even if they are not given in
dependency order.

diffstat:

 usr.bin/rump_allserver/rump_allserver.1 |  21 ++++++--
 usr.bin/rump_allserver/rump_allserver.c |  82 ++++++++++++++++++++++++--------
 2 files changed, 76 insertions(+), 27 deletions(-)

diffs (200 lines):

diff -r 9ac061a4feae -r 0275d50a1bdb usr.bin/rump_allserver/rump_allserver.1
--- a/usr.bin/rump_allserver/rump_allserver.1   Wed Jan 15 22:25:22 2014 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.1   Thu Jan 16 00:31:39 2014 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: rump_allserver.1,v 1.19 2011/03/04 09:13:23 pooka Exp $
+.\"    $NetBSD: rump_allserver.1,v 1.20 2014/01/16 00:31:39 pooka Exp $
 .\"
 .\" Copyright (c) 2010 Antti Kantee.  All rights reserved.
 .\"
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd February 21, 2011
+.Dd January 15, 2014
 .Dt RUMP_SERVER 1
 .Os
 .Sh NAME
@@ -157,9 +157,13 @@
 .Ar library
 can contain a full path or a filename, in which case the standard
 dynamic library search path will be used.
-Libraries are loaded in the order they are given.
-Dependencies are not autoloaded, and the order must be specified
-correctly.
+By default, lazy resolution is used, and may result in a runtime
+error due to missing components.
+To test a configuration, run
+.Nm
+with
+.Ev LD_BIND_NOW=1
+(see examples).
 .It Fl m Ar module
 Load and link a kernel module after the rump kernel is initialized.
 For this to work, the rump kernel must include the vfs faction,
@@ -210,9 +214,14 @@
 $ rump_server tcp://0:3755/
 .Ed
 .Pp
+Test that a configuration contains all of the necessary components:
+.Bd -literal -offset indent
+$ env LD_BIND_NOW=1 rump_server -lrumpvfs -lrumpfs_ffs unix://tsock
+.Ed
+.Pp
 Start a FFS server with a 16MB kernel memory limit.
 .Bd -literal -offset indent
-$ rump_server -lrumpvfs -lrumpfs_ffs -r 16m unix:///tmp/ffs_server
+$ rump_server -lrumpfs_ffs [...] -r 16m unix://ffs
 .Ed
 .Sh SEE ALSO
 .Xr rump.halt 1 ,
diff -r 9ac061a4feae -r 0275d50a1bdb usr.bin/rump_allserver/rump_allserver.c
--- a/usr.bin/rump_allserver/rump_allserver.c   Wed Jan 15 22:25:22 2014 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.c   Thu Jan 16 00:31:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump_allserver.c,v 1.33 2013/12/31 00:23:56 pooka Exp $        */
+/*     $NetBSD: rump_allserver.c,v 1.34 2014/01/16 00:31:39 pooka Exp $        */
 
 /*-
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include <rump/rumpuser_port.h>
 
 #ifndef lint
-__RCSID("$NetBSD: rump_allserver.c,v 1.33 2013/12/31 00:23:56 pooka Exp $");
+__RCSID("$NetBSD: rump_allserver.c,v 1.34 2014/01/16 00:31:39 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -136,6 +136,8 @@
 
 static void processlabel(int, int, int, off_t *, off_t *);
 
+#define ALLOCCHUNK 32
+
 int
 main(int argc, char *argv[])
 {
@@ -143,10 +145,10 @@
        struct etfsreg *etfs = NULL;
        unsigned netfs = 0, curetfs = 0;
        int error;
-       int ch, sflag;
+       int ch, sflag, onthepath;
        unsigned i;
-       char **modarray = NULL;
-       unsigned nmods = 0, curmod = 0;
+       char **modarray = NULL, **libarray = NULL;
+       unsigned nmods = 0, curmod = 0, nlibs = 0, curlib = 0, libidx, liblast;
 
 #ifdef PLATFORM_HAS_SETGETPROGNAME
        setprogname(argv[0]);
@@ -292,10 +294,11 @@
                                ftype = RUMP_ETFS_BLK;
 
                        if (netfs - curetfs == 0) {
-                               etfs = realloc(etfs, (netfs+16)*sizeof(*etfs));
+                               etfs = realloc(etfs,
+                                   (netfs+ALLOCCHUNK)*sizeof(*etfs));
                                if (etfs == NULL)
                                        die(1, errno, "realloc etfs");
-                               netfs += 16;
+                               netfs += ALLOCCHUNK;
                        }
 
                        etfs[curetfs].key = key;
@@ -309,28 +312,25 @@
                        break;
                }
                case 'l':
-                       if (dlopen(optarg, RTLD_LAZY|RTLD_GLOBAL) == NULL) {
-                               char pb[MAXPATHLEN];
-                               /* try to mimic linker -l syntax */
-
-                               snprintf(pb, sizeof(pb), "lib%s.so", optarg);
-                               if (dlopen(pb, RTLD_LAZY|RTLD_GLOBAL) == NULL) {
-                                       fprintf(stderr, "dlopen: %s", dlerror());
-                                       die(1, 0, NULL);
-                               }
+                       if (nlibs - curlib == 0) {
+                               libarray = realloc(libarray,
+                                   (nlibs+ALLOCCHUNK) * sizeof(char *));
+                               if (libarray == NULL)
+                                       die(1, errno, "realloc");
+                               nlibs += ALLOCCHUNK;
                        }
+                       libarray[curlib++] = optarg;
                        break;
-               case 'm': {
-
+               case 'm':
                        if (nmods - curmod == 0) {
                                modarray = realloc(modarray,
-                                   (nmods+16) * sizeof(char *));
+                                   (nmods+ALLOCCHUNK) * sizeof(char *));
                                if (modarray == NULL)
                                        die(1, errno, "realloc");
-                               nmods += 16;
+                               nmods += ALLOCCHUNK;
                        }
                        modarray[curmod++] = optarg;
-                       break; }
+                       break;
                case 'r':
                        setenv("RUMP_MEMLIMIT", optarg, 1);
                        break;
@@ -352,6 +352,45 @@
        if (argc != 1)
                usage();
 
+       /*
+        * Automatically "resolve" component dependencies, i.e.
+        * try to load libs in a loop until all are loaded or a
+        * full loop completes with no loads (latter case is an error).
+        */
+       for (onthepath = 1, nlibs = curlib; onthepath && nlibs > 0;) {
+               onthepath = 0;
+               for (libidx = 0; libidx < curlib; libidx++) {
+                       /* loaded already? */
+                       if (libarray[libidx] == NULL)
+                               continue;
+
+                       /* try to load */
+                       liblast = libidx;
+                       if (dlopen(libarray[libidx],
+                           RTLD_LAZY|RTLD_GLOBAL) == NULL) {
+                               char pb[MAXPATHLEN];
+                               /* try to mimic linker -l syntax */
+                               snprintf(pb, sizeof(pb),
+                                   "lib%s.so", libarray[libidx]);
+                               if (dlopen(pb, RTLD_LAZY|RTLD_GLOBAL) == NULL)
+                                       continue;
+                       }
+
+                       /* managed to load that one */
+                       libarray[libidx] = NULL;
+                       nlibs--;
+                       onthepath = 1;
+               }
+       }
+       if (nlibs > 0) {
+               fprintf(stderr,
+                   "failed to load -libraries, last error from \"%s\":\n",
+                   libarray[liblast]);
+               fprintf(stderr, "  %s", dlerror());
+               die(1, 0, NULL);
+       }
+       free(libarray);
+
        serverurl = argv[0];
 
        if (!sflag) {
@@ -384,6 +423,7 @@
                rump_pub_etfs_remove(ETFSKEY);
 #undef ETFSKEY
        }
+       free(modarray);
 
        /* register host drives */
        for (i = 0; i < curetfs; i++) {



Home | Main Index | Thread Index | Old Index