]> sourceware.org Git - dm.git/commitdiff
Fixing some makesfiles, so that the correct things link against pthreads.
authorBenjamin Marzinski <bmarzins@redhat.com>
Tue, 14 Jun 2005 19:06:26 +0000 (19:06 +0000)
committerBenjamin Marzinski <bmarzins@redhat.com>
Tue, 14 Jun 2005 19:06:26 +0000 (19:06 +0000)
Also changed dmevent so that in no longer links against pthreads, and
dynamically loads libdmevent.so.  Everything seems to work just fine like this.

dmeventd/Makefile.in
dmeventd/dmevent.c
lib/event/Makefile.in
multilog/async/Makefile.in
multilog/pthread_lock/Makefile.in

index ddacbbed3b51d7e10771ee0faa855b0ca74a5f12..394f61e52e0cf1ecfae9a48e016f29ab512e7b34 100644 (file)
@@ -28,7 +28,7 @@ else
   LIB_SHARED = libdmeventdnoop.so
 endif
  
-LDFLAGS += -ldl -ldevmapper -lpthread -lmultilog
+LDFLAGS += -ldl -ldevmapper -lmultilog
 
 include ../make.tmpl
 
@@ -36,11 +36,11 @@ libdmeventdnoop.so: noop.o
 
 dmevent: dmevent.o $(interfacedir)/libdevmapper.$(LIB_SUFFIX) $(top_srcdir)/lib/event/libdmevent.$(LIB_SUFFIX)
        $(CC) -o $@ dmevent.o $(LDFLAGS) \
-             -L$(interfacedir) -L$(DESTDIR)/lib -L$(top_srcdir)/lib/event -L$(top_srcdir)/multilog -ldmevent $(LIBS)
+             -L$(interfacedir) -L$(DESTDIR)/lib -L$(top_srcdir)/lib/event -L$(top_srcdir)/multilog $(LIBS)
 
 dmeventd: dmeventd.o $(interfacedir)/libdevmapper.$(LIB_SUFFIX) $(top_srcdir)/lib/event/libdmevent.$(LIB_SUFFIX)
        $(CC) -o $@ dmeventd.o $(LDFLAGS) \
-             -L$(interfacedir) -L$(DESTDIR)/lib -L$(top_srcdir)/lib/event -L$(top_srcdir)/multilog -ldmevent $(LIBS)
+             -L$(interfacedir) -L$(DESTDIR)/lib -L$(top_srcdir)/lib/event -L$(top_srcdir)/multilog -lpthread -ldmevent $(LIBS)
 
 install: $(INSTALL_TYPE)
 
index 9ea63d6ab892eaa51944814b5531a6cb8a588441..6e9eb46018654441beb08d30079f83be58cc1b31 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <dlfcn.h>
 
 static enum event_type events = ALL_ERRORS; /* All until we can distinguish. */
 static char default_dso_name[] = "noop";  /* default DSO is noop */
 static int default_reg = 1;             /* default action is register */
 static uint32_t timeout;
 
+struct event_ops {
+int (*dm_register_for_event)(char *dso_name, char *device,
+                            enum event_type event_types);
+int (*dm_unregister_for_event)(char *dso_name, char *device,
+                              enum event_type event_types);
+int (*dm_get_registered_device)(char **dso_name, char **device,
+                               enum event_type *event_types, int next);
+int (*dm_set_event_timeout)(char *device, uint32_t time);
+int (*dm_get_event_timeout)(char *device, uint32_t *time);
+};
+
 /* Display help. */
 static void print_usage(char *name)
 {
@@ -102,8 +114,35 @@ static int parse_argv(int argc, char **argv, char **dso_name_arg,
        return 1;
 }
 
+
+static int lookup_symbol(void *dl, void **symbol, const char *name)
+{
+       if ((*symbol = dlsym(dl, name)))
+               return 1;
+
+       fprintf(stderr, "error looking up %s symbol: %s\n", name, dlerror());
+
+       return 0;
+}
+
+static int lookup_symbols(void *dl, struct event_ops *e)
+{
+       return lookup_symbol(dl, (void *) &e->dm_register_for_event,
+                            "dm_register_for_event") &&
+              lookup_symbol(dl, (void *) &e->dm_unregister_for_event,
+                            "dm_unregister_for_event") &&
+              lookup_symbol(dl, (void *) &e->dm_get_registered_device,
+                            "dm_get_registered_device") &&
+              lookup_symbol(dl, (void *) &e->dm_set_event_timeout,
+                            "dm_set_event_timeout") &&
+              lookup_symbol(dl, (void *) &e->dm_get_event_timeout,
+                            "dm_get_event_timeout");
+}
+
 int main(int argc, char **argv)
 {
+       void *dl;
+       struct event_ops e;
        int list = 0, next = 0, ret, reg = default_reg;
        char *device, *device_arg = NULL, *dso_name, *dso_name_arg = NULL;
 
@@ -128,15 +167,22 @@ int main(int argc, char **argv)
        multilog_add_type(standard, NULL);
        multilog_init_verbose(standard, _LOG_DEBUG);
 
+       if (!(dl = dlopen("libdmevent.so", RTLD_NOW))){
+               fprintf(stderr, "Cannot dlopen libdmevent.so: %s\n", dlerror());
+               goto out;
+       }
+       if (!(lookup_symbols(dl, &e)))
+               goto out;
        if (list) {
                while (1) {
-                       if ((ret= dm_get_registered_device(&dso_name, &device,
-                                                          &events, next)))
+                       if ((ret= e.dm_get_registered_device(&dso_name,
+                                                            &device,
+                                                            &events, next)))
                                break;
                        printf("%s %s 0x%x", dso_name, device, events);
                        if (events & TIMEOUT){
-                               if ((ret = dm_get_event_timeout(device,
-                                                               &timeout))) {
+                               if ((ret = e.dm_get_event_timeout(device,
+                                                                 &timeout))) {
                                        ret = EXIT_FAILURE;
                                        goto out;
                                }
@@ -153,14 +199,14 @@ int main(int argc, char **argv)
                goto out;
        }
 
-       if ((ret = reg ? dm_register_for_event(dso_name, device, events) :
-                        dm_unregister_for_event(dso_name, device, events))) {
+       if ((ret = reg ? e.dm_register_for_event(dso_name, device, events) :
+                        e.dm_unregister_for_event(dso_name, device, events))) {
                fprintf(stderr, "Failed to %sregister %s: %s\n",
                        reg ? "": "un", device, strerror(-ret));
                ret = EXIT_FAILURE;
        } else {
                if (reg && (events & TIMEOUT) &&
-                   ((ret = dm_set_event_timeout(device, timeout)))){
+                   ((ret = e.dm_set_event_timeout(device, timeout)))){
                        fprintf(stderr, "Failed to set timeout for %s: %s\n",
                                device, strerror(-ret));
                        ret = EXIT_FAILURE;
index 212fa623e0f9bab7a3d4c745f2214a77f0811c5b..3fb7c477d93054878b6cdee2c211cf702151e2e2 100644 (file)
@@ -27,7 +27,7 @@ else
   LIB_SHARED = libdmevent.so
 endif
 
-LDFLAGS += -ldl -ldevmapper -lpthread
+CLDFLAGS += -ldl -ldevmapper -lpthread
 
 include ../../make.tmpl
 
index f3881ec285fd55d7d21af0215337d34c2783f0dd..b99e0b0cf809140f6e8e807bc4e1884a1f0d5343 100644 (file)
@@ -27,7 +27,7 @@ else
 endif
 
 CFLAGS += -I..
-LDFLAGS += -ldl -ldevmapper -lpthread -L..
+CLDFLAGS += -ldl -ldevmapper -lpthread -L..
 
 include ../../make.tmpl
 
index 6d42bfac85c7c9f6195f0ff4c15b859c814e71a6..10535a2c3a60214ccf9e9d66bd00f148f3336a44 100644 (file)
@@ -26,7 +26,7 @@ else
   LIB_SHARED = libmultilog_pthread_lock.so
 endif
 
-LDFLAGS += -ldl -ldevmapper -lpthread -L..
+CLDFLAGS += -ldl -ldevmapper -lpthread -L..
 
 include ../../make.tmpl
 
This page took 0.032806 seconds and 5 git commands to generate.